secp256k1 icon indicating copy to clipboard operation
secp256k1 copied to clipboard

Add module "musig" that implements MuSig2 multi-signatures (BIP 327)

Open jonasnick opened this issue 1 year ago • 6 comments

EDIT: based on #1518. Closes #1452. Most of the code is a copy from libsecp256k1-zkp. The API added in this PR is identical with the exception of two modifications:

  1. I removed the unused scratch_space argument from secp256k1_musig_pubkey_agg. This argument was intended to allow using ecmult_multi algorithms for key aggregation in the future. But at this point it's unclear whether the scratch_space object will remain in its current form (see #1302).
  2. Support for adaptor signatures was removed and therefore the adaptor argument of musig_nonce_process was also removed.

In contrast to the module in libsecp256k1-zkp, the module is non-experimental. I slightly cleaned up parts of the module, adjusted the code to the new definition of the VERIFY_CHECK macro and applied some simplifications that were possible because the module is now in the upstream repo (ge_from_bytes, ge_to_bytes). You can follow the changes I made to the libsecp256k1-zkp module at https://github.com/jonasnick/secp256k1-zkp/commits/musig2-upstream/.

jonasnick avatar Jan 06 '24 20:01 jonasnick

Rebased on top of master to get https://github.com/bitcoin-core/secp256k1/pull/1480 which allowed dropping a commit. Old state is preserved at https://github.com/jonasnick/secp256k1/tree/musig2-module-backup.

jonasnick avatar Jan 11 '24 14:01 jonasnick

FWIW, we have JVM bindings on top of this branch in https://github.com/ACINQ/secp256k1-kmp/pull/93 and an implementation of swap-in-potentiam (musig2 key-path with alternative delayed script path) in https://github.com/ACINQ/bitcoin-kmp/pull/107 and everything is working fine, and the API is easy enough to use!

t-bast avatar Jan 23 '24 14:01 t-bast

Rebased.

Thanks @t-bast, that's good to hear.

jonasnick avatar Jan 23 '24 19:01 jonasnick

Attaching a visualization for the API flow.

musig2-api-flowchart

Edit: The above visualization is incorrect. I will update it with the correct one soon.

siv2r avatar Feb 01 '24 05:02 siv2r

@josibake

What do you think about splitting out the sort commits into their own PR?

That's a good idea. In particular, if more fixups are needed for the sort commits. See #1518.

jonasnick avatar Apr 16 '24 19:04 jonasnick