Remove zk prefixes
RENAME
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/ZkExponentTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfExponentTests.cs
@@ -10,7 +10,7 @@ using Xunit;
namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
{
- public class ZkExponentTests
+ public class KnowledgeOfExponentTests
{
public static readonly Scalar ScalarLargestOverflow = new Scalar(uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue);
public static readonly Scalar ScalarN = EC.N;
@@ -55,8 +55,8 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var exponent = new Scalar(scalarSeed);
var generator = Generators.G;
var publicPoint = exponent * generator;
- var proof = ZkProver.CreateProof(exponent, publicPoint, generator);
- Assert.True(ZkVerifier.Verify(proof, publicPoint, generator));
+ var proof = Prover.CreateProof(exponent, publicPoint, generator);
+ Assert.True(Verifier.Verify(proof, publicPoint, generator));
}
[Fact]
@@ -66,8 +66,8 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
{
var generator = Generators.G;
var publicPoint = exponent * generator;
- var proof = ZkProver.CreateProof(exponent, publicPoint, generator);
- Assert.True(ZkVerifier.Verify(proof, publicPoint, generator));
+ var proof = Prover.CreateProof(exponent, publicPoint, generator);
+ Assert.True(Verifier.Verify(proof, publicPoint, generator));
}
}
@@ -83,11 +83,11 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
Scalar randomScalar = new Scalar(14);
var nonce = randomScalar * generator;
- var challenge = ZkChallenge.Build(publicPoint, nonce);
+ var challenge = Challenge.Build(publicPoint, nonce);
var response = randomScalar + (secret + Scalar.One) * challenge;
- var proof = new ZkKnowledgeOfExponent(nonce, response);
- Assert.False(ZkVerifier.Verify(proof, publicPoint, generator));
+ var proof = new KnowledgeOfExponent(nonce, response);
+ Assert.False(Verifier.Verify(proof, publicPoint, generator));
// Other false verification tests.
var point1 = new Scalar(3) * Generators.G;
@@ -95,8 +95,8 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var scalar = new Scalar(11);
var gen = Generators.G;
- proof = new ZkKnowledgeOfExponent(point1, scalar);
- Assert.False(ZkVerifier.Verify(proof, point2, gen));
+ proof = new KnowledgeOfExponent(point1, scalar);
+ Assert.False(Verifier.Verify(proof, point2, gen));
}
[Fact]
@@ -106,26 +106,26 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var gen = new Scalar(4) * Generators.G;
var exponent = new Scalar(val, val, val, val, val, val, val, val);
var p = exponent * gen;
- var proof = ZkProver.CreateProof(exponent, p, gen);
- Assert.True(ZkVerifier.Verify(proof, p, gen));
+ var proof = Prover.CreateProof(exponent, p, gen);
+ Assert.True(Verifier.Verify(proof, p, gen));
exponent = EC.N + (new Scalar(1)).Negate();
p = exponent * gen;
- proof = ZkProver.CreateProof(exponent, p, gen);
- Assert.True(ZkVerifier.Verify(proof, p, gen));
+ proof = Prover.CreateProof(exponent, p, gen);
+ Assert.True(Verifier.Verify(proof, p, gen));
exponent = EC.NC;
p = exponent * gen;
- proof = ZkProver.CreateProof(exponent, p, gen);
- Assert.True(ZkVerifier.Verify(proof, p, gen));
+ proof = Prover.CreateProof(exponent, p, gen);
+ Assert.True(Verifier.Verify(proof, p, gen));
exponent = EC.NC + new Scalar(1);
p = exponent * gen;
- proof = ZkProver.CreateProof(exponent, p, gen);
- Assert.True(ZkVerifier.Verify(proof, p, gen));
+ proof = Prover.CreateProof(exponent, p, gen);
+ Assert.True(Verifier.Verify(proof, p, gen));
exponent = EC.NC + (new Scalar(1)).Negate();
p = exponent * gen;
- proof = ZkProver.CreateProof(exponent, p, gen);
- Assert.True(ZkVerifier.Verify(proof, p, gen));
+ proof = Prover.CreateProof(exponent, p, gen);
+ Assert.True(Verifier.Verify(proof, p, gen));
}
[Fact]
@@ -136,17 +136,17 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var publicPoint = point1;
var nonce = Generators.G;
- var challenge = ZkChallenge.Build(publicPoint, nonce);
+ var challenge = Challenge.Build(publicPoint, nonce);
Assert.Equal("secp256k1_scalar = { 0x0F850F8CUL, 0x9D74683AUL, 0xDD03779BUL, 0xFD58F09BUL, 0xE148D87AUL, 0x3477A63FUL, 0xBE5906D3UL, 0x35E5A382UL }", challenge.ToC(""));
publicPoint = Generators.G;
nonce = point2;
- challenge = ZkChallenge.Build(publicPoint, nonce);
+ challenge = Challenge.Build(publicPoint, nonce);
Assert.Equal("secp256k1_scalar = { 0x69823107UL, 0xDA1CE96BUL, 0xBA00C8E7UL, 0x8A031437UL, 0x4D0BC9ADUL, 0x790E6FD8UL, 0x6C2EF5E6UL, 0x8F476E3FUL }", challenge.ToC(""));
publicPoint = point1;
nonce = point2;
- challenge = ZkChallenge.Build(publicPoint, nonce);
+ challenge = Challenge.Build(publicPoint, nonce);
Assert.Equal("secp256k1_scalar = { 0xC5AA9243UL, 0x074DDA7CUL, 0xE8FFD6CAUL, 0xF3613B9EUL, 0x542CBD09UL, 0xF4191712UL, 0x045BD716UL, 0xECCC6626UL }", challenge.ToC(""));
}
@@ -154,27 +154,27 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
public void ChallengeThrows()
{
// Demonstrate when it shouldn't throw.
- ZkChallenge.Build(Generators.G, Generators.Ga);
+ Challenge.Build(Generators.G, Generators.Ga);
// Infinity cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => ZkChallenge.Build(Generators.G, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkChallenge.Build(GroupElement.Infinity, Generators.Ga));
- Assert.ThrowsAny<ArgumentException>(() => ZkChallenge.Build(GroupElement.Infinity, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Challenge.Build(Generators.G, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Challenge.Build(GroupElement.Infinity, Generators.Ga));
+ Assert.ThrowsAny<ArgumentException>(() => Challenge.Build(GroupElement.Infinity, GroupElement.Infinity));
// Public and random points cannot be the same.
- Assert.ThrowsAny<InvalidOperationException>(() => ZkChallenge.Build(Generators.G, Generators.G));
+ Assert.ThrowsAny<InvalidOperationException>(() => Challenge.Build(Generators.G, Generators.G));
}
[Fact]
public void ExponentProofThrows()
{
// Demonstrate when it shouldn't throw.
- new ZkKnowledgeOfExponent(Generators.G, Scalar.One);
+ new KnowledgeOfExponent(Generators.G, Scalar.One);
// Infinity or zero cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => new ZkKnowledgeOfExponent(Generators.G, Scalar.Zero));
- Assert.ThrowsAny<ArgumentException>(() => new ZkKnowledgeOfExponent(GroupElement.Infinity, Scalar.One));
- Assert.ThrowsAny<ArgumentException>(() => new ZkKnowledgeOfExponent(GroupElement.Infinity, Scalar.Zero));
+ Assert.ThrowsAny<ArgumentException>(() => new KnowledgeOfExponent(Generators.G, Scalar.Zero));
+ Assert.ThrowsAny<ArgumentException>(() => new KnowledgeOfExponent(GroupElement.Infinity, Scalar.One));
+ Assert.ThrowsAny<ArgumentException>(() => new KnowledgeOfExponent(GroupElement.Infinity, Scalar.Zero));
}
[Fact]
@@ -183,42 +183,42 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var two = new Scalar(2);
// Demonstrate when it shouldn't throw.
- ZkProver.CreateProof(two, two * Generators.G, Generators.G);
+ Prover.CreateProof(two, two * Generators.G, Generators.G);
// Infinity or zero cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, two * Generators.G, Generators.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(two, GroupElement.Infinity, Generators.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(two, two * Generators.G, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, GroupElement.Infinity, Generators.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, two * Generators.G, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(two, GroupElement.Infinity, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, GroupElement.Infinity, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(Scalar.Zero, two * Generators.G, Generators.G));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(two, GroupElement.Infinity, Generators.G));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(two, two * Generators.G, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(Scalar.Zero, GroupElement.Infinity, Generators.G));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(Scalar.Zero, two * Generators.G, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(two, GroupElement.Infinity, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(Scalar.Zero, GroupElement.Infinity, GroupElement.Infinity));
// Public point must be generator * exponent.
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(two, Generators.G, Generators.G));
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(two, new Scalar(3) * Generators.G, Generators.G));
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(two, Scalar.One * Generators.G, Generators.G));
+ Assert.ThrowsAny<InvalidOperationException>(() => Prover.CreateProof(two, Generators.G, Generators.G));
+ Assert.ThrowsAny<InvalidOperationException>(() => Prover.CreateProof(two, new Scalar(3) * Generators.G, Generators.G));
+ Assert.ThrowsAny<InvalidOperationException>(() => Prover.CreateProof(two, Scalar.One * Generators.G, Generators.G));
// Exponent cannot overflow.
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(EC.N, EC.N * Generators.G, Generators.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(ScalarLargestOverflow, ScalarLargestOverflow * Generators.G, Generators.G));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(EC.N, EC.N * Generators.G, Generators.G));
+ Assert.ThrowsAny<ArgumentException>(() => Prover.CreateProof(ScalarLargestOverflow, ScalarLargestOverflow * Generators.G, Generators.G));
}
[Fact]
public void VerifierThrows()
{
- var proof = new ZkKnowledgeOfExponent(Generators.G, Scalar.One);
+ var proof = new KnowledgeOfExponent(Generators.G, Scalar.One);
// Demonstrate when it shouldn't throw.
- ZkVerifier.Verify(proof, Generators.Ga, Generators.Gg);
+ Verifier.Verify(proof, Generators.Ga, Generators.Gg);
// Infinity cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => ZkVerifier.Verify(proof, GroupElement.Infinity, Generators.Gg));
- Assert.ThrowsAny<ArgumentException>(() => ZkVerifier.Verify(proof, Generators.Ga, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkVerifier.Verify(proof, GroupElement.Infinity, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Verifier.Verify(proof, GroupElement.Infinity, Generators.Gg));
+ Assert.ThrowsAny<ArgumentException>(() => Verifier.Verify(proof, Generators.Ga, GroupElement.Infinity));
+ Assert.ThrowsAny<ArgumentException>(() => Verifier.Verify(proof, GroupElement.Infinity, GroupElement.Infinity));
// Public point should not be equal to the random point of the proof.
- Assert.ThrowsAny<InvalidOperationException>(() => ZkVerifier.Verify(proof, Generators.G, Generators.Ga));
+ Assert.ThrowsAny<InvalidOperationException>(() => Verifier.Verify(proof, Generators.G, Generators.Ga));
}
[Fact]
@@ -229,7 +229,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
{
mockRandom.GetScalarResults.Add(scalar);
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(Scalar.One, Scalar.One * Generators.G, Generators.G, mockRandom));
+ Assert.ThrowsAny<InvalidOperationException>(() => Prover.CreateProof(Scalar.One, Scalar.One * Generators.G, Generators.G, mockRandom));
}
}
@@ -242,7 +242,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
// Don't tolerate if the second zero scalar random is received.
mockRandom.GetScalarResults.Add(Scalar.Zero);
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(Scalar.One, Scalar.One * Generators.G, Generators.G, mockRandom));
+ Assert.ThrowsAny<InvalidOperationException>(() => Prover.CreateProof(Scalar.One, Scalar.One * Generators.G, Generators.G, mockRandom));
}
}
}

