Review report

bitcoin/bitcoin: PR #36442

3 minor findings · 12 suggestions

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

Findings

Link

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

Multipath input now returns the full expression instead of the first branch, so clients following the unchanged help can receive incompatible input for other RPCs.

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

Details and suggested fix

This serializes the multipath parent where the previous implementation serialized its first expansion. A client forwarding descriptor to deriveaddresses now receives per-branch arrays instead of a flat list. Forwarding an unranged result to the mining RPCs, or importing it with an explicit internal value or nonempty label, now fails the existing multipath guards. The help still says only the first descriptor is returned. Update it to describe the retained multipath form and direct single-branch consumers to multipath_expansion[0]. Add a release note covering this change and the newly preserved per-element '/h markers. Because the field changes logical meaning, provide a compatibility transition, such as temporary -deprecatedrpc support for the old value, as described in doc/developer-notes.md:1409.


Link

[minor] · Multipath signer rejection escapes GUI wallet-creation error handling

A configured external signer returning a valid multipath descriptor now throws through the GUI worker, bypassing the wallet-creation error dialog and progress cleanup.

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

Details and suggested fix

SetupDescriptorScriptPubKeyMans() now throws for a multipath getdescriptors entry, whereas the previous code imported its first branch. That exception propagates through wallet creation into the uncaught QTimer::singleShot callback. The callback never sets m_error_message or schedules finish(), so the normal failure dialog and progress cleanup do not run. An exception escaping the callback may also terminate the process, depending on Qt's handling. Malformed signer replies already exposed this handling gap; the PR adds a valid-input trigger. I found no current signer producing that reply, and the documented examples use separate single-path receive and internal descriptors. Keep the rejection, but convert it into a wallet-creation error or catch it at the GUI worker boundary and always schedule finish().


Link

[minor] · Trailing-slash trimming accepts malformed empty key paths

ParseHDKeypath now accepts / and m// as empty paths, although current production callers still reject them later and no derivation result changes.

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

Details and suggested fix

Removing the trailing slash from /, or removing m/ and then the trailing slash from m//, leaves an empty span and returns KeyPath{}. The previous parser rejected the empty element. Consequently, derivehdkey reports a missing hardened step instead of an invalid key path, and legacy keymeta loading reports an unexpected path instead of an invalid key path. Handle the valid empty forms "", "m", and "m/" explicitly, then reject other paths that become empty after trimming. This also avoids relying on sp.size() - 1 wrapping to dynamic_extent for m/, which is currently valid rather than an out-of-bounds access. Add negative vectors for / and m//.


Optional improvements

Link

[suggestion] · Descriptor evaluation re-clones the tree at every range index

Ranged evaluation now rebuilds even single-path descriptors at every index and discards fixed-participant MuSig aggregation caches between positions.

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

Details and suggested fix

GetMultipathExpansion() always clones the descriptor, including when it has only one branch. Calling it inside this loop rebuilds the tree for all 1001 default positions, or up to one million explicitly requested positions, where the previous code reused its parsed vector. For aggregate-then-derive musig() with fixed participants, each fresh provider also repeats participant derivation and MuSig2AggregatePubkeys because Clone() does not retain its aggregate cache. Compute const auto expansions = desc->GetMultipathExpansion(); before the range loop and iterate over it with a distinct variable name. This preserves index-major output order and provider updates while allowing the caches to survive. The runtime cost has not been measured.


Link

[suggestion] · Multipath expansion copies every alternative once per branch

Expanding an element with N alternatives performs O(N²) alternative copies because each branch clones the full list before selecting one entry.

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

Details and suggested fix

For <a1;...;aN>, GetMultipathExpansion() calls Clone() N times. BIP32PubkeyProvider::Clone() copies m_path, including all N alternatives, before ChooseMultipath(pos) replaces that element with a singleton. Nested providers and subdescriptors propagate the same copying. The previous parser substituted a scalar into a placeholder path for each branch. The parser rejects duplicates and multiple multipath elements per path, but has no small alternative-count cap, so large valid inputs incur this extra work. Select the branch during cloning and propagate the position through origin, MuSig, and subdescriptor clones. Each output can still own its data independently. Ordinary two-branch descriptors remain cheap; this is a static operation count, not a measured runtime result.


Link

[suggestion] · Multipath parents silently retain single-path operations

An unexpanded multipath parent can silently use branch 0 or emit unparsable normalized output, although no production caller passing such a parent to these operations was found.

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

Details and suggested fix

ChildNumber() and IsHardened() default to alternative 0. With the private key available, normalizing a key of the form wpkh(xprv/<0h;1h>/*) therefore derives the branch-0 replacement xpub but puts <0h;1h> into its origin, then returns success with a string that origin parsing rejects. Likewise, CanSelfExpand() reports true for xpub/<1;0h>/* despite the other branch requiring private keys. Parent expansion derives only branch 0 while retaining the unresolved path in origin metadata, whose serialization writes only index 0. The wallet constructor also accepts a parent that database loading rejects. Enforce the concrete-branch precondition at the API boundary: reject multipath parents in single-path expansion and normalization methods, make self-expansion checks consider every alternative, and reject parents at wallet construction or insertion. This prevents correctness from depending on every future caller remembering to expand first.


Link

[suggestion] · Mixed hardened markers change Miniscript compatibility hashes

Preserving each hardened marker changes the documented stable compatibility hash, and newly assigned wallet ID, for Miniscript key expressions mixing ' and h.

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

Details and suggested fix

Miniscript's COMPAT serializer deliberately uses PUBLIC key serialization to preserve historical DescriptorSPKM IDs. Previously, one flag selected the marker for every hardened step in a key expression; PUBLIC now preserves each step's marker. For example, [deadbeef/0h/1']xpub.../2/* previously rendered its origin as [deadbeef/0'/1'] in COMPAT and now retains [deadbeef/0h/1'], changing CompatDescriptorHash(). Non-Miniscript COMPAT still forces apostrophes. Loading uses stored IDs and duplicate matching uses canonical equivalence, so no load failure or duplicate import is established. Preserve the historical per-key rendering specifically in the Miniscript COMPAT path and add a mixed-marker compatibility-hash fixture. If this stability is intentionally relaxed, document the narrower guarantee explicitly.


Link

[suggestion] · Ordinary key-origin steps now require individual heap allocations

Using multipath-capable elements in KeyOriginInfo adds a vector allocation per ordinary path step and permits alternatives that origin serialization cannot represent.

Location: src/script/keyorigin.h:16 (head).

Details and suggested fix

Each scalar KeyPathElement constructs a one-element owning vector. Consequently, copying m_path into origin information during derivation copies those allocations, PSBT decoding creates one per four bytes of path data, and the by-value serialization helpers copy them again. Previously the path used one contiguous uint32_t buffer. The origin type also now permits multipath alternatives even though serialization silently writes only index 0. Keep ordinary origin steps inline, either with a single-path origin type or singleton storage that allocates only for genuine multipath elements. Preserve the hardened-marker information and existing wire format. The overhead has not been measured, and RPC/GUI input bounds and practical memory-exhaustion risk remain unestablished; descriptor-expansion and wallet TopUp benchmarks would quantify the tradeoff.


Link

[suggestion] · Wallet fuzz helper stores an unexpanded multipath descriptor

CreateWalletDescriptor retains the multipath parent, creating a fuzz wallet state outside the production import and database-loading contract.

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

Details and suggested fix

A short input such as wpkh(%05/<0;1>/*) survives mocked-key conversion and the expense filters. Its preliminary Expand(0, ...) succeeds using alternative 0, but the unchanged parent then enters WalletDescriptor and AddWalletDescriptor, which persists its multipath string. Production import instead selects concrete expansions, and database loading rejects multipath records. The fuzzer therefore exercises wallet operations on an unsupported fixture and would report fixture-induced failures if a concrete-branch invariant were enforced. Select one GetMultipathExpansion() result before both the expansion check and wallet construction. Taking the first branch restores the previous helper behavior.


Link

[suggestion] · CheckMultipath no longer tests expansion lifetime independence

The lifetime test now operates on the multipath parent rather than a branch surviving destruction of its parent and siblings.

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

Details and suggested fix

The lambda returns parsed itself, so neither ToString() nor Expand() exercises an independently owned expansion after the source object is destroyed. Previously it moved out one branch and destroyed its siblings. DoCheck uses expansions, but retains their parsed parents throughout its checks, leaving parent independence untested. Inside this lambda, obtain GetMultipathExpansion(), move out one branch, assert that it is not multipath, and let the parent and other branches die before using it. For fixtures that can self-expand, also assert that Expand() succeeds.


Link

[suggestion] · Key-path round-trip assertion compares the result with itself

The numeric round-trip assertion always passes, leaving only size and textual-stability checks in this unit test.

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

Details and suggested fix

BOOST_CHECK_EQUAL(res2->at(i).ChildNumber(), res2->at(i).ChildNumber()) compares identical expressions instead of comparing the reparsed path with the original. The following string check can still pass if the first formatting pass loses information, such as hardened markers, and subsequent formatting is stable. Compare the second operand with res1->at(i).ChildNumber() to restore the independent numeric round-trip check.


Link

[suggestion] · Parent serialization lacks assertions and failed parses are dereferenced

Unit and fuzz checks skip retained multipath-parent serialization, and DoCheck dereferences failed parse results after non-fatal checks.

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

Details and suggested fix

DoCheck and both descriptor parser fuzz targets test only GetMultipathExpansion() results. CheckMultipath calls the parent's ToString() but discards it. The functional test checks public serialization for two simple cases, leaving parent private/canonical serialization and Taproot, MuSig, Miniscript, hardened, and mixed-marker round trips unasserted. Add parent serialization assertions in CheckMultipath, using EqualDescriptor for expected public/private strings, and reparse the output to verify the same expansions. Exercise parent round trips in the fuzz targets too. Separately, make the parse prerequisites in DoCheck use BOOST_REQUIRE_MESSAGE: the current non-fatal checks allow a parse regression to continue into a null unique_ptr dereference instead of stopping at the failed prerequisite.


Link

[suggestion] · Parser comments still describe the removed expanded-vector API

The public Parse documentation promises an empty vector on failure, while parser comments describe removed state and already-expanded keys.

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

Details and suggested fix

Parse now returns a nullable std::unique_ptr<Descriptor>, including a retained multipath object on success. Document the null failure result and explain that callers obtain concrete branches through GetMultipathExpansion(). In descriptor.cpp, remove the dangling hardened-state comment before origin_split.size() == 1, and describe KeyParser::m_keys and the multi() provider container as possibly-multipath providers rather than already-expanded keys.


Link

[suggestion] · Indexes exposes internal storage without a caller

The new Indexes() accessor has no caller and unnecessarily exposes the alternatives vector representation.

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

Details and suggested fix

Multipath selection uses Index(pos) in KeyPath::ChooseMultipath, and parsing constructs elements directly. Remove the unused Indexes() accessor while retaining Index() and MultipathLen(), so the public API does not expose storage without a current use.


Link

[suggestion] · ParseScript retains an unused result variable

ParseScript still declares ret even though every branch now returns its result directly.

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

Details and suggested fix

The old vector-valued ret accumulated per-branch descriptors. Its replacement is an unused, default-null unique_ptr, so it misleadingly suggests that the function still builds a shared result. Delete the declaration.


Coverage details

Earlier concerns

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