Review report

bitcoin/bitcoin: PR #36442

3 minor findings · 10 suggestions

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

Findings

Link

[minor] · Rejected descriptors crash both descriptor fuzz targets

Both descriptor fuzz targets dereference Parse's nullable result, turning ordinary parser rejection into a harness crash.

Location: src/test/fuzz/descriptor_parse.cpp:114 (head).

Details and suggested fix

Parse() now returns a null unique_ptr on checksum or syntax failure, but both targets immediately call desc->GetMultipathExpansion(). In descriptor_parse, even an empty buffer or a valid checksum-free descriptor fails the first, checksum-required iteration and reaches this dereference. The mocked converter also permits malformed syntax after substitution. Previously, both loops safely skipped an empty vector. Add if (!desc) continue; in the checksum loop so the checksum-optional pass still runs, and if (!desc) return; in the mocked target. Update Parse's header comment to describe its null failure result.


Link

[minor] · getdescriptorinfo help still promises the first multipath branch

For multipath input, descriptor now contains the full multipath expression, although the RPC help still promises a single-path expansion.

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

Details and suggested fix

Previously, getdescriptorinfo returned descs.at(0)->ToString(); it now serializes the multipath parent. A client forwarding this field to deriveaddresses therefore gets nested branch arrays rather than the previous flat address list. Update the result help to describe the retained multipath form and direct clients needing the old value to multipath_expansion[0]. Document the compatibility change in a release note. The RPC compatibility guidance in doc/developer-notes.md:1409 also recommends a temporary -deprecatedrpc option for changes in a field's logical meaning.


Link

[minor] · ParseHDKeypath accepts malformed root-path spellings

Slash trimming now accepts "/" and "m//" as an empty path, whereas the previous parser rejected them.

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

Details and suggested fix

For "/", removing the trailing slash leaves an empty span. For "m//", removing the m/ prefix and trailing slash does the same. Both therefore return KeyPath{} instead of rejecting an empty path element. Current production callers still reject the result through their hardened-step or path-shape checks, so the demonstrated impact is different error selection, not successful derivation or changed wallet state. Handle the accepted root spellings "", "m", and "m/" explicitly, then reject a path made empty by trimming. Add rejection tests for "/" and "m//".


Optional improvements

Link

[suggestion] · Range evaluation rebuilds the descriptor expansion at every index

EvalDescriptorStringOrObject repeatedly clones descriptor trees and discards reusable MuSig aggregate caches during ranged evaluation.

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

Details and suggested fix

GetMultipathExpansion() now runs inside the derivation-index loop, even for a single-path descriptor. Ranged inputs default to 1001 positions, whereas the previous code reused its parsed descriptors throughout the range. Each MuSig clone also starts without its aggregate provider, so aggregate-then-derive expressions with non-ranged participants repeat cache initialization and aggregation at every index. Compute const auto expansion = desc->GetMultipathExpansion(); before the outer loop and reuse it. This preserves index-major output order and the existing signing-provider updates for descriptor-based scans and PSBT processing. The runtime cost has not been measured.


Link

[suggestion] · Multipath expansion copies all alternatives into every branch

Expanding N alternatives copies their entire vector into each of N clones before selecting a branch, producing quadratic alternative-copying work.

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

Details and suggested fix

BIP32PubkeyProvider::Clone() copies m_path by value, including every alternative in each multipath element. Calling it once per branch therefore copies roughly N² alternative entries, after which ChooseMultipath() constructs another path and discards the unused alternatives. The previous parser substituted a scalar into each branch path instead. Valid descriptors have no small alternative-count limit, although the practical runtime cost has not been measured. Use a branch-selecting clone that copies only the selected alternative into each new provider. It can retain branch order, independent ownership, and an unchanged source descriptor without copying the unresolved alternatives into every result.


Link

[suggestion] · Multipath parents leave single-path operation preconditions unenforced

An unexpanded multipath Descriptor can silently use branch zero for derivation and report successful normalization that Parse rejects.

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

Details and suggested fix

