Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btcec/schnorr/musig2: update to musig 1.0.0 #1894

Merged
merged 9 commits into from
Oct 25, 2022

Conversation

Roasbeef
Copy link
Member

@Roasbeef Roasbeef commented Oct 6, 2022

The two concrete changes between version 0.4.0 (where we are before
this commit), and version 0.7.0 are:

  1. Variable length messages are now allowed, this comes with a new 8
    byte prefix for the messages.

    • Our implementation was already using a []byte for the
      message/hash, so no extra API changes are needed here.
  2. The serialization for a blank message and a normal message (for
    nonce gen) is now distinct. A single byte is added (either 0 or 1)
    to indicate if a message was passed into nonce generation.

The major change in musig 1.0.0 is that plain public keys are used as
input to key aggregation.

Some correctness tests are failing, so leaving this in draft until I fix those
and also update to the latest set of test vectors.

@Roasbeef
Copy link
Member Author

Roasbeef commented Oct 8, 2022

Correctness tests work now, next step is to update all the test vectors.

The two _concrete_ changes between version 0.4.0 (where we are before
this commit), and version 0.7.0 are:

  1. Variable length messages are now allowed, this comes with a new 8
     byte prefix for the messages.

     * Our implementation was already using a `[]byte` for the
       message/hash, so no extra API changes are needed here.

  2. The serialization for a blank message and a normal message (for
     nonce gen) is now distinct. A single byte is added (either 0 or 1)
     to indicate if a message was passed into nonce generation.
The major change in musig 1.0.0 is that plain public keys are used as
input to key aggregation.
@Roasbeef
Copy link
Member Author

Ok, this is ready for review now: all test vectors pass!

@Roasbeef Roasbeef marked this pull request as ready for review October 21, 2022 00:58
@coveralls
Copy link

coveralls commented Oct 21, 2022

Pull Request Test Coverage Report for Build 3325072371

  • 77 of 83 (92.77%) changed or added relevant lines in 4 files are covered.
  • 11 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-19.3%) to 52.519%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcec/schnorr/musig2/nonces.go 13 19 68.42%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 2 86.07%
peer/peer.go 9 73.49%
Totals Coverage Status
Change from base Build 3220143279: -19.3%
Covered Lines: 23426
Relevant Lines: 44605

💛 - Coveralls

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice that we're now using the BIP's test vectors directly. LGTM 🎉

btcec/schnorr/musig2/sign.go Show resolved Hide resolved
// If the message isn't present, then we'll just write out a single
// uint8 of a zero byte: m_prefixed = bytes(1, 0).
case 0:
case opts.msg == nil:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: squash this commit with previous one that updates the message encoding logic?

Copy link
Collaborator

@sputn1ck sputn1ck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

In order to mitigate https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-October/021000.html we could add in the public key to GenNonces, as in jonasnick/bips#74.

Another fix would be to make our WithSecretKey option mandatory.

If you use the btcd musig session, we are already safe, as GenNonces is called with the privkey option.

localNonces, err = GenNonces(

I think there is no reason to not add the privkey to the other use of GenNonces here
ctx.sessionNonce, err = GenNonces()

However adding the pubkey to GenNonces or making WithSecretKey mandatory would make outside usage of GenNonces less user error prone.

@Roasbeef
Copy link
Member Author

I think there is no reason to not add the privkey to the other use of GenNonces here

Great point, added in a new commit tacked onto the end.

In order to mitigate https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-October/021000.html we could add in the public key to GenNonces, as in jonasnick/bips#74.

So this is already available as a cutom option via WithNonceCombinedKeyAux.

@Roasbeef Roasbeef merged commit 2cc1908 into btcsuite:master Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants