Skip to content

Commit

Permalink
Fix the incorrect Affine - Projective implementation (arkworks-rs#822)
Browse files Browse the repository at this point in the history
* Fix the subtraction between Affine and Projective points

* Add unit test for Affine - Projective

* Update changelog

* Faster subtraction

---------

Co-authored-by: Pratyush Mishra <pratyush795@gmail.com>
  • Loading branch information
winderica and Pratyush authored Apr 25, 2024
1 parent bf8114e commit 065cd24
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions ec/src/models/short_weierstrass/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ impl<P: SWCurveConfig, T: Borrow<Self>> Sub<T> for Affine<P> {
impl<P: SWCurveConfig> Sub<Projective<P>> for Affine<P> {
type Output = Projective<P>;
fn sub(self, other: Projective<P>) -> Projective<P> {
other - self
self + (-other)
}
}

impl<'a, P: SWCurveConfig> Sub<&'a Projective<P>> for Affine<P> {
type Output = Projective<P>;
fn sub(self, other: &'a Projective<P>) -> Projective<P> {
*other - self
self + (-*other)
}
}

Expand Down
4 changes: 2 additions & 2 deletions ec/src/models/twisted_edwards/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ impl<P: TECurveConfig, T: Borrow<Self>> Sub<T> for Affine<P> {
impl<P: TECurveConfig> Sub<Projective<P>> for Affine<P> {
type Output = Projective<P>;
fn sub(self, other: Projective<P>) -> Projective<P> {
other - self
self + (-other)
}
}

impl<'a, P: TECurveConfig> Sub<&'a Projective<P>> for Affine<P> {
type Output = Projective<P>;
fn sub(self, other: &'a Projective<P>) -> Projective<P> {
*other - self
self + (-*other)
}
}

Expand Down
3 changes: 3 additions & 0 deletions test-templates/src/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 065cd24

Please sign in to comment.