1 minor finding · 4 suggestions
Findings
[minor] · Matching first_addresses can hide a multisig sorting mismatch
Comparing only first_addresses can miss a multi()/sortedmulti() mismatch when index-0 keys are sorted, allowing later address divergence despite both policies being recognized; analysis.sorted already exposes the difference.
Location: src/wallet/rpc/wallet.cpp:1108 (head).
Details and suggested fix
FirstAddress() expands only index 0. With the same threshold and key expressions, multi() and sortedmulti() produce identical addresses whenever the derived keys are already sorted on every path. A coordinator can arrange this directly for a single-path setup. The same applies to multi_a() and sortedmulti_a(). In this RPC, only analysis.sorted distinguishes the two results. If participants compare addresses alone and import different forms, later indices with a different key order produce different scripts. A wallet or backup using one form then misses payments to the other form, although the same cosigners can still spend those outputs with the correct descriptor. Document that participants must also compare analysis.sorted and the agreed threshold before treating matching first addresses as setup confirmation.
Optional improvements
[suggestion] · No summary when wallet-owned cosigner slots meet the threshold
Hardened sibling accounts can remain recognized while one wallet owns a signing threshold; the per-key mine entries reveal this, but no wallet-level advisory highlights an accidental duplicate contribution.
Location: src/wallet/descriptor_analyzer.cpp:194 (head).
Details and suggested fix
For an unlocked wallet holding the master, accounts at paths such as m/48h/1h/0h/2h and m/48h/1h/1h/2h both match as mine. Their roots and first-derived keys differ, and neither is the other's unhardened child, so the public repeated-key check leaves the setup recognized. CanSign() returns true after finding just one owned key. A caller must currently join analysis.cosigners with the per-key ownership values to notice that this wallet alone meets the threshold. Expose the owned cosigner IDs and add a wallet-level advisory when their count reaches the threshold. Count only cosigner slots marked mine, not MuSig participant occurrences or keys marked unknown, and leave the structural recognition result unchanged.
[suggestion] · Shared origin fingerprints produce no setup advisory
Otherwise acceptable cosigner slots with the same claimed master fingerprint remain recognized without an advisory, missing a wallet-free hint of accidental same-seed entries; matching fingerprints do not prove shared ownership.
Location: src/script/descriptor_analyzer.cpp:182 (head).
Details and suggested fix
CheckRepeatedKeys() deliberately checks key material and derivable relationships, not explicit origins. The functional test consequently recognizes a parent/account pair carrying origins [fp/48h/1h/0h] and [fp/48h/1h/0h/2h] from the same master. Add a separate, non-blocking hint listing cosigner IDs whose origins share a master fingerprint. This would help participants notice an accidental double entry during wallet-free preflight. Keep recognized unchanged and do not classify the hint as repeated_key: origins are unauthenticated, can be stripped, and 32-bit fingerprints can collide.
[suggestion] · The supplied-xprv test misses the wallet-ownership boundary
The wallet_analyzedescriptor.py case checks only first_addresses, so treating caller-supplied secrets as wallet-owned keys would not fail that assertion.
Location: test/functional/wallet_analyzedescriptor.py:113 (head).
Details and suggested fix
Alice never imports TPRV, but this case supplies it in wpkh(TPRV/84h/1h/0h/0/*) to derive the first address. The current implementation correctly uses the parsed provider for address derivation and computes ownership separately from the wallet's keys. Keep the result in a variable and also assert that its sole key has wallet: "not_mine" and that can_sign is false. This protects the distinction between deriving with caller-supplied secrets and confirming that the participant's wallet holds a key, using the existing fixture.
[suggestion] · Wallet HD-root collection repeats the descriptor traversal
WalletHDKeys() traverses every descriptor manager twice under cs_wallet, although its inventory traversal already contains every BIP32 root needed for the final map.
Location: src/wallet/descriptor_analyzer.cpp:160 (head).
Details and suggested fix
GetHDPubKeys(All) visits every manager, obtains a WalletDescriptor by value and collects its ordinary extended-key roots. WalletHDKeys() then visits every manager again, obtains another value copy and builds an inventory containing those same roots plus MuSig participants. Initialize hd_keys.keys empty and insert every BIP32Key::root with its desc_spkm in the existing inventory loop, rather than inserting only participant roots there. This preserves the final root-to-manager map, origin collection and descriptor-local private-key checks while removing the first traversal and one value copy per manager. Other callers of GetHDPubKeys() need no changes.
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 was intended to include participant-side verification before import, not merely correct construction by a coordinator. The planned preflight output included signing capability, the wallet’s own slot, threshold, output type, cosigner fingerprints and paths, and a first address.
This explains why the change separates wallet-free policy recognition from wallet ownership and address derivation. A structurally acceptable descriptor, inclusion of the participant’s actual key, and agreement on the resulting wallet are different checks.
Duplicate-key checking was explicitly required at verification time because an apparent k-of-n can otherwise be spendable by fewer holders. The subsequent exchange favored a visible warning before confirmation rather than refusing an otherwise valid descriptor: construction aimed at hardware-wallet interoperability, while Core should remain able to sign valid policies.
This supports reporting repeated keys as setup issues without making descriptor parsing or analysis itself reject the input. It also explains why a threshold or an own-key match alone was not considered sufficient evidence of the agreed setup.
Source 1 · Source 2 · Source 3
The historical warning discussion acknowledged a fundamental ownership limit: a participant cannot tell whether all other public keys are controlled by one party.
The intended protection was therefore not proof of n independent people or organizations. Related-xpub detection can identify some collapsed signer slots, but cannot establish real-world independence, exclusive control, or honest key generation.
A NUMS internal key exists to make Taproot key-path spending unavailable, leaving script-path spending as the authorization mechanism.
This is the historical reason a recognizable unspendable internal key can accompany a threshold leaf without introducing another spending authority. It is a constraint on the alternative spending path, not merely a preferred descriptor spelling.
The setup workflow deliberately shares account xpubs derived through hardened paths, distinct from default single-signature descriptors. Related public-descriptor import work sought to avoid exposing private material by locating wallet keys through a fingerprint and then deriving and verifying the specified xpub.
Origins are useful lookup instructions, not sufficient ownership evidence by themselves. This also explains the distinction between hardened origin derivation needed to establish ownership and unhardened derivation after the shared account xpub needed by all participants to derive addresses.
Partial-private-key multisig descriptors were an intentional supported case: a private-key-enabled wallet can contain an xpub whose private key it does not have. The gethdkeys repair preserved that distinction rather than treating wallet-wide private-key capability as ownership of every listed HD key.
The analyzer’s ownership answer must be per key. Merely finding a cosigner xpub in a wallet, including a wallet that holds another cosigner’s private key, does not establish that this wallet can sign with that xpub.
Ralph's inferences
The single-leaf and internal-key restrictions can be understood as preserving the set of authorized coalitions. The k-of-n leaf supplies every k-cosigner coalition; NUMS supplies no additional authority. A MuSig aggregate containing only distinct leaf cosigners and requiring at least k of them adds a spending route for a coalition already authorized by the leaf. Fewer participants or outsiders would not satisfy that argument.
This explains accepting at least k rather than necessarily all n aggregate participants. Requiring a single threshold leaf also avoids having to analyze additional script alternatives. This is a derivation from the authorization requirement and pinned implementation, not evidence that the exact broader acceptance rule was previously agreed.
The recognition guarantee is bounded by what the descriptor reveals about its keys. Detecting equal roots, equal first-derived keys, and certain direct unhardened parent-child relationships catches concrete ways one holder can occupy multiple slots; it is not a general proof that every slot has a separate, usable secret.
The pinned contract expressly excludes complete detection of related keys and unknown unspendable keys. The earlier participant-verification requirement remains complementary: each participant checks their actual key, while structural analysis and address comparison answer different questions. None authenticates the other participants’ independence.
Descriptor-local private-key ownership follows the existing signing model rather than mathematical possession alone. At the base, gethdkeys checks private keys in the managers using each xpub, and signing expansion obtains keys from each descriptor manager’s own store. The analyzer correspondingly does not combine an xpub in one descriptor with a bare private scalar stored only in another.
This makes 'mine' a statement about usable wallet key material under Core’s descriptor model, not an inventory of everything theoretically derivable after combining all wallet secrets. Origin matching verifies derived key material, including account-origin prefixes. Its metadata-insensitive comparison is also distinct from the earlier import-substitution discussion’s preference for exact xpub matching to avoid surprising private-key replacement.
Locked-wallet results distinguish possession from present access and uncertainty from a negative match. Exact or publicly derivable matches can establish private-key possession without unlocking. A potentially matching hardened origin needs the candidate private key, so a locked wallet cannot yet establish the match. Consequently, can_sign is true if any key is known mine, absent if none is mine but some remain unknown, and false otherwise.
Here can_sign means possession of at least one relevant private key—not immediate ability to produce a signature while locked, satisfaction of the threshold, or recognition of a safe setup. UNKNOWN takes precedence over a watch-only match because unlocking might establish private ownership. The implementation decrypts only the candidate key, leaves public analysis and address derivation separate, and does not count externally held signer keys as locally held private keys.