Simplify eqns matrix and responses vector dims
MODIFY
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Knowledge.cs
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Knowledge.cs
@@ -29,9 +29,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
public IEnumerable<ScalarVector> RespondToChallenge(Scalar challenge, IEnumerable<ScalarVector> allSecretNonces)
{
// allSecretNonces should have the same dimension as the equation matrix
- Guard.NotNullOrEmpty(nameof(allSecretNonces), allSecretNonces);
- var n = Statement.Equations.First().Generators.Count();
- Guard.True(nameof(allSecretNonces), allSecretNonces.All(x => x.Count() == n));
+ Statement.Equations.CheckDimesions(allSecretNonces);
return Statement.Equations.Zip(allSecretNonces, (equation, secretNonces) => equation.Respond(Witness, secretNonces, challenge));
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Statement.cs
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Statement.cs
@@ -30,7 +30,7 @@ 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());
- CheckDimesions(allResponses);
+ Equations.CheckDimesions(allResponses);
return Equations.Zip(publicNonces, allResponses, (equation, R, s) => equation.Verify(R, challenge, s)).All(x => x);
}
@@ -38,18 +38,9 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
public GroupElementVector SimulatePublicNonces(Scalar challenge, IEnumerable<ScalarVector> allGivenResponses)
{
// The responses matrix should match the generators in the equations and
- CheckDimesions(allGivenResponses);
+ Equations.CheckDimesions(allGivenResponses);
return new GroupElementVector(Enumerable.Zip(Equations, allGivenResponses, (e, r) => e.Simulate(challenge, r)));
}
-
- private void CheckDimesions(IEnumerable<ScalarVector> allResponses)
- {
- if (Equations.Count() != allResponses.Count() ||
- Enumerable.Zip(Equations, allResponses).Any(x => x.First.Generators.Count() != x.Second.Count()))
- {
- throw new ArgumentException("The number of responses and the number of generators in the equations do not match.");
- }
- }
}
}

Simplify eqns matrix and responses vector dims