Skip to content

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

Open
mjdietzx wants to merge 1 commit into
bitcoin:masterfrom
mjdietzx:test_tr_miniscript_decaying_multiscript_descriptor
Open

mjdietzx wants to merge 1 commit into
bitcoin:masterfrom
mjdietzx:test_tr_miniscript_decaying_multiscript_descriptor

Conversation

@mjdietzx

@mjdietzx mjdietzx commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

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.

@DrahtBot DrahtBot added the Tests label Jun 2, 2026
@DrahtBot

DrahtBot commented Jun 2, 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 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

@rkrux rkrux 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.

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

mjdietzx commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

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.

sedited added a commit that referenced this pull request Jun 8, 2026
…criptor_psbt

5b65e31 test: remove two unnecessary nodes from the test (rkrux)

Pull request description:

  A discussion in the review of #35443 PR brought this test to my attention.

  The test needs multiple wallets that can be created on a single node, multiple nodes are not required.

  As there is a cost associated with setting-up and tearing-down nodes, this patch helps in reducing the test time as well.

ACKs for top commit:
  ekzyis:
    ACK 5b65e31
  polespinasa:
    lgtm ACK 5b65e31
  sedited:
    ACK 5b65e31

Tree-SHA512: f6b4a96b9beee968ef5438fd9db582a48834ff36ba27c19dd7012902528fa713424212530e34cc16b58c19c023f1accd2b89fe846ef2cc36677c24e160c5b817
@sedited
sedited requested a review from darosior August 27, 2026 11:22
@sedited
sedited requested a review from rkrux October 9, 2026 12:38

@rkrux rkrux 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.

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).

@@ -0,0 +1,176 @@
#!/usr/bin/env python3
# Copyright (c) 2024-present The Bitcoin Core developers

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.

s/2024/2026

Comment on lines +118 to +121
under_signed = multisig.walletcreatefundedpsbt(inputs=[], outputs={receiver.getnewaddress(): amount}, feeRate=0.00010, locktime=0)["psbt"]
for _ in range(2):
under_signed = self.node.combinepsbt([signers[m].walletprocesspsbt(under_signed, finalize=False)["psbt"] for m in range(self.N - 1)])
assert_equal(self.node.finalizepsbt(under_signed)["complete"], False)

@rkrux rkrux Oct 12, 2026 •

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.

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

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.

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

@rkrux rkrux 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.

lgtm ACK e588094

Comment thread doc/descriptors.md

Whenever all four signers are available, the funds are spent through the **key path** using a single key that aggregates the participants. This is the cheapest and most private spend: it looks like any other single-key output and produces just one signature, though it takes two rounds of communication (each signer first contributes a public nonce, then a partial signature, exchanged as PSBTs). The key path remains available at all times — the wallet does not "decay" into needing fewer signers.

The **script path** is a fallback used only when a key has become inaccessible. Each halvening relaxes that fallback to require one fewer signer (3-of-4, then 2-of-4, then 1-of-4), so a lost key never permanently strands the funds. It is otherwise avoided because revealing the script makes the spend larger and less private.

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.

Each halvening

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

Comment on lines +118 to +121
under_signed = multisig.walletcreatefundedpsbt(inputs=[], outputs={receiver.getnewaddress(): amount}, feeRate=0.00010, locktime=0)["psbt"]
for _ in range(2):
under_signed = self.node.combinepsbt([signers[m].walletprocesspsbt(under_signed, finalize=False)["psbt"] for m in range(self.N - 1)])
assert_equal(self.node.finalizepsbt(under_signed)["complete"], False)

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.

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

@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.

tACK e588094

I compared the test's descriptor, its five spends and the new doc/descriptors.md example with code outside Core, on master 49c3c7f 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

sedited commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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?

@mjdietzx

Copy link
Copy Markdown
Contributor Author

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

I preferred this all things considered. Hard to know what most would prefer so I went with what I considered simpler and easier to understand

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants