diff --git a/NBitcoin.Tests/Secp256k1Tests.cs b/NBitcoin.Tests/Secp256k1Tests.cs index 6b2aa78c0..be56f1d8d 100644 --- a/NBitcoin.Tests/Secp256k1Tests.cs +++ b/NBitcoin.Tests/Secp256k1Tests.cs @@ -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()); diff --git a/NBitcoin/Secp256k1/Musig/MusigContext.cs b/NBitcoin/Secp256k1/Musig/MusigContext.cs index 1401e97a7..233a12a70 100644 --- a/NBitcoin/Secp256k1/Musig/MusigContext.cs +++ b/NBitcoin/Secp256k1/Musig/MusigContext.cs @@ -467,7 +467,7 @@ public ECPrivKey Extract(SecpSchnorrSignature signature, MusigPartialSignature[] /// A private nonce whose public part intended to be sent to other signers public MusigPrivNonce GenerateNonce(ECPubKey signingPubKey) { - return GenerateNonce(signingPubKey, Array.Empty()); + return GenerateNonce(signingPubKey, null); } /// /// This function derives a secret nonce that will be required for signing and