Skip to content

Psa and wally bump - #203

Merged
odudex merged 102 commits into
masterfrom
PSA-and-wally-bump
Nov 4, 2026
Merged

odudex merged 102 commits into
masterfrom
PSA-and-wally-bump

Conversation

@odudex

@odudex odudex commented Nov 4, 2026

Copy link
Copy Markdown
Owner

No description provided.

odudex added 30 commits November 4, 2026 09:57
libwally now generates wsh() witness scripts up to 3600 bytes and multi() up to 20 keys, so the 520-byte inner script cap the comments credited to libwally is Kern's own.
The pinned libwally now updates PSBT_GLOBAL_TX_MODIFIABLE for every signature its signer stores, so Kern's own pass after signing is redundant. test_sign_clears_tx_modifiable now pins libwally's behaviour.
libwally's ccan backend now hashes through the PSA Crypto API, replacing the legacy mbedTLS SHA shims.
The post-build objcopy weakening ccan's sha256/sha512 init/done symbols was a Krux leftover: nothing else in the firmware defines them, and without it the code segments are byte-identical while kern.elf keeps libwally's symbols for panic decoding. The VALIDATION_UNSUPPORTED_MINISCRIPT comment predates tr() miniscript support.
libwally tests BUILD_ELEMENTS with #ifdef, so -DBUILD_ELEMENTS=0 turned Elements on: Kern parsed Liquid PSETs, ran the zkp proof checks on scanned data and would sign them. Dropping it and the Elements-only secp modules removes 47 KB of code from the firmware; Bitcoin behaviour is unchanged.
Only the first key with the wallet fingerprint was checked against the seed, yet the load screen and the registered-descriptor view show every such key as the wallet's, so a coordinator could label its own xpub with our fingerprint. The boot rescan of stored backups goes through the same check.
scripts/test.sh does not clean, so local runs kept binaries built from older sources: test_bip138_backup linked descriptor_validator.c without depending on it, and several rules left out stubs and headers they compile. libwally.a and libur.a also rebuild when their sources change now.
Own keys were checked by comparing base58 text at an "m/<origin>" string cut to 72 bytes: an xpub rebuilt without its parent fingerprint (as from a UR hd-key) read as a mismatch, an origin over 69 characters was checked at a truncated path, and a master key ([fp]xpub) failed as an internal error. An origin deeper than the derivation limit is now a parse error.
…p front

A raw key carrying our fingerprint is now compared with our public key at its full origin path (x coordinate only in tr()) instead of being refused as a parse error. The registry tracks the first own key by its origin, so a raw one, a master origin or an origin over six steps used to pass validation and then fail registration after the user confirmed; both validation paths now refuse them before any dialog.
libwally keeps hash and raw-key hex as written, so an uppercase hex digit ending a hash or a broken line was painted as a key letter on the load screen and in the registered view, and an uppercase raw key made the policy fail because libwally returns keys lowercase.
Watch-only skips xpub verification, yet both views mark keys carrying the loaded key's fingerprint as ours. The registered view now marks nothing on watch-only entries.
tr() is not bound by the 520-byte inner script cap, so a 27-key tr() passed validation, extract_descriptor_info failed unnoticed and the load screen listed no keys and no policy. It is now refused as too many keys on every validation path, and a failed extraction fails the load.
The policy was copied into a 512-byte buffer; a longer one was cut and the indenter closed the open nodes, so the truncated tree looked complete. The info now carries the heap string, freed with the validation context.
…to the keys below it

Coldcard, Sparrow and Nunchuk setup files can put a Derivation line before each key. The converter read only the first one and applied it to every key, so a file listing two of the wallet's own accounts was rejected as an xpub mismatch and cosigners could get the wrong origin. A key with no Derivation line above it now rejects the file. The converter moves to core/multisig_setup.c so it can be host-tested.
A wrong passphrase changes the master fingerprint and fails as "Key not found in descriptor". An xpub mismatch means a key carrying this wallet's fingerprint is not this wallet's key: a forged key, a wrong origin path or a coordinator error.
…key load

