Repository navigation
Fix/descriptor hardening - #19
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.