Review report

core: PR #36325

6 minor findings · 4 suggestions

Findings

Link

[minor] · Repeated keys are counted as separate multisig cosigners

A received descriptor can pass verification as k-of-n even when one key holder can fill multiple signing slots.

Location: contrib/multisig/wizard.py:201 (head).

Details and suggested fix

parse_multi() returns every key without checking for duplicates, and Core accepts repeated keys in these multisig expressions. As a result, a received wsh(sortedmulti(2,A/<0;1>/*,B/<0;1>/*,B/<0;1>/*)) is reported as 2-of-3 and imports, although B's holder can satisfy both B slots and spend without A. The same issue affects tr(musig(...),sortedmulti_a(...)) when the repeated keys match on both sides. The add_cosigner() check also compares serialized xpub strings, so the same account key can pass when re-encoded with different origin metadata. Compare decoded public keys and chain codes, ignoring origin and serialization metadata, and reject or prominently warn about repeats in both new and received descriptors.


Link

[minor] · Key matching calls derivehdkey with paths the RPC rejects

For certain accepted keys, verify() and import_descriptor() abort with an RPC error instead of recognizing a key the wallet holds.

Location: contrib/multisig/wizard.py:274 (head).

Details and suggested fix

derivehdkey rejects paths with no hardened step, but find_own_key() calls it with m for an exact xpub match and with the descriptor's origin path in the derived-key branch. An account xprv stored as an unused key can therefore fail the exact-match branch. The derived-key branch can fail for received descriptors with a fingerprint-only origin or an origin containing only unhardened steps. In either case, a participant whose wallet holds an unused key cannot verify or import the descriptor. For an exact match, use the xprv from gethdkeys(private=True); in the derived branch, skip candidates whose origin has no hardened step. generate_key() only creates master-level unused keys, and no checked-in caller builds such a descriptor, so production impact is unconfirmed.


Link

[minor] · Origin-tagged raw public keys pass validation but cannot be ranged

add_cosigner() can accept a key that later makes descriptor assembly fail after all cosigner keys have been collected.

Location: contrib/multisig/wizard.py:81 (head).

Details and suggested fix

validate_key() accepts an origin-annotated hex public key when its origin has the expected BIP 87 path. build_descriptor() then appends /<0;1>/* to every key, but Core accepts a raw hex key only without a derivation suffix. As a result, getdescriptorinfo fails and assemble() reports only Invalid descriptor. Require an extended key in validate_key(), for example by checking that pkh({key}/*) parses, and add tests for origin-tagged compressed and uncompressed raw keys. No checked-in caller supplies this form, so production impact is unconfirmed.


Link

[minor] · Importing with timestamp "now" can hide payments made before import

A participant or watch-only coordinator importing after funding will not see earlier payments until a rescan.

Location: contrib/multisig/wizard.py:345 (head).

Details and suggested fix

verify() returns the first receive address before import, but import_descriptor() always passes timestamp: "now". That timestamp bypasses scanning for outputs known never to have been used; the RPC otherwise scans only two hours before the supplied timestamp. If the address was paid earlier, the wallet misses the payment until someone runs rescanblockchain, and getnewaddress can return the already-used address in the meantime. Record a creation time in setup() or accept a timestamp and pass it to importdescriptors. The intended order has every participant importing before funding, and no checked-in caller funds before import, so production impact is unconfirmed.


Link

[minor] · Received descriptors can import another cosigner's private key

A shared descriptor containing a cosigner's xprv can give the importer enough signing keys to spend below the reported threshold.

Location: contrib/multisig/wizard.py:221 (head).

Details and suggested fix

analyze_descriptor() calls getdescriptorinfo() but does not check hasprivatekeys, and it retains the original descriptor body. import_descriptor() submits that body after replacing only the participant's own key. If a received descriptor contains another cosigner's xprv, verification still reports the stated threshold, while import stores that private key in the participant's wallet. In a 2-of-3, the importer then holds two keys and can sign alone. Reject descriptors for which getdescriptorinfo() reports hasprivatekeys, and add a verification and import test for this case. No checked-in caller produces such a descriptor, so production impact is unconfirmed.


Link

[minor] · Importing a second multisig makes it active and redirects change

In a wallet holding two vaults of the same output type, a spend from one vault can send change to the other, and coin selection can combine both vaults' coins.

Location: contrib/multisig/wizard.py:345 (head).

Details and suggested fix

import_descriptor() always imports with active: True, which replaces the wallet's active external and internal descriptors for that output type. The existing second-multisig test confirms that getnewaddress then returns the second vault's address. A later spend from the wallet can send change from vault-1 coins to vault 2, whose cosigners or threshold may differ. Coin selection can also select coins from both vaults, requiring both cosigner sets to sign and linking the vaults on-chain. Either keep one wallet per setup, as create_wallet() already names the wallet after the setup, and refuse imports when an active descriptor of that type exists; or import additional multisigs as inactive behind an explicit option and document the behavior.


Optional improvements

Link

[suggestion] · The account parameter derives from a new seed on every call

account=N suggests account separation under one seed, but each call to generate_key() creates a fresh seed.

Location: contrib/multisig/wizard.py:51 (head).

Details and suggested fix

generate_key() calls addhdkey() without an argument, which generates a new random seed, and then derives m/87h/{coin}h/{account}h from that seed. Thus, generate_key(cosigner_wallet, account=1) on a wallet that already holds a seed creates keys from a new seed at account 1, not account 1 of the existing seed. The account index does not separate keys, and restoring only the first seed will not recover later keys. Reuse the existing unused seed when there is exactly one, calling addhdkey() only when there is none; alternatively, remove account from generate_key() and document that each multisig uses a fresh seed.


Link

[suggestion] · verify() fetches private keys it does not use

Each verify() call sends account xprvs over JSON-RPC even though verification needs only a public-key match.

Location: contrib/multisig/wizard.py:277 (head).

Details and suggested fix

find_own_key() always calls derivehdkey with private=True, but verify() retains only the matched public-key expression. Deriving the public key requires the same hardened path and wallet unlock, so verification can use private=False without changing the match. As written, it fetches an xprv over the RPC connection for every hardened origin path in the descriptor and every unused seed. Add a private flag to find_own_key() and enable it only when import_descriptor() calls the helper.


Link

[suggestion] · The NUMS xpub check rejects derived and test-network forms

Descriptors using a derived NUMS xpub or a test-network encoding are rejected, and the constant itself is not exercised by the functional test.

Location: contrib/multisig/wizard.py:247 (head).

Details and suggested fix

analyze_descriptor() accepts a NUMS key path only when the internal key exactly equals NUMS_H or NUMS_H_XPUB. The latter is a mainnet xpub that getdescriptorinfo rejects on test chains, so the functional test exercises only NUMS_H. A NUMS xpub with /<0;1>/* derivation falls through to the error that the key path may be spendable on its own, even though its children remain unspendable. To support this descriptor form, recognize network-appropriate NUMS xpubs with the multipath suffix and add a check that decodes the constant to 02||NUMS_H. Alternatively, remove NUMS_H_XPUB if an underived xpub is unnecessary.


Link

[suggestion] · The README incorrectly requires private keys for every step

The instructions may lead a watch-only coordinator to use a wallet with private keys even though it does not need one.

Location: contrib/multisig/README.md:10 (head).

Details and suggested fix

The README says every step requires an unlocked wallet with private keys enabled, then says a coordinator that contributes no key needs a watch-only wallet. The code and functional tests support a watch-only coordinator running verification and import. Clarify that generate_key() and participant imports need an unlocked private-key wallet, while a coordinator that contributes no key can use a watch-only wallet for verification and import.


Coverage details