Generalize old challenge builder.
MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Challenge.cs
WalletWasabi/Crypto/ZeroKnowledge/Challenge.cs
@@ -10,20 +10,27 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
{
public static class Challenge
{
- public static Scalar Build(GroupElement publicPoint, GroupElement nonce)
+ public static Scalar Build(GroupElement publicPoint, GroupElement nonce, IEnumerable<GroupElement> generators)
{
Guard.False($"{nameof(publicPoint)}.{nameof(publicPoint.IsInfinity)}", publicPoint.IsInfinity);
Guard.False($"{nameof(nonce)}.{nameof(nonce.IsInfinity)}", nonce.IsInfinity);
+ foreach (var generator in generators)
+ {
+ Guard.False($"{nameof(generator)}.{nameof(generator.IsInfinity)}", generator.IsInfinity);
+ }
if (publicPoint == nonce)
{
throw new InvalidOperationException($"{nameof(publicPoint)} and {nameof(nonce)} should not be equal.");
}
- return HashToScalar(publicPoint, nonce);
+ return HashToScalar(new[] { publicPoint, nonce }.Concat(generators));
}
- public static Scalar HashToScalar(IEnumerable<GroupElement> transcript)
+ public static Scalar Build(GroupElement publicPoint, GroupElement nonce, params GroupElement[] generators)
+ => Build(publicPoint, nonce, generators as IEnumerable<GroupElement>);
+
+ private static Scalar HashToScalar(IEnumerable<GroupElement> transcript)
{
var concatenation = ByteHelpers.Combine(transcript.Select(x => x.ToBytes()));
using var sha256 = System.Security.Cryptography.SHA256.Create();
@@ -31,8 +38,5 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
var challenge = new Scalar(hash);
return challenge;
}
-
- public static Scalar HashToScalar(params GroupElement[] transcript)
- => HashToScalar(transcript as IEnumerable<GroupElement>);
}
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Prover.cs
WalletWasabi/Crypto/ZeroKnowledge/Prover.cs
@@ -46,7 +46,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
nonce += randomPoint;
}
- var challenge = Challenge.HashToScalar(new[] { publicPoint, nonce }.Concat(secretGeneratorPairs.Select(x => x.generator)));
+ var challenge = Challenge.Build(publicPoint, nonce, secretGeneratorPairs.Select(x => x.generator));
var responses = new List<Scalar>();
foreach (var (secret, randomScalar) in secretGeneratorPairs

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Verifier.cs
WalletWasabi/Crypto/ZeroKnowledge/Verifier.cs
@@ -33,7 +33,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
var nonce = proof.Nonce;
var responses = proof.Responses;
- var challenge = Challenge.HashToScalar(new[] { publicPoint, nonce }.Concat(generators));
+ var challenge = Challenge.Build(publicPoint, nonce, generators);
var a = challenge * publicPoint + nonce;
var b = GroupElement.Infinity;

Generalize old challenge builder.