AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 26 Bitcoin

Merge bitcoin/bitcoin#32784: wallet: derivehdkey RPC to get xpub at arbitrary path

Public commit record

What the developer wrote

Authored by Ava Chow

96/100 · Strong
Merge bitcoin/bitcoin#32784: wallet: derivehdkey RPC to get xpub at arbitrary path

c3945bfd2bf87ae6fe7be1c0cee58b21c4269aec doc: use derivehdkey in multisig tutorial (Sjors Provoost)
3662e3366978e1ecff1924da100cd2606899126e test: use derivehdkey in M-of-N multisig demo (Sjors Provoost)
d9570f0838355bca638ac3287fd334905fb29e16 rpc: add derivehdkey (Sjors Provoost)
62da9f9614508f6bfd30126a73c59d0c4004066e wallet: add GetExtKey helper (Sjors Provoost)
aaf1548475ded41889d5041fc2d60e8b2ca9ddcd wallet: generalize GetActiveHDPubKeys helper (Sjors Provoost)
3821452c4af1440484ddd5ccc83f83cc4c307af3 refactor: add hardened derivation helper (Sjors Provoost)
0ab61caafd10d0539da626bd4354cb7e6df15e54 rpc: ParsePathBIP32 helper (Sjors Provoost)
e36c4b76e198751c14da8d32655e47bd5678abb6 util: reject out-of-range BIP32 keypath indices (Sjors Provoost)
ba78c31a00c912ec440dfb677997b51c72058bab fuzz: check ParseHDKeypath/WriteHDKeypath round-trip (Sjors Provoost)
8cce969085dbe3137c738cbe691008974059af1e Have ParseHDKeypath handle h derivation marker (Sjors Provoost)
fc5307776236c6f08aec94978672626f5aae1aaa test: move parse_hd_keypath test to bip32_tests (Sjors Provoost)
dab525eb7717af3b246a5aa32acea174cd9bd453 key: add DeriveExtKey() helper (Sjors Provoost)

Pull request description:

Adds a `derivehdkey` RPC that returns an xpub, or optionally the xprv, at an arbitrary BIP32 path (with at least one hardened step), derived from a wallet HD key.

The main use case is coordinating a multisig setup, where each participant shares an xpub derived at a hardened path (e.g. `m/87h/0h/0h`) distinct from their default single-signature descriptors. See the (updated) `doc/multisig-tutorial.md` and (updated) functional test to see how that workflow improves.

The first commits are some helpful helpers:

- _key: add DeriveExtKey() helper_ - performs the actual derivation
- _test: move parse_hd_keypath test to bip32_tests_ - from `psbt_wallet_tests`
- _Have ParseHDKeypath handle h derivation marker_
- _util: reject out-of-range BIP32 keypath indices_ - `ParseHDKeypath` would previously map overflowing values without `h` to hardened.
- _fuzz: check ParseHDKeypath/WriteHDKeypath round-trip_
- _rpc: ParsePathBIP32 helper_
- _refactor: add hardened derivation helper_ - `HasHardenedDerivation()`, to enforce the "at least one hardened step" rule
- _wallet: generalize GetActiveHDPubKeys helper_ - extracts code from `gethdkeys` which `derivehdkey` needs
- _wallet: add GetExtKey helper_ - reconstruct an xprv from a wallet xpub (analog of `GetKey()`); behavior-preserving prep, also simplifies `gethdkeys`.

Meat and potatoes:
- _rpc: add derivehdkey_ - the RPC itself, plus the `UnusedKey` filter on `GetHDPubKeys` that drives key selection.
- _test: use derivehdkey in M-of-N multisig demo_ - rewrites the functional multisig test to use the RPC and `<0;1>` syntax.
- _doc: use derivehdkey in multisig tutorial_ - same for the prose tutorial.

ACKs for top commit:
pseudoramdom:
code review ACK c3945bfd2bf87ae6fe7be1c0cee58b21c4269aec
achow101:
ACK c3945bfd2bf87ae6fe7be1c0cee58b21c4269aec
w0xlt:
That being the case, ACK c3945bfd2b

Tree-SHA512: 661f17c9bfe26017eb14c27ba7af37093387100d3baa25f5d29bba9c1aedc40d19afe1bdfc126a18d018857bb02f1fc84386f10b8f4f4b8e9d6f4b0691d9e302
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit adds a new Bitcoin Core wallet RPC called derivehdkey that lets a user derive an extended public key (xpub) — or optionally the matching extended private key (xprv) — at a chosen BIP32 path from one of the wallet's own HD keys. The main intended use is making multisig setup easier. The commit also fixes a small input-validation bug in BIP32 path parsing where very large numbers could previously be misinterpreted as hardened indices. There is no evidence in the commit of an active vulnerability being exploited; it reads as a feature addition with defensive hardening.

Recommended action

Review the new derivehdkey RPC access controls in production deployments; ensure only authorized callers can call it, especially with private=true. Verify that the hardened-step requirement and descriptor-source restrictions match intended policy. The BIP32 parsing hardening should be backported if older branches parse user-supplied BIP32 paths.

Security signals we found

01

New RPC exposes xpub/xprv derivation from wallet HD keys

02

Requires at least one hardened derivation step

03

Rejects watch-only wallets and locked/encrypted wallets

04

Only allows HD keys from active or unused(KEY) descriptors, not used inactive descriptors

05

Fixes BIP32 path parsing to reject out-of-range indices that previously could set the hardened bit

06

Adds fuzz round-trip test for ParseHDKeypath/WriteHDKeypath

Risk score

Why this scored 26/100

Our methodology →
Potential impact 4/30
Exploitability 3/25
Stealth signal 2/15
Affected reach 5/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.