Fix transcript sequence
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
@@ -158,7 +158,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
var transcript = new Transcript(protocol);
var secretNonceProvider = transcript.CreateSyntheticSecretNonceProvider(witness, rnd);
- var secretNonce = secretNonceProvider.Sequence.First();
+ var secretNonce = secretNonceProvider.GetScalarVector();
Assert.Equal(secretNonce.Count(), witness.Length );
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Statement.cs
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Statement.cs
@@ -44,7 +44,6 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
// The responses matrix should match the generators in the equations and
// there should be once nonce per equation.
Guard.True(nameof(publicNonces), Equations.Count() == publicNonces.Count());
- // Equations.CheckDimensions(allResponses);
return Equations.Zip(publicNonces, (equation, r) => equation.Verify(r, challenge, responses)).All(x => x);
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/NonInteractive/FiatShamirTransform/Prover.cs
WalletWasabi/Crypto/ZeroKnowledge/NonInteractive/FiatShamirTransform/Prover.cs
@@ -39,7 +39,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.NonInteractive.FiatShamirTransform
// different challenges which would leak the witness, these are generated
// as synthetic nonces that also depend on the witness data.
var secretNonceProvider = transcript.CreateSyntheticSecretNonceProvider(Knowledge.Witness, random);
- var secretNonces = secretNonceProvider.Sequence.First(); // FIXME refactor GetVector()
+ var secretNonces = secretNonceProvider.GetScalarVector();
// The prover then commits to these, adding the corresponding public
// points to the transcript.

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/SyntheticSecretNonceProvider.cs
WalletWasabi/Crypto/ZeroKnowledge/SyntheticSecretNonceProvider.cs
@@ -10,12 +10,13 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
public class SyntheticSecretNonceProvider
{
private readonly Strobe128 _strobe;
+ private readonly int _secretCount;
public SyntheticSecretNonceProvider(Strobe128 strobe, IEnumerable<Scalar> secrets, WasabiRandom random)
{
Guard.NotNullOrEmpty(nameof(secrets), secrets);
-
_strobe = strobe;
+ _secretCount = secrets.Count();
// add secret inputs as key material
foreach (var secret in secrets)
@@ -23,36 +24,21 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
_strobe.Key(secret.ToBytes(), false);
}
- // add randomness as key material
_strobe.Key(random.GetBytes(32), false);
-
- // Set up a generator of vectors of scalars the size as secrets vector
- Sequence = VectorGenerator(secrets.Count());
- }
-
- public IEnumerable<ScalarVector> Sequence { get; }
-
- public Scalar GetScalar()
- {
- return new Scalar(_strobe.Prf(32, false));
}
- private IEnumerable<Scalar> ScalarGenerator()
+ private IEnumerable<Scalar> Sequence()
{
while (true)
{
- yield return GetScalar();
+ yield return new Scalar(_strobe.Prf(32, false));
}
}
- private IEnumerable<ScalarVector> VectorGenerator(int len)
- {
- while (true)
- {
- // ScalarVector's constructor will call ToArray internally, hopefully
- // minimizing copying
- yield return new ScalarVector(ScalarGenerator().Take(len));
- }
- }
+ public Scalar GetScalar() =>
+ Sequence().First();
+
+ public ScalarVector GetScalarVector() =>
+ new ScalarVector(Sequence().Take(_secretCount));
}
}
\ No newline at end of file

Fix transcript sequence