descriptor: add CreateMultisigDescriptor() #36143

Open
rxbryan wants to merge 3 commits from create-multisig-descriptor into master AGit
rxbryan commented 2026-09-01 23:57:02 +00:00 (Migrated from github.com)

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.

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 commented 2026-09-01 23:57:10 +00:00 (Migrated from github.com)

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

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36143 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36143.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36143#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept NACK | [Sjors](https://github.com/bitcoin/bitcoin/pull/36143#issuecomment-5508988125) | | Concept ACK | [fametrano](https://github.com/bitcoin/bitcoin/pull/36143#pullrequestreview-5838137065) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36154](https://github.com/bitcoin/bitcoin/pull/36154) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36154.svg"></sub> (wallet: fill PSBT_GLOBAL_XPUB by jeanpablojp) * [#35918](https://github.com/bitcoin/bitcoin/pull/35918) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35918.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible typos and grammar issues: - `src/script/descriptor.cpp`: `complaint hardware wallets` → `compliant hardware wallets` [wrong word changes the intended meaning] <sup>2026-11-29 08:11:35</sup>
Sjors commented 2026-09-02 11:44:14 +00:00 (Migrated from github.com)

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. https://github.com/Sjors/bitcoin/pull/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.

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. https://github.com/Sjors/bitcoin/pull/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 commented 2026-09-02 23:23:56 +00:00 (Migrated from github.com)

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?

> 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 commented 2026-09-03 06:27:51 +00:00 (Migrated from github.com)

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.

> 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.
DrahtBot commented 2026-09-17 02:28:41 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
rxbryan commented 2026-09-26 09:31:44 +00:00 (Migrated from github.com)

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.

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 commented 2026-09-26 09:34:41 +00:00 (Migrated from github.com)

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.

> 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 commented 2026-09-29 22:11:52 +00:00 (Migrated from github.com)

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.

> 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.
First-time contributor

Earlier concerns neither republished nor resolved: 5 suggestions. See the Run archive linked from the Review report for their assessments.

🔴 Major · Metadata aliases bypass the multisig duplicate-key check

CreateMultisigDescriptor() accepts metadata variants of the same xpub as distinct cosigners, allowing one holder to satisfy a nominal 2-of-3 threshold; no current production caller was found.

Location: src/script/descriptor.cpp:3131 (head).

🟠 Minor · Depth-254/255 xpubs produce descriptors that cannot expand

With an unusually deep or metadata-altered xpub at depth 254 or 255, CreateMultisigDescriptor() succeeds although neither branch can generate addresses; no current production caller supplying such inputs was found.

Location: src/script/descriptor.cpp:3154 (head).

🔵 Suggestion · Private-key rejection echoes secrets in diagnostics

Only unit tests currently call CreateMultisigDescriptor(), but rejected WIF and xprv inputs are copied verbatim into its returned diagnostics.

Location: src/script/descriptor.cpp:3104 (head).

🔵 Suggestion · The Taproot commit lacks its positive construction test

The positive test for tr(musig(...),sortedmulti_a(...)) appears only in the later sorting commit, leaving the Taproot commit without an assertion of the output it introduces.

Location: src/script/descriptor.cpp:3068 (commit).

Review coverage was incomplete.


Reviewed: 753744fd5c88 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afedb19cca4c3b40d89514fb0c66b0c20e4f5d62 --> <!-- ralph-head:753744fd5c88e515b2e92b769d8e348f06f54217 --> <!-- ralph-case:7dd419f4acd8523165a3ba368d7a05a173e85f5d5a22d00572ce4dd44dfe5161 --> Earlier concerns neither republished nor resolved: 5 suggestions. See the Run archive linked from the Review report for their assessments. **🔴 Major · Metadata aliases bypass the multisig duplicate-key check** `CreateMultisigDescriptor()` accepts metadata variants of the same `xpub` as distinct cosigners, allowing one holder to satisfy a nominal 2-of-3 threshold; no current production caller was found. Location: [`src/script/descriptor.cpp:3131`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/753744fd5c88e515b2e92b769d8e348f06f54217/src/script/descriptor.cpp#L3131>) (head). **🟠 Minor · Depth-254/255 `xpub`s produce descriptors that cannot expand** With an unusually deep or metadata-altered `xpub` at depth 254 or 255, `CreateMultisigDescriptor()` succeeds although neither branch can generate addresses; no current production caller supplying such inputs was found. Location: [`src/script/descriptor.cpp:3154`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/753744fd5c88e515b2e92b769d8e348f06f54217/src/script/descriptor.cpp#L3154>) (head). **🔵 Suggestion · Private-key rejection echoes secrets in diagnostics** Only unit tests currently call `CreateMultisigDescriptor()`, but rejected `WIF` and `xprv` inputs are copied verbatim into its returned diagnostics. Location: [`src/script/descriptor.cpp:3104`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/753744fd5c88e515b2e92b769d8e348f06f54217/src/script/descriptor.cpp#L3104>) (head). **🔵 Suggestion · The Taproot commit lacks its positive construction test** The positive test for `tr(musig(...),sortedmulti_a(...))` appears only in the later sorting commit, leaving the Taproot commit without an assertion of the output it introduces. Location: src/script/descriptor.cpp:3068 (commit). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`753744fd5c88`](<https://git.fish.foo/bitcoin/bitcoin/commit/753744fd5c88e515b2e92b769d8e348f06f54217>) · [Review report](<https://review.fish.foo/report/36143-753744fd5c88e515b2e92b769d8e348f06f54217-3295-4.html>) · [Previous reports](<https://review.fish.foo/traces/36143/>) [permalink](<https://review.fish.foo/report/36143-753744fd5c88e515b2e92b769d8e348f06f54217-3295-4.html>)
rxbryan commented 2026-10-06 12:57:31 +00:00 (Migrated from github.com)

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.

`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.
fametrano (Migrated from github.com) reviewed 2026-11-10 07:24:07 +00:00
fametrano (Migrated from github.com) left a comment

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 589f3fe6b5. 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

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 589f3fe6b5. 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
rxbryan commented 2026-11-29 08:33:25 +00:00 (Migrated from github.com)

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.

Thanks @fametrano for the checks. [753744f](https://github.com/bitcoin/bitcoin/pull/36143/commits/753744fd5c88e515b2e92b769d8e348f06f54217) 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 in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36143
No description provided.