tests: add functional test for tr musig2 miniscript decaying multisig #35443

Open
mjdietzx wants to merge 1 commit from test_tr_miniscript_decaying_multiscript_descriptor into master AGit
mjdietzx commented 2026-06-02 16:02:07 +00:00 (Migrated from github.com)

This is closely based on test/functional/wallet_miniscript_decaying_multisig_descriptor_psbt.py both in code and concept. It builds the same "decaying" multisig that starts as 4-of-4 and decays to 3-of-4, 2-of-4, and finally 1-of-4 at each future halvening block height, but as a Taproot output, combining Taproot, Miniscript, and MuSig2 in a single descriptor of the form tr(musig(key_1,key_2,key_3,key_4),thresh(4,pk(key_1),s:pk(key_2),s:pk(key_3),s:pk(key_4),sln:after(t1),sln:after(t2),sln:after(t3))). While every signer is available the 4-of-4 is spent through the Taproot key path using a MuSig2 aggregate of the participants, which is the cheapest and most private spend, while the Miniscript script path is a fallback used only when a key becomes inaccessible, so a lost key never permanently strands the funds and the key path stays available even after the multisig has fully decayed. As with the wsh version the signers are plain single-key wallets and the multisig is watch-only, so everything needed to sign (including the MuSig2 participant pubkeys) is carried in the PSBT and signers never import the multisig descriptor. It serves as integration testing for Taproot, Miniscript, and MuSig2 descriptors working together, and like the wsh test is meant to be documentation as much as a functional test, so it is kept as simple and readable as possible.

Note: this thresh-based design has BIP110-invalid script-path spends. sln:after compiles to OP_IF in the tapscript leaf (the key-path spend is unaffected). I implemented an alternative that avoids this by splitting the decay into separate timelocked multi_a tapleaves (no OP_IF) in e0482ec. It's a quick, less-thoroughly-tested implementation, but I wanted to present it in case reviewers prefer that approach.

