Review report

bitcoin/bitcoin: PR #36443

3 minor findings · 11 suggestions

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Findings

Link

[minor] · Reconstruction accepts repeated branches and can produce rejected descriptor syntax

Repeated branches can make reconstruction return duplicate multipath indexes or silently omit an input instead of rejecting the sequence.

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

Details and suggested fix

After the first differing relative, p contains multiple indexes. Comparing that vector with a later singleton rp always reports inequality, so the repetition guard cannot fire. With one xpub X, base wpkh(X/0/*) and relatives /1/*, /1/* produce <0;1;1>, which Parse rejects. Relatives /0/*, /1/* instead silently produce only two branches for three inputs. An already-multipath relative also contributes only Index(0). MuSig aggregate paths use the same loop, and the descriptor-level check compares lengths between keys rather than against the input count. Build alternatives against immutable single-path elements, reject repeated child numbers and multipath inputs, and verify the resulting expansion has relatives.size() + 1 entries. Add three-input negative cases for both path types. No production caller of this API was found at this head, so production impact remains unconfirmed.


Link

[minor] · getdescriptorinfo help still describes the old multipath result

For multipath input, descriptor now contains the full expression rather than the first branch, but RPC help still promises the old result.

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

Details and suggested fix

Returning desc->ToString() changes the logical meaning of descriptor from the first expansion to the full multipath expression, including its checksum. The functional test now expects this, but the help still says only the first descriptor is returned, and the PR adds no release note. A client forwarding this field to importdescriptors with internal specified now receives the multipath/internal rejection. Update the help to explain that the expression is preserved and individual branches are in multipath_expansion. Document the compatibility change in a release note and provide the old behavior through a deprecation transition as described in doc/developer-notes.md.


Link

[minor] · Mixed hardened markers change Miniscript compatibility hashes

Preserving each hardened marker changes the COMPAT string and new-import SPKM ID for mixed-marker Miniscript input, despite the documented stable-hash contract.

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

Details and suggested fix

Miniscript's COMPAT branch deliberately requests PUBLIC serialization. Previously, parsing left one marker flag for the whole key expression, so X/0'/1h printed as X/0h/1h; head preserves X/0'/1h. That changes CompatDescriptorHash, which initializes SPKM IDs for new imports of the same input. Marker changes can also span the origin and suffix because the old origin inherited the flag left by inner-key parsing. Existing wallets load their stored IDs, and their previously stored strings already have uniform markers; no path recomputing and checking those IDs on load was found. Restore the legacy uniform-marker rule specifically for Miniscript COMPAT serialization and pin it with a mixed-marker op_compat_desc_hash vector. The accompanying PUBLIC and private-string output changes should be treated as an explicit serialization change rather than allowed to alter COMPAT accidentally.


Optional improvements

Link

[suggestion] · Descriptor evaluation rebuilds the multipath expansion at every index

Each ranged derivation index deep-clones the descriptor again and discards fixed-participant MuSig aggregation state that base reused.

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

Details and suggested fix

GetMultipathExpansion() runs inside the index loop, so a ranged descriptor using the default inclusive range [0,1000] rebuilds its expansion 1,001 times, including when it is single-path. Each MuSig clone starts without m_aggregate_provider, causing aggregate-then-derive descriptors to repeat cache initialization, including fixed-participant derivation and aggregation. Non-ranged descriptors are restricted to one iteration. Compute const auto expansions = desc->GetMultipathExpansion(); before the outer loop and iterate that retained vector inside it. This preserves script ordering and ExpandPrivate accumulation while avoiding the repeated cloning and aggregate initialization.


Link

[suggestion] · Multipath expansion copies every alternative into every branch

Clone-then-select performs quadratic alternative copies where base's placeholder substitution was linear.

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

Details and suggested fix

For a wpkh path with N alternatives, expansion performs N clones. Each BIP32 clone copies m_path, including all N alternatives, before ChooseMultipath replaces them with one index. Base instead copied a scalar placeholder path and substituted one child per output. This affects callers such as getdescriptorinfo, deriveaddresses, and descriptor import, independently of the separate per-index repetition in RPC evaluation. Use a branch-selecting clone that copies only the chosen index into each independently owned result, preserving the expansion order. The quadratic copy count follows from the source; its runtime magnitude has not been measured.


Link

[suggestion] · Single-path operations silently accept unexpanded multipath objects

Expansion uses branch 0 while origin metadata can retain alternatives, leaving correctness dependent on callers selecting a branch first.

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

Details and suggested fix

ChildNumber() and IsHardened() default to position 0, but GetPubKey copies the entire unresolved path into the origin and serialization writes only index 0. Normalization past a hardened step can move an earlier multipath element into the origin, producing syntax that Parse rejects. A path such as <0;1h> also reports self-expandable based only on its first alternative. Inspected production callers split or reject multipath before expansion or wallet storage; no production caller bypassing that convention was found, although the SPKM fuzz helper does. Enforce the invariant at Expand, ExpandFromCache, and ToNormalizedString by rejecting unexpanded multipath objects and requiring branch selection through GetMultipathExpansion(). Update the test that currently expands the parent.


Link

[suggestion] · Key-origin paths allocate per step and admit unrepresentable alternatives

Nonempty origin paths now allocate for every step, and their type permits multipath state that serialization silently truncates.

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

Details and suggested fix

KeyOriginInfo::path now uses KeyPath, whose ordinary elements each own a one-entry vector. PSBT deserialization therefore allocates per step, origin copies deep-copy those allocations, and the by-value PSBT serialization helpers copy them again. BIP32 derivation also copies the path into each origin. Origins need one resolved path, not alternatives, yet KeyPathElement::Serialize silently writes only the first alternative. Keep origin paths single-path, for example as std::vector<SingleKeyPathElement>, and convert resolved descriptor paths at that boundary. This preserves hardened-marker information and the existing child-number wire format. The allocation pattern is established, but the runtime gain is unmeasured.


Link

[suggestion] · Round-trip test checks the wrong object's private serialization

The expansion-string reconstruction block rechecks the earlier object, leaving its own private serialization untested.

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

Details and suggested fix

exp_recon_pub is reconstructed from independently parsed expansion strings, and its public string is checked. The following assertions instead call recon_pub->ToPrivateString and compare the earlier recon_pub_privs, repeating the preceding route's checks. Call exp_recon_pub->ToPrivateString(prov, exp_recon_pub_privs) and compare exp_recon_pub_privs with prv. The provider already contains the fixture's private keys, so this exercises the intended conversion.


Link

[suggestion] · Standalone-expansion lifetime test now exercises the parent

The test no longer exercises an expansion after destroying its source and siblings, as its comment intends.

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

Details and suggested fix

The lambda now returns parsed itself, so the subsequent ToString() and Expand() calls operate on the multipath parent. It never creates an expansion whose independence could be checked. Inside the lambda, obtain parsed->GetMultipathExpansion() and return one moved-out entry. That destroys the parent and other expansions before exercising the survivor, restoring the intended lifetime coverage.


Link

[suggestion] · Keypath round-trip assertion compares res2 with itself

The migrated numeric round-trip assertion cannot detect changed child numbers.

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

Details and suggested fix

BOOST_CHECK_EQUAL(res2->at(i).ChildNumber(), res2->at(i).ChildNumber()) compares identical values. Replace the second operand with res1->at(i).ChildNumber() to check that formatting and reparsing preserve the original child number. The string-idempotence and fuzz checks retain overlapping coverage, but an idempotent formatter can still lose information, so the direct numeric comparison remains useful.


Link

[suggestion] · SPKM fuzz harness stores unexpanded multipath descriptors

The harness can construct wallet descriptors that production import would split and database loading refuses to reload.

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

Details and suggested fix

CreateWalletDescriptor now puts the full Parse() result into WalletDescriptor. A valid multipath xpub descriptor can pass the Expand(0, ...) check because expansion derives branch 0 without resolving the stored descriptor. The harness then passes that multipath object to AddWalletDescriptor, whereas production import builds one wallet descriptor per expansion and FromStream rejects multipath storage. Select one GetMultipathExpansion() entry before both the expansion check and construction. Choosing the first branch preserves the base harness behavior.


Link

[suggestion] · ParseHDKeypath accepts slash-only forms as empty paths

The rewritten string parser accepts / and m//, although base rejected both as malformed paths.

Location: src/util/bip32.cpp:86 (head).

Details and suggested fix

Removing an optional m/ and then one trailing slash reduces both inputs to an empty span, which returns KeyPath{}. derivehdkey still rejects them for lacking a hardened step, and legacy keymeta loading still returns NONCRITICAL_ERROR, but both now reach later path checks rather than reporting a parse error. No current producer of these strings was identified, so production impact is unconfirmed. Recognize only "", m, and m/ as explicit empty paths and reject other forms that reduce to empty. Add / and m// as invalid cases in the parser table.


Link

[suggestion] · External-signer multipath rejection lacks a documented transition

A configured signer returning multipath descriptors now makes wallet creation throw instead of selecting branch 0, without documenting the change.

Location: src/wallet/wallet.cpp:3519 (head).

Details and suggested fix

Base selected the first expansion for every descriptor in both receive and internal; head explicitly rejects multipath responses. Keep the rejection rather than restoring silent branch-0 selection, which could select the same branch for the internal list. Document the new restriction in a release note and add a mock-signer case asserting the rejection. No signer producing these responses was identified, and the current mock returns separate /0/* and /1/* descriptors, so actual user impact remains unconfirmed.


Link

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

The failure contract and parser comments still describe the old vector-returning and shared-marker design.

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

Details and suggested fix

Document Parse failure as returning nullptr, not an empty vector. The comments on KeyParser::m_keys and the multisig providers list should describe potentially multipath providers rather than already expanded keys. Remove the comment before origin_split.size() == 1 that described the deleted hardened-marker flag.


Coverage details

Earlier concerns

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