RENAME
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/ZkRepresentationTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfRepresentationTests.cs
@@ -8,7 +8,7 @@ using Xunit;
namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
{
- public class ZkRepresentationTests
+ public class KnowledgeOfRepresentationTests
{
[Theory]
[InlineData(1, 1)]
@@ -28,8 +28,8 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
{
publicPoint += exponents[i] * generators[i];
}
- var proof = ZkProver.CreateProof(exponents, publicPoint, generators);
- Assert.True(ZkVerifier.Verify(proof, publicPoint, generators));
+ var proof = Prover.CreateProof(exponents, publicPoint, generators);
+ Assert.True(Verifier.Verify(proof, publicPoint, generators));
}
}
}

RENAME
WalletWasabi/Crypto/ZeroKnowledge/ZkChallenge.cs
WalletWasabi/Crypto/ZeroKnowledge/Challenge.cs
@@ -8,7 +8,7 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
- public static class ZkChallenge
+ public static class Challenge
{
public static Scalar Build(GroupElement publicPoint, GroupElement nonce)
{

RENAME
WalletWasabi/Crypto/ZeroKnowledge/ZkKnowledgeOfExponent.cs
WalletWasabi/Crypto/ZeroKnowledge/KnowledgeOfExponent.cs
@@ -7,9 +7,9 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
- public class ZkKnowledgeOfExponent
+ public class KnowledgeOfExponent
{
- public ZkKnowledgeOfExponent(GroupElement nonce, Scalar response)
+ public KnowledgeOfExponent(GroupElement nonce, Scalar response)
{
Guard.False($"{nameof(nonce)}.{nameof(nonce.IsInfinity)}", nonce.IsInfinity);
Guard.False($"{nameof(response)}.{nameof(response.IsZero)}", response.IsZero);

RENAME
WalletWasabi/Crypto/ZeroKnowledge/ZkKnowledgeOfRepresentation.cs
WalletWasabi/Crypto/ZeroKnowledge/KnowledgeOfRepresentation.cs
@@ -6,9 +6,9 @@ using WalletWasabi.Crypto.Groups;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
- public class ZkKnowledgeOfRepresentation
+ public class KnowledgeOfRepresentation
{
- public ZkKnowledgeOfRepresentation(GroupElement nonce, IEnumerable<Scalar> responses)
+ public KnowledgeOfRepresentation(GroupElement nonce, IEnumerable<Scalar> responses)
{
Nonce = nonce;
Responses = responses;

RENAME
WalletWasabi/Crypto/ZeroKnowledge/ZkProver.cs
WalletWasabi/Crypto/ZeroKnowledge/Prover.cs
@@ -9,9 +9,9 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
- public static class ZkProver
+ public static class Prover
{
- public static ZkKnowledgeOfExponent CreateProof(Scalar exponent, GroupElement publicPoint, GroupElement generator, WasabiRandom? random = null)
+ public static KnowledgeOfExponent CreateProof(Scalar exponent, GroupElement publicPoint, GroupElement generator, WasabiRandom? random = null)
{
Guard.False($"{nameof(exponent)}.{nameof(exponent.IsOverflow)}", exponent.IsOverflow);
Guard.False($"{nameof(exponent)}.{nameof(exponent.IsZero)}", exponent.IsZero);
@@ -24,10 +24,10 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
var proof = CreateProof(new[] { exponent }, publicPoint, new[] { generator }, random);
- return new ZkKnowledgeOfExponent(proof.Nonce, proof.Responses.First());
+ return new KnowledgeOfExponent(proof.Nonce, proof.Responses.First());
}
- public static ZkKnowledgeOfRepresentation CreateProof(IEnumerable<Scalar> exponents, GroupElement publicPoint, IEnumerable<GroupElement> generators, WasabiRandom? random = null)
+ public static KnowledgeOfRepresentation CreateProof(IEnumerable<Scalar> exponents, GroupElement publicPoint, IEnumerable<GroupElement> generators, WasabiRandom? random = null)
{
Guard.False($"{nameof(publicPoint)}.{nameof(publicPoint.IsInfinity)}", publicPoint.IsInfinity);
@@ -57,7 +57,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
nonce += randomPoint;
}
- var challenge = ZkChallenge.HashToScalar(new[] { publicPoint, nonce }.Concat(generators).ToArray());
+ var challenge = Challenge.HashToScalar(new[] { publicPoint, nonce }.Concat(generators).ToArray());
var responses = new List<Scalar>();
for (int i = 0; i < exponentArray.Length; i++)
@@ -68,7 +68,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
responses.Add(response);
}
- return new ZkKnowledgeOfRepresentation(nonce, responses);
+ return new KnowledgeOfRepresentation(nonce, responses);
}
private static Scalar GetNonZeroRandomScalar(WasabiRandom? random = null)

RENAME
WalletWasabi/Crypto/ZeroKnowledge/ZkVerifier.cs
WalletWasabi/Crypto/ZeroKnowledge/Verifier.cs
@@ -7,9 +7,9 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
- public static class ZkVerifier
+ public static class Verifier
{
- public static bool Verify(ZkKnowledgeOfExponent proof, GroupElement publicPoint, GroupElement generator)
+ public static bool Verify(KnowledgeOfExponent proof, GroupElement publicPoint, GroupElement generator)
{
Guard.False($"{nameof(generator)}.{nameof(generator.IsInfinity)}", generator.IsInfinity);
Guard.False($"{nameof(publicPoint)}.{nameof(publicPoint.IsInfinity)}", publicPoint.IsInfinity);
@@ -19,11 +19,11 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
throw new InvalidOperationException($"{nameof(publicPoint)} and {nameof(proof.Nonce)} should not be equal.");
}
- var zkor = new ZkKnowledgeOfRepresentation(proof.Nonce, new[] { proof.Response });
- return Verify(zkor, publicPoint, new[] { generator });
+ var knowledge = new KnowledgeOfRepresentation(proof.Nonce, new[] { proof.Response });
+ return Verify(knowledge, publicPoint, new[] { generator });
}
- public static bool Verify(ZkKnowledgeOfRepresentation proof, GroupElement publicPoint, IEnumerable<GroupElement> generators)
+ public static bool Verify(KnowledgeOfRepresentation proof, GroupElement publicPoint, IEnumerable<GroupElement> generators)
{
foreach (var generator in generators)
{
@@ -33,7 +33,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
var nonce = proof.Nonce;
var responses = proof.Responses.ToArray();
- var challenge = ZkChallenge.HashToScalar(new[] { publicPoint, nonce }.Concat(generators).ToArray());
+ var challenge = Challenge.HashToScalar(new[] { publicPoint, nonce }.Concat(generators).ToArray());
var a = challenge * publicPoint + nonce;
var b = GroupElement.Infinity;

Remove zk prefixes