The boot scan skipped an approved backup that no longer passes keyed validation with only a log line, so a registered wallet vanished silently. Count those skips (not backups for another key, unapproved ones, or another network's after a network switch) and show the count once the post-load page is up.
…malformed

A first own key that is raw, a master key or over six steps deep, and an origin past the derivation limit, come from descriptors libwally parses fine; Kern only cannot use them. They were reported as "Invalid descriptor format".
The indenter built the one-line form from each child's first rendered line, so a combinator child such as a:or_b(pk(C),a:pk(D)) collapsed to a:or_b() and its keys vanished from the policy the user approves.
The whitelist refuses outputs past index 200 as change, but a registry claim had no cap, so multisig or miniscript change at /1/2000000000 counted as safe change: funds no gap-limited wallet scan would find. Past the cap the output is still provably ours, so it classifies OWNED_UNSAFE and needs Permissive signing, like single-sig change past the cap.
Any provably-owned output on a change chain was summed into the green Change total, with no address or wallet: change to a different account or script type, or to another registered descriptor (one loaded from the review's own 'Load a descriptor now?' prompt included). Change now has to share a wallet with an owned input; every other owned output is listed under Self-Transfer with its address and the wallet it pays.
…ed text

The checker validated the scanned address with libwally, threw the decoded script away and matched the generated addresses with strcasecmp. Base58Check is case-sensitive: a coordinator that knows the xpub or descriptor can grind a case variant that still passes the checksum, and Kern showed 'Address Verified' for a hash160 nobody owns. Matching moves to core/address_match.c and compares scriptPubKey bytes, which also accepts uppercase bech32 and skips encoding an address per index.
A single-path descriptor has no change branch, so the change sweep regenerated the receive addresses a second time, doubling every miss on the LVGL thread. The not-found prompt now says only receive addresses were searched.
The last-word helpers pack all of the seed's entropy (minus a few bits for the candidates) into stack buffers, the camera entropy page formats its digest as hex, and the word and roll labels are built in stack buffers; none were wiped, and the LVGL stack is never scrubbed. Each is now wiped after use, on every exit, and the last-word candidate cache is cleared with its count.
Only the display was scrubbed on lock. The LVGL task stack lives in internal RAM and below the live frames still holds whatever mnemonic entry, signing or key derivation left there, readable over JTAG until it is locked down. Locking now refills that region with FreeRTOS's 0xa5 fill pattern, which the stack canary and high-water mark expect, leaving a margin for interrupt frames.
…ltisig

Kern called a descriptor miniscript only when libwally cleared WALLY_MS_IS_DESCRIPTOR, which a taproot tree whose leaves are all pk() or pkh() keeps. tr(NUMS,pk(ours)) and tr(ours,pk(other)) were titled and labelled 'Multisig (0 of N)', a label the PSBT review then showed as the input's wallet, and no policy tree was drawn. One shared predicate now also treats any tr() script tree as a policy.
Two defaults of the pinned libwally fork had no test: rejecting non-sane miniscript (repeated keys, mixed height and time locks, a branch spendable without a signature) and signing a segwit input that carries only its previous transaction with the BIP143 sighash. A re-point that dropped either would still compile and pass. Each shape is now checked to parse only when non-sane scripts are allowed, the BIP143 signature is verified against both sighashes, and wallet.c refuses to build against a libwally without the non-sane flag.
…'s parser

Kern reads taproot_leaf_paths, taproot_leaf_signatures and the TAP_KEY_SIG field directly, but no test built a taproot PSBT through serialize and parse, so the taproot claim paths, the key-path and script-path restore on denied inputs and psbt_trim's TAP_KEY_SIG copy had no positive coverage. Fixtures are now populated by libwally from tr() descriptors and reparsed at v0 and v2.
…h group

Keypath matching took the step after the first own key's origin as libwally's multi_index, which is a position in the <a;b;...> tuple, not a path value, and required exactly two steps after the origin. <2;3>-only keys, a third tuple position, /0/<0;1>/* and single-path /1/* never matched, and <1;0> regenerated the script from the wrong branch: loaded descriptors were refused with a 'Load a descriptor now?' prompt. Registration now records the origin and child path of every key carrying our fingerprint, and matching expands each child path per group and takes the child number from the wildcard step.
An input counted as signed after one key: psbt_sign derived the path of the keypath that matched and called wally_psbt_sign once. When one seed holds keys in two multipath groups of a registered policy (Liana's primary <0;1> and recovery <2;3> keys, in wsh or tr) and the PSBT lists both, only the first signed and the export looked complete. A registry claim proves every own key of its descriptor at the claim's index, so each now signs; keys the PSBT merely lists are never used. An input is complete only once every listed key of ours has signed, and the incomplete-signing notice says when a spending path is what is missing.
Hints carried only the first occurrence's origin per recipient key. When our xpub appears twice and the first occurrence has no origin or a foreign one, our real origin was never stored, and unless it is a common path the backup could not be reopened: the registration vanished at the next key load. Every distinct origin of a recipient key expression is now a hint.
odudex added 18 commits November 4, 2026 09:59
cUR cannot encode multipath, miniscript or tr() tree descriptors, and every failed encode returned early, so 'UR' kept showing the previous format's QR.
The Load? screen and the session label said only 'Single-sig', so a user could load or watch pkh, wpkh, sh(wpkh) or tr without seeing which.
The gate lived in the scan page between its dialogs, so which refusal a PSBT with several problems gets was untested. psbt_gate_check returns the first gate that fires with what its dialog names; the page keeps only the messages.
The page derived it itself from a copy of the master key, so the spec vectors tested libwally rather than Kern's code.
The mnemonic editor packed word indices into entropy itself, a copy of the packing behind the valid-last-word list, and neither had a test.
The Elements code is not built, yet every ext_key carried a 32-byte tweak sum and every transaction input and output its Elements fields. The define changes the layouts, so it reaches every build of code that includes the headers.
For BIP39 seeds: 2048 iterations take about 200 ms through PSA on a wave_43 and 26 ms on the accelerator, with the same per-call known-answer check and PSA fallback as SHA-256.
A typed login derives the same seed about five times, so at 200 ms each the seed alone cost about a second.
…tor addresses

On a wave_43 a 100+100 address check of a 2-of-3 wallet took 6.4 s and takes 3.7 s; a page of 8 addresses took 258 ms and takes 144 ms, after a 70 ms build when the page opens.
cUR now tracks its own header dependencies, so the QR tests no longer rebuild it with make -B.
…tation

The expected signature comes from a standard-library Python RFC6979 implementation, which reproduces the published secp256k1 RFC6979 vectors, run on BIP84's private key for the path. A nonce function that adds anything to RFC6979 fails the test.
Kern has no duplicate-key check of its own and relies on the fork's, which now derives keys. Pin the shapes the previous pin let through, and the disjoint reuse multipath wallets need.
…r and signing tests

The signing tests called only wally_init, so a nonce hook installed at boot would have left their known-answer signatures passing.
Comment thread main/core/multisig_setup.c Fixed
@odudex
odudex force-pushed the PSA-and-wally-bump branch from 0c7797f to 415b46c Compare November 4, 2026 17:09
scan_ctx.is_testnet ? "Testnet" : "Mainnet");

snprintf(message + offset, sizeof(message) - offset,
snprintf(message, sizeof(message),
@odudex
odudex merged commit 26fed6d into master Nov 4, 2026
126 checks passed
@odudex
odudex deleted the PSA-and-wally-bump branch November 6, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants