Review report

bitcoin/bitcoin: PR #36442

1 minor finding · 10 suggestions

Earlier concerns neither republished nor resolved: 1 minor finding · 4 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · getdescriptorinfo changes the descriptor field without updating its contract

For multipath input, getdescriptorinfo now returns the full expression rather than its first branch, but its help still promises the first branch and no release note explains the compatibility changes.

Location: src/rpc/output_script.cpp:212 (head).

Details and suggested fix

The handler now serializes the multipath parent, whereas the previous descriptor value matched multipath_expansion[0]. Clients forwarding this field to deriveaddresses consequently receive nested branch arrays instead of a flat list. generatetodescriptor rejects the multipath form, including unranged inputs whose returned first branch previously worked, and importdescriptors rejects it when internal is specified. Separately, mixed ' and h markers now retain their per-element spelling rather than one spelling per key expression, changing the returned string and checksum. Update the help to describe the preserved multipath form and direct clients needing the old value to multipath_expansion[0]. Add a release note covering both changes and address whether a -deprecatedrpc transition is needed under doc/developer-notes.md:1409.


Optional improvements

Link

[suggestion] · Ranged descriptor evaluation rebuilds its expansion at every index

EvalDescriptorStringOrObject repeatedly clones ranged descriptors, including single-path ones, and discards fixed-participant MuSig aggregate caches between indices.

Location: src/rpc/util.cpp:1368 (head).

Details and suggested fix

GetMultipathExpansion() always clones at least once, but this call now occurs inside the derivation-range loop. A ranged descriptor therefore gets rebuilt at every position: 1001 by default and up to 1,000,000 with an explicit range. For aggregate-then-derive MuSig descriptors with non-ranged participants, each fresh provider also repeats aggregate-cache initialization and key aggregation. The base reused its parsed descriptor vector. Store the expansion before the outer loop and iterate that vector at each index. This preserves index-major output order and signing-provider updates while allowing caches to survive. The runtime cost has not been measured.


Link

[suggestion] · Mixed hardened markers change Miniscript compatibility hashes

A newly imported Miniscript descriptor with mixed hardened markers now receives a different wallet ID from older versions, despite CompatDescriptorHash's documented stability guarantee.

Location: src/script/descriptor.cpp:314 (head).

Details and suggested fix

