From ac6565b2f15cd3ce9eee59239de65ebd7d3d54c0 Mon Sep 17 00:00:00 2001 From: winderica Date: Tue, 23 Apr 2024 20:14:26 +0800 Subject: [PATCH 1/4] Fix the subtraction between Affine and Projective points --- ec/src/models/short_weierstrass/affine.rs | 4 ++-- ec/src/models/twisted_edwards/affine.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ec/src/models/short_weierstrass/affine.rs b/ec/src/models/short_weierstrass/affine.rs index 2a47f5cb3..23c7cac11 100644 --- a/ec/src/models/short_weierstrass/affine.rs +++ b/ec/src/models/short_weierstrass/affine.rs @@ -305,14 +305,14 @@ impl> Sub for Affine

{ impl Sub> for Affine

{ type Output = Projective

; fn sub(self, other: Projective

) -> Projective

{ - other - self + self.into_group() - other } } impl<'a, P: SWCurveConfig> Sub<&'a Projective

> for Affine

{ type Output = Projective

; fn sub(self, other: &'a Projective

) -> Projective

{ - *other - self + self.into_group() - other } } diff --git a/ec/src/models/twisted_edwards/affine.rs b/ec/src/models/twisted_edwards/affine.rs index 72a3e4f7e..91592ea58 100644 --- a/ec/src/models/twisted_edwards/affine.rs +++ b/ec/src/models/twisted_edwards/affine.rs @@ -255,14 +255,14 @@ impl> Sub for Affine

{ impl Sub> for Affine

{ type Output = Projective

; fn sub(self, other: Projective

) -> Projective

{ - other - self + self.into_group() - other } } impl<'a, P: TECurveConfig> Sub<&'a Projective

> for Affine

{ type Output = Projective

; fn sub(self, other: &'a Projective

) -> Projective

{ - *other - self + self.into_group() - other } } From 5fe0f95ce063e2594cad7f1a6cfba05df2ed6427 Mon Sep 17 00:00:00 2001 From: winderica Date: Tue, 23 Apr 2024 20:17:22 +0800 Subject: [PATCH 2/4] Add unit test for Affine - Projective --- test-templates/src/groups.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test-templates/src/groups.rs b/test-templates/src/groups.rs index 5ad7e33b2..625a26d7c 100644 --- a/test-templates/src/groups.rs +++ b/test-templates/src/groups.rs @@ -67,6 +67,9 @@ macro_rules! __test_group { assert_eq!(a - zero, a); assert_eq!(b - zero, b); + + // Affine - Projective + assert_eq!(a.into_affine() - b, a - b); } } From eed949fd109125435fb610378609c4fda06c4c57 Mon Sep 17 00:00:00 2001 From: winderica Date: Tue, 23 Apr 2024 20:25:55 +0800 Subject: [PATCH 3/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc24c3f58..bc2472ee2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - [\#747](https://github.com/arkworks-rs/algebra/pull/747) (`ark-ff-macros`) Fix fetching attributes in `MontConfig` macro. - [\#803](https://github.com/arkworks-rs/algebra/pull/803) (`ark-ec`, `ark-test-template`) Fix incorrect decomposition in GLV. - [\#806](https://github.com/arkworks-rs/algebra/pull/806) (`ark-ff`) Fix the impl for `Display`ing zero element in Fp. +- [\#822](https://github.com/arkworks-rs/algebra/pull/822) (`ark-ec`, `ark-test-template`) Fix the incorrect `Affine - Projective` implementation ## v0.4.2 From 81c08a10fffb1eedb14c3df54a2622dd8f1475be Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Wed, 24 Apr 2024 11:10:58 -0700 Subject: [PATCH 4/4] Faster subtraction --- ec/src/models/short_weierstrass/affine.rs | 4 ++-- ec/src/models/twisted_edwards/affine.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ec/src/models/short_weierstrass/affine.rs b/ec/src/models/short_weierstrass/affine.rs index 23c7cac11..82e127928 100644 --- a/ec/src/models/short_weierstrass/affine.rs +++ b/ec/src/models/short_weierstrass/affine.rs @@ -305,14 +305,14 @@ impl> Sub for Affine

{ impl Sub> for Affine

{ type Output = Projective

; fn sub(self, other: Projective

) -> Projective

{ - self.into_group() - other + self + (-other) } } impl<'a, P: SWCurveConfig> Sub<&'a Projective

> for Affine

{ type Output = Projective

; fn sub(self, other: &'a Projective

) -> Projective

{ - self.into_group() - other + self + (-*other) } } diff --git a/ec/src/models/twisted_edwards/affine.rs b/ec/src/models/twisted_edwards/affine.rs index 91592ea58..1d93882a1 100644 --- a/ec/src/models/twisted_edwards/affine.rs +++ b/ec/src/models/twisted_edwards/affine.rs @@ -255,14 +255,14 @@ impl> Sub for Affine

{ impl Sub> for Affine

{ type Output = Projective

; fn sub(self, other: Projective

) -> Projective

{ - self.into_group() - other + self + (-other) } } impl<'a, P: TECurveConfig> Sub<&'a Projective

> for Affine

{ type Output = Projective

; fn sub(self, other: &'a Projective

) -> Projective

{ - self.into_group() - other + self + (-*other) } }