wallet: Be able to receive and spend inputs involving MuSig2 aggregate keys #29675

pull achow101 wants to merge 29 commits into bitcoin:master from achow101:musig2 changing 26 files +1875 −120
  1. 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.

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/29675.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK jonatack

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #31244 (descriptors: MuSig2 by achow101)
    • #31243 (descriptor: Move filling of keys from DescriptorImpl::MakeScripts to PubkeyProvider::GetPubKey by achow101)
    • #30243 (Tr partial descriptors by Eunovo)
    • #21283 (Implement BIP 370 PSBTv2 by achow101)

    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.

  3. DrahtBot added the label Wallet on Mar 18, 2024
  4. DrahtBot added the label CI failed on Mar 19, 2024
  5. 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.

    Debug: https://github.com/bitcoin/bitcoin/runs/22808312237

  6. in test/functional/wallet_musig.py:128 in a1e4c323db outdated
    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 = []
    


    Sjors commented at 10:49 am on March 19, 2024:
    a1e4c323dbff9fa5095cf216d7cd528f10a1feeb: I assume this where the first nonce collection round starts, maybe say so in a comment?
  7. in test/functional/wallet_musig.py:152 in a1e4c323db outdated
    155+        comb_nonce_psbt = self.nodes[0].combinepsbt(nonce_psbts)
    156+
    157+        dec_psbt = self.nodes[0].decodepsbt(comb_nonce_psbt)
    158+        assert_equal(len(dec_psbt["inputs"][0]["musig2_pubnonces"]), exp_key_leaf)
    159+
    160+        psig_psbts = []
    


    Sjors commented at 10:51 am on March 19, 2024:
    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)
  8. in test/functional/wallet_musig.py:158 in a1e4c323db outdated
    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)
    


    Sjors commented at 10:54 am on March 19, 2024:
    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.
  9. 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.:

    1. Alice: send
    2. Alice: processpsbt
    3. Bob: processpsbt
    4. 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: 6470719924404054174
    22024-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)

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

  11. 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.:

    1. Alice: `send`
    
    2. Alice: `processpsbt`
    
    3. Bob: `processpsbt`
    
    4. 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: 6470719924404054174
    22024-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.

  12. 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!

  13. achow101 force-pushed on Mar 19, 2024
  14. achow101 force-pushed on Mar 20, 2024
  15. achow101 force-pushed on Mar 25, 2024
  16. achow101 force-pushed on Mar 25, 2024
  17. achow101 force-pushed on Mar 25, 2024
  18. achow101 force-pushed on Mar 26, 2024
  19. DrahtBot added the label Needs rebase on Mar 29, 2024
  20. achow101 force-pushed on Apr 1, 2024
  21. DrahtBot removed the label Needs rebase on Apr 1, 2024
  22. Sjors commented at 10:36 am on April 2, 2024: member
    Only 3 red CI machines to go :-)
  23. achow101 force-pushed on Apr 2, 2024
  24. achow101 commented at 5:10 pm on April 2, 2024: member

    Only 3 red CI machines to go :-)

    Only the tidy job is an actual failure from this PR. MSan is an issue with libsecp that needs to be fixed in https://github.com/bitcoin-core/secp256k1/pull/1479. The ASan failure affects all PRs currently, see #29788

  25. Sjors commented at 8:05 am on April 3, 2024: member
    The test passes for me now on macOS.
  26. DrahtBot added the label Needs rebase on Apr 6, 2024
  27. achow101 force-pushed on Apr 16, 2024
  28. bitcoin deleted a comment on May 23, 2024
  29. 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:

    https://github.com/bigspider/moosig

    It works for both keypath and script path spending (but it was only tested on very simple policies, so far).

    ADDENDUM: MuSig2 support will not be available on Nano S. Sorry, not enough RAM to make it fit.

  30. achow101 force-pushed on Oct 12, 2024
  31. achow101 commented at 0:18 am on October 12, 2024: member

    Rebased and updated the libsecp subtree to its master

    Still need to work on the location of musig specific functions as currently it requires linking secp256k1 directly for a bunch of targets.

  32. DrahtBot removed the label Needs rebase on Oct 12, 2024
  33. achow101 force-pushed on Oct 24, 2024
  34. achow101 force-pushed on Oct 25, 2024
  35. achow101 force-pushed on Oct 25, 2024
  36. achow101 force-pushed on Oct 25, 2024
  37. achow101 force-pushed on Oct 25, 2024
  38. achow101 force-pushed on Oct 29, 2024
  39. DrahtBot removed the label CI failed on Oct 29, 2024
  40. achow101 force-pushed on Nov 1, 2024
  41. DrahtBot added the label CI failed on Nov 1, 2024
  42. achow101 force-pushed on Nov 4, 2024
  43. DrahtBot removed the label CI failed on Nov 4, 2024
  44. in src/psbt.h:55 in 6d8213dda3 outdated
    49@@ -50,6 +50,9 @@ static constexpr uint8_t PSBT_IN_TAP_LEAF_SCRIPT = 0x15;
    50 static constexpr uint8_t PSBT_IN_TAP_BIP32_DERIVATION = 0x16;
    51 static constexpr uint8_t PSBT_IN_TAP_INTERNAL_KEY = 0x17;
    52 static constexpr uint8_t PSBT_IN_TAP_MERKLE_ROOT = 0x18;
    53+static constexpr uint8_t PSBT_IN_MUSIG2_PARTICIPANT_PUBKEYS = 0x19;
    54+static constexpr uint8_t PSBT_IN_MUSIG2_PUB_NONCE = 0x1a;
    55+static constexpr uint8_t PSBT_IN_MUSIG2_PARTIAL_SIG = 0x1b;
    


    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.
  45. achow101 force-pushed on Nov 5, 2024
  46. fanquake referenced this in commit 80cb630bd9 on Nov 6, 2024
  47. 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:

    Descriptor: tr(musig([f5acc2fd/44'/1'/0']tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT,tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6)/<0;1>/*)

    (where core has the private key for the second tpub).

    Descriptors (with tprivs) imported in core:

    0[{'desc': "tr(musig([f5acc2fd/44'/1'/0']tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT,tprv8ZgxMBicQKsPehMjviGVbsCXGVnN5PMniVWAfyiNXHt5rANKD8wW3ASWAVnoD3FPLGH3v7RGJ4FffNHhZQbUGN1cRDKQ1CosyX2MQtFsGht)/0/*)#j27a8m7j", 'active': True, 'internal': False, 'timestamp': 'now'}, {'desc': "tr(musig([f5acc2fd/44'/1'/0']tpubDCwYjpDhUdPGP5rS3wgNg13mTrrjBuG8V9VpWbyptX6TRPbNoZVXsoVUSkCjmQ8jJycjuDKBb9eataSymXakTTaGifxR6kmVsfFehH1ZgJT,tprv8ZgxMBicQKsPehMjviGVbsCXGVnN5PMniVWAfyiNXHt5rANKD8wW3ASWAVnoD3FPLGH3v7RGJ4FffNHhZQbUGN1cRDKQ1CosyX2MQtFsGht)/1/*)#r7mu6ww2", 'active': True, 'internal': True, 'timestamp': 'now'}]
    

    Unsigned psbt:

    0cHNidP8BAH0CAAAAAdL2NNlBE2JSvqSfT7rD55qtlQo0vpBj+7qay5jlRK8aAQAAAAD9////AkBCDwAAAAAAFgAU2bY05Ye8D/o31ppWq8ycsL5td1WxU4kAAAAAACJRIG8BY+C8txooPxDbrDXmFNCHPn5OWgStjAvWJPmkG/CSAAAAAAABASuAlpgAAAAAACJRIMlJh9KeiTnXKN2Ieci1qmwhtFxhowdR45TK++8OWX8UIRaZg4sXm+qcswzNRehImrkH8m8OkH3oq9iqbJO4E9721AUAG4RQpCEW29VNEFgkvwKv+7zMiMVCtBJrM43iZkRMWEATVlTy31YNACbnYhIAAAAAAwAAACEW6Ex/S3Zi+u2fXrLYEtm3vPDgvyozsXrEXji4RZZpwyERAPWswv0sAACAAQAAgAAAAIABFyDb1U0QWCS/Aq/7vMyIxUK0EmszjeJmRExYQBNWVPLfViIaA0gHk0hckD8RuKzi2BqJ9MDsOxlEr5i2BIQm01cD+YmKQgOZg4sXm+qcswzNRehImrkH8m8OkH3oq9iqbJO4E9721APoTH9LdmL67Z9estgS2be88OC/KjOxesReOLhFlmnDIQAAAQUg9zq5DQINlksdoy1F6n8H4aGsIgVYVEHwMprZjOBWEKUhB5mDixeb6pyzDM1F6EiauQfybw6Qfeir2Kpsk7gT3vbUBQAbhFCkIQfoTH9LdmL67Z9estgS2be88OC/KjOxesReOLhFlmnDIREA9azC/SwAAIABAACAAAAAgCEH9zq5DQINlksdoy1F6n8H4aGsIgVYVEHwMprZjOBWEKUNACbnYhIBAAAAAAAAACIIA0gHk0hckD8RuKzi2BqJ9MDsOxlEr5i2BIQm01cD+YmKQgOZg4sXm+qcswzNRehImrkH8m8OkH3oq9iqbJO4E9721APoTH9LdmL67Z9estgS2be88OC/KjOxesReOLhFlmnDIQA=
    

    PSBT processed by core:

    0cHNidP8BAH0CAAAAAdL2NNlBE2JSvqSfT7rD55qtlQo0vpBj+7qay5jlRK8aAQAAAAD9////AkBCDwAAAAAAFgAU2bY05Ye8D/o31ppWq8ycsL5td1WxU4kAAAAAACJRIG8BY+C8txooPxDbrDXmFNCHPn5OWgStjAvWJPmkG/CSAAAAAAABASuAlpgAAAAAACJRIMlJh9KeiTnXKN2Ieci1qmwhtFxhowdR45TK++8OWX8UIRaZg4sXm+qcswzNRehImrkH8m8OkH3oq9iqbJO4E9721AUAG4RQpCEW29VNEFgkvwKv+7zMiMVCtBJrM43iZkRMWEATVlTy31YNACbnYhIAAAAAAwAAACEW6Ex/S3Zi+u2fXrLYEtm3vPDgvyozsXrEXji4RZZpwyERAPWswv0sAACAAQAAgAAAAIABFyDb1U0QWCS/Aq/7vMyIxUK0EmszjeJmRExYQBNWVPLfViIaA0gHk0hckD8RuKzi2BqJ9MDsOxlEr5i2BIQm01cD+YmKQgOZg4sXm+qcswzNRehImrkH8m8OkH3oq9iqbJO4E9721APoTH9LdmL67Z9estgS2be88OC/KjOxesReOLhFlmnDIUMbA5mDixeb6pyzDM1F6EiauQfybw6Qfeir2Kpsk7gT3vbUA0gHk0hckD8RuKzi2BqJ9MDsOxlEr5i2BIQm01cD+YmKQgPQuidM6rVFptyqaKqAOFl7PD7UfSkbp1rMhATpFUiEXwN8MICPo5paODBnrSm6350HF7EjM5LWgYTPXWGmFhFW1QAAAQUg9zq5DQINlksdoy1F6n8H4aGsIgVYVEHwMprZjOBWEKUhB5mDixeb6pyzDM1F6EiauQfybw6Qfeir2Kpsk7gT3vbUBQAbhFCkIQfoTH9LdmL67Z9estgS2be88OC/KjOxesReOLhFlmnDIREA9azC/SwAAIABAACAAAAAgCEH9zq5DQINlksdoy1F6n8H4aGsIgVYVEHwMprZjOBWEKUNACbnYhIBAAAAAAAAACIIA0gHk0hckD8RuKzi2BqJ9MDsOxlEr5i2BIQm01cD+YmKQgOZg4sXm+qcswzNRehImrkH8m8OkH3oq9iqbJO4E9721APoTH9LdmL67Z9estgS2be88OC/KjOxesReOLhFlmnDIQA=
    

    PSBT processed by core, decoded:

      0{
      1  "tx": {
      2    "txid": "71ac326e339863accc5ccb85d071ac41a7162fc1406c322c23648c0fe5839b92",
      3    "hash": "71ac326e339863accc5ccb85d071ac41a7162fc1406c322c23648c0fe5839b92",
      4    "version": 2,
      5    "size": 125,
      6    "vsize": 125,
      7    "weight": 500,
      8    "locktime": 0,
      9    "vin": [
     10      {
     11        "txid": "1aaf44e598cb9abafb6390be340a95ad9ae7c3ba4f9fa4be52621341d934f6d2",
     12        "vout": 1,
     13        "scriptSig": {
     14          "asm": "",
     15          "hex": ""
     16        },
     17        "sequence": 4294967293
     18      }
     19    ],
     20    "vout": [
     21      {
     22        "value": 0.01000000,
     23        "n": 0,
     24        "scriptPubKey": {
     25          "asm": "0 d9b634e587bc0ffa37d69a56abcc9cb0be6d7755",
     26          "desc": "addr(bcrt1qmxmrfev8hs8l5d7knft2hnyukzlx6a64ystah7)#4sr0u9wg",
     27          "hex": "0014d9b634e587bc0ffa37d69a56abcc9cb0be6d7755",
     28          "address": "bcrt1qmxmrfev8hs8l5d7knft2hnyukzlx6a64ystah7",
     29          "type": "witness_v0_keyhash"
     30        }
     31      },
     32      {
     33        "value": 0.08999857,
     34        "n": 1,
     35        "scriptPubKey": {
     36          "asm": "1 6f0163e0bcb71a283f10dbac35e614d0873e7e4e5a04ad8c0bd624f9a41bf092",
     37          "desc": "rawtr(6f0163e0bcb71a283f10dbac35e614d0873e7e4e5a04ad8c0bd624f9a41bf092)#f0mm5uaz",
     38          "hex": "51206f0163e0bcb71a283f10dbac35e614d0873e7e4e5a04ad8c0bd624f9a41bf092",
     39          "address": "bcrt1pduqk8c9ukudzs0csmwkrtes56zrnuljwtgz2mrqt6cj0nfqm7zfqgd563z",
     40          "type": "witness_v1_taproot"
     41        }
     42      }
     43    ]
     44  },
     45  "global_xpubs": [
     46  ],
     47  "psbt_version": 0,
     48  "proprietary": [
     49  ],
     50  "unknown": {
     51  },
     52  "inputs": [
     53    {
     54      "witness_utxo": {
     55        "amount": 0.10000000,
     56        "scriptPubKey": {
     57          "asm": "1 c94987d29e8939d728dd8879c8b5aa6c21b45c61a30751e394cafbef0e597f14",
     58          "desc": "rawtr(c94987d29e8939d728dd8879c8b5aa6c21b45c61a30751e394cafbef0e597f14)#qt9mflrv",
     59          "hex": "5120c94987d29e8939d728dd8879c8b5aa6c21b45c61a30751e394cafbef0e597f14",
     60          "address": "bcrt1pe9yc05573yuaw2xa3puu3dd2dssmghrp5vr4rcu5eta77rje0u2qamzrjq",
     61          "type": "witness_v1_taproot"
     62        }
     63      },
     64      "taproot_bip32_derivs": [
     65        {
     66          "pubkey": "99838b179bea9cb30ccd45e8489ab907f26f0e907de8abd8aa6c93b813def6d4",
     67          "master_fingerprint": "1b8450a4",
     68          "path": "m",
     69          "leaf_hashes": [
     70          ]
     71        },
     72        {
     73          "pubkey": "dbd54d105824bf02affbbccc88c542b4126b338de266444c5840135654f2df56",
     74          "master_fingerprint": "26e76212",
     75          "path": "m/0/3",
     76          "leaf_hashes": [
     77          ]
     78        },
     79        {
     80          "pubkey": "e84c7f4b7662faed9f5eb2d812d9b7bcf0e0bf2a33b17ac45e38b8459669c321",
     81          "master_fingerprint": "f5acc2fd",
     82          "path": "m/44h/1h/0h",
     83          "leaf_hashes": [
     84          ]
     85        }
     86      ],
     87      "taproot_internal_key": "dbd54d105824bf02affbbccc88c542b4126b338de266444c5840135654f2df56",
     88      "musig2_participant_pubkeys": [
     89        {
     90          "aggregate_pubkey": "03480793485c903f11b8ace2d81a89f4c0ec3b1944af98b6048426d35703f9898a",
     91          "participant_pubkeys": [
     92            "0399838b179bea9cb30ccd45e8489ab907f26f0e907de8abd8aa6c93b813def6d4",
     93            "03e84c7f4b7662faed9f5eb2d812d9b7bcf0e0bf2a33b17ac45e38b8459669c321"
     94          ]
     95        }
     96      ],
     97      "musig2_pubnonces": [
     98        {
     99          "participant_pubkey": "0399838b179bea9cb30ccd45e8489ab907f26f0e907de8abd8aa6c93b813def6d4",
    100          "aggregate_pubkey": "03480793485c903f11b8ace2d81a89f4c0ec3b1944af98b6048426d35703f9898a",
    101          "pubnonce": "03d0ba274ceab545a6dcaa68aa8038597b3c3ed47d291ba75acc8404e91548845f037c30808fa39a5a383067ad29badf9d0717b1233392d68184cf5d61a6161156d5"
    102        }
    103      ]
    104    }
    105  ],
    106  "outputs": [
    107    {
    108    },
    109    {
    110      "taproot_internal_key": "f73ab90d020d964b1da32d45ea7f07e1a1ac2205585441f0329ad98ce05610a5",
    111      "taproot_bip32_derivs": [
    112        {
    113          "pubkey": "99838b179bea9cb30ccd45e8489ab907f26f0e907de8abd8aa6c93b813def6d4",
    114          "master_fingerprint": "1b8450a4",
    115          "path": "m",
    116          "leaf_hashes": [
    117          ]
    118        },
    119        {
    120          "pubkey": "e84c7f4b7662faed9f5eb2d812d9b7bcf0e0bf2a33b17ac45e38b8459669c321",
    121          "master_fingerprint": "f5acc2fd",
    122          "path": "m/44h/1h/0h",
    123          "leaf_hashes": [
    124          ]
    125        },
    126        {
    127          "pubkey": "f73ab90d020d964b1da32d45ea7f07e1a1ac2205585441f0329ad98ce05610a5",
    128          "master_fingerprint": "26e76212",
    129          "path": "m/1/0",
    130          "leaf_hashes": [
    131          ]
    132        }
    133      ],
    134      "musig2_participant_pubkeys": [
    135        {
    136          "aggregate_pubkey": "03480793485c903f11b8ace2d81a89f4c0ec3b1944af98b6048426d35703f9898a",
    137          "participant_pubkeys": [
    138            "0399838b179bea9cb30ccd45e8489ab907f26f0e907de8abd8aa6c93b813def6d4",
    139            "03e84c7f4b7662faed9f5eb2d812d9b7bcf0e0bf2a33b17ac45e38b8459669c321"
    140          ]
    141        }
    142      ]
    143    }
    144  ],
    145  "fee": 0.00000143
    146}
    

    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.

  48. lozanopo approved
  49. achow101 force-pushed on Nov 6, 2024
  50. 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.

  51. achow101 marked this as ready for review on Nov 6, 2024
  52. achow101 force-pushed on Nov 6, 2024
  53. achow101 force-pushed on Nov 6, 2024
  54. DrahtBot added the label CI failed on Nov 6, 2024
  55. DrahtBot commented at 8:09 pm on November 6, 2024: contributor

    🚧 At least one of the CI tasks failed. Debug: https://github.com/bitcoin/bitcoin/runs/32617937935

    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.

  56. DrahtBot removed the label CI failed on Nov 6, 2024
  57. 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.

  58. achow101 force-pushed on Nov 6, 2024
  59. 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.

    Also opened https://github.com/bitcoin/bips/pull/1695 to clarify in the BIP.

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

    The descriptors had the form:

    tr(musig(ledger_key, bitcoin_core_key)/<0;1>/*)

    and:

    tr(nums_key/<0;1>/*, musig(ledger_key, bitcoin_core_key)/<0;1>/*)

    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.

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

    Same descriptor formatted:

     0tr(
     1  musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6,tpubD6NzVbkrYhZ4WSLhjy9cMaGTEW7No4ALTRikqWo5xFsiTTkRfxA8eRyj2GTkFbkKU6HeW5z8LqrcgHbcVoVg2QZ8JECSHv4PpQ5vUdKJbkR)/1/*,
     2  {
     3    and_v(
     4      v:pk(musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6)/1/*),
     5      older(12960)
     6    ),
     7    {
     8      and_v(
     9        v:pk(musig(tpubDD863BuWFdsaCg6f1SGdwLxp9mDcm3YRm3HxxbppBrizxvU1MqhQ1WpMwhz4vrZHNT7NFbXQ35CquVG9xaLsWaUWfSMZamDESisvtKZ7veF,tpubD6NzVbkrYhZ4WSLhjy9cMaGTEW7No4ALTRikqWo5xFsiTTkRfxA8eRyj2GTkFbkKU6HeW5z8LqrcgHbcVoVg2QZ8JECSHv4PpQ5vUdKJbkR)/1/*),
    10        older(12960)
    11      ),
    12      and_v(
    13        v:pk(musig(tpubD6NzVbkrYhZ4YAPXpMw61GrdqXJJEiYhHo6wxVkfwZgUged5qXm6Df4NLf8ZTFXxW1UhxDKGeKdAVxZtmodC8KfR7SqmW6LGQfDGfnFLmQ6,tpubD6NzVbkrYhZ4WSLhjy9cMaGTEW7No4ALTRikqWo5xFsiTTkRfxA8eRyj2GTkFbkKU6HeW5z8LqrcgHbcVoVg2QZ8JECSHv4PpQ5vUdKJbkR)/1/*),
    14        older(12960)
    15      )
    16    }
    17  }
    18)
    

    Been staring at it for a while, it seems valid to me. Am I missing something? Sorry if it’s obvious

  62. achow101 commented at 4:51 pm on November 7, 2024: member
    musig() is not being parsed in Miniscript expressions yet.
  63. 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!

  64. achow101 force-pushed on Nov 7, 2024
  65. psbt: Implement un/ser of musig2 fields a6bcb764aa
  66. rpc: Include MuSig2 fields in decodepsbt 2f8617b2b3
  67. psbt: Use specified sighash or SIGHASH_DEFAULT when dummy signing
    When dummy signing for finalizing, use either the specificed sighash, or
    SIGHASH_DEFAULT, rather than always SIGHASH_ALL.
    
    For outputs, just use SIGHASH_DEFAULT.
    c122152c15
  68. desc spkm: Return SigningProvider only if we have the privkey
    If we know about a pubkey that's in our descriptor, but we don't have
    the private key, don't return a SigningProvider for that pubkey.
    
    This is specifically an issue for Taproot outputs that use the H point
    as the resulting PSBTs may end up containing irrelevant information
    because the H point was detected as a pubkey each unrelated descriptor
    knew about.
    feb86f7e39
  69. wallet, rpc: Only allow keypool import from single key descriptors
    Instead of relying on implicit assumptions about whether pubkeys show up
    or now after expanding a descriptor, just explicitly allow only single
    key descriptors to import keys into a legacy wallet's keypool.
    d1359eff3d
  70. descriptors: Have GetPubKey fill origins directly
    Instead of having ExpandHelper fill in the origins in the
    FlatSigningProvider output, have GetPubKey do it by itself. This reduces
    the extra variables needed in order to track and set origins in
    ExpandHelper.
    
    Also changes GetPubKey to return a std::optional<CPubKey> rather than
    using a bool and output parameters.
    719739aa39
  71. descriptors: Move FlatSigningProvider pubkey filling to GetPubKey
    Instead of MakeScripts inconsistently filling the output
    FlatSigningProvider with the pubkeys involved, just do it in GetPubKey.
    883d24d24d
  72. descriptors: Have GetPrivKey fill keys directly
    Instead of GetPrivKey returning a key and having the caller fill the
    FlatSigningProvider, have GetPrivKey take the FlatSigningProvider and
    fill it by itself.
    
    GetPrivKey is now changed to void as the caller no longer cares whether
    it succeeds or fails.
    9e96339576
  73. 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.
    636a59e221
  74. spanparsing: Allow Const to not skip the found constant 508302f0c4
  75. descriptors: Add PubkeyProvider::IsBIP32() 1bfb5510e3
  76. build: Enable secp256k1 musig module 320e6b0042
  77. sign: Add GetAggregateParticipantPubkeys to SigningProvider f020d406c0
  78. Add MuSig2 Keyagg Cache class and functions
    - MuSig2KeyAggCache contains a MuSig2KeyAggCacheImpl which has the
      secp256ke_musig_keyagg_cache object to avoid having to link libsecp256k1
      everywhere.
    - GetMuSig2KeyAggCache creates the MuSig2KeyAggCache from a
      std::vector<CPubKey>
    - GetCPubKeyFromMuSig2KeyAggCache creates a CPubKey from a cache created
      with GetMuSig2KeyAggCache
    - MuSig2AggregatePubKeys does the two above functions together.
    2abb1fe0d2
  79. descriptor: Add MuSigPubkeyProvider 0e508cedcc
  80. descriptor: Parse musig() key expressions 7053cebb11
  81. tests: Test musig() parsing 38dc94681e
  82. 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.
    bbe4665d50
  83. pubkey: Return tweaks from BIP32 derivation f94a9ed428
  84. sign: Include taproot output key's KeyOriginInfo in sigdata 0a4fcbf2b6
  85. Add MuSig2SecNonce class for secure allocation of musig nonces 2e3343b3ff
  86. 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.
    c7a62f5c39
  87. achow101 marked this as a draft on Nov 7, 2024
  88. 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.
  89. achow101 force-pushed on Nov 7, 2024
  90. sign: Add CreateMuSig2AggregateSig 3dde12d319
  91. sign: Add CreateMuSig2Nonce 3f5699702c
  92. sign: Add CreateMuSig2PartialSig 029800f046
  93. 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.
    1a488142d4
  94. wallet: Keep secnonces in DescriptorScriptPubKeyMan b8bb007926
  95. psbt: MuSig2 data in Fill/FromSignatureData 5afc5d06f9
  96. test: Test MuSig2 in the wallet 3649c2eb20
  97. achow101 force-pushed on Nov 7, 2024
  98. 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.
  99. 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).

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

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

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


github-metadata-mirror

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: 2024-12-03 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me