Skip to content
This repository was archived by the owner on Oct 22, 2026. It is now read-only.

13.x: descriptor: reject keys deeper than BIP32 allows - #1074

Merged
apoelstra merged 3 commits into
rust-bitcoin:release-13.xfrom
starius:13.x/bip32-depth
Oct 17, 2026
Merged

apoelstra merged 3 commits into
rust-bitcoin:release-13.xfrom
starius:13.x/bip32-depth

Conversation

@starius

@starius starius commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Backport of #1065.

It also needs 97c948d from #913, which isn't on 13.x: without it, at_derivation_index panics on the new depth error instead of returning it.

13.x has no NonDefiniteKeyError::NoWildcard, into_definite or derive_at_index, so those parts of #1065 are left out, and its test uses at_derivation_index(0) instead of into_definite().

🤖 AI disclosure: the backport was prepared with Claude Opus 5.5.

Velnbur and others added 3 commits October 17, 2026 00:22
DefiniteDescriptorKey::new checks for wildcards, hardened steps and
multipath derivation, but not for BIP32's maximum depth of 255. A key
that passes these checks but derives past that depth makes rust-bitcoin
return MaximumDepthExceeded, and derive_public_key turns this error
into a panic labeled "cryptographically unreachable". A descriptor
string can trigger it: an xpub with a long enough path parses, becomes
definite, and panics when its script pubkey is computed.

Return the new NonDefiniteKeyError::MaximumDepthExceeded from
DefiniteDescriptorKey::new instead. Derivation at an index goes through
it, so it returns the error too. Only the steps after the extended key
count, since its depth already includes its origin steps.

Assisted-by: Claude Opus 5.5
A key expression that derives past BIP32's maximum depth of 255 can
never produce a key. The previous commit rejects such a key when it
becomes definite. Reject it when parsing too, so that the error points
at the string that caused it.

Count the steps after the extended key, plus one for a wildcard, for
xpubs and xprvs, including multipath keys. Origin steps don't count.

Assisted-by: Claude Opus 5.5
@starius

starius commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

CI jobs failing seem to be unrelated. A re-run should fix them.

  • Cause: the integration tests depend on zip 0.6 (through corepc-node 0.4.0). When the jobs ran, at 00:25 UTC, every zip 0.6.x release was yanked on crates.io.
  • Fixed upstream: crates.io shows all of them un-yanked at 00:28 UTC, three minutes later.

@apoelstra

Copy link
Copy Markdown
Member

Glad they're unyanked. We may want to update corepc which has dropped the offending dep https://git.rust-bitcoin.org/rust-bitcoin/corepc/pulls/720

@apoelstra apoelstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 561042b; successfully ran local tests

@apoelstra
apoelstra merged commit 403f343 into rust-bitcoin:release-13.x Oct 17, 2026
43 of 60 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants