Normalize in constructor.
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/GroupElementTests.cs
WalletWasabi.Tests/UnitTests/Crypto/GroupElementTests.cs
@@ -180,7 +180,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
{
var expectedGenerator = "Standard Generator, secp256k1_fe x = { 0x02F81798UL, 0x00A056C5UL, 0x028D959FUL, 0x036CB738UL, 0x03029BFCUL, 0x03A1C2C1UL, 0x0206295CUL, 0x02EEB156UL, 0x027EF9DCUL, 0x001E6F99UL, 1, 1 };secp256k1_fe y = { 0x0310D4B8UL, 0x01F423FEUL, 0x014199C4UL, 0x01229A15UL, 0x00FD17B4UL, 0x0384422AUL, 0x024FBFC0UL, 0x03119576UL, 0x027726A3UL, 0x00120EB6UL, 1, 1 };";
var expectedInfinity = "Infinity";
- var expectedTwo = "secp256k1_fe x = { 0x00709EE5UL, 0x03026E57UL, 0x03CA7ABAUL, 0x012E33BCUL, 0x005C778EUL, 0x01701F36UL, 0x005406E9UL, 0x01F5B4C1UL, 0x039441EDUL, 0x0031811FUL, 1, 0 };secp256k1_fe y = { 0x00CFE52AUL, 0x010C6A54UL, 0x010E1236UL, 0x0194C99BUL, 0x02F7F632UL, 0x019B3ABBUL, 0x00584194UL, 0x030CE68FUL, 0x00FEA63DUL, 0x0006B85AUL, 1, 0 };";
+ 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(expectedInfinity, GroupElement.Infinity.ToString());
@@ -384,7 +384,6 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
Assert.ThrowsAny<ArgumentException>(() => GroupElement.FromBytes(serialized));
}
-
[Fact]
public void NonNormalizedPointDeserialization()
{

MODIFY
WalletWasabi/Crypto/GroupElement.cs
WalletWasabi/Crypto/GroupElement.cs
@@ -18,7 +18,7 @@ namespace WalletWasabi.Crypto
else
{
Guard.True($"{nameof(groupElement)}.{nameof(groupElement.IsValidVariable)}", groupElement.IsValidVariable);
- Ge = groupElement;
+ Ge = new GE(groupElement.x.Normalize(), groupElement.y.Normalize());
}
}
@@ -129,9 +129,8 @@ namespace WalletWasabi.Crypto
const int CompressedLength = 32 + 1;
Span<byte> buffer = new byte[CompressedLength];
- // We cannot assume the Group Element was already normalized somewhere else.
- var x = Ge.x.NormalizeVariable();
- var y = Ge.y.NormalizeVariable();
+ var x = Ge.x;
+ var y = Ge.y;
buffer[0] = (Ge.IsInfinity, y.IsOdd) switch
{

Normalize in constructor.