Skip to content

Commit

Permalink
Fix: GenerateNonce(ECPubKey) wasn't random as expected (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Sep 22, 2024
1 parent 4623e56 commit 46af199
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit 46af199

Please sign in to comment.