achow101
commented at 10:32 pm on March 18, 2024:
member
This PR implements MuSig2 descriptors (BIP 390), derivation (BIP 328), and PSBT fields (BIP 373) so that the wallet can receive and spend from taproot addresses that have keys involving a MuSig2 aggregate key.
The libsecp musig module is enabled so that it can be used for all of the MuSig2 cryptography.
Secnonces are handled in a separate class which holds the libsecp secnonce object in a secure_unique_ptr. Since secnonces must not be used, this class has no serialization and will only live in memory. A restart of the software will require a restart of the MuSig2 signing process.
DrahtBot
commented at 10:32 pm on March 18, 2024:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
#32489 (wallet: Add exportwatchonlywallet RPC to export a watchonly version of a wallet by achow101)
#32471 (wallet/rpc: fix listdescriptors RPC fails to return descriptors with private key information when wallet contains descriptors missing any key by Eunovo)
#32332 (refactor: Update XOnlyPubKey::GetKeyIDs() to return a pair of pubkeys by w0xlt)
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:
in musig.h: “secp25k1_musig_secnonce” → “secp256k1_musig_secnonce” [correct the library name for clarity]
drahtbot_id_4_m
DrahtBot added the label
Wallet
on Mar 18, 2024
DrahtBot added the label
CI failed
on Mar 19, 2024
DrahtBot
commented at 2:45 am on March 19, 2024:
contributor
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.
Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
Leave a comment here, if you need help tracking down a confusing failure.
in
test/functional/wallet_musig.py:125
in
a1e4c323dboutdated
144+ for deriv_path in dec_psbt["inputs"][0]["taproot_bip32_derivs"]:
145+ if deriv_path["pubkey"] in part_pks:
146+ part_pks.remove(deriv_path["pubkey"])
147+ assert_equal(len(part_pks), 0)
148+
149+ nonce_psbts = []
a1e4c323dbff9fa5095cf216d7cd528f10a1feeb: and that this is where round 2 happens (maybe link to the BIP at the top of the test and briefly summarise the steps)
in
test/functional/wallet_musig.py:155
in
a1e4c323dboutdated
161+ for wallet in wallets:
162+ proc = wallet.walletprocesspsbt(comb_nonce_psbt)
163+ assert_equal(proc["complete"], False)
164+ psig_psbts.append(proc["psbt"])
165+
166+ comb_psig_psbt = self.nodes[0].combinepsbt(psig_psbts)
a1e4c323dbff9fa5095cf216d7cd528f10a1feeb: because all wallets live on the same node, it’s useful to point out here that anyone, including non-participants can combine the partial signatures. Which is why the non-wallet combinepsbt and finalizepsbt RPC’s are used.
Sjors
commented at 2:22 pm on March 19, 2024:
member
Very cool stuff! Will review more later.
This pulls in (an older version of) the musig module in libsecp
What do you mean by “older”? Just that the PR to libsecp needs another rebase?
An open question is whether the approach for handling the secnonces is ideal and safe. Since nonces must not be reused, this PR holds them exclusively in memory, so a restart of the software will require a restart of the MuSig2 signing process.
It sounds safe, but not ideal, which might make it unsafe. Every Bitcoin Core instance involved would need to keep running, with the wallet loaded (and decrypted?) throughout the two rounds. For an airgapped setup with keys in multiple locations, the node in each location would have to be left running unattended (assuming one person running between them).
My understanding is that Ledger (cc @bigspider) creates a nonce, stores it, and then deletes it from storage as soon as it’s loaded (before signing). We could similarly store the nonce in our wallet and then delete the field at the start of the new round. For safety we could disable backups and dump RPC’s while a round is in progress (e.g. with a NO_BACKUP flag).
That only prevents accidental replay, not a replay attack, but it seems that anyone who is able to replay a node, already has access to its private keys (from the time a wallet was decrypted), so can’t do additional harm?
Implementation questions.
I tried making a 2 party tr(musig(A,B)) in a blank wallet. Initially I obtained two private keys and their public keys from another legacy wallet. I gave the new Alice wallet her private key and Bob’s public key, i.e. tr(musig(a,B)/0/*) but this failed with Ranged musig() requires all participants to be xpubs. Why though? Given that bip-musig2-derivation defines a virtual root xpub, and providers a fake chaincode, this restriction seems unneeded? (though it’s not blocker either, with descriptor wallets it’s easy to get an xpub - after #29130 anyway)
Once I had two wallets, I could see they generated the same receive address, nice! I then imported the same xpub/xpriv pair for the change address 1/*. I sent some (signet) coins to it, which arrived and confirmed.
Sadly after the GUI rugged me :-) Trying to send any amount elsewhere resulted in “Signing transaction failed” followed by “Transaction creation failed!”. Whereas I was hoping to get a PSBT this way.
Using the send RPC I do get a PSBT (from Alice). I had the musig2_participant_pubkeys set, but no musig2_pubnonces. That required calling walletprocesspsbt which seems an unnecessary extra step (but such fine tuning can wait). On Bob’s side the GUI complained with “Could not sign any more inputs”, but it did add a nonce.
At this point all the nonces were commited, so Bob could have added his partial signature. But at the stage the GUI crashes when trying to sign: [libsecp256k1] illegal argument: secp256k1_memcmp_var(&nonce->data[0], secp256k1_musig_pubnonce_magic, 4) == 0.
After a restart Bob’s walletprocesspsbt command didn’t fail. Which seems wrong: at this point the nonce should be gone, which he should complain about.
Starting with a fresh transaction, sing only the RPC I got the same crash, i.e.:
Alice: send
Alice: processpsbt
Bob: processpsbt
Bob: processpsbt: crash
Perhaps relevant: Bob’s wallet is encrypted, though it was unlocked throughout steps 3 and 4.
0% test/functional/wallet_musig.py
12024-03-19T14:23:33.113000Z TestFramework (INFO): PRNG seed is: 647071992440405417422024-03-19T14:23:33.115000Z TestFramework (INFO): Initializing test directory /var/folders/h6/qrb4j9vn6530kp7j4ymj934h0000gn/T/bitcoin_func_test_66knao3l
32024-03-19T14:23:35.070000Z TestFramework (INFO): Testing rawtr(musig(keys/*))
42024-03-19T14:23:35.192000Z TestFramework (ERROR): Unexpected exception caught during testing
(didn’t check if it’s the same crash)
bigspider
commented at 2:36 pm on March 19, 2024:
none
My understanding is that Ledger (cc @bigspider) creates a nonce, stores it, and then deletes it from storage as soon as it’s loaded (before signing). We could similarly store the nonce in our wallet and then delete the field at the start of the new round. For safety we could disable backups and dump RPC’s while a round is in progress (e.g. with a NO_BACKUP flag).
Not yet implemented, but that’s the plan: store nonces in flash memory (persistent memory) after generation; remove them from flash memory before signing starts (therefore, they’re gone even if there is a later failure, and signing must restart from nonce generation).
Note that there is no backup possibility for the persistent memory.
achow101
commented at 3:52 pm on March 19, 2024:
member
What do you mean by “older”? Just that the PR to libsecp needs another rebase?
I pulled in a commit that is probably outdated at this point. There may have been API changes since.
We could similarly store the nonce in our wallet and then delete the field at the start of the new round. For safety we could disable backups and dump RPC’s while a round is in progress (e.g. with a NO_BACKUP flag).
Disabling backups with a flag would not help as an oft suggested method for backing up a wallet is by copying the wallet file. There’s nothing that we can do about that, so to be safe, I don’t think we can store the nonces in the wallet file.
I tried making a 2 party tr(musig(A,B)) in a blank wallet. Initially I obtained two private keys and their public keys from another legacy wallet. I gave the new Alice wallet her private key and Bob’s public key, i.e. tr(musig(a,B)/0/*) but this failed with Ranged musig() requires all participants to be xpubs. Why though? Given that bip-musig2-derivation defines a virtual root xpub, and providers a fake chaincode, this restriction seems unneeded? (though it’s not blocker either, with descriptor wallets it’s easy to get an xpub - after #29130 anyway)
It’s specified in bip-musig2-descriptors that the musig must only contain xpubs if the aggregate will be derived from. I believe the rationale for this is that xpubs are intended to have derivation done on them whereas normal keys are not, and so there may be particular handling of such keys to deal with possibilities of derivation doing something unexpected, and so if we do anything with derivation, we should only use keys that are intended for derivation to avoid any confusion. I think @sipa was the one who made this suggestion.
Sadly after the GUI rugged me :-) Trying to send any amount elsewhere resulted in “Signing transaction failed” followed by “Transaction creation failed!”. Whereas I was hoping to get a PSBT this way.
The GUI may be expecting that at least one signature is produced, but we can’t do that with musig without at least one round with the cosigners. I have it implemented such that ProduceSignature does not report the tx as being signed until there is actually a signature, so even the partial sigs generation will not return “signed”.
After a restart Bob’s walletprocesspsbt command didn’t fail. Which seems wrong: at this point the nonce should be gone, which he should complain about.
Currently it just ignores if there is already a nonce for a participant’s key. It doesn’t replace the nonce, but it also doesn’t validate whether that key belongs to the wallet or whether the nonce exists in the wallet.
At this point all the nonces were commited, so Bob could have added his partial signature. But at the stage the GUI crashes when trying to sign: [libsecp256k1] illegal argument: secp256k1_memcmp_var(&nonce->data[0], secp256k1_musig_pubnonce_magic, 4) == 0.
…
Starting with a fresh transaction, sing only the RPC I got the same crash, i.e.:
Perhaps relevant: Bob’s wallet is encrypted, though it was unlocked throughout steps 3 and 4.
0% test/functional/wallet_musig.py
12024-03-19T14:23:33.113000Z TestFramework (INFO): PRNG seed is: 647071992440405417422024-03-19T14:23:33.115000Z TestFramework (INFO): Initializing test directory /var/folders/h6/qrb4j9vn6530kp7j4ymj934h0000gn/T/bitcoin_func_test_66knao3l
32024-03-19T14:23:35.070000Z TestFramework (INFO): Testing rawtr(musig(keys/*))
42024-03-19T14:23:35.192000Z TestFramework (ERROR): Unexpected exception caught during testing
(didn’t check if it’s the same crash)
Huh, works fine for me.
Sjors
commented at 4:37 pm on March 19, 2024:
member
Huh, works fine for me.
This was on Intel macOS 14.4 with a clean checkout and ./configure --disable-bench --disable-tests --enable-wallet --disable-fuzz-binary --disable-zmq --with-gui.
On Ubuntu 23.10 with gcc 13.2.0 the test do pass, odd.
(if this still happens after CI passes, I’ll dig a bit deeper, for now I’ll just test on Ubuntu)
I don’t think we can store the nonces in the wallet file.
Storing them in some other file might be fine too. As long as we delete it upon read, don’t sign anything if deletion fails and maybe also commit to some unique property of the PSBT.
Currently it just ignores if there is already a nonce for a participant’s key.
I guess we need to distinguish here between a nonce for our own key and one for other participants. We have no idea if some other node crashed. But it does seem reasonable to fail if we see a nonce for ourselves. Whether we previously crashed or if someone is trying a replay attack doesn’t really matter. Though it’s unusual for processpsbt to fail when called twice normally, here it seems justifiable.
Update: successfully completed the MuSig2 signing on Ubuntu!
achow101 force-pushed
on Mar 19, 2024
achow101 force-pushed
on Mar 20, 2024
achow101 force-pushed
on Mar 25, 2024
achow101 force-pushed
on Mar 25, 2024
achow101 force-pushed
on Mar 25, 2024
achow101 force-pushed
on Mar 26, 2024
DrahtBot added the label
Needs rebase
on Mar 29, 2024
achow101 force-pushed
on Apr 1, 2024
DrahtBot removed the label
Needs rebase
on Apr 1, 2024
Sjors
commented at 10:36 am on April 2, 2024:
member
Only 3 red CI machines to go :-)
achow101 force-pushed
on Apr 2, 2024
achow101
commented at 5:10 pm on April 2, 2024:
member
Sjors
commented at 8:05 am on April 3, 2024:
member
The test passes for me now on macOS.
DrahtBot added the label
Needs rebase
on Apr 6, 2024
achow101 force-pushed
on Apr 16, 2024
bitcoin deleted a comment
on May 23, 2024
bigspider
commented at 11:43 am on June 6, 2024:
none
Hi all,
an early alpha of the Ledger Bitcoin Testnet app with MuSig2 support is available for testing. (NB: the app is called Bitcoin Test Musig and not Bitcoin Test). It should be compatible with the latest draft of the specs.
Instructions and an easy end-2-end script for MuSig signing to play with it is available here for anyone interested in trying it out:
bigspider
commented at 6:09 pm on November 5, 2024:
These three constants are 0x1a , 0x1b, 0x1c in the final version of BIP-373.
achow101
commented at 8:11 pm on November 5, 2024:
Good catch! Fixed.
achow101 force-pushed
on Nov 5, 2024
fanquake referenced this in commit
80cb630bd9
on Nov 6, 2024
bigspider
commented at 11:37 am on November 6, 2024:
none
EDIT: this is now resolved.
The current implementation seems to be using the aggregate pubkey (before the tweaks) inside the key of the PSBT_IN_MUSIG2_PUB_NONCE (and I’d assume PSBT_IN_MUSIG2_PARTIAL_SIGNATURE, but I didn’t reach there, yet); instead, BIP-373 says that it must be the key found in the script and not the aggregate public key that it was derived from, if it was derived from an aggregate key. Therefore, I interpreted it as the taproot pubkey for a keypath spend, and the exact key that appears in the tapleaf for a scriptspend.
Using the aggregate key pre-tweaks could be problematic if the same aggregate key appears multiple times, for example in something like:
tr(NUMS/<0;1>/*,or_d(pk(musig(A,B)/<0;1>/*),pk(musig(A,B)/<2;3>/*)))
Here, the two musigs have the same participants, and same aggregate key pre-tweaks (and they are in the same leaf, so even the tapleaf_hash won’t help); only the tweaks allow the disambiguation.
Here’s what I pulled from the test I’m working on:
The aggregate_pubkey added by core is 03480793485c903f11b8ace2d81a89f4c0ec3b1944af98b6048426d35703f9898a, but I think it should be 02c94987d29e8939d728dd8879c8b5aa6c21b45c61a30751e394cafbef0e597f14 (after the BIP32-tweaks + the taptweak), matching the pubkey in the Script, if my understanding of BIP-373 is correct.
As a consequence, the musig2_pubnonces should probably use the name aggregate_pubkey_tweaked or something else that avoids confusion with the untweaked aggregate_pubkey that appears in musig2_participant_pubkeys.
achow101 force-pushed
on Nov 6, 2024
achow101
commented at 6:01 pm on November 6, 2024:
member
The current implementation seems to be using the aggregate pubkey (before the tweaks) inside the key of the PSBT_IN_MUSIG2_PUB_NONCE
Indeed, fixed.
Therefore, I interpreted it as the taproot pubkey for a keypath spend
I’ve interpreted (and implemented) it as also allowing the taproot internal key, not just the output key. I think that is actually what I meant when writing the BIP, but it’s been a while.
achow101 marked this as ready for review
on Nov 6, 2024
achow101 force-pushed
on Nov 6, 2024
achow101 force-pushed
on Nov 6, 2024
DrahtBot added the label
CI failed
on Nov 6, 2024
DrahtBot
commented at 8:09 pm on November 6, 2024:
contributor
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
DrahtBot removed the label
CI failed
on Nov 6, 2024
bigspider
commented at 9:53 pm on November 6, 2024:
none
I’ve interpreted (and implemented) it as also allowing the taproot internal key, not just the output key. I think that is actually what I meant when writing the BIP, but it’s been a while.
I think it’s important that the (aggregate) plain key used in the key of PSBT_IN_MUSIG2_PUB_NONCE/PSBT_IN_MUSIG2_PARTIAL_SIGNATURE is unambiguous and clearly specified, or implementations will essentially have to try both in order to find in the PSBT all the pubnonces/musig_partial_signatures for a certain key.
Using the same public key that can be used to verify the final signature (therefore, the tweaked taproot pubkey for keypath spends, or the pubkey as it appears in tapleaves for script spends) seems the most natural choice to me.
I don’t have an opinion on PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS - I’m not using it, since it’s redundant in the context of signing based on BIP-388 wallet policies.
achow101 force-pushed
on Nov 6, 2024
achow101
commented at 10:46 pm on November 6, 2024:
member
Using the same public key that can be used to verify the final signature (therefore, the tweaked taproot pubkey for keypath spends, or the pubkey as it appears in tapleaves for script spends) seems the most natural choice to me.
That’s a good point, I don’t feel too strongly about this, it was just a bit more annoying to figure out how. I’ve updated the PR to do that.
bigspider
commented at 1:34 pm on November 7, 2024:
none
Looking good!
I can confirm that I was able to complete two e2e tests on regtest (commit 09a6091711eef299de7cfbfd340a112706422c81), using Ledger’s MuSig2 implementation for a cosigner and bitcoin-core for the other one.
In both cases, the Ledger device was just the MuSig2 cosigner, while bitcoin-core was both the other musig cosigner and the combiner/finalizer/extractor.
I will report more once I have more extensive tests.
bigspider
commented at 4:44 pm on November 7, 2024:
none
Attempting some fancier setups, I’m trying to do a “decaying MuSig” that starts as a 3-of-3 in the keypath, with 3 timelocked 2-of-2 in the scriptpaths. Not managing to work with the descriptor in core:
0$ ./bitcoin-cli -regtest getdescriptorinfo "tr(musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6,tpubD6NzVbkrYhZ4WSLhjy9cMaGTEW7No4ALTRikqWo5xFsiTTkRfxA8eRyj2GTkFbkKU6HeW5z8LqrcgHbcVoVg2QZ8JECSHv4PpQ5vUdKJbkR)/1/*,{and_v(v:pk(musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6)/1/*),older(12960)),{and_v(v:pk(musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4WSLhjy9cMaGTEW7No4ALTRikqWo5xFsiTTkRfxA8eRyj2GTkFbkKU6HeW5z8LqrcgHbcVoVg2QZ8JECSHv4PpQ5vUdKJbkR)/1/*),older(12960)),and_v(v:pk(musig(tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6,tpubD6NzVbkrYhZ4WSLhjy9cMaGTEW7No4ALTRikqWo5xFsiTTkRfxA8eRyj2GTkFbkKU6HeW5z8LqrcgHbcVoVg2QZ8JECSHv4PpQ5vUdKJbkR)/1/*),older(12960))}})"
1error code: -5
2error message:
3'and_v(v:pk(musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6)/1/*),older(12960))' is not a valid descriptor function
Been staring at it for a while, it seems valid to me. Am I missing something?
Sorry if it’s obvious
achow101
commented at 4:51 pm on November 7, 2024:
member
musig() is not being parsed in Miniscript expressions yet.
bigspider
commented at 4:58 pm on November 7, 2024:
none
musig() is not being parsed in Miniscript expressions yet.
Ah, ok, I’ll keep an eye for updates.
Thanks!
achow101 force-pushed
on Nov 7, 2024
achow101 marked this as a draft
on Nov 7, 2024
achow101
commented at 6:23 pm on November 7, 2024:
member
Several earlier commits have been split out into separate PRs. See the tracking issue #31246 for the breakdown.
achow101 force-pushed
on Nov 7, 2024
achow101 force-pushed
on Nov 7, 2024
NicolasDorier
commented at 4:12 am on November 8, 2024:
contributor
Given BIP373 doesn’t have test vectors, it would be very useful that either this PR or the BIP include some hard coded PSBT examples to ensure every implementations are on the same page.
jonatack
commented at 12:54 pm on November 26, 2024:
member
Concept ACK
Given BIP373 doesn’t have test vectors, it would be very useful that either this PR or the BIP include some hard coded PSBT examples to ensure every implementations are on the same page.
Good point (the BIP373 test vector section currently states “TBD” and seems worth completing even if the implementation here also has tests).
Sjors
commented at 3:24 pm on November 26, 2024:
member
It might be useful if someone expands doc/multisig-tutorial.md to add a MuSig2 section. That doesn’t have to go in this PR, but it will make testing and review easier. The functional test added in this PR can be used for inspiration.
It can take advantage of the new <0;1> syntax and the new gethdkeys RPC.
I was able to generate a simple 2-of-2 tr(musig(A,B)/<0;1>/*) watch-only wallet on testnet4 and receive to it. Keys A and B were extracted from regular wallets by taking the pkh() account level xpub, including its origin.
However when trying to send walletprocesspsbt (with the wallet that has private keys) does not add any fields.
Sjors
commented at 9:49 am on December 3, 2024:
member
I also tried @bigspider’s MooSig demo which worked. I then crafted a multisig between A and the device: tr(musig(A,L)/<0;1>/*). I managed to register the policy (after several mistakes, it’s very tedious to do this manually).
I wanted to try using HWI to display the address, but I would have to modify it to work with the test app. I just yolo funded it.
I then created a withdrawal PSBT and pasted it in the Moosig script, modifying it to only add its public nonce. I also hardcoded the registered hmac. The device recognized the account being spent from. I can see that musig2_pubnonces was added to the PSBT.
I then ran it through walletprocesspsbt in wallet A. The resulting PSBT was longer, but it didn’t add its nonce to musig2_pubnonces.
Sjors
commented at 10:02 am on December 3, 2024:
member
Looking at the functional tests in 3649c2eb2053a0c166c68beb310c9c64ddc5b273 it seems the way this is designed to work is by swapping out the active tr([m/86'/1'/0']xpriv/<0;1>)/* descriptor for tr(musig([m/86'/1'/0']xpriv,other,other)/<0;1>)/*.
I guess that’s fine for the purpose of getting MuSig2 functionality in for experimental use, but it seems a bit unsafe and confusing for general use.
The test could make the intention a bit more clear by starting with blank wallets, only adding a tr() descriptor and mentioning in a comment that we just want its keys.
So instead of creating a watch-only wallet, I created a blank wallet. I imported the same tr(musig(A,L)/<0;1>/*) descriptor, but using the xpriv instead of xpub for A. It found the deposited coin. This time I started the withdrawal from the Core, so the Moosig could do its two calls to device in quick succession.
Even though I had “enable PSBT controls” selected, the GUI did not give me a chance to create a PSBT and immediately complained “Signing transaction failed” after I clicked “Send”.
The send RPC did work though it didn’t add a nonce. I had to use walletprocesspsbt for that.
I fed the result to Moosig generate_public_nonces and generate_partial_signatures. I fed the result to walletprocesspsbt et voila! Money back.
bigspider
commented at 4:03 pm on December 3, 2024:
none
I just updated it with a new version (Bitcoin Test Musig v2.4.0-rc):
Some bug fixes for more complex policies. Testing is still not extensive, but it should work for all combinations of musig and miniscript (with the due limits to the policy size; currently, at most 5 keys for MuSig2).
If a psbt is sent where only MuSig2 round 1 is executed (no signatures returned), the app will return pubnonces with no user interaction. Note that if there are other internal keys in the wallet policy for whom the PSBT_IN_TAP_BIP32_DERIVATION is present, then the device will sign for those, and in that case confirmation is of course still required.
Does /** in descriptors mean a combination of /0/* and /1/*? I.e. a receive and a change descriptor.
hugohn
commented at 4:35 pm on January 4, 2025:
contributor
@starius Kind of. We build on top of the descriptor template defined in BIP 129 (BSMS). The above snippet is part of a larger BSMS wallet configuration file, which includes derivation path restrictions.
starius
commented at 10:41 pm on January 4, 2025:
contributor
@hugohn I built bitcoin core using this PR rebased on master.
I tried the descriptor from your message, replacing /**/ with /0/* and /1/*. It works!
bigspider
commented at 10:50 pm on January 4, 2025:
none
@starius Kind of. We build on top of the descriptor template defined in BIP 129 (BSMS). The above snippet is part of a larger BSMS wallet configuration file, which includes derivation path restrictions.
@hugohn: FYI BIP-388 generalizes descriptor templates to arbitrary wallets, including with miniscript and musig; it should be entirely compatible with the special cases defined in BIP-129 for multisig.
starius
commented at 4:28 am on January 5, 2025:
contributor
I attempted to test this on Signet with a 2-of-2 MuSig2 Taproot address (without script leaves).
Succeeded using walletprocesspsbt, but failed when using GUI “Load PSBT from keyboard” option.
I copied it to node 2, loaded PSBT there, signed,
then copied to node 3, loaded PSBT there, signed,
then copied to node 2, loaded PSBT there, signed,
then copied to node 3, loaded PSBT there, signed.
Issue:
Despite including a taproot_key_path_sig, the transaction remains incomplete. Why?
When I use walletprocesspsbt instead of GUI for nonce exchange and signing (4 times), the process completes and I get a hex encoded final transaction.
Any insights or clarifications on this would be appreciated!
bigspider
commented at 6:44 pm on January 5, 2025:
none
Sample descriptors: tr(musig([15d62cdf/87'/0'/0']xpub6CpM1svHYyNMTVdmDh5syFXCJHKctJNajbyLEdA8pAgAeg1jotmg9G1aVkND5Rzf37uhwhs8o2Lvq22iRpWwcbNGCrYxAozQfYQYi1eduES/**,[7f15646b/87'/0'/0']xpub6ChFTmSdBrhN3D16Rna7hJVQe4w56Gx83U4uNhT3oJaEXiPv7LKnY2gXi3FbbusCb145c3SMEUsSLMRdkxa82MNKqkatnK5b77BXPc3aK8h/**),{{{pk(musig([15d62cdf/87'/0'/0']xpub6CpM1svHYyNMTVdmDh5syFXCJHKctJNajbyLEdA8pAgAeg1jotmg9G1aVkND5Rzf37uhwhs8o2Lvq22iRpWwcbNGCrYxAozQfYQYi1eduES/**,[07895d1c/87'/0'/0']xpub6DF4oz8Ws6Qcd87qKeKFJCMMvcY3X8vQkS5uQE6P5GxCjNE6XfCeak8xc7VUWjUnH4W1N9rmyjVrUHS5S5odkipXkH8G3VGqVoqoRJzL3UZ/**)),pk(musig([15d62cdf/87'/0'/0']xpub6CpM1svHYyNMTVdmDh5syFXCJHKctJNajbyLEdA8pAgAeg1jotmg9G1aVkND5Rzf37uhwhs8o2Lvq22iRpWwcbNGCrYxAozQfYQYi1eduES/**,[17f48baa/87'/0'/0']xpub6DQGEWSeUwmDE9HHzV3Biwj6VWxJj3VkGjefC7zqRJWM1xTU1s5dozA7DNty3ZniaejgLZBPVhsmrR88cpAeW8E3yieJHhfkPVDmAtuhkym/**))},{pk(musig([7f15646b/87'/0'/0']xpub6ChFTmSdBrhN3D16Rna7hJVQe4w56Gx83U4uNhT3oJaEXiPv7LKnY2gXi3FbbusCb145c3SMEUsSLMRdkxa82MNKqkatnK5b77BXPc3aK8h/**,[07895d1c/87'/0'/0']xpub6DF4oz8Ws6Qcd87qKeKFJCMMvcY3X8vQkS5uQE6P5GxCjNE6XfCeak8xc7VUWjUnH4W1N9rmyjVrUHS5S5odkipXkH8G3VGqVoqoRJzL3UZ/**)),pk(musig([7f15646b/87'/0'/0']xpub6ChFTmSdBrhN3D16Rna7hJVQe4w56Gx83U4uNhT3oJaEXiPv7LKnY2gXi3FbbusCb145c3SMEUsSLMRdkxa82MNKqkatnK5b77BXPc3aK8h/**,[17f48baa/87'/0'/0']xpub6DQGEWSeUwmDE9HHzV3Biwj6VWxJj3VkGjefC7zqRJWM1xTU1s5dozA7DNty3ZniaejgLZBPVhsmrR88cpAeW8E3yieJHhfkPVDmAtuhkym/**))}},pk(musig([07895d1c/87'/0'/0']xpub6DF4oz8Ws6Qcd87qKeKFJCMMvcY3X8vQkS5uQE6P5GxCjNE6XfCeak8xc7VUWjUnH4W1N9rmyjVrUHS5S5odkipXkH8G3VGqVoqoRJzL3UZ/**,[17f48baa/87'/0'/0']xpub6DQGEWSeUwmDE9HHzV3Biwj6VWxJj3VkGjefC7zqRJWM1xTU1s5dozA7DNty3ZniaejgLZBPVhsmrR88cpAeW8E3yieJHhfkPVDmAtuhkym/**))})@hugohn: Update: I notice now that you are using the derive-then-aggregate pattern (musig(xpub1/**,xpub2/**,...)), instead of the aggregate-then-derive one: (musig(xpub1,xpub2,...)/**); therefore, contrarily to what I claimed above, it is not compatible with BIP-388, which only supports the latter.
Descriptors, as currently specified, support both, which I think it’s unfortunate.
I recommend using the aggregate-then-derive pattern as it is going to be a lot more efficient in hardware signing devices - and the only one compatible with BIP-388.
hugohn
commented at 2:22 am on January 6, 2025:
contributor
Our main concern would be compatibility with other wallets. Do you know what wallets support BIP-388 right now (besides Ledger)? Does Sparrow support it?
bigspider
commented at 8:22 am on January 6, 2025:
none
Our main concern would be compatibility with other wallets. Do you know what wallets support BIP-388 right now (besides Ledger)? Does Sparrow support it?
BIP-388 is the base for the miniscript implementation used currently in Ledger, BitBox and Jade.
Sparrow only supports the standard multisig types, and I suppose it works with most devices.
The musig part of BIP-388 is currently only implemented in Ledger in a test application (details here), and should reach production this quarter.
Sjors
commented at 9:25 am on January 6, 2025:
member
Maybe we should have a wallet or importdescriptors flag that restricts imported descriptors to BIP-388? Whether to make that the default would be a separate debate.
achow101 force-pushed
on Jan 6, 2025
achow101
commented at 9:19 pm on January 6, 2025:
member
Succeeded using walletprocesspsbt, but failed when using GUI “Load PSBT from keyboard” option.
Thanks for testing! This revealed an issue with sighash type handling in the aggregation code. I’ve pushed a fix for it, as well as a functional test which could replicate the issue with walletprocesspsbt.
This fix does require changing how we handle non-default sighash types - namely we now will add PSBT_IN_SIGHASH to an input if we are trying to sign it with something other than SIGHASH_DEFAULT (note that SIGHASH_DEFAULT == SIGHASH_ALL for non-taproot, so the normal non-taproot won’t have this field added, unless SIGHASH_ALL was explicitly specified on the command line).
starius
commented at 3:08 am on January 7, 2025:
contributor
@achow101 I tried the updated version (2da3f0e659d3e89da0cdf525f8ce370bb35365a1).
I tested GUI flow - it works the same (doesn’t produce a transaction).
I also re-tested walletprocesspsbt flow - now it is also broken:
0walletprocesspsbt "cHNidP8BAH4CAAAAAfkoG4WU8+OG7ihR9ax1V+NQK6C9ZIEbsNH8qfB/A90YAAAAAAD9////AlcDAAAAAAAAF6kUp6q1daWOXVcRwue0FRtYgEAxvTCHKCMAAAAAAAAiUSBug0N9qhtsEJizov7RUbZtdDokLCvlo5+zNl+ocwJn636BAwAAAQErECcAAAAAAAAiUSBZP7q1V48G5XegaVSU+plRyc0hddLNxEwKjgaxGnEVXwEDBAEAAAAhFkNN5PloHAjb0E0osBGFERJSFPdYILJBOGBJ2JaPanvHBQBF3NXJIRZv7RyVBRBNtuBaMSje0M/TrzPCwWIAwsFJNQSMJyagTBkANwwcGFYAAIABAACAAAAAgAAAAAACAAAAIRbk+7os0tinqFncH2A0ptli9Ee0Bworam/Red00sAzNTxkApZtNq1YAAIABAACAAAAAgAAAAAACAAAAARcgQ03k+WgcCNvQTSiwEYURElIU91ggskE4YEnYlo9qe8ciGgNDTeT5aBwI29BNKLARhRESUhT3WCCyQThgSdiWj2p7x0IC5Pu6LNLYp6hZ3B9gNKbZYvRHtAcKK2pv0XndNLAMzU8Db+0clQUQTbbgWjEo3tDP068zwsFiAMLBSTUEjCcmoEwAAAEFIM2w2fouNow30T2TaXy1RedtUv3HPUlj94AmquLBD4vjIQciy89SfFIJjEsrmkBUGjRAF5uKUVaoO7YceX7/+NFBjRkANwwcGFYAAIABAACAAAAAgAEAAAACAAAAIQe3pe9vP18BEUSz/NdpLmQETB90YgqM4GKWJYx6VawM7hkApZtNq1YAAIABAACAAAAAgAEAAAACAAAAIQfNsNn6LjaMN9E9k2l8tUXnbVL9xz1JY/eAJqriwQ+L4wUAqsEXDyIIA82w2fouNow30T2TaXy1RedtUv3HPUlj94AmquLBD4vjQgIiy89SfFIJjEsrmkBUGjRAF5uKUVaoO7YceX7/+NFBjQK3pe9vP18BEUSz/NdpLmQETB90YgqM4GKWJYx6VawM7gA=" true
12Specified sighash value does not match value stored in PSBT (code -22)
achow101
commented at 4:52 am on January 7, 2025:
member
@achow101 I tried the updated version (2da3f0e). I tested GUI flow - it works the same (doesn’t produce a transaction). I also re-tested walletprocesspsbt flow - now it is also broken:
Ah, the sighash stuff needs a bit more work, and it also has impacts outside of MuSig support.
For the GUI workflow, if you apply https://github.com/bitcoin-core/gui/pull/850 on top of 3649c2e, it should “work”. However that is not a complete fix as it doesn’t work with other sighash types
achow101
commented at 2:10 am on January 9, 2025:
member
I’ve pushed several commits to fix the sighash issues. These are also opened in their own PR #31622
Sjors
commented at 10:52 am on January 16, 2025:
member
Can you update the PR description to have a list of pre-requisite PRs?
fanquake referenced this in commit
f9032a4abb
on Jan 16, 2025
achow101
commented at 8:16 pm on January 16, 2025:
member
Can you update the PR description to have a list of pre-requisite PRs?
There’s a tracking issue with everything listed #31246
achow101 force-pushed
on Jan 22, 2025
DrahtBot added the label
Needs rebase
on Feb 4, 2025
achow101 force-pushed
on Feb 10, 2025
DrahtBot removed the label
Needs rebase
on Feb 12, 2025
DrahtBot added the label
Needs rebase
on Mar 20, 2025
achow101 force-pushed
on Apr 10, 2025
DrahtBot removed the label
Needs rebase
on Apr 11, 2025
DrahtBot added the label
CI failed
on Apr 11, 2025
DrahtBot
commented at 1:23 am on April 11, 2025:
contributor
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
achow101 force-pushed
on Apr 14, 2025
DrahtBot removed the label
CI failed
on Apr 14, 2025
glozow referenced this in commit
c7b592fbd7
on Apr 18, 2025
DrahtBot added the label
Needs rebase
on Apr 18, 2025
achow101 force-pushed
on Apr 18, 2025
DrahtBot removed the label
Needs rebase
on Apr 19, 2025
glozow referenced this in commit
3e78ac6811
on Apr 21, 2025
DrahtBot added the label
Needs rebase
on Apr 21, 2025
achow101 force-pushed
on Apr 21, 2025
DrahtBot removed the label
Needs rebase
on Apr 21, 2025
DrahtBot added the label
CI failed
on May 1, 2025
achow101 force-pushed
on May 1, 2025
DrahtBot removed the label
CI failed
on May 1, 2025
DrahtBot added the label
Needs rebase
on May 7, 2025
achow101 force-pushed
on May 7, 2025
DrahtBot removed the label
Needs rebase
on May 7, 2025
DrahtBot added the label
Needs rebase
on May 14, 2025
achow101 force-pushed
on May 14, 2025
DrahtBot removed the label
Needs rebase
on May 14, 2025
achow101 force-pushed
on May 21, 2025
Sjors
commented at 1:47 pm on June 2, 2025:
member
It seems that if a (miniscript, not yet spendable) script path is present in the descriptor, then walletprocesspsbt won’t provide a pubnonce. (nvm, mistake in my testing flow)
@bigspider what version of the Ledger test app is required? And can it just sign (or provide the nonce) the PSBT (via HWI) and register the policy on first use? Or do you have to first explicitly register the policy like Moosig does?
bigspider
commented at 5:54 pm on June 2, 2025:
none
@bigspider what version of the Ledger test app is required? And can it just sign (or provide the nonce) the PSBT (via HWI) and register the policy on first use? Or do you have to first explicitly register the policy like Moosig does?
@Sjors, musig2 is supported from version 2.4.0 of the Bitcoin app, which at this time is the latest version. Note that the firmware OS must be up to date, or you would only find older versions of the app.
Registration is necessary (and not implemented in HWI).
Sjors
commented at 6:01 pm on June 2, 2025:
member
@bigspider Ledger Live says my LedgerX device is up to date. The mainnet Bitcoin app version is 2.4.0, but the testnet is at 2.3.0.
Or do I need the Bitcoin Test Legacy app? That one has a version 2.4.7, but it throws “ClaNotSupported” if I try it with async-hwidevice list command.
bigspider
commented at 7:48 pm on June 2, 2025:
none
@bigspider Ledger Live says my LedgerX device is up to date. The mainnet Bitcoin app version is 2.4.0, but the testnet is at 2.3.0.
Or do I need the Bitcoin Test Legacy app? That one has a version 2.4.7, but it throws “ClaNotSupported” if I try it with async-hwidevice list command.
No, “Bitcoin Test” version 2.4.0 is the correct app; maybe something went wrong and its deployment is missing - I’ll check tomorrow. What is the firmware version on your LNX?
Sjors
commented at 5:06 am on June 3, 2025:
member
@bigspider OS (firmware) version 2.4.2. I tried removing and reinstalling Bitcoin Test, but that didn’t bump the version. Will await your update. So you’re testing on mainnet then? :-)
bigspider
commented at 7:48 am on June 3, 2025:
none
@bigspider OS (firmware) version 2.4.2. I tried removing and reinstalling Bitcoin Test, but that didn’t bump the version. Will await your update. So you’re testing on mainnet then? :-)
@Sjors thanks for pointing that out, you should now be able to find Bicoin Test version 2.4.0 in the store!
Sjors
commented at 8:18 am on June 3, 2025:
member
@bigspider got it! Registration seems to work and device recognized which of the keys is “ours”. Though after approval async-hwi threw Error: Device("ClientError(\n \"Failed to parse descriptor\",\n)") and did not return an HMAC.
bigspider
commented at 8:30 am on June 3, 2025:
none
@Sjors async-hwi probably doesn’t support musig() in descriptors. Rust libraries are generally waiting for upstream support in rust-bitcoin.
The python package ledger-bitcoin is currently the only client library that is expected to work with musig2 (but it doesn’t have a CLI).
Sjors
commented at 9:01 am on June 3, 2025:
member
I see. So instead I registered the policy by tweaking Moosig. That worked and returned an HMAC.
I then hardcode that HMAC into moosig.py along with the PSBT generated by Bitcoin Core and try to make it request a pubnonce. For this I removed the HotMusig2Cosigner.
The device recognizes the policy, destination address, amount and fees which I then approve. But then it fails again:
0🐮 Requesting pubnonces (Round 1)
1Traceback (most recent call last):
2 File "/Users/sjors/dev/moosig/moosig.py", line 104, in <module>
3 main(client)
4 File "/Users/sjors/dev/moosig/moosig.py", line 74, in main
5 signer.generate_public_nonces(psbt)
6 File "/Users/sjors/dev/moosig/utils/musig2.py", line 812, in generate_public_nonces
7 res = self.client.sign_psbt(psbt, self.wallet_policy, self.wallet_hmac)
8 File "/Users/sjors/dev/moosig/venv/lib/python3.10/site-packages/ledger_bitcoin/client.py", line 330, in sign_psbt
9 raise DeviceException(error_code=sw, ins=BitcoinInsType.SIGN_PSBT)
10ledger_bitcoin.exception.errors.IncorrectDataError: ('0x6a80', 'Error in <BitcoinInsType.SIGN_PSBT: 4> command', '')
I tried both a PSBT generated with send, as well as one that went through walletprocesspsbt which added the public nonce from Bitcoin Core’s side.
Unfortunately that error is a bit cryptic.
bigspider
commented at 9:24 am on June 3, 2025:
none
If you’re only requesting pubnonces to the device, this should happen silently (without on-screen interaction). So if you’re validating the transaction in what is supposed to be round 1, it ain’t round 1 :)
If you have multiple spending paths, it might be doing round 1 for the musig2 key, and signing normally for the other spending path(s).
Just in case, I restarted the signing session by having Bitcoin Core make a fresh musig2_pubnonces for its key.
Are your e2e tests running against the latest version of this branch?
and signing normally for the other spending path(s).
The other paths don’t have enough confirmations yet, but I guess that doesn’t mattter?
Update: I get the same error with the following policy: tr(musig(@0,@1)/**) if I pass it a PSBT that already has the Bitcoin Core public nonce. It also prompts to confirm the send, so it’s clearly doing round 2 if the public nonce is present.
But when I pass a PSBT without the Bitcoin Core public nonce, it goes ahead and does round 1 without prompt. I then take the PSBT to Bitcoin Core, has it add its nonce and sign (two calls to walletprocesspsbt) and then give that back to the Ledger. Then it happily signs and the transaction can be broadcast.
Do PRINTF( statements get propagated to the caller? In that case it would aid in debugging to add these to more failure modes. Otherwise it’s hard to figure out which of the 37 SW_INCORRECT_DATA checks triggered the error.
I guess it doesn’t, because if I deliberately pass an invalid HMAC, I don’t see the message generated by PRINTF("Incorrect hmac\n");. I guess I need to run an emulator for that?
I’m able to run the emulator using the Visual Studio extension, but I have no idea how to connect to it from the host machine.
So I think there’s two things the device doesn’t like:
If there’s a script path it can spend
If it’s not the first to provide a public nonce
Though it’s possible I’m still doing something wrong on my end.
bigspider
commented at 2:31 pm on June 3, 2025:
none
Are your e2e tests running against the latest version of this branch?
The container is rebuilt every time a PR is merged, and the musig2 test never failed over the last 6+ months since they were added.
I rebuilt the container today and confirmed it works on the tagged commit for 2.4.0 release (this is the CI run).
But when I pass a PSBT without the Bitcoin Core public nonce, it goes ahead and does round 1 without prompt. I then take the PSBT to Bitcoin Core, has it add its nonce and sign (two calls to walletprocesspsbt) and then give that back to the Ledger. Then it happily signs and the transaction can be broadcast.
Yes, the app expects that there are either no nonces, or all nonces.
I guess it doesn’t, because if I deliberately pass an invalid HMAC, I don’t see the message generated by PRINTF("Incorrect hmac\n");. I guess I need to run an emulator for that?
PRINTFs are only present in the debug builds for the emulator.
I’m able to run the emulator using the Visual Studio extension, but I have no idea how to connect to it from the host machine.
I recommend to only use the VSCode extension to build it, but then install and run Speculos locally, so you don’t have to deal with containers. Other people work entirely inside the containers, but I personally don’t like Docker that much.
So I think there’s two things the device doesn’t like:
If there’s a script path it can spend
The expected behavior is that the app will sign (or run the first round) for all the internal key placeholders (where a key placeholder is internal if it’s a key controlled by the signing device, or a MuSig with a key controlled by the device), as long as the BIP-32 derivations are present for that internal key.
That’s because the API is sign(psbt, wallet_policy), so there’s otherwise no way of determining which key you want the device to sign for.
Before MuSig2, signing for unnecessary paths was only a waste of time, but now that’s necessary in order to be able to keep the first round silent.
Prior to version 2.4.0 the app might have signed for some spending paths even with incomplete or BIP32_DERIVATION.
If it’s not the first to provide a public nonce
The workflow I’m expecting is that the coordinator would give the same PSBT in parallel to all the signers, which execute round 1, then all nonces are added to the PSBT, and eah signer is invoked again and produces the partial musig signatures. If only some nonces are present, then the device assumes Round 1 already happened, but it will fail to run Round 2.
Sjors
commented at 2:52 pm on June 3, 2025:
member
If only some nonces are present, then the device assumes Round 1 already happened, but it will fail to run Round 2.
Ok, that explains issue (2).
But not why it failed with (1), because the policy variant with older fallback triggers the error without a public nonce from Bitcoin Core for the key path.
The workflow I’m expecting is that the coordinator would give the same PSBT in parallel to all the signers, which execute round 1, then all nonces are added to the PSBT, and eah signer is invoked again and produces the partial musig signatures.
That’s suboptimal though. In a two-of-two, if you need to physically go to a second location, you’ll want to:
site A: get nonce 1
site B: get nonce 2
site B: get partial signature 2
site A: get partial signature 2 and broadcast
Where ideally step (2) and (3) are a single action. Though you can still achieve this by running combinepsbt in site B after step (2).
Are your e2e tests running against the latest version of this branch?
The container is rebuilt every time a PR is merged
Right, but that just tests Bitcoin Core master, not this PR?
I guess if I want to debug this further, I’d have to modify the e2e test to use this branch and recreate the multisig setup I described in the test. Then if a test fails it will log the specific error in the console (if I add a few more PRINTFs).
but then install and run Speculos locally, so you don’t have to deal with containers
I couldn’t figure out how to do that on an M4 mac, but it might be easier on my Ubuntu machine. I’m not a Docker fan either.
On a different note, thinking about MuSig2 session management a bit more, the BIP says:
To avoid accidental reuse of secnonce, an implementation may securely erase the secnonce argument by overwriting it with 64 zero bytes after it has been read by Sign. A secnonce consisting of only zero bytes is invalid for Sign and will cause it to fail.
So if the user makes multiple calls to walletprocesspsbt, and the psbt contains our public nonce, then the first call would return a PSBT with a partial signature. If the call is repeated, i.e. without the partial signature that we produced earlier, it should fail (not silently).
Currently it just quietly removes musig2_partial_sigs, which may have contributed to my confusion.
0diff --git a/test/functional/wallet_musig.py b/test/functional/wallet_musig.py
1index b7f3cc9d96..9c8e0a8fd3 100755
2--- a/test/functional/wallet_musig.py
3+++ b/test/functional/wallet_musig.py
4@@ -8,7 +8,7 @@ import re
5 from test_framework.descriptors import descsum_create
6 from test_framework.key import H_POINT
7 from test_framework.test_framework import BitcoinTestFramework
8-from test_framework.util import assert_equal
9+from test_framework.util import assert_equal, assert_raises_rpc_error
1011 PRIVKEY_RE = re.compile(r"^tr\((.+?)/.+\)#.{8}$")
12 PUBKEY_RE = re.compile(r"^tr\((\[.+?\].+?)/.+\)#.{8}$")
13@@ -150,6 +150,9 @@ class WalletMuSigTest(BitcoinTestFramework):
14 for wallet in wallets:
15 proc = wallet.walletprocesspsbt(psbt=comb_nonce_psbt, sighashtype=sighash_type)
16 assert_equal(proc["complete"], False)
17+ # Never sign twice:
18+ assert_raises_rpc_error(-1, "sec nonce lost in tragic boating accident", wallet.walletprocesspsbt, psbt=comb_nonce_psbt, sighashtype=sighash_type)
19+
20 psig_psbts.append(proc["psbt"])
bigspider
commented at 3:20 pm on June 3, 2025:
none
But not why it failed with (1), because the policy variant with older fallback triggers the error without a public nonce from Bitcoin Core for the key path.
Please feel free to open an issue and I’ll investigate.
The workflow I’m expecting is that the coordinator would give the same PSBT in parallel to all the signers, which execute round 1, then all nonces are added to the PSBT, and eah signer is invoked again and produces the partial musig signatures.
That’s suboptimal though. In a two-of-two, if you need to physically go to a second location, you’ll want to:
site A: get nonce 1
site B: get nonce 2
site B: get partial signature 2
site A: get partial signature 2 and broadcast
Where ideally step (2) and (3) are a single action. Though you can still achieve this by running combinepsbt in site B after step (2).
Sure, but while the Ledger app is using PSBT in its protocol, it is not designed to be a full implementation of the PSBT standard, as it’s running in a very constrained setting where it doesn’t even have full access to the PSBT without communicating with the client. Verifying if ‘my nonce is present’ is a substantial amount of work, while checking if ‘some nonces’ are present is trivial by iterating once through the PSBT keys.
It is much easier to handle this on the client side (‘if only some but not all nonces are present, delete them before calling the device"), rather than implementing such complex logic on the device.
Right, but that just tests Bitcoin Core master, not this PR?
I’m currently using Bitcoin Core compiled from this PR, since MuSig2 is part of the CI; I’ll switch back to master once this PR is merged.
Sjors
commented at 3:31 pm on June 3, 2025:
member
But not why it failed with (1), because the policy variant with older fallback triggers the error without a public nonce from Bitcoin Core for the key path.
Please feel free to open an issue and I’ll investigate.
I’ll test it once more and will open an issue if needed.
Verifying if ‘my nonce is present’ is a substantial amount of work, while checking if ‘some nonces’ are present is trivial by iterating once through the PSBT keys.
I see. It would be good to document these caveats somewhere. They’re easy to work around, but hard to debug if you run into them.
in
src/musig.h:42
in
5e90a3c747outdated
39@@ -40,8 +40,7 @@ std::optional<CPubKey> MuSig2AggregatePubkeys(const std::vector<CPubKey>& pubkey
40 class MuSig2SecNonce
41 {
42 private:
43- //! The actual secnonce itself
44- secure_unique_ptr<secp256k1_musig_secnonce> m_nonce;
45+ std::unique_ptr<MuSig2SecNonceImpl> m_impl;
in commit 5e90a3c747ac2d44f9f52a3eeffbbe391f837bd8: seems like this change should be part of the earlier commit 01f639835783aa10d4c4b63da477c0300bc8495f, which currently doesn’t compile
0...
1In file included from /home/thestack/bitcoin_prrev/pr29675/src/musig.cpp:5:
2/home/thestack/bitcoin_prrev/pr29675/src/musig.h:44:5: error: no template named 'secure_unique_ptr'
3 secure_unique_ptr<secp256k1_musig_secnonce> m_nonce;
45/home/thestack/bitcoin_prrev/pr29675/src/musig.cpp:74:36: error: member initializer 'm_impl' does not name a non-static data member or base class
6MuSig2SecNonce::MuSig2SecNonce() : m_impl{std::make_unique<MuSig2SecNonceImpl>()} {}
7...
(not sure why the test-each-commit CI job doesn’t detect this though?)
theStack
commented at 1:18 pm on June 5, 2025:
contributor
Concept ACK
achow101 force-pushed
on Jun 5, 2025
achow101 force-pushed
on Jun 11, 2025
DrahtBot added the label
CI failed
on Jun 16, 2025
achow101 force-pushed
on Jun 17, 2025
achow101 force-pushed
on Jun 17, 2025
DrahtBot removed the label
CI failed
on Jun 17, 2025
achow101 force-pushed
on Jun 18, 2025
XOnlyPubKey: Add GetCPubKeys
We need to retrieve the even and odd compressed pubkeys for xonly
pubkeys, so add a function to do that. Also reuse it in GetKeyIDs.
8a409b050e
script/parsing: Allow Const to not skip the found constant
When parsing a descriptor, it is useful to be able to check whether a
string begins with a substring without consuming that substring as
another function such as Func() will be used later which requires that
substring to be present at the beginning.
Specifically, for MuSig2, this modified Const will be used to determine
whether a an expression begins with "musig(" before a subsequent
Func("musig", ...) is used.
4bf9e64e0c
util/string: Allow Split to include the separator
When splitting a string, sometimes the separator needs to be included.
Split will now optionally include the separator at the end of the left
side of the splits, i.e. it appears at the end of the splits, except
for the last one.
Specifically, for musig() descriptors, Split is used to separate a
musig() from any derivation path that follows it by splitting on the
closing parentheses. Since that parentheses is needed for Func() and
Expr(), Split() needs to preserve the end parentheses instead of
discarding it.
sign: Add GetMuSig2ParticipantPubkeys to SigningProvider721f0a10a2
Add MuSig2 Keyagg Cache helper functions
secp256k1 provides us secp256k1_musig_keyagg_cache objects which we are
used as part of session info and to get the aggregate pubkey. These
helper functions help us convert to/from the secp256k1 C objects into
the Bitcoin Core C++ objects.
sign: Refactor Schnorr sighash computation out of CreateSchnorrSig
There will be other functions within MutableTransactionSignatureCreator
that need to compute the same sighash, so make it a separate member
function.
8da82482e7
pubkey: Return tweaks from BIP32 derivationec4ecfd3e1
sign: Include taproot output key's KeyOriginInfo in sigdata13b534a7a4
Add MuSig2SecNonce class for secure allocation of musig nonces8ca3968377
signingprovider: Add musig2 secnonces
Adds GetMuSig2SecNonces which returns secp256k1_musig_secnonce*, and
DeleteMuSig2Session which removes the MuSig2 secnonce from wherever it
was retrieved. FlatSigningProvider stores it as a pointer to a map of
session id to secnonce so that deletion will actually delete from the
object that actually owns the secnonces.
The session id is just a unique identifier for the caller to determine
what secnonces have been created.
fe5d88ef16
sign: Add CreateMuSig2AggregateSigaba5cd81d0
sign: Add CreateMuSig2Nonce2e44c1a3d4
sign: Add CreateMuSig2PartialSig19ebc0c0fc
sign: Create MuSig2 signatures for known MuSig2 aggregate keys
When creating Taproot signatures, if the key being signed for is known
to be a MuSig2 aggregate key, do the MuSig2 signing algorithms.
First try to create the aggregate signature. This will fail if there are
not enough partial signatures or public nonces. If it does fail, try to
create a partial signature with all participant keys. This will fail for
those keys that we do not have the private keys for, and if there are
not enough public nonces. Lastly, if the partial signatures could be
created, add our own public nonces for the private keys that we know, if
they do not yet exist.
8caaac6de4
wallet: Keep secnonces in DescriptorScriptPubKeyManaea1d92a47
psbt: MuSig2 data in Fill/FromSignatureData091de9b570
test: Test MuSig2 in the wallet54d1e74046
achow101 force-pushed
on Jun 19, 2025
DrahtBot added the label
CI failed
on Jun 19, 2025
DrahtBot
commented at 0:16 am on June 19, 2025:
contributor
🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/runs/44377387322
LLM reason (✨ experimental): The CI failure is caused by a clang-tidy error due to the use of a variable ‘match’ that is copy-constructed from a const reference but not used, which is treated as an error.
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
DrahtBot removed the label
CI failed
on Jun 19, 2025
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2025-06-28 09:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me