wallet, rpc: Add analyzedescriptor for multisig setups

bitcoin/bitcoin: PR #36885

7 minor findings · 1 suggestion

Findings

Link

[minor] · Hardened MuSig participants still receive a recognized setup verdict

A MuSig participant such as A/0h still yields recognized: true even though other cosigners cannot derive the output; missing first_address and failed public-descriptor import limit the impact.

Location: src/script/descriptor_analyzer.cpp:125 (head).

Details and suggested fix

For xpubs A, B and C, tr(musig(A/0h,B,C)/<0;1>/*,sortedmulti_a(2,A/<0;1>/*,B/<0;1>/*,C/<0;1>/*)) parses and passes classification because ClassifyKeyPath compares participant roots only. CheckCosignerKeys checks only the leaf slots. Computing the internal key requires deriving A/0h, so B and C cannot independently derive outputs or construct script-path control blocks without A supplying the derived public key. This contradicts the recognized setup's public-derivability requirement. Reject MuSig participants requiring hardened derivation during classification and add a regression for this example. Public expansion also omits first_address, and importing the public descriptor fails, so this establishes an incorrect verdict rather than a demonstrated theft path.


Link

[minor] · Child xpubs escape repeated-key detection with different suffixes

An xpub and its unhardened child with different suffixes can be reported as distinct cosigners, although the parent's private-key holder can satisfy both slots.

Location: src/script/descriptor_analyzer.cpp:82 (head).

Details and suggested fix

Let B be ChildXpub(A,0). In wsh(sortedmulti(2,A/0/*,B/1/*,C/0/*)), the roots differ, and the first derived keys are A/0/0 and A/0/1/0, so neither comparison detects the relationship. Both slots pass the public ranged-derivation checks and the setup is recognized. The existing child-xpub test covers only aligned suffixes. Confirm immediate unhardened ancestry by deriving the child indicated by its metadata and comparing the resulting public key and chain code, then add a differing-suffix regression. Arbitrary-depth ancestry is not generally recoverable, and this check still cannot establish that distinct keys belong to different people.


Link

[minor] · Generated HD child keys are reported as not_mine

For constant keys from generated HD addresses, analyzedescriptor reports not_mine and can_sign: false despite available signing keys; no current in-tree caller constructing these inputs was found.

Location: src/wallet/descriptor_analyzer.cpp:88 (head).

Details and suggested fix

Generate a normal bech32 address, obtain its public key P from getaddressinfo, and analyze wpkh(P). MatchConstKey calls HasPrivKey, which checks only directly stored private keys. Generated children instead live in m_map_pubkeys; signing finds their derivation index there and obtains their private keys through ExpandPrivate. Extend constant-key matching to recognize cached HD children whose private derivation is available, while preserving locked-wallet capability reporting. Add a regression using a generated address rather than AddKey, which bypasses the missing lookup.


Link

[minor] · MuSig-only participant keys are absent from wallet matching

A wallet holding an xprv only inside musig() reports its participant as not_mine and can_sign: false; no current in-tree MuSig-only caller was found.

Location: src/wallet/descriptor_analyzer.cpp:126 (head).

Details and suggested fix

Import tr(musig(xprvA,xpubB)/<0;1>/*) into a blank wallet, then analyze its public form. The import stores A's private key, but GetHDPubKeys builds the matching candidates through GetPubKeys, which does not traverse MuSig participants. The aggregate provider returns no root xpub, leaving MatchExtKey without a candidate for A. Include participant roots when building the analyzer's candidate map, for example by walking each wallet descriptor's key inventory. Add a blank-wallet regression so another single-key descriptor cannot mask the omission.


Link

[minor] · Compressed Taproot constants are incorrectly matched by parity

An opposite-parity compressed Taproot key is reported as not_mine despite an available signing key, unlike its equivalent x-only notation; no current in-tree producer of that encoding was found.

Location: src/wallet/descriptor_analyzer.cpp:82 (head).

Details and suggested fix

If the wallet stores the private key for 03||x, analyzing tr(02||x) checks only the CKeyID of 02||x because the parser sets ConstKey.xonly from the encoding rather than the signing context. Taproot uses the same x coordinate for both representations, and Schnorr signing finds the stored key through GetKeyByXOnly. Pass the occurrence role into MatchConstKey and check both parities for TAPROOT_INTERNAL, TAPROOT_OUTPUT and TAPSCRIPT, while retaining full-key matching for ECDSA and MUSIG_PARTICIPANT.


Link

[minor] · first_address discards private keys supplied in the descriptor

Private descriptors with hardened derivation omit a derivable first_address because analysis discards parsed private keys; recognized public-derivable multisig setups are unaffected.

Location: src/wallet/descriptor_analyzer.cpp:98 (head).

Details and suggested fix

For an input such as wpkh(xprv/84h/1h/0h/0/*), Parse stores the root private key in the caller's provider. Both the RPC and wallet interface then pass only the descriptors to analysis, and FirstAddress expands with FlatSigningProvider{}. Hardened expansion cannot retrieve the root key and silently omits the address, although expansion with the parsed provider succeeds. Pass that provider through wallet analysis to FirstAddress, keeping it local to the call, and add a private-descriptor regression.


Link

[minor] · Repeated-key groups omit transitively linked slots

Mixed root and derived-key matches can omit duplicate slots from issues[].keys, although the descriptor remains unrecognized.

Location: src/script/descriptor_analyzer.cpp:86 (head).

Details and suggested fix

Let A1 be ChildXpub(A,1) and analyze wsh(sortedmulti(2,A/0/*,A/1/*,A1/*)). Slots 0 and 1 share root A, while slots 1 and 2 derive the same first key, A/1/0. The loop compares candidates only with slot 0, emits {0,1}, then skips the reported slot 1, so slot 2 never joins the group. Consumers displaying the involved key IDs receive an incomplete duplicate set. Build connected components over the matching pairs, for example with union-find, and add this mixed-chain case alongside the identical-root test.


Optional improvements

Link

[suggestion] · UNKNOWN conflates locked keys with missing private keys

A public-only HD candidate with a matching fingerprint and hardened origin can suppress can_sign even in an unlocked wallet, leaving callers unable to distinguish a potentially useful unlock from one that cannot help.

Location: src/wallet/descriptor_analyzer.cpp:67 (head).

Details and suggested fix

After the exact-key check fails, !has_private || wallet.IsLocked() maps both cases to UNKNOWN. Without a better match, CanSign then returns nullopt, although unlocking cannot provide the private key missing from that candidate. Separate unverifiable public-only ownership from unlock-dependent verification, and let only the latter make local signing capability indeterminate. This preserves a possible watch-only relationship without giving callers futile unlock guidance. The trigger is uncommon because an account xpub's own fingerprint normally differs from its master-origin fingerprint.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Descriptors exist because keys alone do not identify a wallet's outputs: script types and derivation paths must also be explicit for interoperable recovery and watch-only export. Their checksum protects against transcription errors, not agreement on the intended spending arrangement.

At the pinned base, getdescriptorinfo returns a public descriptor, checksum and broad properties such as isrange and issolvable, but no structured account of its keys or spending structure. The head adds keys, policy and analysis while retaining those existing fields. This extends the descriptor's original role as an explicit description rather than replacing it with a threshold label.

Source 1

Multisig setup verification addresses a concrete tampering threat: changing membership, script type, derivation paths or the required signature count can redirect funds or hold them for ransom. BIP 129 requires the receiving signer to match its actual key—not merely a spoofable fingerprint—and display policy parameters, its key positions and the first address.

This explains why the head's structural analysis is supplemented by wallet-specific key matching and first_address. In src/wallet/descriptor_analyzer.cpp, an origin fingerprint selects candidates, but a derived public key and chain code must match before ownership is asserted. Merely finding the expected fingerprint or threshold would answer a weaker question than the historical setup procedure requires.

Source 1 · Source 2

Policy inspection is a security and usability problem, not simply descriptor parsing. BIP 388 assumes the computer connected to a hardware signer may be attacker-controlled; users must be able to verify the script and involved keys, and change must remain protected by the approved policy. Separating key information from policy structure makes that inspection more manageable.

The head exposes public key occurrences and a policy tree separately from the multisig verdict. Historical Core issue #32659 specifically proposed keys and policy fields for getdescriptorinfo to aid signing-device verification. The head's policy array is structural information, however, not itself a BIP 388 wallet-policy encoding or proof of user approval.

Source 1 · Source 2

Repeated multisig keys distinguish a signature threshold from a threshold of independent holders. In the setup tracking discussion, a participant proposed refusing duplicates because one holder could fill multiple slots. Another argued for warning because duplication can be intentional and distinct keys cannot establish distinct ownership. The original proposer accepted a warning before confirmation; a later comment distinguished interoperable descriptor construction from Core's ability to sign valid descriptors.

The head preserves equal keys as separate occurrences, reports repeated_key, and withholds a recognized setup without refusing to parse or analyze the descriptor. This follows the historical distinction between describing valid script behavior and endorsing it as the intended k-of-n arrangement. It does not establish that different keys belong to different people.

Source 1 · Source 2 · Source 3 · Source 4

HD wallets deliberately separate address generation from spending authority. BIP 32 motivates public derivation so an online system can generate fresh addresses without private keys. BIP 48 places hardened derivation above the shared account/script xpub and public derivation at the change and address-index levels. BIP 380 correspondingly instructs public exports to move intermediate hardened derivation into the key origin.

This explains the distinction in CheckCosignerKeys between an acceptable hardened origin and hardened derivation still required after the supplied xpub. The former records how a signer obtained its account key; the latter prevents other participants from deriving addresses using public information alone. The wallet matcher may consequently need private material to verify the origin even though first-address generation does not.

Source 1 · Source 2 · Source 3

Taproot intentionally permits spending by a key or by a committed script. Its design uses cooperative key aggregation to make multiparty spending efficient and private, without revealing the script alternative when the key path is used.

A threshold leaf therefore cannot by itself describe all spending authority. ClassifyKeyPath in the head separately examines the internal key, recognizing NUMS H or an aggregate of sufficiently many distinct leaf cosigners. Core's earlier NUMS_H proposal documents H's deterministic construction and its intended reuse throughout the codebase. The historical Taproot rationale explains why the analyzer must account for both paths; it does not establish the correctness of this particular classifier.

Source 1 · Source 2

Multipath descriptors were introduced to represent closely related receive and change descriptors together. BIP 389 specifies lockstep expansion across keys and conventionally assigns the first expansion to receiving and the second to change. BIP 388 treats both as one logical account whose policy must remain consistent.

The head analyzes every parsed expansion while returning the first branch's keys and policy, and derives first_address from that branch. This is also relevant to the historical preference for starting inspection in getdescriptorinfo: issue #32659 noted that imported receive/change descriptors were stored separately, losing the original combined expression.

Source 1 · Source 2 · Source 3

Ralph's inferences

Structural recognition, local signing participation and agreement on the generated destination are separate checks. None substitutes for the others: possessing a key does not establish the intended threshold policy, and recognizing a policy does not identify its real-world participants.

The head expresses these separately as analysis.recognized, per-key wallet matches/can_sign, and first_address. In particular, CanSign() means that the wallet holds at least one relevant private key, not that it can complete a threshold spend alone. This separation is consistent with BIP 129's distinct membership, policy and address checks.

Source 1 · Source 2

Returning an unknown ownership result for a locked wallet preserves a useful distinction between missing evidence and a negative match. Public policy inspection need not require exposing private keys merely because one ownership check requires hardened derivation.

MatchExtKey returns UNKNOWN when verifying a candidate origin requires unavailable private material; CanSign() remains indeterminate unless another key is known to be held. Structural analysis and public first-address derivation continue independently. This is an interpretation of the head's information boundaries, supported by the historical separation between public derivation and spending authority, rather than an explicitly documented historical decision about this RPC.

Source 1 · Source 2 · Source 3