Test for Point that are not on the curve
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/GroupElementTests.cs
WalletWasabi.Tests/UnitTests/Crypto/GroupElementTests.cs
@@ -373,6 +373,17 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
Assert.Equal(GroupElement.G.Negate(), GroupElement.FromBytes(ByteHelpers.FromHex(hexGodd)));
}
+ [Fact]
+ public void PointOutOfCurveDeserialization()
+ {
+ var serialized = FillByteArray(length: 33, character: 0);
+ serialized[0] = GE.SECP256K1_TAG_PUBKEY_EVEN;
+ Assert.ThrowsAny<ArgumentException>(() => GroupElement.FromBytes(serialized));
+
+ serialized[0] = GE.SECP256K1_TAG_PUBKEY_ODD;
+ Assert.ThrowsAny<ArgumentException>(() => GroupElement.FromBytes(serialized));
+ }
+
[Fact]
public void MultiplyByScalar()
{

MODIFY
WalletWasabi/Crypto/GroupElement.cs
WalletWasabi/Crypto/GroupElement.cs
@@ -151,14 +151,14 @@ namespace WalletWasabi.Crypto
static GroupElement Parse(Span<byte> buffer, bool isOdd) =>
FE.TryCreate(buffer, out var x) && GE.TryCreateXOVariable(x, isOdd, out var ge)
? new GroupElement(ge)
- : throw new InvalidOperationException("Group element could not be deserialized.");
+ : throw new ArgumentException("Argument is not a valid group element.", nameof(bytes));
return bytes[0] switch
{
0 => Infinity,
GE.SECP256K1_TAG_PUBKEY_ODD => Parse(bytes[1..], isOdd: true),
GE.SECP256K1_TAG_PUBKEY_EVEN => Parse(bytes[1..], isOdd: false),
- _ => throw new ArgumentException("Argument is not a valid group element.", nameof(bytes))
+ _ => throw new ArgumentException($"Argument is not a well-formatted group element.", nameof(bytes))
};
}
}

Test for Point that are not on the curve