You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 22, 2026. It is now read-only.
Repository navigation
Commit 96a1c91
Browse filesBrowse the repository at this point in the historyBrowse files
Merge #1065: descriptor: reject keys deeper than BIP32 allows
f2862f7 descriptor: reject keys deeper than BIP32 allows when parsing (Boris Nagaev)
613ed0d descriptor: reject definite keys deeper than BIP32 allows (Boris Nagaev)
Pull request description:
`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 that error into a panic labeled "cryptographically unreachable". A descriptor string is enough to trigger it: `tr(xpub/0/0/.../0)` with 256 steps below a master xpub parses, passes `into_definite()`, and panics in `script_pubkey()`.
This is missing validation in miniscript. Deriving that deep used to overflow rust-bitcoin's depth counter (rust-bitcoin/rust-bitcoin#4308). `rust-bitcoin 0.32.6` made it a recoverable error (rust-bitcoin/rust-bitcoin#4434), which miniscript doesn't handle.
The first commit makes `DefiniteDescriptorKey::new` return the new `NonDefiniteKeyError::MaximumDepthExceeded`. `into_definite()` and derivation at an index go through it, so they report the error too. Only the steps after the extended key count, since its depth already includes the steps of its origin.
The second commit rejects such key expressions when parsing, with the new `MalformedKeyDataKind::MaximumDepthExceeded`. It counts a wildcard as one more step and covers xprvs and multipath keys. It's a separate commit because some strings that parse today will stop parsing, even though no key can be derived from them. It can be dropped if parsing should stay unchanged.
Together, they remove the deterministic depth panic. Derivation can still fail in BIP32's invalid-child case, which has a probability below 2^-127 and stays `unreachable!`.
Tests cover depths 255 and 256, a nonzero starting depth, wildcard derivation, multipath keys, xprvs and origin paths.
This pre-existing bug was found while working on #954.
🤖 _AI disclosure: The patch, tests and this description were generated with Claude Opus 5.5. Codex reviewed the approach._
ACKs for top commit:
apoelstra:
ACK f2862f7; successfully ran local tests
Tree-SHA512: 671b1a6b284fe1a3357c9b39236ad41cbe267059c18c4db93a147c76038fb349db7897a6662530d958ca61e97c11eb81718c14316dd6f8df2ad1449612bf5dd4
0 commit comments