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

Fix: GenerateNonce(ECPubKey) wasn't random as expected #1228

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NBitcoin.Tests/Secp256k1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3985,6 +3985,13 @@ public void musig_tweaked_test()
// Add the scripts there
var treeInfo = builder.Finalize(new TaprootInternalPubKey(aggregatedKey.ToXOnlyPubKey().ToBytes()));
musig = new MusigContext(ecPubKeys, msg32);

// Sanity check that GenerateNonce do not reuse nonces
var n1 = musig.GenerateNonce(ecPubKeys[0]);
var n2 = musig.GenerateNonce(ecPubKeys[0]);
Assert.NotEqual(Encoders.Hex.EncodeData(n1.CreatePubNonce().ToBytes()), Encoders.Hex.EncodeData(n2.CreatePubNonce().ToBytes()));
//

nonces = ecPubKeys.Select(c => musig.GenerateNonce(c)).ToArray();
musig.Tweak(treeInfo.OutputPubKey.Tweak.Span);
musig.ProcessNonces(nonces.Select(n => n.CreatePubNonce()).ToArray());
Expand Down
2 changes: 1 addition & 1 deletion NBitcoin/Secp256k1/Musig/MusigContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public ECPrivKey Extract(SecpSchnorrSignature signature, MusigPartialSignature[]
/// <returns>A private nonce whose public part intended to be sent to other signers</returns>
public MusigPrivNonce GenerateNonce(ECPubKey signingPubKey)
{
return GenerateNonce(signingPubKey, Array.Empty<byte>());
return GenerateNonce(signingPubKey, null);
}
/// <summary>
/// This function derives a secret nonce that will be required for signing and
Expand Down
Loading