Skip to content

bip32: add some of the new bip32 checks to bip32_key_unserialize#522

Merged
jgriffiths merged 1 commit intomasterfrom
bip32_updates
Mar 19, 2026
Merged

bip32: add some of the new bip32 checks to bip32_key_unserialize#522
jgriffiths merged 1 commit intomasterfrom
bip32_updates

Conversation

@jgriffiths
Copy link
Copy Markdown
Contributor

Based on the patch from @kuliq23 in #521

Note as per the test comments, we don't fail keys for zero fingerprints or inconsistent indices.

@kuliq23
Copy link
Copy Markdown
Contributor

kuliq23 commented Mar 18, 2026

Note as per the test comments, we don't fail keys for zero fingerprints or inconsistent indices.


# Note we don't currently fail keys where the fingerprint
# and index are inconsistent,
some implementations do
# not set them correctly (but nonetheless work for their
# intended purpose (s)).

That´s interesting. I understand the design choice.

Do you have any concrete examples of implementations where fingerprint/index fields are known to be incorrect?

@jgriffiths
Copy link
Copy Markdown
Contributor Author

Do you have any concrete examples of implementations where fingerprint/index fields are known to be incorrect?

There was some discussion in this repo long ago about tightening these checks/inferring meaning from the depth/fingerprint etc; there's probably some background there. We've found that various tools/wallets over the years can fail to populate some fields correctly, see e.g. Blockstream/gdk@cb324bb. Also some fields may be skipped by choice, for example in wally you can skip the fingerprint calculation for speed when deriving (the fingerprint is meant to be an optimization for locating potential matches in some use cases, and was not originally imbued with any meaning such as zero meaning a master key).

In general unless the data included would cause invalid derivations/addresses to be produced we should attempt to be liberal in what we accept and conservative in what we output. So checking invalid pubkeys (where we haven't derived it from a private key) makes sense to check, for example.

@jgriffiths jgriffiths merged commit 2b74c8d into master Mar 19, 2026
5 checks passed
@jgriffiths jgriffiths deleted the bip32_updates branch March 19, 2026 03:11
Comment on lines +414 to +429
# and index are inconsistent, as some implementations do
# not set them correctly (but nonetheless work for their
# intended purpose(s)).
# zero depth with non-zero parent fingerprint (xprv)
#'xprv9s2SPatNQ9Vc6GTbVMFPFo7jsaZySyzk7L8n2uqKXJen3KUmvQNT'
#'uLh3fhZMBoG3G4ZW1N2kZuHEPY53qmbZzCHshoQnNf4GvELZfqTUrcv',
# zero depth with non-zero parent fingerprint (xpub)
#'xpub661no6RGEX3uJkY4bNnPcw4URcQTrSibUZ4NqJEw5eBkv7ovTwgi'
#'T91XX27VbEXGENhYRCf7hyEbWrR3FewATdCEebj6znwMfQkhRYHRLpJ',
# zero depth with non-zero index (xprv)
#'xprv9s21ZrQH4r4TsiLvyLXqM9P7k1K3EYhA1kkD6xuquB5i39AU8KF4'
#'2acDyL3qsDbU9NmZn6MsGSUYZEsuoePmjzsB3eFKSUEh3Gu1N3cqVUN',
# zero depth with non-zero index (xpub)
#'xpub661MyMwAuDcm6CRQ5N4qiHKrJ39Xe1R1NyfouMKTTWcguwVcfrZJ'
#'aNvhpebzGerh7gucBvzEQWRugZDuDXjNDRmXzSZe4c7mnTK97pTvGS8',
# unknown extended key version (1)
Copy link
Copy Markdown

@quapka quapka Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible nit: From looking into src/test/* I see that one can skip tests. Would it maybe be a bit clearer if these test vectors were explicitly skipped instead of commented out? That is, have a custom test for checking the fingerprint and skip it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM we only use skipTest for 2 reasons: whether elements is enabled or to skip exhaustive/expensive tests. I'd like to keep usage down to just those two reasons. I think if we revisit and want to enable these tests at some point in the future there won't be any difficulty finding them.

@quapka
Copy link
Copy Markdown

quapka commented Mar 20, 2026

[... ] for example in wally you can skip the fingerprint calculation [...]

In general unless the data included would cause invalid derivations/addresses to be produced we should attempt to be liberal [...]

Interesting, so extended keys are malleable. Not saying in what context could this be a problem, just did not think about them in this way.

@jgriffiths
Copy link
Copy Markdown
Contributor Author

Interesting, so extended keys are malleable.

in toto yes, via the key metadata (which I distinguish from the 'core' data required to derive). Many (most?) users of extended keys prior to PSBT don't need the fingerprints at all for example, so you could put anything in there most of the time. Thats billions of different representations of the same key.

Descriptor expressions are also malleable in many ways by (poor) design.

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.

3 participants