Skip to content

Fix/descriptor hardening - #19

Merged
odudex merged 8 commits into
mainfrom
fix/descriptor-hardening
Oct 17, 2026
Merged

odudex merged 8 commits into
mainfrom
fix/descriptor-hardening

Conversation

@odudex

@odudex odudex commented Oct 17, 2026

Copy link
Copy Markdown
Owner

No description provided.

output_from_descriptor_string() now accepts only xpub and tpub keys whose key-data starts with 02 or 03. An xprv, tprv, SLIP-132 or otherwise unknown version, or a 04/00-prefixed key returns NULL instead of being copied into the hd-key as a public key, which put 00 || private key into key-data. Tests use embit-encoded keys from the BIP32 test vector 1 seed.
A key with a single-step origin and no parent fingerprint (a BIP45 m/45' cosigner, for example) still takes the origin's source fingerprint as the xpub's parent, but no longer drops [fp/path] from the descriptor. The output_9 vector is the BCR-2020-015 m/45' cosigner without field 8, encoded by urtypes, and must render the spec's descriptor text.
The hd-key decoder now reads use_info (key 5, crypto-coin-info 305) and rejects a non-BTC coin type, a network other than mainnet or testnet, and a malformed coin-info. Descriptor text uses that network, so a testnet key on a coin 0' or BIP45 path renders as a tpub and a mainnet key on a coin 1' path as an xpub. Keys without use_info still guess from the coin type. Keys parsed from text keep their xpub/tpub version: a tpub encodes use_info testnet, and an xpub stays implicit except on a coin 1' path, where it encodes mainnet. The output_10-13 vectors are urtypes CBOR whose expected text comes from embit and matches urtypes' own rendering.
BCR-2020-015 tags each crypto-account output #6.308, and Hummingbird (Sparrow) encodes it that way, but the account decoder only took untagged outputs, so the spec's own test vector failed to decode. Both forms are now accepted. The account_2 vector is the BCR-2020-015 test vector.
The account decoder now requires key 1, the master fingerprint (a uint32), and applies it to each decoded output: an origin without a source fingerprint takes it, and an origin naming another fingerprint fails the output, since an account describes one seed. A partial origin path (depth set and different from its length) does not start at the master and is left as it is. The account_3 vector is the BCR-2020-015 account with every source fingerprint removed, encoded by urtypes, and must render the spec's descriptor text.
output_descriptors_from_cbor_account() decodes each output once, in order, with the master fingerprint rules, and returns an array where an output that cannot be decoded is NULL; output_descriptors_free() releases it. An empty outputs array gives a count of 0 and a non-account input gives NULL. output_descriptor_from_cbor_account() is kept for the bindings and documented as first-output only. The account suite now checks every output: account_2 and account_3 expect all seven BCR-2020-015 descriptors.
Library objects are compiled with -MMD -MP and the generated .d files are included, replacing the hand-written dependency list that covered 12 of the 22 objects, so editing a header such as src/types/cbor_decoder.h rebuilds every object that includes it and relinks libur.a. Objects also depend on the Makefile, so a tree built before this change is rebuilt once and gets its .d files. make clean already removes them with the object directory. make test now runs check-header-deps, which dry-runs make with cbor_decoder.h taken as new and checks that hd_key.o and output.o are rebuilt, crc32.o is not, libur.a is relinked, and a second make has nothing to do.
The README now states that output-descriptor (40308) and the other version 2 types are not decoded or encoded, and that keypath range and pair components are rejected, so multipath, miniscript and tr() script-tree descriptors have to travel as descriptor text.
@odudex
odudex merged commit 33d8a67 into main Oct 17, 2026
4 checks passed
@odudex
odudex deleted the fix/descriptor-hardening branch October 30, 2026 14:48
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.

1 participant