wallet, rpc: Add analyzedescriptor for multisig setups

bitcoin/bitcoin: PR #36885

Provider refusals

write_verifier: Provider declined the request because of a cybersecurity restriction. Experiments remain incomplete; static verification can continue.

1 major finding · 2 minor findings · 3 suggestions

Findings

Link

[major] · IsDirectChild aborts on hardened xpub child-number metadata

Verifying a coordinator-supplied multisig descriptor with matching parent metadata and a hardened nChild can abort the process through CPubKey::Derive, even with otherwise unhardened derivation suffixes.

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

Details and suggested fix

For a supported multisig shape, two cosigner xpubs with different roots and first-derived keys reach IsDirectChild. If one xpub's parent fingerprint matches the other's fingerprint, its nChild is passed directly to CExtPubKey::Derive. With a parent below depth 255 and a hardened child number, this reaches CPubKey::Derive's unhardened-index assertion, which remains enabled in release builds. An xpub beside its real hardened child, both followed by /0/*, supplies such an input; a coordinator can also forge the nonzero-depth metadata using only public information. The suffix checks do not inspect this metadata. A participant verifying it through getdescriptorinfo with verbose=true, the analyzedescriptor RPC, or interfaces::Wallet::analyzeDescriptor reaches the abort. Base getdescriptorinfo did not perform this comparison. Restart recovers availability, and no funds are affected. Return false for a hardened child.nChild before calling Derive, and add regressions for real and forged hardened-child metadata in both slot orders.


Link

[minor] · WATCH_ONLY hides locked-wallet uncertainty in can_sign

With overlapping public-account and private-master keys, a locked wallet can return can_sign: false instead of leaving it unknown; no current in-tree setup flow producing this state was found.

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

Details and suggested fix

A wallet can hold a private master in one descriptor and its public account xpub in another. An accepted partial-private multisig import can create the latter by including the account xpub alongside an unrelated xprv. When analyzing the account key with its hardened origin, MatchHDKeys gets WATCH_ONLY from the exact account match and UNKNOWN from the locked master. Best prefers WATCH_ONLY, so if no other analyzed key is MINE, CanSign() returns false and removes the documented signal to unlock and retry. Unlocking resolves the master derivation to MINE; signing authority is unchanged. Rank the results as MINE > UNKNOWN > WATCH_ONLY > NOT_MINE, and extend the locked-wallet test with the overlapping public-account representation.


Link

[minor] · Depth-exhausted cosigner keys still receive recognized: true

A depth-exhausted cosigner can produce recognized: true despite being unable to derive an address; no current coordinator flow producing such keys was found.

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

Details and suggested fix

For example, wsh(multi(1,X/*)) parses when X is a valid xpub serialized at depth 255. CheckCosignerKeys accepts its unhardened wildcard, and FirstDerivedKey returns nullopt when CExtPubKey::Derive hits the depth limit. That failure only disables a duplicate comparison and records no issue, leaving the setup recognized. The wallet analysis omits first_address, and importdescriptors later rejects expansion, so the preflight verdict describes a setup Core cannot use. Record a derivation-failure issue for an otherwise eligible cosigner and clear recognition. Add a depth-exhaustion regression test.


Optional improvements

Link

[suggestion] · Multipath analysis discards later-branch diagnostics

Multipath descriptors remain correctly unrecognized, but discarding later-branch issues hides which key or derivation needs correction.

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

Details and suggested fix

For wsh(sortedmulti(2,A/<0;1>/*,B/<0;1h>/*,C/<0;1>/*)), the change branch produces hardened_derivation for key 1, but the combined result returns only branches_differ with no keys, as the functional test expects. If the receive branch instead fails on A and the change branch fails on B, Unrecognize resets every compared setup field, so the two failures compare equal and only A's issue survives. Preserve later-branch issues with branch context, including when both summaries are unrecognized, so callers can identify the actual cause without reparsing the descriptor. Parse-produced multisig branches retain slot order, but preserve or verify key-ID correspondence when returning those diagnostics. Recognition behavior need not change.


Link

[suggestion] · CheckRepeatedKeys misses origin-provable deeper descendants

Best-effort repeated-key detection recognizes an ancestor/grandchild pair with different suffixes even when public derivation from their origins could prove that one holder controls both slots.

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

Details and suggested fix

In wsh(sortedmulti(2,A/0/*,G/*,C/0/*)), let G be the xpub at A/1/2 and C be unrelated. The roots differ, the first-derived keys are A/0/0 and A/1/2/0, and IsDirectChild cannot link them. The existing chain test catches a grandchild only because another slot supplies the bridging A/1/2/* expression. Extend the check for matching origin fingerprints whose paths have an unhardened ancestor/descendant relationship: derive the relative path from the ancestor xpub and compare the resulting public key and chain code. This verifies the relationship rather than trusting annotations. Add an isolated grandchild test without the bridging slot. The extension would catch honest key reuse, not establish independent ownership; a malicious cosigner can still supply unrelated keys.


Link

[suggestion] · Explicitly watched constant keys are reported as not_mine

Under the documented constant-key matching rules, a watch-only wallet reports its imported wpkh(P) key as not_mine, unlike a stored public xpub.

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

Details and suggested fix

Without a stored private key, MatchConstKey relies on HD-origin matching. A standalone public wpkh(P) contributes no HD root, and its recorded constant-key origin does not establish such a relationship, so analyzing the wallet's own descriptor returns not_mine. Add a lower-priority WATCH_ONLY fallback when the key appears explicitly in a stored descriptor's GetKeyInventory(), without overriding MINE or UNKNOWN. Restricting this to explicit occurrences preserves the existing NOT_MINE result for other cosigners' keys merely derived into caches. Update the documented constant-key rule and add a public-constant membership test. can_sign remains false, and signing behavior does not change.


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

Multisig setup verification exists because a modified configuration can redirect funds, enable theft or ransom, or compromise privacy—not merely produce an incorrect-looking descriptor.

BIP 129 requires signers to verify their actual key, validate the first address, and display policy parameters including M, N and their key positions. The earlier Core coordination proposal likewise calls for participants to persist the configuration, check change addresses, and compare the first receive address. These requirements explain why the affected API separates policy recognition, wallet membership and address agreement rather than treating successful parsing as setup verification.

Source 1 · Source 2 · Source 3

Repeated-key warnings belong at the receiving participant's verification step, even if descriptor construction already checks duplicates; warning is distinct from rejecting a valid descriptor.

The tracking discussion explicitly describes repeated keys allowing fewer signers than the displayed threshold to spend. An objection notes that duplication can be intentional and that software cannot establish whether apparently distinct keys belong to independent parties. Subsequent comments accept a visible verification warning while distinguishing hardware-wallet compatibility rules from Core's ability to sign valid descriptors. This directly contextualizes an unrecognized verdict that still returns inspection results rather than refusing the descriptor.

Source 1 · Source 2 · Source 3 · Source 4

Taproot's key path is an independent authorization route, and aggregation was designed to make cooperative spending efficient and private without revealing the script alternatives.

BIP 341 explains that an output can be spent by its key or optional script and that an aggregate key requires cooperation among its participants. The historical BIP 388 changeset illustrates a 3-of-5 wallet with a 5-of-5 MuSig key path, 3-party aggregate script paths and a multi_a fallback when interactive signing is unavailable. Thus a threshold leaf alone is insufficient to describe the complete authorization policy, while cooperative key paths and noninteractive script fallbacks have an explicit historical purpose.

Source 1 · Source 2