Miniscript COMPAT serialization deliberately uses PUBLIC key strings. Previously, one shared apostrophe flag determined the spelling throughout a key expression; PUBLIC now preserves each element's marker. For example, [deadbeef/0h/1']xpub.../2/* previously rendered its origin as [deadbeef/0'/1'] but now retains [deadbeef/0h/1'], changing CompatDescriptorHash() and the ID assigned on import. Non-Miniscript COMPAT still forces apostrophes. Stored IDs are retained on load and import matching uses canonical equivalence, so this does not establish a load failure or duplicate insertion. Preserve the historical rendering specifically for Miniscript COMPAT, or explicitly narrow the stability guarantee if this change is intentional. Add a mixed-marker Miniscript op_compat_desc_hash case to lock in that decision.


Link

[suggestion] · Multipath parents accept single-branch operations without a guard

A multipath parent can successfully normalize to an unparsable string or claim self-expansion when another branch needs private keys; no current production caller triggering these cases was found.

Location: src/script/descriptor.cpp:601 (head).

Details and suggested fix

ChildNumber() and IsHardened() default to alternative zero. With private keys, normalizing wpkh(xprv/<0h;1h>/*) copies the unresolved multipath element into the origin but derives the replacement xpub only along 0h. It returns success even though the result misdescribes the other branch and cannot be reparsed because origins prohibit multipath. Likewise, CanSelfExpand() reports true for xpub/<1;0h>/* because HasHardenedDerivation() checks only the first alternative. Direct expansion also leaves unresolved alternatives in key origins, whose serialization writes only index zero. Enforce a concrete-branch precondition on expansion and normalization operations, and make the self-expansion check inspect every alternative. A distinct multipath interface exposing only serialization and branch expansion would also enforce this boundary.


Link

[suggestion] · Multipath expansion copies alternatives quadratically

GetMultipathExpansion clones the full alternative list once per branch before selecting a single alternative, causing quadratic copying for large multipath specifiers.

Location: src/script/descriptor.cpp:1246 (head).

Details and suggested fix

For <a1;...;aN>, the loop calls Clone() N times. Each BIP32 provider clone copies m_path, including the N-entry vector inside its multipath element, before ChooseMultipath(pos) replaces that copy with a concrete path. The base parser instead substituted one scalar into a placeholder path for each branch. Two-branch receive/change descriptors remain cheap, but large valid specifiers supplied through RPC incur about N² alternative copies. Add a branch-aware clone that constructs each path with ChooseMultipath(pos) directly and propagates the selection through origins, MuSig participants and subdescriptors. Runtime impact has not been measured; a benchmark varying N would quantify it.


Link

[suggestion] · Wallet fuzz setup stores an unexpanded multipath parent

CreateWalletDescriptor now constructs wallet state from a multipath parent, although production import stores concrete branches and database loading rejects multipath descriptors.

Location: src/wallet/test/fuzz/scriptpubkeyman.cpp:80 (head).

Details and suggested fix

An input such as wpkh(%04/<0;1>/*) survives mocked-key conversion and the expense filters. Expand(0, ...) derives alternative zero successfully but leaves the descriptor multipath, so moving that same object into WalletDescriptor does not establish the concrete-branch invariant. The fuzz target then adds it through AddWalletDescriptor, which writes its multipath string. Production ImportDescriptor instead selects GetMultipathExpansion() elements, and WalletDescriptor::FromStream rejects the representation created here. Move a concrete expansion out before the Expand check and wallet construction, restoring the previous helper's first-branch behavior. Otherwise the fuzzer exercises unsupported wallet states that can produce fuzz-only failures when concrete-descriptor invariants are enforced.


Link

[suggestion] · CheckMultipath retains the parent instead of testing a standalone branch

The unit helper no longer exercises an expansion after parent destruction, and it discards the parent's serialized string instead of checking the multipath round-trip.

Location: src/test/descriptor_tests.cpp:568 (head).

Details and suggested fix

The lifetime-check lambda now returns parsed, so its later operations use the multipath parent rather than a surviving concrete branch. DoCheck does select branches, but keeps their parsed parents alive throughout the checks. A child borrowing parent storage would therefore not cross the intended destruction boundary. Obtain the expansion inside the lambda, move one branch out, and destroy the parent and siblings before using it. Also compare the parent's ToString() with pub, using EqualDescriptor, and check the private equivalent with the available private keys. The RPC functional test covers two simple public multipath forms, but this helper's broader fixtures currently validate only branch serialization. Successful expansion assertions should use fixtures derivable with the available keys.


Link

[suggestion] · The key-path round-trip assertion compares the reparsed path with itself

The rewritten element-wise assertion always passes, leaving this unit test without its original check that formatting and reparsing preserve child numbers.

Location: src/test/bip32_tests.cpp:474 (head).

Details and suggested fix

BOOST_CHECK_EQUAL(res2->at(i).ChildNumber(), res2->at(i).ChildNumber()) compares the same value twice rather than comparing the reparsed path with res1. The final formatted-string comparison only checks stability: an idempotent formatter error, such as dropping hardened markers, can satisfy it while changing the path. Compare the right-hand operand with res1->at(i).ChildNumber(), or compare the two complete paths. Their equality ignores hardened-marker spelling.


Link

[suggestion] · DoCheck dereferences failed parse results after non-fatal checks

A failed Parse in DoCheck is followed by a null dereference, turning a parser regression into undefined behavior in the unit-test helper.

Location: src/test/descriptor_tests.cpp:206 (head).

Details and suggested fix

BOOST_CHECK_MESSAGE records a failure but continues execution. If either parse returns null, the subsequent GetMultipathExpansion() call dereferences that null unique_ptr. The base accessed an empty vector with at(), which threw std::out_of_range instead. Use BOOST_REQUIRE_MESSAGE for both parse-result checks so the helper stops after reporting the parse error.


Link

[suggestion] · Ordinary key-path steps now require separate heap allocations

Using a vector for every KeyPathElement adds one allocation per ordinary step, including in KeyOriginInfo copies used by derivation, PSBT and wallet origin handling.

Location: src/util/bip32.h:72 (head).

Details and suggested fix

The former std::vector<uint32_t> stored a path in one contiguous buffer. Each ordinary KeyPathElement(uint32_t) now allocates its own one-element m_indexes vector. GetPubKey copies these buffers into info.path on every derivation, PSBT decoding allocates one per encoded index, and the by-value PSBT serialization helpers copy them again. Key origins also gain multipath capability that their serialized formats cannot represent. Store the single-index case inline and allocate only for multipath elements, for example with a singleton/vector variant. This can preserve hardened-marker information and the existing child-number wire format. The runtime cost has not been measured; descriptor expansion and wallet TopUp benchmarks would quantify the tradeoff.


Link

[suggestion] · Parse documentation still describes the removed vector result

The public Parse comment promises an empty vector on failure and does not explain that successful multipath parsing now returns one object.

Location: src/script/descriptor.h:232 (head).

Details and suggested fix

Document a null unique_ptr as the failure result and explain that callers obtain concrete branches through GetMultipathExpansion(). The parser comments also need updating: the hardened-derivation comment above origin_split.size() == 1 describes the removed apostrophe local, while KeyParser::m_keys and the multi() providers comment still describe multipath-expanded keys even though those containers now retain unexpanded providers.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.