VerifySolutions only on Debug mode
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
@@ -211,7 +211,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
if (!pass)
{
- Assert.Throws<ArgumentOutOfRangeException>(() => ProofSystem.RangeProof(amountScalar, randomness, width, rnd));
+ Assert.Throws<ArgumentException>(() => ProofSystem.RangeProof(amountScalar, randomness, width, rnd));
}
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Equation.cs
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Equation.cs
+using System;
+using System.Diagnostics;
using NBitcoin.Secp256k1;
using WalletWasabi.Crypto.Groups;
using WalletWasabi.Helpers;
@@ -71,7 +73,13 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
return secretNonces + challenge * witness;
}
- internal bool VerifySolution(ScalarVector witness)
- => PublicPoint == witness * Generators;
+ [Conditional("DEBUG")]
+ internal void CheckSolution(ScalarVector witness)
+ {
+ if (PublicPoint != witness * Generators)
+ {
+ throw new ArgumentException($"{nameof(witness)} is not solution of the equation");
+ }
+ }
}
}

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Knowledge.cs
WalletWasabi/Crypto/ZeroKnowledge/LinearRelation/Knowledge.cs
@@ -15,7 +15,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge.LinearRelation
// don't try to prove something which isn't true
foreach (var equation in statement.Equations)
{
- Guard.True(nameof(witness), equation.VerifySolution(witness), $"{nameof(witness)} is not solution of the {nameof(equation)}");
+ equation.CheckSolution(witness);
}
Statement = statement;

VerifySolutions only on Debug mode