mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 16:05:36 +00:00
descriptor: Represent multipath descriptors in a single Descriptor object #36442
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36442
Loading…
Reference in a new issue
No description provided.
Delete branch "multipath-first-class"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently, multipath descriptor strings treat the multipath specifiers as syntactic sugar. Once we finish parsing such a string, the multipath elements are lost as the result is the multiple distinct descriptors that the multipath is a shorthand for. This means that we are unable to return the multipath string for such descriptors.
This PR allows descriptors to actually be multipath where the multipath specifiers are represented inside of the paths of
BIP32PubkeyProviders. This allows for the multipath string to be produced.In order to achieve this, a lot of derivation path parsing is refactored.
KeyPathis promoted to being its own class (which subclassesstd::vector), while the individual derivation indexes become aKeyPathElementobject so that the multipath elements can be represented. Furthermore, hardened derivation characters are now being stored withinKeyPathElements so each element knows what the original hardened character was. This also cleans up a little bit of the descriptor implementation as we no longer have to carry aroundbool apostrophein a bunch of places.Lastly,
Parsenow returns a singleDescriptorobject, rather than a vector of them. If the descriptor is a multipath descriptor, the expansion can be retrieved usingGetMultipathExpansion(). The wallet uses this and still must not store multipath descriptors.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
LLM Linter (✨ experimental)
Possible typos and grammar issues:
src/util/bip32.h:for a give multipath position→for a given multipath position[“give” is a typo]Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):src/qt/test/wallettests.cpp:WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1)src/script/descriptor.cpp:std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, false)src/script/descriptor.cpp:std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, true)src/script/descriptor.cpp:std::make_unique<ConstPubkeyProvider>(0, pubkey, false)src/script/descriptor.cpp:std::make_unique<ConstPubkeyProvider>(0, pubkey, true)src/test/psbt_tests.cpp:WalletDescriptor w_desc(std::move(desc), 0, 0, 10, 0)src/wallet/rpc/spend.cpp:Parse(desc_str, desc_out, error, true)src/wallet/scriptpubkeyman.cpp:Parse(desc_str, provider, error, false)src/wallet/scriptpubkeyman.cpp:Parse(desc_str, provider, error, false)src/wallet/test/util.cpp:Parse(desc_str, keys, error, false)src/wallet/test/wallet_tests.cpp:WalletDescriptor w_desc{std::move(desc), 0, 0, 0, 0}src/wallet/walletutil.cpp:Parse(desc_str, keys, error, false)src/wallet/walletutil.cpp:WalletDescriptor w_desc(std::move(desc), creation_time, 0, 0, 0)2026-11-24 21:29:50
4 additional verified findings in the Review report.
Earlier concerns neither republished nor resolved: 2 minor findings · 5 suggestions. See the Run archive linked from the Review report for their assessments.
🟠 Minor ·
getdescriptorinfochanges output without updating its RPC contractgetdescriptorinfochanges both multipathdescriptoroutput and mixed hardened-marker rendering without updating its help, adding a release note, or providing a compatibility option.Location:
src/rpc/output_script.cpp:212(head).🟠 Minor ·
EvalDescriptorStringOrObjectrebuilds descriptor branches at every indexRanged RPC evaluation repeatedly clones even single-path descriptors and discards MuSig's cached aggregate provider instead of reusing it across indexes.
Location:
src/rpc/util.cpp:1368(head).🔵 Suggestion · Multipath expansion makes quadratic copies of alternatives
Expanding an N-branch tuple copies its N alternatives into every branch before selection, although ordinary two-branch descriptors pay only a small constant cost.
Location:
src/script/descriptor.cpp:1246(head).🔵 Suggestion · Unexpanded descriptors expose implicit branch-0 derivation
Unexpanded multipath descriptors can produce branch-0 keys with multipath origins that serialize lossily; no current production caller deriving from such an object was identified.
Location:
src/script/descriptor.h:207(head).🔵 Suggestion ·
CheckMultipathmisses expansion lifetime and string checksIn
CheckMultipath, the ownership check now operates on the parent, and multipath string results are discarded instead of checked.Location:
src/test/descriptor_tests.cpp:570(head).🔵 Suggestion ·
parse_hd_keypathcompares the reparsed element with itselfThe self-comparison no longer checks whether formatting and reparsing preserve the original child numbers and hardened bits.
Location:
src/test/bip32_tests.cpp:475(head).Review coverage was incomplete.
Reviewed:
975c5c58eeb9· Review report · Previous reportspermalink
🚧 At least one of the CI tasks failed.
Task
ASan + LSan + UBSan + integer: https://github.com/bitcoin/bitcoin/actions/runs/37381217840/job/112003412636LLM reason (✨ experimental): The build failed because
walletload_tests.cppassignsParse()’sstd::unique_ptr<Descriptor>result to a vector of unique pointers.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK
Concept ACK.
Sorry for the pingback noise. I've now adjusted my merge skill to stop pinging the main repo from fork PRs.
🐙 This pull request conflicts with the target branch and needs rebase.
On this head,
migratewalletturns every step of an imported key's origin path into a hardened step.SingleKeyPathElement::Unserializeassigns abooltostd::optional<char> m_hardened. The optional is then always engaged, soChildNumber()sets the hardened bit on every step read from disk. It came with "util: Store hardened character in KeyPathElement". A v29.4 legacy watch-only wallet holdingwpkh([d34db33f/84h/0h/0h/0/5]<pubkey>)migrates to84h/0h/0h/0/5on v31.1 and to84h/0h/0h/0h/5hon this head. With the change suggested inline, the migrated descriptors match v31.1.The multipath round trip agrees with btclib-wallet, a BIP389 implementation I maintain. On 25 descriptors (wpkh, sh-wsh multisig, tr trees, miniscript, musig, steps of three and five elements),
getdescriptorinfokeeps each input's paths and markers, and itsmultipath_expansionandderiveaddressesmatch btclib-wallet. Both refuse the same 8 malformed ones. As the description says, markers are now kept as written; v31.1 printed one per key. A descriptor mixinghand'thus prints, with its checksum, differently from v31.1, which may deserve a release note. I can share the scripts and outputs.Engaged only for a hardened step, so an unhardened step read from disk stays unhardened:
Fixed
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
Code review up to
b2205211a6util: Store hardened character in KeyPathElementIn
b2205211a6util: Store hardened character in KeyPathElement nit: lost=in the comment.In
7fac1374f3util: Change all key path operations to operate with std::vector nit:KeyPathElement&is more clear.In
7fac1374f3util: Change all key path operations to operate with std::vectorIt still passes after this fix.
In
7fac1374f3util: Change all key path operations to operate with std::vector: if you makeONLY_EMPTYaconst std::set<KeyPath>, the compiler makes life easier (thanks Claude...):In
b2205211a6util: Store hardened character in KeyPathElement nit:charcan stayconstIn
b2205211a6util: Store hardened character in KeyPathElement:(all three assumes that I suggested for this commit pass the tests)
In
b2205211a6util: Store hardened character in KeyPathElement: worth elaborating in the commit message why you're doing this. E.g.:Note that this breaks downgrading a mixed usage miniscript:
We could refuse to import those, but BIP380 permits it.
Or restore the previous behavior:
In
7fac1374f3util: Change all key path operations to operate with std::vector: let'sAssumeorAssertthatindex < BIP32_HARDENED_FLAG.In
b2205211a6util: Store hardened character in KeyPathElement:In
b2205211a6util: Store hardened character in KeyPathElement:In
b2205211a6util: Store hardened character in KeyPathElement: light preference for dropping these defaults. In e.g.scriptpubkeyman.cppyou're settinghanyway.concept ACK
i've reviewed
2f727b3552to13d56f38eband added few remarks inlineit seems a single constructor works?
this test currently cant fail
constseems have inadvertly droppedI think it worth have constant for the default hardened marker:
(see
github.com/bitcoin/bitcoin@159c260fb6)SetHardenedCharcan read like if it set the hardened property, while it only overwrite the hardened char. Since all callers uses the hardcoded default char maybe the method can be renamed to smth likeNormalizedHardenedMarker, it would also prevent a future caller to pass an arbitrary char?I'd rename the field as the "index" semantic seems not fit there,
SingleKeyPathElementcarry not only the index but also the hardened marker2 remarks here:
multipath_posdefault to 0 in order to mirrorChildNumber()andIsHardened()?Indexreturn aSinglePathElementbecause its < & == operate on the child number rather the underlyingm_indexmaybe here it should be documented that operators apply on the child number but not on the marker char
shouldnt we return an
Expectedhere?The
migratewalletfix holds on0f2dc37a8b, but the PR adds no test for it.achow101 fixed
SingleKeyPathElement::Unserializeafter my inline note on74915efa. When I migrate a v29.4 legacy watch-only wallet that holdswpkh([d34db33f/84h/0h/0h/0/5]<pubkey>),0f2dc37akeeps the origin path84h/0h/0h/0/5, as v31.1 does;74915efagave84h/0h/0h/0h/5h. On74915efabip32_testsanddescriptor_testsstill pass. The test below reads aKeyOriginInfoback from its serialization: it fails on74915efa(2147483648 != 0) and passes on0f2dc37a.The script that builds the wallet, the commands and their output are in https://gist.github.com/fametrano/fc7fd1b054657138a96a73befa81da66/5dabccf7307d47f9f2063df62fb7ce93e54ca0ab.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
Concept ACK for the overall refactor and plus one on returning a single object from the Parse method, I never liked reading a vector being returned from it.