This is closely based on [test/functional/wallet_miniscript_decaying_multisig_descriptor_psbt.py](https://github.com/bitcoin/bitcoin/blob/master/test/functional/wallet_miniscript_decaying_multisig_descriptor_psbt.py) both in code and concept. It builds the same "decaying" multisig that starts as 4-of-4 and decays to 3-of-4, 2-of-4, and finally 1-of-4 at each future halvening block height, but as a Taproot output, combining Taproot, Miniscript, and MuSig2 in a single descriptor of the form `tr(musig(key_1,key_2,key_3,key_4),thresh(4,pk(key_1),s:pk(key_2),s:pk(key_3),s:pk(key_4),sln:after(t1),sln:after(t2),sln:after(t3)))`. While every signer is available the 4-of-4 is spent through the Taproot key path using a MuSig2 aggregate of the participants, which is the cheapest and most private spend, while the Miniscript script path is a fallback used only when a key becomes inaccessible, so a lost key never permanently strands the funds and the key path stays available even after the multisig has fully decayed. As with the `wsh` version the signers are plain single-key wallets and the multisig is watch-only, so everything needed to sign (including the MuSig2 participant pubkeys) is carried in the PSBT and signers never import the multisig descriptor. It serves as integration testing for Taproot, Miniscript, and MuSig2 descriptors working together, and like the `wsh` test is meant to be documentation as much as a functional test, so it is kept as simple and readable as possible. Note: this thresh-based design has BIP110-invalid script-path spends. `sln:after` compiles to `OP_IF` in the tapscript leaf (the key-path spend is unaffected). I implemented an alternative that avoids this by splitting the decay into separate timelocked `multi_a` tapleaves (no `OP_IF`) in [e0482ec](https://github.com/bitcoin/bitcoin/commit/e0482eca19d520ff69dcdd59c676affc5ecf7c66). It's a quick, less-thoroughly-tested implementation, but I wanted to present it in case reviewers prefer that approach.
DrahtBot commented 2026-06-02 16:02:15 +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
ACK rkrux, fametrano

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • halvening -> halving [misspelled; the intended Bitcoin term is “halving”]

2026-06-02 16:02:31

<!--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/35443 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35443.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35443#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 | | ---- | --------- | | ACK | [rkrux](https://github.com/bitcoin/bitcoin/pull/35443#pullrequestreview-5668461708), [fametrano](https://github.com/bitcoin/bitcoin/pull/35443#pullrequestreview-5819349355) | 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. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible typos and grammar issues: - halvening -> halving [misspelled; the intended Bitcoin term is “halving”] <sup>2026-06-02 16:02:31</sup>
rkrux (Migrated from github.com) reviewed 2026-06-03 15:25:42 +00:00
rkrux (Migrated from github.com) left a comment

Concept ACK e588094

Based on a cursory glance, there is a lot of similarity with the other test mentioned in the PR description along with a duplicated method.

Consider merging these two files into one while getting rid of the duplication?

Concept ACK e588094 Based on a cursory glance, there is a lot of similarity with the other test mentioned in the PR description along with a duplicated method. Consider merging these two files into one while getting rid of the duplication?
mjdietzx commented 2026-06-03 16:57:14 +00:00 (Migrated from github.com)

there is a lot of similarity with the other test mentioned in the PR description

Correct, the two tests are (intentionally) similar. This is meant to be a "baby step" improving the privacy of wallet_miniscript_decaying_multisig_descriptor_psbt.py

Screenshot 2026-06-03 at 10 44 47 AM

So they are generally the same aside from _spend_keypath and the test conditions exercising that.

That said, my preference is keeping these tests separate to prioritize them being maximally simple and easy to follow. I think the "documentation" value of these tests is greater than the test coverage provided. So in that spirit I intentionally duplicated some code to keep these tests elegant and straightforward incase someone references it while creating a wallet.

Thanks for the valid feedback, if more reviewers prefer consolidating I am open to it! These tests could be easily combined (also the OG test/functional/wallet_multisig_descriptor_psbt.py). But I preferred the 3 part series showing my preferred multisig in core as new technology matures: basic m-of-n => decaying miniscript => this.

> there is a lot of similarity with the other test mentioned in the PR description Correct, the two tests are (intentionally) similar. This is meant to be a "baby step" improving the privacy of `wallet_miniscript_decaying_multisig_descriptor_psbt.py` <img width="1186" height="77" alt="Screenshot 2026-06-03 at 10 44 47 AM" src="/attachments/969b525c-b944-427d-ab8b-7aa82d0db62a" /> So they are generally the same aside from `_spend_keypath` and the test conditions exercising that. That said, my preference is keeping these tests separate to prioritize them being maximally simple and easy to follow. I think the "documentation" value of these tests is greater than the test coverage provided. So in that spirit I intentionally duplicated some code to keep these tests elegant and straightforward incase someone references it while creating a wallet. Thanks for the valid feedback, if more reviewers prefer consolidating I am open to it! These tests could be easily combined (also the OG `test/functional/wallet_multisig_descriptor_psbt.py`). But I preferred the 3 part series showing my preferred multisig in core as new technology matures: basic m-of-n => decaying miniscript => this.
First-time contributor

Base: 631b0065a7f2696a7240db4bbb63589444dc96b8
Head: e5880944cba298c04ad5fe4acd2c6208784554cc

Findings

Minor

The example’s first decay height has already passed (doc/descriptors.md:51, head)

Block 840,000 was mined on April 20, 2024. The example’s after(840000) branch is therefore already satisfied, so adapting the descriptor with your own keys permits a 3-of-4 script-path spend immediately, contrary to the description of a future decay. Update the Taproot example’s locktimes or label them as historical. No current production wallet using this example was identified, so deployment impact is unconfirmed. (blockchain.com)

Suggestions

Exercise non-prefix signer subsets in decayed spends (test/functional/wallet_taproot_decaying_multisig_descriptor_psbt.py:135, head)

random.sample(range(self.M), self.M) randomizes signing order but always selects the first M signers. Thus the 3-of-4, 2-of-4, and 1-of-4 script-path cases only use indices 0–2, 0–1, and 0, respectively; the initial 4-of-4 spend does not test those lower thresholds with a non-prefix subset. Please choose deterministic representative subsets across the decay stages so the test covers lower-threshold spends that include later-index signers.

Previously reported; verified as still present in this revision. Status: still_present. Author position: none. Originally reported at e5880944cba298c04ad5fe4acd2c6208784554cc. The prefix-only signer selection remains in the new Taproot test. The base WSH test has an analogous sampling pattern, but this PR adds the Taproot-specific test and its subset-coverage gap, so the finding is not unchanged.

Review coverage was incomplete.

Review limitations
  • verifier: Decision withheld: invalid candidate ID accounting
  • verifier: Finding withheld: Candidate ID appears in multiple decisions

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:07e6f9b519d677c46869e755d75661fb116896a6f8263852f18f7dadf6dbfe40:7904dbcc7b2243bfe123ccb0aaaca2ac080b278ec99bb35aa62cf1481ce82fc1 --> Base: `631b0065a7f2696a7240db4bbb63589444dc96b8` Head: `e5880944cba298c04ad5fe4acd2c6208784554cc` <!-- ralph-case:4cdf0fd27fa2af2ffa99ec976d989772c9bc7f5892970fe958a4d669f9d0a773 --> ##### Findings **Minor** **The example’s first decay height has already passed** (doc/descriptors.md:51, head) Block 840,000 was mined on April 20, 2024. The example’s `after(840000)` branch is therefore already satisfied, so adapting the descriptor with your own keys permits a 3-of-4 script-path spend immediately, contrary to the description of a future decay. Update the Taproot example’s locktimes or label them as historical. No current production wallet using this example was identified, so deployment impact is unconfirmed. ([blockchain.com](https://www.blockchain.com/en/explorer/blocks/btc/840000?utm_source=openai)) **Suggestions** **Exercise non-prefix signer subsets in decayed spends** (test/functional/wallet_taproot_decaying_multisig_descriptor_psbt.py:135, head) `random.sample(range(self.M), self.M)` randomizes signing order but always selects the first M signers. Thus the 3-of-4, 2-of-4, and 1-of-4 script-path cases only use indices 0–2, 0–1, and 0, respectively; the initial 4-of-4 spend does not test those lower thresholds with a non-prefix subset. Please choose deterministic representative subsets across the decay stages so the test covers lower-threshold spends that include later-index signers. Previously reported; verified as still present in this revision. Status: still_present. Author position: none. Originally reported at `e5880944cba298c04ad5fe4acd2c6208784554cc`. The prefix-only signer selection remains in the new Taproot test. The base WSH test has an analogous sampling pattern, but this PR adds the Taproot-specific test and its subset-coverage gap, so the finding is not unchanged. Review coverage was incomplete. ##### Review limitations - verifier: Decision withheld: invalid candidate ID accounting - verifier: Finding withheld: Candidate ID appears in multiple decisions [Full review report](<https://review.fish.foo/traces/35443-e5880944cba298c04ad5fe4acd2c6208784554cc-1483-2.html>)
rkrux (Migrated from github.com) reviewed 2026-10-12 14:16:58 +00:00
rkrux (Migrated from github.com) left a comment

Please rebase this PR over master, otherwise there's a CMake error in building this branch on local related to the outdate libevent library (which can be worked around by rebasing on local though).

Please rebase this PR over master, otherwise there's a CMake error in building this branch on local related to the outdate libevent library (which can be worked around by rebasing on local though).
rkrux (Migrated from github.com) commented 2026-10-12 14:15:35 +00:00

Doesn't this assert need to be in the loop?

Doesn't this assert need to be in the loop?
rkrux (Migrated from github.com) approved these changes 2026-10-27 14:17:15 +00:00
rkrux (Migrated from github.com) left a comment

lgtm ACK e5880944cb

lgtm ACK e5880944cba298c04ad5fe4acd2c6208784554cc
rkrux (Migrated from github.com) commented 2026-10-27 14:13:04 +00:00

Each halvening

This particular example doesn't contain any halvening related timelocks. It can be avoided in the description as well.

> Each halvening This particular example doesn't contain any halvening related timelocks. It can be avoided in the description as well.
rkrux (Migrated from github.com) commented 2026-10-27 14:14:03 +00:00

Nvm, this seems fine outside the loop to check the final completeness of the PSBT post both the rounds.

Nvm, this seems fine outside the loop to check the final completeness of the PSBT post both the rounds.
fametrano (Migrated from github.com) reviewed 2026-11-08 19:34:39 +00:00
fametrano (Migrated from github.com) left a comment

tACK e5880944cb

I compared the test's descriptor, its five spends and the new doc/descriptors.md example with code outside Core, on master 49c3c7fe09 with this commit applied. bip32-descriptors, a library I maintain, derives the same receive and change addresses as deriveaddresses at indexes 0 to 19, for the test's descriptor and for the doc example: 80 of 80. btclib's script interpreter accepts all five spends the test broadcasts, each against an output script bip32-descriptors derived. Two are MuSig2 key-path spends. The script-path spends with lock times 104, 106 and 108 carry 3, 2 and 1 signatures and execute 1, 2 and 3 CHECKLOCKTIMEVERIFY. A flipped signature byte makes each spend fail. Raising the first after() by one block changes all 80 addresses.

Gist: https://gist.github.com/fametrano/43a546b703a720c9313995568ddb00b3/0b0054e0143591d093a65d5231af7e3bae134a3b

tACK e5880944cba298c04ad5fe4acd2c6208784554cc I compared the test's descriptor, its five spends and the new doc/descriptors.md example with code outside Core, on master 49c3c7fe09 with this commit applied. bip32-descriptors, a library I maintain, derives the same receive and change addresses as `deriveaddresses` at indexes 0 to 19, for the test's descriptor and for the doc example: 80 of 80. btclib's script interpreter accepts all five spends the test broadcasts, each against an output script bip32-descriptors derived. Two are MuSig2 key-path spends. The script-path spends with lock times 104, 106 and 108 carry 3, 2 and 1 signatures and execute 1, 2 and 3 CHECKLOCKTIMEVERIFY. A flipped signature byte makes each spend fail. Raising the first `after()` by one block changes all 80 addresses. Gist: https://gist.github.com/fametrano/43a546b703a720c9313995568ddb00b3/0b0054e0143591d093a65d5231af7e3bae134a3b
sedited commented 2026-11-12 13:40:22 +00:00 (Migrated from github.com)

I implemented an alternative that avoids this by splitting the decay into separate timelocked multi_a tapleaves

That seems preferable to me. Why did you not push that instead?

> I implemented an alternative that avoids this by splitting the decay into separate timelocked multi_a tapleaves That seems preferable to me. Why did you not push that instead?
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!35443
No description provided.