ChildNumber() and IsHardened() default to alternative zero. With private keys available, normalizing wpkh(xprv/<0h;1h>/*) therefore derives the 0h xpub but copies <0h;1h> into its origin, which Parse rejects because multipath origins are forbidden. Likewise, CanSelfExpand() reports true for xpub/<1;0h>/*, and direct expansion retains unresolved alternatives in origin data whose serialization writes only index zero. No current production caller invoking these operations on an unexpanded multipath parent was found; inspected callers expand first or reject multipath. Enforce the single-path precondition on Expand, ExpandPrivate, ExpandFromCache, and ToNormalizedString, rather than silently selecting a branch. Make CanSelfExpand consider every alternative and clarify the differing meanings of HasHardenedDerivation and HasHardened.


Link

[suggestion] · Wallet fuzzing now persists unexpanded multipath descriptors

CreateWalletDescriptor constructs wallet states that production import avoids and WalletDescriptor::FromStream refuses to load.

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

Details and suggested fix

A short unhardened xpub multipath descriptor passes the helper's checks because direct Expand(0) derives alternative zero without removing the multipath information. The helper then moves that parent into WalletDescriptor, and the insertion path writes its multipath string. Production ImportDescriptor instead stores individual expansions, and FromStream explicitly rejects a persisted multipath parent. This spends fuzz effort on states outside the production import domain. Select a branch from GetMultipathExpansion() before the expansion check and construction; taking the first branch restores the helper's previous behavior.


Link

[suggestion] · CheckMultipath no longer exercises expansion lifetime independence

The standalone-lifetime test now keeps the parent itself, so it cannot detect an expansion that borrows state from its destroyed source.

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

Details and suggested fix

The lambda returns parsed, and the following ToString() and Expand() calls operate on that multipath parent without creating an expansion. The earlier DoCheck calls do select branches, but their source parents remain alive throughout those checks. Inside this lambda, obtain a local expansion vector and return std::move(exp.at(0)). That destroys both the parsed parent and the sibling branches before operating on the survivor, restoring the intended standalone-lifetime check for the new API.


Link

[suggestion] · Mixed hardened markers change Miniscript compatibility hashes

Preserving per-element hardened markers changes newly imported Miniscript descriptor IDs despite CompatDescriptorHash's documented stability contract.

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

Details and suggested fix

Miniscript's COMPAT serialization deliberately uses PUBLIC key formatting. Previously, a key expression used one hardened marker selected during parsing; now each element retains its own marker. Thus an origin such as [deadbeef/0h/1'] with an unhardened suffix was serialized as [deadbeef/0'/1'] before this change but retains 0h/1' now, changing the hash used for a new DescriptorSPKM ID. Non-Miniscript COMPAT still forces apostrophes. Loading trusts stored IDs and duplicate detection uses canonical equivalence; no load failure or duplication was found. Preserve the historical single-marker rendering specifically for Miniscript COMPAT and add a mixed-marker op_compat_desc_hash fixture. If this narrow stability-contract change is intentional instead, document it explicitly.


Link

[suggestion] · Single-index key paths now allocate a vector per step

Using the multipath-capable KeyPath in KeyOriginInfo adds a heap allocation per populated step to ordinary derivation and PSBT origin handling.

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

Details and suggested fix

Each ordinary KeyPathElement initializes a one-element std::vector, rather than storing its index inline. BIP32PubkeyProvider::GetPubKey() then copies all those vectors into info.path on every derivation, and DeserializeKeyOrigin() allocates one for every PSBT path index. This carries allocation costs and multipath-capable storage into origins that represent only one concrete path. Store the single-index case inline and allocate alternative storage only for actual multipath elements, retaining hardened-marker semantics and the existing child-number wire format. The performance effect has not been measured; descriptor and wallet TopUp benchmarks could quantify it.


Link

[suggestion] · KeyPathElement exposes an unused backing-vector accessor

The new Indexes() accessor exposes the alternative container without any checked-in consumer.

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

Details and suggested fix

Multipath selection uses Index(pos) through KeyPath::ChooseMultipath, and the parser constructs elements directly. Nothing at head calls Indexes(). Remove this accessor so the public API does not expose backing storage it currently has no reason to expose; retain the used Index() and MultipathLen() operations.


Link

[suggestion] · ParseScript retains an unused result object

After the single-descriptor conversion, ParseScript declares ret but never assigns, reads, or returns it.

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

Details and suggested fix

The old vector-valued ret accumulated branch descriptors. Every branch now returns its descriptor or {} directly, leaving this default-null unique_ptr unused. Remove the declaration so the function no longer suggests that it is accumulating a result.


Link

[suggestion] · The parser rewrite leaves unused standard-library includes

The removed stringstream parser and descriptor-local duplicate detection leave two includes without remaining users.

Location: src/util/bip32.cpp:43 (base).

Details and suggested fix

util/bip32.cpp now parses with spans and util::Split, so it no longer uses <sstream>. The removed ParseKeyPath supplied the last use of <unordered_set> in script/descriptor.cpp. Delete those two includes, while retaining <unordered_set> in bip32.cpp, where duplicate detection now lives.


Coverage details

Earlier concerns

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