Skip to content

Contrib: add multisig wizard - #36325

Closed
rxbryan wants to merge 5 commits into
bitcoin:masterfrom
rxbryan:contrib_multisig
Closed

rxbryan wants to merge 5 commits into
bitcoin:masterfrom
rxbryan:contrib_multisig

Conversation

@rxbryan

@rxbryan rxbryan commented Sep 24, 2026

Copy link
Copy Markdown

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()) or tr(musig(),sortedmulti_a()) descriptor, verifying it, and importing it.

Gaps that need new functionality in C++

Part of #35645.

@DrahtBot

DrahtBot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

Type Reviewers
ACK BenWestgate
Concept NACK pseudoramdom

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:

  • #29247 (CAT in Tapscript (BIP-347) by arminsabouri)

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.

@rxbryan
rxbryan marked this pull request as ready for review September 24, 2026 21:29
Following the discussion on bitcoin#36143, this commit adds a python
utility implementing the multisig setup flow tracked in bitcoin#35645
using available RPCs and implements work arounds for missing RPC
or wallet features.

Adds wallet creation and key generation step.

The wallet cannot store a name for a key, so cosigner names live
in the setup and are lost on import.
Check a key expression before recording it, and reject private keys,
derivation paths, multipath derivations, keys without origin information
and duplicates.

The wizard also requires the BIP 87 path, which the descriptor layer does
not.
Builds the ranged, multipath descriptor from the collected keys and
a call to getdescriptorinfo checks the resulting descriptor and
supplys the checksum.

For taproot the key path is a MuSig2 aggregate of all n keys
rather than a fixed or variable NUMS point: it cannot bypass the
policy, since spending that way needs every signer, and it avoids
the fingerprinting using a well-known internal key would cause.
analyze_descriptor reports what the descriptor requires to spend.
Which cosigner we are, and the first receive address,

Accepted shapes are wsh(sortedmulti(...)) and, for taproot,
tr(KEY,sortedmulti_a(...)) where KEY is either musig() of exactly
the keys in the leaf, so that spending by key path needs
every cosigner, or the NUMS point, which is provably unspendable.
Anything else is rejected.

Names are local, so any cosigner we have no name for is reported
by fingerprint.
During the import process, the participant swaps their own key
expression in the descriptor for the private one since
importdescriptors reject a descriptor with no private keys when
the wallet has private keys enabled. See bitcoin#35377
@sedited

sedited commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Do we need this in the repository? Seems fine to me if it were just an external script.

@rxbryan

rxbryan commented Sep 26, 2026

Copy link
Copy Markdown
Author

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.

@BenWestgate BenWestgate left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK, only cursory code review of wizard.py but the interface and usage looks correct.

As for @sedited wondering if we need this in the repository:
For years, Core having user unfriendly multisig has been exploited by scammers to promote alternative multisig wallets with substantially less scrutiny than this repository.

Guides an orchestrator/participant through setting up a k-of-n multisig descriptor wallet.

This utility implements the multisig setup flow tracked in #35645 using available
RPCs and implements workarounds for missing RPC or wallet feature.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RPCs and implements workarounds for missing RPC or wallet feature.
RPCs and implements workarounds for missing RPC or wallet features.

*configurations*
`rpc` is a wallet rpc handle.
All steps require an unlocked wallet with private keys enabled.
A coordinator that does not contribute keys needs a watch-only wallet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A coordinator that does not contribute keys needs a watch-only wallet
A coordinator that does not contribute keys needs a watch-only wallet.

@kevkevinpal

Copy link
Copy Markdown
Contributor

I'm not sure we want this in this repository.

Looking at the other scripts in contrib I 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 #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.

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.

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

@BenWestgate

Copy link
Copy Markdown
Contributor

maintainers will need to worry about forever.

@rxbryan are you willing to maintain this script (including bug fixing) until the RPC obsoletes it?

If this were to be added it would make more sense to add it to the Bitcoin Core wallet.

@Sjors said in #36143 (comment) a wallet c++ implementation is premature and he preferred to:

1.introduce a Python utility that helps the user construct and import a multisig descriptor
2. gradually improve / add RPC methods to simplify that utility and eventually make it unnecessary

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.

@rxbryan

rxbryan commented Oct 5, 2026

Copy link
Copy Markdown
Author

maintainers will need to worry about forever.

@rxbryan are you willing to maintain this script (including bug fixing) until the RPC obsoletes it?

Yes. I'll maintain it, we have enough test cases to force a maintenance contract on whoever modifies code touching it.

@pseudoramdom

Copy link
Copy Markdown
Contributor

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

@BenWestgate

BenWestgate commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merging this would mean reviewing ~700 lines (script and functional test) whose job is to work around things we plan to fix.

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.

We'd then have to review again each time one of those fixes lands and removes a workaround.

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.

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.

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.

@BenWestgate

BenWestgate commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

tACK 2803e15
All wizard steps run on an offline node for 2-of-3 wsh(sortedmulti) at m/87h/1h/0h: create_wallet, generate_key, add_cosigner, assemble, verify and import_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, and testmempoolaccept allowed the result.

Review nits

  1. import_descriptor uses "timestamp": "now". In importdescriptors, "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 with Prune: 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: pass int(time.time()), or let the caller give a timestamp. On an online node the result is the same as "now".
  2. No backup step. After 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.

@achow101

achow101 commented Nov 3, 2026

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants