Move generators to Generators class
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/GroupElements/GeneralTests.cs
WalletWasabi.Tests/UnitTests/Crypto/GroupElements/GeneralTests.cs
@@ -169,28 +169,28 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
var expectedInfinity = "Infinity";
var expectedTwo = "secp256k1_fe x = { 0x00709EE5UL, 0x03026E57UL, 0x03CA7ABAUL, 0x012E33BCUL, 0x005C778EUL, 0x01701F36UL, 0x005406E9UL, 0x01F5B4C1UL, 0x039441EDUL, 0x0031811FUL, 1, 1 };secp256k1_fe y = { 0x00CFE52AUL, 0x010C6A54UL, 0x010E1236UL, 0x0194C99BUL, 0x02F7F632UL, 0x019B3ABBUL, 0x00584194UL, 0x030CE68FUL, 0x00FEA63DUL, 0x0006B85AUL, 1, 1 };";
- Assert.Equal(expectedGenerator, GroupElement.G.ToString());
+ Assert.Equal(expectedGenerator, Generators.G.ToString());
Assert.Equal(expectedInfinity, GroupElement.Infinity.ToString());
Assert.Equal(expectedTwo, new GroupElement(EC.G * new Scalar(2)).ToString());
- var expectedOther = $"{nameof(GroupElement.Gw)} Generator, secp256k1_fe x = {{ 0x01013C2FUL, 0x02740389UL, 0x008F54EFUL, 0x0113E5FFUL, 0x01427B04UL, 0x013DC46AUL, 0x024707DBUL, 0x026081FEUL, 0x02E54CCBUL, 0x000E292AUL, 1, 1 }};secp256k1_fe y = {{ 0x011FAF6BUL, 0x00B7E446UL, 0x00391D3CUL, 0x02DC9E83UL, 0x0104B9F8UL, 0x00A538B6UL, 0x0300C87BUL, 0x03B57940UL, 0x0176D2D7UL, 0x00219279UL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gw.ToString());
- expectedOther = $"{nameof(GroupElement.GV)} Generator, secp256k1_fe x = {{ 0x01C14967UL, 0x032B8C8CUL, 0x00BCF412UL, 0x02990EB3UL, 0x036E253AUL, 0x010A2C08UL, 0x03184692UL, 0x010747EDUL, 0x000F8A3BUL, 0x0008B07BUL, 1, 1 }};secp256k1_fe y = {{ 0x03CE6291UL, 0x016336FEUL, 0x02C3A482UL, 0x03FE0AD3UL, 0x00E48CBCUL, 0x03359AC5UL, 0x027BD948UL, 0x02022579UL, 0x01C5FA64UL, 0x00172057UL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.GV.ToString());
- expectedOther = $"{nameof(GroupElement.Ga)} Generator, secp256k1_fe x = {{ 0x0266ABAEUL, 0x0004B9CFUL, 0x02E7378EUL, 0x00EBC73BUL, 0x018E34BDUL, 0x01312796UL, 0x0234D9B7UL, 0x018E7FE4UL, 0x018F3EB9UL, 0x000BDEFCUL, 1, 1 }};secp256k1_fe y = {{ 0x0006FA9BUL, 0x01CE10D2UL, 0x03470431UL, 0x006E8AF0UL, 0x010326A6UL, 0x0175DCEDUL, 0x019B66BFUL, 0x00F74680UL, 0x03D9DD5FUL, 0x002BCC33UL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Ga.ToString());
- expectedOther = $"{nameof(GroupElement.Gg)} Generator, secp256k1_fe x = {{ 0x026C277DUL, 0x00C330E9UL, 0x00EAC3DEUL, 0x0359F156UL, 0x03047FE9UL, 0x00C6F7BAUL, 0x03130E6AUL, 0x01535284UL, 0x00A880CBUL, 0x0011E1F1UL, 1, 1 }};secp256k1_fe y = {{ 0x018C0772UL, 0x00789C4DUL, 0x00C7FBD0UL, 0x02F58835UL, 0x02321AA5UL, 0x0331FF52UL, 0x03063B93UL, 0x02EAD3B9UL, 0x00CD2B17UL, 0x003A8A67UL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gg.ToString());
- expectedOther = $"{nameof(GroupElement.Gh)} Generator, secp256k1_fe x = {{ 0x03DEAC03UL, 0x02849530UL, 0x006C9A8DUL, 0x03A97B7BUL, 0x02C1B389UL, 0x01F35E2FUL, 0x017513A7UL, 0x01A34B45UL, 0x033B63E0UL, 0x0016BC8EUL, 1, 1 }};secp256k1_fe y = {{ 0x0145B539UL, 0x032AA24FUL, 0x0169F63DUL, 0x02F69B76UL, 0x0267A0ADUL, 0x01D42286UL, 0x00A32FC8UL, 0x01165B84UL, 0x0057FC53UL, 0x001364BFUL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gh.ToString());
- expectedOther = $"{nameof(GroupElement.Gs)} Generator, secp256k1_fe x = {{ 0x008C7263UL, 0x03D6A57FUL, 0x0367F61CUL, 0x017F373BUL, 0x038D86E3UL, 0x03BF070AUL, 0x02E2F848UL, 0x01997C26UL, 0x0090B66BUL, 0x0006DE19UL, 1, 1 }};secp256k1_fe y = {{ 0x038CCC8BUL, 0x028AAAFEUL, 0x01B21F36UL, 0x0003B3E9UL, 0x01BA251EUL, 0x03B46C48UL, 0x02C48003UL, 0x019FD6C4UL, 0x016C02D3UL, 0x00202E60UL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gs.ToString());
- expectedOther = $"{nameof(GroupElement.Gwp)} Generator, secp256k1_fe x = {{ 0x03A4F16CUL, 0x01610768UL, 0x017DAC47UL, 0x036A2588UL, 0x019961D9UL, 0x038F8689UL, 0x01B0D71FUL, 0x03266FC3UL, 0x021F53BFUL, 0x00291589UL, 1, 1 }};secp256k1_fe y = {{ 0x0069FEE2UL, 0x03EF9C5DUL, 0x00990987UL, 0x0123332DUL, 0x02BF866AUL, 0x00A2CB4CUL, 0x01DE709CUL, 0x02036AA6UL, 0x01D2B679UL, 0x001F716FUL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gwp.ToString());
- expectedOther = $"{nameof(GroupElement.Gx0)} Generator, secp256k1_fe x = {{ 0x00282D76UL, 0x00B3C8A0UL, 0x002FCDC6UL, 0x01C2A54BUL, 0x01CCE6D4UL, 0x01531403UL, 0x03250329UL, 0x0098CA40UL, 0x00F60042UL, 0x002079EFUL, 1, 1 }};secp256k1_fe y = {{ 0x02134910UL, 0x015FFE0DUL, 0x028F258DUL, 0x02473F56UL, 0x00B9B563UL, 0x01324EA8UL, 0x037EA618UL, 0x024B4CB2UL, 0x01A9AB0FUL, 0x00179972UL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gx0.ToString());
- expectedOther = $"{nameof(GroupElement.Gx1)} Generator, secp256k1_fe x = {{ 0x001A5105UL, 0x029F1DCBUL, 0x02C35E8DUL, 0x01D06A6CUL, 0x006748FAUL, 0x0120993CUL, 0x00241D5EUL, 0x000B8FA1UL, 0x02979549UL, 0x00280C7FUL, 1, 1 }};secp256k1_fe y = {{ 0x02601941UL, 0x017DC826UL, 0x0392A4CCUL, 0x000E1939UL, 0x02BDFDB2UL, 0x000D9228UL, 0x01EBCC89UL, 0x00F3257FUL, 0x01312A11UL, 0x000BFA1CUL, 1, 1 }};";
- Assert.Equal(expectedOther, GroupElement.Gx1.ToString());
+ var expectedOther = $"{nameof(Generators.Gw)} Generator, secp256k1_fe x = {{ 0x01013C2FUL, 0x02740389UL, 0x008F54EFUL, 0x0113E5FFUL, 0x01427B04UL, 0x013DC46AUL, 0x024707DBUL, 0x026081FEUL, 0x02E54CCBUL, 0x000E292AUL, 1, 1 }};secp256k1_fe y = {{ 0x011FAF6BUL, 0x00B7E446UL, 0x00391D3CUL, 0x02DC9E83UL, 0x0104B9F8UL, 0x00A538B6UL, 0x0300C87BUL, 0x03B57940UL, 0x0176D2D7UL, 0x00219279UL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gw.ToString());
+ expectedOther = $"{nameof(Generators.GV)} Generator, secp256k1_fe x = {{ 0x01C14967UL, 0x032B8C8CUL, 0x00BCF412UL, 0x02990EB3UL, 0x036E253AUL, 0x010A2C08UL, 0x03184692UL, 0x010747EDUL, 0x000F8A3BUL, 0x0008B07BUL, 1, 1 }};secp256k1_fe y = {{ 0x03CE6291UL, 0x016336FEUL, 0x02C3A482UL, 0x03FE0AD3UL, 0x00E48CBCUL, 0x03359AC5UL, 0x027BD948UL, 0x02022579UL, 0x01C5FA64UL, 0x00172057UL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.GV.ToString());
+ expectedOther = $"{nameof(Generators.Ga)} Generator, secp256k1_fe x = {{ 0x0266ABAEUL, 0x0004B9CFUL, 0x02E7378EUL, 0x00EBC73BUL, 0x018E34BDUL, 0x01312796UL, 0x0234D9B7UL, 0x018E7FE4UL, 0x018F3EB9UL, 0x000BDEFCUL, 1, 1 }};secp256k1_fe y = {{ 0x0006FA9BUL, 0x01CE10D2UL, 0x03470431UL, 0x006E8AF0UL, 0x010326A6UL, 0x0175DCEDUL, 0x019B66BFUL, 0x00F74680UL, 0x03D9DD5FUL, 0x002BCC33UL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Ga.ToString());
+ expectedOther = $"{nameof(Generators.Gg)} Generator, secp256k1_fe x = {{ 0x026C277DUL, 0x00C330E9UL, 0x00EAC3DEUL, 0x0359F156UL, 0x03047FE9UL, 0x00C6F7BAUL, 0x03130E6AUL, 0x01535284UL, 0x00A880CBUL, 0x0011E1F1UL, 1, 1 }};secp256k1_fe y = {{ 0x018C0772UL, 0x00789C4DUL, 0x00C7FBD0UL, 0x02F58835UL, 0x02321AA5UL, 0x0331FF52UL, 0x03063B93UL, 0x02EAD3B9UL, 0x00CD2B17UL, 0x003A8A67UL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gg.ToString());
+ expectedOther = $"{nameof(Generators.Gh)} Generator, secp256k1_fe x = {{ 0x03DEAC03UL, 0x02849530UL, 0x006C9A8DUL, 0x03A97B7BUL, 0x02C1B389UL, 0x01F35E2FUL, 0x017513A7UL, 0x01A34B45UL, 0x033B63E0UL, 0x0016BC8EUL, 1, 1 }};secp256k1_fe y = {{ 0x0145B539UL, 0x032AA24FUL, 0x0169F63DUL, 0x02F69B76UL, 0x0267A0ADUL, 0x01D42286UL, 0x00A32FC8UL, 0x01165B84UL, 0x0057FC53UL, 0x001364BFUL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gh.ToString());
+ expectedOther = $"{nameof(Generators.Gs)} Generator, secp256k1_fe x = {{ 0x008C7263UL, 0x03D6A57FUL, 0x0367F61CUL, 0x017F373BUL, 0x038D86E3UL, 0x03BF070AUL, 0x02E2F848UL, 0x01997C26UL, 0x0090B66BUL, 0x0006DE19UL, 1, 1 }};secp256k1_fe y = {{ 0x038CCC8BUL, 0x028AAAFEUL, 0x01B21F36UL, 0x0003B3E9UL, 0x01BA251EUL, 0x03B46C48UL, 0x02C48003UL, 0x019FD6C4UL, 0x016C02D3UL, 0x00202E60UL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gs.ToString());
+ expectedOther = $"{nameof(Generators.Gwp)} Generator, secp256k1_fe x = {{ 0x03A4F16CUL, 0x01610768UL, 0x017DAC47UL, 0x036A2588UL, 0x019961D9UL, 0x038F8689UL, 0x01B0D71FUL, 0x03266FC3UL, 0x021F53BFUL, 0x00291589UL, 1, 1 }};secp256k1_fe y = {{ 0x0069FEE2UL, 0x03EF9C5DUL, 0x00990987UL, 0x0123332DUL, 0x02BF866AUL, 0x00A2CB4CUL, 0x01DE709CUL, 0x02036AA6UL, 0x01D2B679UL, 0x001F716FUL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gwp.ToString());
+ expectedOther = $"{nameof(Generators.Gx0)} Generator, secp256k1_fe x = {{ 0x00282D76UL, 0x00B3C8A0UL, 0x002FCDC6UL, 0x01C2A54BUL, 0x01CCE6D4UL, 0x01531403UL, 0x03250329UL, 0x0098CA40UL, 0x00F60042UL, 0x002079EFUL, 1, 1 }};secp256k1_fe y = {{ 0x02134910UL, 0x015FFE0DUL, 0x028F258DUL, 0x02473F56UL, 0x00B9B563UL, 0x01324EA8UL, 0x037EA618UL, 0x024B4CB2UL, 0x01A9AB0FUL, 0x00179972UL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gx0.ToString());
+ expectedOther = $"{nameof(Generators.Gx1)} Generator, secp256k1_fe x = {{ 0x001A5105UL, 0x029F1DCBUL, 0x02C35E8DUL, 0x01D06A6CUL, 0x006748FAUL, 0x0120993CUL, 0x00241D5EUL, 0x000B8FA1UL, 0x02979549UL, 0x00280C7FUL, 1, 1 }};secp256k1_fe y = {{ 0x02601941UL, 0x017DC826UL, 0x0392A4CCUL, 0x000E1939UL, 0x02BDFDB2UL, 0x000D9228UL, 0x01EBCC89UL, 0x00F3257FUL, 0x01312A11UL, 0x000BFA1CUL, 1, 1 }};";
+ Assert.Equal(expectedOther, Generators.Gx1.ToString());
}
private byte[] FillByteArray(int length, byte character)
@@ -236,7 +236,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
[Fact]
public void Serialization()
{
- var ge = GroupElement.G;
+ var ge = Generators.G;
var ge2 = GroupElement.FromBytes(ge.ToBytes());
Assert.Equal(ge, ge2);
@@ -285,11 +285,11 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
var hexG = "0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798";
var hexGodd = "0379BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798";
- Assert.Equal(hexG, ByteHelpers.ToHex(GroupElement.G.ToBytes()));
- Assert.Equal(GroupElement.G, GroupElement.FromBytes(ByteHelpers.FromHex(hexG)));
+ Assert.Equal(hexG, ByteHelpers.ToHex(Generators.G.ToBytes()));
+ Assert.Equal(Generators.G, GroupElement.FromBytes(ByteHelpers.FromHex(hexG)));
- Assert.Equal(hexGodd, ByteHelpers.ToHex(GroupElement.G.Negate().ToBytes()));
- Assert.Equal(GroupElement.G.Negate(), GroupElement.FromBytes(ByteHelpers.FromHex(hexGodd)));
+ Assert.Equal(hexGodd, ByteHelpers.ToHex(Generators.G.Negate().ToBytes()));
+ Assert.Equal(Generators.G.Negate(), GroupElement.FromBytes(ByteHelpers.FromHex(hexGodd)));
}
[Fact]

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/GroupElements/GeneratorTests.cs
WalletWasabi.Tests/UnitTests/Crypto/GroupElements/GeneratorTests.cs
@@ -14,31 +14,31 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
{
var generator = new GroupElement(EC.G);
var generator2 = new GroupElement(new GE(EC.G.x, EC.G.y));
- Assert.Equal(GroupElement.G, generator);
- Assert.Equal(GroupElement.G, generator2);
+ Assert.Equal(Generators.G, generator);
+ Assert.Equal(Generators.G, generator2);
- Assert.NotEqual(GroupElement.G, GroupElement.Infinity);
- Assert.NotEqual(GroupElement.G, new GroupElement(EC.G * Scalar.Zero));
- Assert.NotEqual(GroupElement.G, new GroupElement(EC.G * new Scalar(2)));
+ Assert.NotEqual(Generators.G, GroupElement.Infinity);
+ Assert.NotEqual(Generators.G, new GroupElement(EC.G * Scalar.Zero));
+ Assert.NotEqual(Generators.G, new GroupElement(EC.G * new Scalar(2)));
var infinity = new GroupElement(new GE(EC.G.x, EC.G.y, infinity: true));
- Assert.NotEqual(GroupElement.G, infinity);
+ Assert.NotEqual(Generators.G, infinity);
Assert.True(infinity.IsInfinity);
}
[Fact]
public void GeneratorsArentChanged()
{
- Assert.Equal("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", ByteHelpers.ToHex(GroupElement.G.ToBytes()));
- Assert.Equal("032F7BF18F3EB9639FF9234D9B74C49E598E34BD3AF1CEEE7378E012E73E66ABAE", ByteHelpers.ToHex(GroupElement.Ga.ToBytes()));
- Assert.Equal("024787C4A880CB54D4A13130E6A31BDEEB047FE9D67C558EAC3DE30CC3A66C277D", ByteHelpers.ToHex(GroupElement.Gg.ToBytes()));
- Assert.Equal("035AF23B3B63E068D2D157513A77CD78BEC1B389EA5EDEC6C9A8DA1254C3DEAC03", ByteHelpers.ToHex(GroupElement.Gh.ToBytes()));
- Assert.Equal("031B786490B66B665F09AE2F848EFC1C2B8D86E35FCDCEF67F61CF5A95FC8C7263", ByteHelpers.ToHex(GroupElement.Gs.ToBytes()));
- Assert.Equal("0322C1EC0F8A3B41D1FB7184692428B0236E253AA643ACCBCF412CAE3231C14967", ByteHelpers.ToHex(GroupElement.GV.ToBytes()));
- Assert.Equal("0338A4AAE54CCB98207FA4707DB4F711A9427B0444F97FC8F54EF9D00E25013C2F", ByteHelpers.ToHex(GroupElement.Gw.ToBytes()));
- Assert.Equal("02A456261F53BFC99BF0DB0D71FE3E1A259961D9DA896217DAC475841DA3A4F16C", ByteHelpers.ToHex(GroupElement.Gwp.ToBytes()));
- Assert.Equal("0281E7BCF60042263290325032954C500DCCE6D470A952C2FCDC62CF2280282D76", ByteHelpers.ToHex(GroupElement.Gx0.ToBytes()));
- Assert.Equal("03A031FE97954902E3E84241D5E48264F06748FA741A9B2C35E8DA7C772C1A5105", ByteHelpers.ToHex(GroupElement.Gx1.ToBytes()));
+ Assert.Equal("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", ByteHelpers.ToHex(Generators.G.ToBytes()));
+ Assert.Equal("032F7BF18F3EB9639FF9234D9B74C49E598E34BD3AF1CEEE7378E012E73E66ABAE", ByteHelpers.ToHex(Generators.Ga.ToBytes()));
+ Assert.Equal("024787C4A880CB54D4A13130E6A31BDEEB047FE9D67C558EAC3DE30CC3A66C277D", ByteHelpers.ToHex(Generators.Gg.ToBytes()));
+ Assert.Equal("035AF23B3B63E068D2D157513A77CD78BEC1B389EA5EDEC6C9A8DA1254C3DEAC03", ByteHelpers.ToHex(Generators.Gh.ToBytes()));
+ Assert.Equal("031B786490B66B665F09AE2F848EFC1C2B8D86E35FCDCEF67F61CF5A95FC8C7263", ByteHelpers.ToHex(Generators.Gs.ToBytes()));
+ Assert.Equal("0322C1EC0F8A3B41D1FB7184692428B0236E253AA643ACCBCF412CAE3231C14967", ByteHelpers.ToHex(Generators.GV.ToBytes()));
+ Assert.Equal("0338A4AAE54CCB98207FA4707DB4F711A9427B0444F97FC8F54EF9D00E25013C2F", ByteHelpers.ToHex(Generators.Gw.ToBytes()));
+ Assert.Equal("02A456261F53BFC99BF0DB0D71FE3E1A259961D9DA896217DAC475841DA3A4F16C", ByteHelpers.ToHex(Generators.Gwp.ToBytes()));
+ Assert.Equal("0281E7BCF60042263290325032954C500DCCE6D470A952C2FCDC62CF2280282D76", ByteHelpers.ToHex(Generators.Gx0.ToBytes()));
+ Assert.Equal("03A031FE97954902E3E84241D5E48264F06748FA741A9B2C35E8DA7C772C1A5105", ByteHelpers.ToHex(Generators.Gx1.ToBytes()));
}
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/GroupElements/OperationTests.cs
WalletWasabi.Tests/UnitTests/Crypto/GroupElements/OperationTests.cs
@@ -12,11 +12,11 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
[Fact]
public void Addition()
{
- var gen1 = GroupElement.Infinity + GroupElement.G;
- var gen2 = GroupElement.G + GroupElement.Infinity;
+ var gen1 = GroupElement.Infinity + Generators.G;
+ var gen2 = Generators.G + GroupElement.Infinity;
var inf = GroupElement.Infinity + GroupElement.Infinity;
- Assert.Equal(GroupElement.G, gen1);
- Assert.Equal(GroupElement.G, gen2);
+ Assert.Equal(Generators.G, gen1);
+ Assert.Equal(Generators.G, gen2);
Assert.Equal(GroupElement.Infinity, inf);
var one = new GroupElement(new Scalar(1) * EC.G);
@@ -24,7 +24,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
var three = new GroupElement(new Scalar(3) * EC.G);
var zero = new GroupElement(Scalar.Zero * EC.G);
- Assert.Equal(GroupElement.G, one);
+ Assert.Equal(Generators.G, one);
Assert.True(zero.IsInfinity);
Assert.Equal(two, one + one);
@@ -41,11 +41,11 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
[Fact]
public void Subtraction()
{
- var minusGen = GroupElement.Infinity - GroupElement.G;
- var gen = GroupElement.G - GroupElement.Infinity;
+ var minusGen = GroupElement.Infinity - Generators.G;
+ var gen = Generators.G - GroupElement.Infinity;
var inf = GroupElement.Infinity - GroupElement.Infinity;
Assert.Equal(new GroupElement(EC.G.Negate()), minusGen);
- Assert.Equal(GroupElement.G, gen);
+ Assert.Equal(Generators.G, gen);
Assert.Equal(GroupElement.Infinity, inf);
var minusOne = new GroupElement(new Scalar(1) * EC.G.Negate());
@@ -55,7 +55,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
var three = new GroupElement(new Scalar(3) * EC.G);
var zero = new GroupElement(Scalar.Zero * EC.G);
- Assert.Equal(GroupElement.G, one);
+ Assert.Equal(Generators.G, one);
Assert.True(zero.IsInfinity);
Assert.Equal(zero, one - one);
@@ -81,7 +81,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
[Fact]
public void Negation()
{
- Assert.Equal(new GroupElement(EC.G.Negate()), GroupElement.G.Negate());
+ Assert.Equal(new GroupElement(EC.G.Negate()), Generators.G.Negate());
Scalar one = new Scalar(1);
Assert.Equal(new GroupElement(EC.G.Negate() * one), new GroupElement(EC.G * one).Negate());
Assert.Equal(GroupElement.Infinity, GroupElement.Infinity.Negate());
@@ -91,7 +91,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
public void MultiplyByScalar()
{
// Scalar one.
- var g = GroupElement.G;
+ var g = Generators.G;
var scalar = Scalar.One;
var expected = new GroupElement(EC.G * scalar);
Assert.Equal(expected, g * scalar);
@@ -149,7 +149,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.GroupElements
[Fact]
public void OverflownScalar()
{
- var g = GroupElement.G;
+ var g = Generators.G;
// Scalar overflown N.
var scalar = EC.N;

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/ZkExponentTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/ZkExponentTests.cs
@@ -53,7 +53,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
public void End2EndVerifiesSimpleProof(uint scalarSeed)
{
var exponent = new Scalar(scalarSeed);
- var generator = GroupElement.G;
+ var generator = Generators.G;
var publicPoint = exponent * generator;
var proof = ZkProver.CreateProof(exponent, publicPoint, generator);
Assert.True(ZkVerifier.Verify(proof, publicPoint, generator));
@@ -64,7 +64,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
{
foreach (var exponent in GetScalars(x => !x.IsOverflow && !x.IsZero))
{
- var generator = GroupElement.G;
+ var generator = Generators.G;
var publicPoint = exponent * generator;
var proof = ZkProver.CreateProof(exponent, publicPoint, generator);
Assert.True(ZkVerifier.Verify(proof, publicPoint, generator));
@@ -78,7 +78,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
// if the final response is not valid wrt the verification equation,
// the verifier should still reject.
var secret = new Scalar(7);
- var generator = GroupElement.G;
+ var generator = Generators.G;
var publicPoint = secret * generator;
Scalar randomScalar = new Scalar(14);
@@ -90,10 +90,10 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
Assert.False(ZkVerifier.Verify(proof, publicPoint, generator));
// Other false verification tests.
- var point1 = new Scalar(3) * GroupElement.G;
- var point2 = new Scalar(7) * GroupElement.G;
+ var point1 = new Scalar(3) * Generators.G;
+ var point2 = new Scalar(7) * Generators.G;
var scalar = new Scalar(11);
- var gen = GroupElement.G;
+ var gen = Generators.G;
proof = new ZkKnowledgeOfExponent(point1, scalar);
Assert.False(ZkVerifier.Verify(proof, point2, gen));
@@ -103,7 +103,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
public void VerifyLargeScalar()
{
uint val = int.MaxValue;
- var gen = new Scalar(4) * GroupElement.G;
+ 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);
@@ -131,15 +131,15 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
[Fact]
public void BuildChallenge()
{
- var point1 = new Scalar(3) * GroupElement.G;
- var point2 = new Scalar(7) * GroupElement.G;
+ var point1 = new Scalar(3) * Generators.G;
+ var point2 = new Scalar(7) * Generators.G;
var publicPoint = point1;
- var randomPoint = GroupElement.G;
+ var randomPoint = Generators.G;
var challenge = ZkChallenge.Build(publicPoint, randomPoint);
Assert.Equal("secp256k1_scalar = { 0x0F850F8CUL, 0x9D74683AUL, 0xDD03779BUL, 0xFD58F09BUL, 0xE148D87AUL, 0x3477A63FUL, 0xBE5906D3UL, 0x35E5A382UL }", challenge.ToC(""));
- publicPoint = GroupElement.G;
+ publicPoint = Generators.G;
randomPoint = point2;
challenge = ZkChallenge.Build(publicPoint, randomPoint);
Assert.Equal("secp256k1_scalar = { 0x69823107UL, 0xDA1CE96BUL, 0xBA00C8E7UL, 0x8A031437UL, 0x4D0BC9ADUL, 0x790E6FD8UL, 0x6C2EF5E6UL, 0x8F476E3FUL }", challenge.ToC(""));
@@ -154,25 +154,25 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
public void ChallengeThrows()
{
// Demonstrate when it shouldn't throw.
- ZkChallenge.Build(GroupElement.G, GroupElement.Ga);
+ ZkChallenge.Build(Generators.G, Generators.Ga);
// Infinity cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => ZkChallenge.Build(GroupElement.G, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkChallenge.Build(GroupElement.Infinity, GroupElement.Ga));
+ 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));
// Public and random points cannot be the same.
- Assert.ThrowsAny<InvalidOperationException>(() => ZkChallenge.Build(GroupElement.G, GroupElement.G));
+ Assert.ThrowsAny<InvalidOperationException>(() => ZkChallenge.Build(Generators.G, Generators.G));
}
[Fact]
public void ExponentProofThrows()
{
// Demonstrate when it shouldn't throw.
- new ZkKnowledgeOfExponent(GroupElement.G, Scalar.One);
+ new ZkKnowledgeOfExponent(Generators.G, Scalar.One);
// Infinity or zero cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => new ZkKnowledgeOfExponent(GroupElement.G, Scalar.Zero));
+ 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));
}
@@ -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 * GroupElement.G, GroupElement.G);
+ ZkProver.CreateProof(two, two * Generators.G, Generators.G);
// Infinity or zero cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, two * GroupElement.G, GroupElement.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(two, GroupElement.Infinity, GroupElement.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(two, two * GroupElement.G, GroupElement.Infinity));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, GroupElement.Infinity, GroupElement.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(Scalar.Zero, two * GroupElement.G, GroupElement.Infinity));
+ 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));
// Public point must be generator * exponent.
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(two, GroupElement.G, GroupElement.G));
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(two, new Scalar(3) * GroupElement.G, GroupElement.G));
- Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(two, Scalar.One * GroupElement.G, GroupElement.G));
+ 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));
// Exponent cannot overflow.
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(EC.N, EC.N * GroupElement.G, GroupElement.G));
- Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(ScalarLargestOverflow, ScalarLargestOverflow * GroupElement.G, GroupElement.G));
+ Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(EC.N, EC.N * Generators.G, Generators.G));
+ Assert.ThrowsAny<ArgumentException>(() => ZkProver.CreateProof(ScalarLargestOverflow, ScalarLargestOverflow * Generators.G, Generators.G));
}
[Fact]
public void VerifierThrows()
{
- var proof = new ZkKnowledgeOfExponent(GroupElement.G, Scalar.One);
+ var proof = new ZkKnowledgeOfExponent(Generators.G, Scalar.One);
// Demonstrate when it shouldn't throw.
- ZkVerifier.Verify(proof, GroupElement.Ga, GroupElement.Gg);
+ ZkVerifier.Verify(proof, Generators.Ga, Generators.Gg);
// Infinity cannot pass through.
- Assert.ThrowsAny<ArgumentException>(() => ZkVerifier.Verify(proof, GroupElement.Infinity, GroupElement.Gg));
- Assert.ThrowsAny<ArgumentException>(() => ZkVerifier.Verify(proof, GroupElement.Ga, GroupElement.Infinity));
+ 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));
// Public point should not be equal to the random point of the proof.
- Assert.ThrowsAny<InvalidOperationException>(() => ZkVerifier.Verify(proof, GroupElement.G, GroupElement.Ga));
+ Assert.ThrowsAny<InvalidOperationException>(() => ZkVerifier.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 * GroupElement.G, GroupElement.G, mockRandom));
+ Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.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 * GroupElement.G, GroupElement.G, mockRandom));
+ Assert.ThrowsAny<InvalidOperationException>(() => ZkProver.CreateProof(Scalar.One, Scalar.One * Generators.G, Generators.G, mockRandom));
}
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/ZkRepresentationTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/ZkRepresentationTests.cs
@@ -22,7 +22,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
public void End2EndVerifiesSimpleProof(uint scalarSeed1, uint scalarSeed2)
{
var exponents = new[] { new Scalar(scalarSeed1), new Scalar(scalarSeed2) };
- var generators = new[] { GroupElement.G, GroupElement.Ga };
+ var generators = new[] { Generators.G, Generators.Ga };
var publicPoint = GroupElement.Infinity;
for (int i = 0; i < exponents.Length; i++)
{

ADD
WalletWasabi/Crypto/Groups/Generators.cs
+using NBitcoin.Secp256k1;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WalletWasabi.Crypto.Groups
+{
+ public static class Generators
+ {/// <summary>
+ /// The base point defined in the secp256k1 standard used in ECDSA public key derivation.
+ /// </summary>
+ public static GroupElement G { get; } = new GroupElement(EC.G);
+
+ /// <summary>
+ /// Generator for MAC and Show.
+ /// </summary>
+ public static GroupElement Gw { get; } = GroupElement.FromText("Gw");
+
+ /// <summary>
+ /// Generator for MAC and Show.
+ /// </summary>
+ public static GroupElement Gwp { get; } = GroupElement.FromText("Gwp");
+
+ /// <summary>
+ /// Generator for MAC and Show.
+ /// </summary>
+ public static GroupElement Gx0 { get; } = GroupElement.FromText("Gx0");
+
+ /// <summary>
+ /// Generator for MAC and Show.
+ /// </summary>
+ public static GroupElement Gx1 { get; } = GroupElement.FromText("Gx1");
+
+ /// <summary>
+ /// Generator for MAC and Show.
+ /// </summary>
+ public static GroupElement GV { get; } = GroupElement.FromText("GV");
+
+ /// <summary>
+ /// Generator for Pedersen commitments.
+ /// </summary>
+ public static GroupElement Gg { get; } = GroupElement.FromText("Gg");
+
+ /// <summary>
+ /// Generator for Pedersen commitments.
+ /// </summary>
+ public static GroupElement Gh { get; } = GroupElement.FromText("Gh");
+
+ /// <summary>
+ /// Generator for attributes M_{ai}.
+ /// </summary>
+ public static GroupElement Ga { get; } = GroupElement.FromText("Ga");
+
+ /// <summary>
+ /// Generator for serial numbers.
+ /// </summary>
+ public static GroupElement Gs { get; } = GroupElement.FromText("Gs");
+ }
+}

MODIFY
WalletWasabi/Crypto/Groups/GroupElement.cs
WalletWasabi/Crypto/Groups/GroupElement.cs
@@ -29,56 +29,6 @@ namespace WalletWasabi.Crypto.Groups
public static GroupElement Infinity { get; } = new GroupElement(GE.Infinity);
- /// <summary>
- /// The base point defined in the secp256k1 standard used in ECDSA public key derivation.
- /// </summary>
- public static GroupElement G { get; } = new GroupElement(EC.G);
-
- /// <summary>
- /// Generator for MAC and Show.
- /// </summary>
- public static GroupElement Gw { get; } = FromText("Gw");
-
- /// <summary>
- /// Generator for MAC and Show.
- /// </summary>
- public static GroupElement Gwp { get; } = FromText("Gwp");
-
- /// <summary>
- /// Generator for MAC and Show.
- /// </summary>
- public static GroupElement Gx0 { get; } = FromText("Gx0");
-
- /// <summary>
- /// Generator for MAC and Show.
- /// </summary>
- public static GroupElement Gx1 { get; } = FromText("Gx1");
-
- /// <summary>
- /// Generator for MAC and Show.
- /// </summary>
- public static GroupElement GV { get; } = FromText("GV");
-
- /// <summary>
- /// Generator for Pedersen commitments.
- /// </summary>
- public static GroupElement Gg { get; } = FromText("Gg");
-
- /// <summary>
- /// Generator for Pedersen commitments.
- /// </summary>
- public static GroupElement Gh { get; } = FromText("Gh");
-
- /// <summary>
- /// Generator for attributes M_{ai}.
- /// </summary>
- public static GroupElement Ga { get; } = FromText("Ga");
-
- /// <summary>
- /// Generator for serial numbers.
- /// </summary>
- public static GroupElement Gs { get; } = FromText("Gs");
-
private GE Ge { get; }
public bool IsInfinity => Ge.IsInfinity;
@@ -120,45 +70,45 @@ namespace WalletWasabi.Crypto.Groups
{
return "Infinity";
}
- else if (Ge.x == G.Ge.x && Ge.y == G.Ge.y)
+ else if (Ge.x == Generators.G.Ge.x && Ge.y == Generators.G.Ge.y)
{
return $"Standard Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gw.Ge.x && Ge.y == Gw.Ge.y)
+ else if (Ge.x == Generators.Gw.Ge.x && Ge.y == Generators.Gw.Ge.y)
{
- return $"{nameof(Gw)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gw)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gwp.Ge.x && Ge.y == Gwp.Ge.y)
+ else if (Ge.x == Generators.Gwp.Ge.x && Ge.y == Generators.Gwp.Ge.y)
{
- return $"{nameof(Gwp)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gwp)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gx0.Ge.x && Ge.y == Gx0.Ge.y)
+ else if (Ge.x == Generators.Gx0.Ge.x && Ge.y == Generators.Gx0.Ge.y)
{
- return $"{nameof(Gx0)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gx0)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gx1.Ge.x && Ge.y == Gx1.Ge.y)
+ else if (Ge.x == Generators.Gx1.Ge.x && Ge.y == Generators.Gx1.Ge.y)
{
- return $"{nameof(Gx1)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gx1)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == GV.Ge.x && Ge.y == GV.Ge.y)
+ else if (Ge.x == Generators.GV.Ge.x && Ge.y == Generators.GV.Ge.y)
{
- return $"{nameof(GV)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.GV)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gg.Ge.x && Ge.y == Gg.Ge.y)
+ else if (Ge.x == Generators.Gg.Ge.x && Ge.y == Generators.Gg.Ge.y)
{
- return $"{nameof(Gg)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gg)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gh.Ge.x && Ge.y == Gh.Ge.y)
+ else if (Ge.x == Generators.Gh.Ge.x && Ge.y == Generators.Gh.Ge.y)
{
- return $"{nameof(Gh)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gh)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Ga.Ge.x && Ge.y == Ga.Ge.y)
+ else if (Ge.x == Generators.Ga.Ge.x && Ge.y == Generators.Ga.Ge.y)
{
- return $"{nameof(Ga)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Ga)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
- else if (Ge.x == Gs.Ge.x && Ge.y == Gs.Ge.y)
+ else if (Ge.x == Generators.Gs.Ge.x && Ge.y == Generators.Gs.Ge.y)
{
- return $"{nameof(Gs)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
+ return $"{nameof(Generators.Gs)} Generator, {Ge.x.ToC("x")}{Ge.y.ToC("y")}";
}
else
{

Move generators to Generators class