mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 15:11:38 +00:00
Contrib: add multisig wizard #36325
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36325
Loading…
Reference in a new issue
No description provided.
Delete branch "contrib_multisig"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Per the discussion in #35645, this PR adds a Python utility that performs the multisig setup process, so that RPC and interface work is shaped by what that flow actually needs.
It covers wallet creation, key generation at the BIP 87 path, collecting cosigner keys, assembling a
wsh(sortedmulti())ortr(musig(),sortedmulti_a())descriptor, verifying it, and importing it.Gaps that need new functionality in C++
importdescriptorsrejects a descriptor with no private keys when the wallet has private keys enabled. See #35377.pkh()forgetdescriptorinfoto parse. See #35918, which exposesParsePubkey().createmultisigonly takes plain public keys, not extended keys with origins, and cannot build a ranged or taproot multisig descriptor.Part of #35645.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Do we need this in the repository? Seems fine to me if it were just an external script.
Aside from being a demonstration of the multisig setup flow, the utility is intended to become a command-line equivalent of the GUI wizard that ships with Core so users can set up multisig without hand-assembling descriptors.
The workarounds in it will eventually be superseded as functionality is moved to C++.
Whether that belongs in the repo is worth settling first.
cACK, only cursory code review of
wizard.pybut the interface and usage looks correct.As for @sedited wondering if we need this in the repository:
For a while now, Core offline signing and multisig being non-technologist unfriendly has been exploited by scammers to push alternative multisig and airgap wallets with substantially less review than this repository.
4 minor findings · 4 suggestions · 2 previous findings
🟠 Minor
Repeated keys are counted as separate multisig cosigners
Location:
contrib/multisig/wizard.py:201(head).A received descriptor can pass verification as k-of-n even when one key holder can fill multiple signing slots.
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 receivedwsh(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 affectstr(musig(...),sortedmulti_a(...))when the repeated keys match on both sides. Theadd_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.Previous reports
First reported at
2803e1518bb22394a80bac94e2435bb3982d0cde. Last checked at2803e1518bb22394a80bac94e2435bb3982d0cde.🟠 Minor
Key matching calls derivehdkey with paths the RPC rejects
Location:
contrib/multisig/wizard.py:274(head).For certain accepted keys,
verify()andimport_descriptor()abort with an RPC error instead of recognizing a key the wallet holds.Details and suggested fix
derivehdkeyrejects paths with no hardened step, butfind_own_key()calls it withmfor 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 fromgethdkeys(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.Previous reports
First reported at
2803e1518bb22394a80bac94e2435bb3982d0cde. Last checked at2803e1518bb22394a80bac94e2435bb3982d0cde.🟠 Minor
Received descriptors can import another cosigner's private key
Location:
contrib/multisig/wizard.py:221(head).A shared descriptor containing a cosigner's xprv can give the importer enough signing keys to spend below the reported threshold.
Details and suggested fix
analyze_descriptor()callsgetdescriptorinfo()but does not checkhasprivatekeys, 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 whichgetdescriptorinfo()reportshasprivatekeys, and add a verification and import test for this case. No checked-in caller produces such a descriptor, so production impact is unconfirmed.🟠 Minor
Importing a second multisig makes it active and redirects change
Location:
contrib/multisig/wizard.py:345(head).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.
Details and suggested fix
import_descriptor()always imports withactive: True, which replaces the wallet's active external and internal descriptors for that output type. The existing second-multisig test confirms thatgetnewaddressthen 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, ascreate_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.🔵 Suggestion
The account parameter derives from a new seed on every call
Location:
contrib/multisig/wizard.py:51(head).account=Nsuggests account separation under one seed, but each call togenerate_key()creates a fresh seed.Details and suggested fix
generate_key()callsaddhdkey()without an argument, which generates a new random seed, and then derivesm/87h/{coin}h/{account}hfrom 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, callingaddhdkey()only when there is none; alternatively, removeaccountfromgenerate_key()and document that each multisig uses a fresh seed.🔵 Suggestion
verify() fetches private keys it does not use
Location:
contrib/multisig/wizard.py:277(head).Each
verify()call sends account xprvs over JSON-RPC even though verification needs only a public-key match.Details and suggested fix
find_own_key()always callsderivehdkeywithprivate=True, butverify()retains only the matched public-key expression. Deriving the public key requires the same hardened path and wallet unlock, so verification can useprivate=Falsewithout 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 aprivateflag tofind_own_key()and enable it only whenimport_descriptor()calls the helper.🔵 Suggestion
The NUMS xpub check rejects derived and test-network forms
Location:
contrib/multisig/wizard.py:247(head).Descriptors using a derived NUMS xpub or a test-network encoding are rejected, and the constant itself is not exercised by the functional test.
Details and suggested fix
analyze_descriptor()accepts a NUMS key path only when the internal key exactly equalsNUMS_HorNUMS_H_XPUB. The latter is a mainnet xpub thatgetdescriptorinforejects on test chains, so the functional test exercises onlyNUMS_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 to02||NUMS_H. Alternatively, removeNUMS_H_XPUBif an underived xpub is unnecessary.🔵 Suggestion
The README incorrectly requires private keys for every step
Location:
contrib/multisig/README.md:10(head).The instructions may lead a watch-only coordinator to use a wallet with private keys even though it does not need one.
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.Previous findings (2)
[Minor · still present] 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.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,getdescriptorinfofails andassemble()reports onlyInvalid descriptor. Require an extended key invalidate_key(), for example by checking thatpkh({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.Location:
contrib/multisig/wizard.py:81(head).First reported at
2803e1518bb22394a80bac94e2435bb3982d0cde. Last checked at2803e1518bb22394a80bac94e2435bb3982d0cde.[Minor · still present] 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.
verify()returns the first receive address before import, butimport_descriptor()always passestimestamp: "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 runsrescanblockchain, andgetnewaddresscan return the already-used address in the meantime. Record a creation time insetup()or accept a timestamp and pass it toimportdescriptors. The intended order has every participant importing before funding, and no checked-in caller funds before import, so production impact is unconfirmed.Location:
contrib/multisig/wizard.py:345(head).First reported at
2803e1518bb22394a80bac94e2435bb3982d0cde. Last checked at2803e1518bb22394a80bac94e2435bb3982d0cde.Review coverage was incomplete.
Reviewed:
2803e1518bb2· Full review report · Previous reportsI'm not sure we want this in this repository.
Looking at the other scripts in
contribI don't see any that handle wallet utilities. If this were to be added it would make more sense to add it to the Bitcoin Core wallet.From what I understand in the discussion in https://github.com/bitcoin/bitcoin/issues/35645, this would not be used, as once the work in the GUI and wallet has finished, that would be preferred. The script is still valuable, but we might not want it with the contrib scripts.
I don't think the goal of Bitcoin Core is to be "non-technologist" friendly, and also adding a new script to the repo does not guarantee that it will be maintained. It is just another piece of code the Bitcoin Core maintainers will need to worry about forever.
To me, it makes the most sense to keep this change on your own fork and share it with the group in the thread so they can still use it without merging it into this repo, where it will need to be maintained
@rxbryan are you willing to maintain this script (including bug fixing) until the RPC obsoletes it?
@Sjors said in https://github.com/bitcoin/bitcoin/pull/36143#issuecomment-5508988125 a wallet c++ implementation is premature and he preferred to:
The script serves as a functional to-do checklist for multisig, with its workarounds deleted as wallet PRs land.
The advantage of merging it into this repo is better scrutiny and CI against bugs for adventurous users who'd like to use it on mainnet.
Yes. I'll maintain it, we have enough test cases to force a maintenance contract on whoever modifies code touching it.
Thanks for putting this together and listing the gaps.
That said, I'm leaning Concept NACK on merging this into the repo.
The goal of #35645 is for the wallet to handle multisig setup by itself - a GUI wizard on top of
interfaces::Wallet, plus the RPCs behind it. Like you said that work would supersede this script. Merging this would mean reviewing ~700 lines (script and functional test) whose job is to work around things we plan to fix. We'd then have to review again each time one of those fixes lands and removes a workaround. I'd rather prefer we direct our resources at implementing items in #35645, since they reach both RPC and GUI users.Also putting a script in
contrib/makes it look like a recommended tool and that's hard to undo once people use it with real funds.What we can do
createmultisigdescriptor,analyzeDescriptor)Even I, supporting the idea of merging this into the repo due to the demand for a well reviewed multisig setup, did not fully code review it due to it's length and my expectation that it would receive cNACKs.
What's the absolute smallest it could be made to maximize the number of people willing to review it and minimize the time it takes them? For example were it 100-300 lines I likely would have code reviewed despite my expectations.
Could you modularize it so that each time one of our workarounds lands, we just delete a function or module and replace it with the new RPC? So it's a +1/-?? diff to review? I think that would maximizes the chances of support and review interest.
Agreed, if the goal of this script is to disappear that means we want a terminal or CLI wizard for multisig so that it is eventually replaced by something in C++, I haven't seen that talked about if that is the goal, although I would cACK that also since it's better than nothing and no GUI.
tACK
2803e1518All wizard steps run on an offline node for 2-of-3
wsh(sortedmulti)atm/87h/1h/0h:create_wallet,generate_key,add_cosigner,assemble,verifyandimport_descriptor, for three key wallets and a watch-only coordinator. The watch-only wallet was restored online and created a PSBT. Two key wallets signed it offline, andtestmempoolacceptallowed the result.Review nits
import_descriptoruses"timestamp": "now". Inimportdescriptors, "now" means the best block's time. An offline node has only the genesis block, so the wallet's birth time is genesis. Restoring that wallet's backup on a pruned online node then fails withPrune: last wallet synchronisation goes beyond pruned data. You need to -reindex. The same descriptor imported with the current time restored fine on the same pruned node. Suggested fix: passint(time.time()), or let the caller give a timestamp. On an online node the result is the same as "now".import_descriptor, each participant has to back up their key wallet and the descriptor. A key wallet alone can't rebuild the multisig. The wizard's docstrings don't mention this. It may belong in the README rather than the code.Concept NACK
The purpose of #35645 is to add a first class feature into the software, a contrib script is not this, nor is it something that meaningfully contributes to the completion of that feature as most of the work is not visible on RPC, or is in the GUI.