Skip to content

descriptor: add CreateMultisigDescriptor() - #36143

Open
rxbryan wants to merge 3 commits into
bitcoin:masterfrom
rxbryan:create-multisig-descriptor
Open

rxbryan wants to merge 3 commits into
bitcoin:masterfrom
rxbryan:create-multisig-descriptor

Conversation

@rxbryan

@rxbryan rxbryan commented Sep 1, 2026

Copy link
Copy Markdown

The multisig setup flows need to assemble a descriptor from collected cosigner keys without hand-crafting the descriptor string, which today means bash interpolation with no validation of key forms, duplicates, or threshold.

CreateMultisigDescriptor() takes a threshold, a list of key expressions with origin info, and an output type, and returns a ranged, multipath wsh(sortedmulti(...)) descriptor with checksum.

Part of the multisig wizard tracking issue #35645.

@DrahtBot

DrahtBot commented Sep 1, 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
Concept NACK Sjors
Concept ACK fametrano

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:

  • #36154 (wallet: fill PSBT_GLOBAL_XPUB by jeanpablojp)
  • #35918 (descriptor: Expose key expression parsing by pseudoramdom)

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.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • src/script/descriptor.cpp: complaint hardware wallets → compliant hardware wallets [wrong word changes the intended meaning]

2026-11-29 08:11:35

@Sjors

Sjors commented Sep 2, 2026

Copy link
Copy Markdown
Member

Concept NACK, unless this is part of a larger end-to-end implementation (with some buy-in), like a GUI or RPC that actually uses this new method.

But I also think that's premature. Wallet setup is a one-off thing, and it's not obvious what the best approach is. A Python utility is more flexible. A full c++ implementation is also likely to need a huge stack of commits, see e.g. Sjors#91 which only implements spending from an existing multisig wallet.

So I think the better sequence is:

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

Step (2) is where changes like this may be useful.

@rxbryan

rxbryan commented Sep 2, 2026

Copy link
Copy Markdown
Author

So I think the better sequence is:

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

That sequencing makes sense. Would exposing this via an RPC in the same PR address the "nothing uses it" concern, or do you specifically want the Python flow to exist first so the RPC surface is shaped by what that flow needs?

@Sjors

Sjors commented Sep 3, 2026

Copy link
Copy Markdown
Member

Would exposing this via an RPC in the same PR address the "nothing uses it" concern

Yes, but.

do you specifically want the Python flow to exist first so the RPC surface is shaped by what that flow needs?

I think that's the better yes.

@rxbryan rxbryan mentioned this pull request Sep 4, 2026
4 of 12 tasks
rxbryan added a commit to rxbryan/bitcoin that referenced this pull request Sep 24, 2026
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.
rxbryan added a commit to rxbryan/bitcoin that referenced this pull request Sep 25, 2026
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.
@rxbryan

rxbryan commented Sep 26, 2026

Copy link
Copy Markdown
Author

Following the Python wizard #36325, which exercises the actual setup flow, the contract for createMultisigDescriptor() is now concrete and has real consumers: the Python utility (#36325), the GUI, and potentially the createmultisig RPC.

It becomes a function that constructs ranged, multipath descriptors for bech32 and bech32m, as well as the unranged plain-key case createmultisig builds today.

This fits the multisig setup process better because the descriptor is built up front and becomes the source of truth, and bech32m falls out naturally. By contrast, createmultisig recovers its descriptor with InferDescriptor, which only sees the script: it always produces multi(...), since nothing in the script records that the keys were sorted, and its inputs are raw public keys, so there are no origins or ranges to express.

@rxbryan

rxbryan commented Sep 26, 2026

Copy link
Copy Markdown
Author

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

Step 1 is #36325. CreateMultisigDescriptor() would be the first change step 2 asks for.

@achow101

achow101 commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

unless this is part of a larger end-to-end implementation (with some buy-in), like a GUI or RPC that actually uses this new method.

In general it is, we want the GUI to be calling a utility function like this one to construct the descriptors for import.

We already have a createmultisig RPC, and it should be modernized to produce descriptors.

1.introduce a Python utility that helps the user construct and import a multisig descriptor

I think this is entirely unnecessary. The RPC already exists, it should be modernized and refactored such that the GUI can use it too.

@rxbryan
rxbryan force-pushed the create-multisig-descriptor branch from e0b664f to 13fed1a Compare October 6, 2026 12:41
@rxbryan

rxbryan commented Oct 6, 2026

Copy link
Copy Markdown
Author

createmultisig can delegate to CreateMultisigDescriptor() for key expressions and bech32m, while keeping its existing contract for hex pubkeys unchanged. That gives the GUI and the RPC one assembly function.

@rxbryan
rxbryan force-pushed the create-multisig-descriptor branch from 13fed1a to f89c8dd Compare October 6, 2026 12:58
@rxbryan
rxbryan marked this pull request as ready for review October 6, 2026 12:58
@rxbryan
rxbryan force-pushed the create-multisig-descriptor branch from f89c8dd to 589f3fe Compare October 6, 2026 16:20

@fametrano fametrano left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Concept ACK

rxbryan wrote that the descriptor is built up front and becomes the source of truth for the setup, so I checked that string against code outside Core, on 589f3fe. Over 98 cases (2 to 6 account xpubs with origin, every threshold, 49 per output type), Core's string equals the descriptor I expected, checksummed by bip32-descriptors, a library I maintain, in 98 of 98. The library derives the same receive and change scriptPubKeys at indexes 0 to 4: 980 of 980, 490 of them Taproot.

The string still depends on the order the keys come in: the six orders of the test's three keys give six descriptors and six checksums per output type, with the same scriptPubKeys, so cosigners who enter the keys in a different order get descriptors that do not compare equal. Sorting canonical_keys before assembly gave one descriptor for all six orders, scriptPubKeys unchanged. Could the keys be sorted, or the header say that the string depends on their order?

Gist: https://gist.github.com/fametrano/cc31cf590d6f7a977866849b1e67a998/3fb58384cdeb54184ce5f8599e351015c5d8a69e

The multisig setup flows need to assemble a descriptor from collected
cosigner keys without hand-crafting the descriptor string, which today
means bash interpolation with no validation of key forms, duplicates, or
threshold.

CreateMultisigDescriptor() takes a threshold, a list of key expressions
with origin info, and an output type, and returns a ranged, multipath
wsh(sortedmulti(...)) descriptor with checksum.

Parsing is done by the existing internal ParsePubkey(); the setup-specific
policy is applied here on top of it. Private key, missing origin
info, keys that already carry a derivation, and duplicate keys are all
rejected. The /<0;1>/* suffix is appended internally, so callers supply
bare account xpubs only.

Covered by unit tests in descriptor_tests.cpp.

Part of the multisig wizard backend tracked in bitcoin#35645.
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 that a well-known internal key would cause.

keys must be bare because derivation before aggregation cannot be
expressed in a BIP 388 policy
sortedmulti and sortedmulti_a sort keys when building the script,
and musig() sorts its participants when aggregating, so the key
input order does not affect address generation but does affect the
descriptor string.

We sort the keys so descriptor string and checksum produced
doesn't vary with key input order.
@rxbryan
rxbryan force-pushed the create-multisig-descriptor branch from 589f3fe to 753744f Compare November 29, 2026 08:11
@rxbryan

rxbryan commented Nov 29, 2026

Copy link
Copy Markdown
Author

Thanks @fametrano for the checks.
753744f now sorts the keys so a key set always produces the same descriptor string and checksum, whatever order the keys come in. Also added a test case for it.

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.

5 participants