From 872252832f0456e4b7a2b21bc15c8753fe53941c Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 2 Apr 2017 12:50:25 -0600 Subject: [PATCH 1/2] The point at infinity is only representable in the jacobian at y = 1. --- src/groups/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/groups/mod.rs b/src/groups/mod.rs index 1e08534..fb19ef7 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -383,10 +383,14 @@ impl Neg for G

{ type Output = G

; fn neg(self) -> G

{ - G { - x: self.x, - y: -self.y, - z: self.z + if self.is_zero() { + self + } else { + G { + x: self.x, + y: -self.y, + z: self.z + } } } } From b6f2ab337703286a78454fbfb62ad5d027b62cd4 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 2 Apr 2017 13:48:53 -0600 Subject: [PATCH 2/2] Add test that y coordinate remains 1 in jacobian when G1/G2 are negated. --- src/groups/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/groups/mod.rs b/src/groups/mod.rs index fb19ef7..8983779 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -947,4 +947,12 @@ fn affine_fail() { fn affine_ok() { let res = AffineG1::new(Fq::one(), G1Params::coeff_b()); assert!(res.is_err(), "Affine initialization should be ok because the point is on the curve"); -} \ No newline at end of file +} + +fn test_y_at_point_at_infinity() { + assert!(G1::zero().y == Fq::one()); + assert!((-G1::zero()).y == Fq::one()); + + assert!(G2::zero().y == Fq2::one()); + assert!((-G2::zero()).y == Fq2::one()); +}