Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Mar 8, 2024
1 parent 324160f commit 20742c8
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion crates/starknet-types-core/src/curve/projective_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ impl ops::AddAssign<&ProjectivePoint> for ProjectivePoint {
}
}

impl ops::Add<ProjectivePoint> for ProjectivePoint {
type Output = ProjectivePoint;

fn add(self, rhs: ProjectivePoint) -> ProjectivePoint {
ProjectivePoint(self.0.operate_with(&rhs.0))
}
}

impl ops::AddAssign<ProjectivePoint> for ProjectivePoint {
fn add_assign(&mut self, rhs: ProjectivePoint) {
self.0 = self.0.operate_with(&rhs.0);
}
}

impl core::ops::Neg for &ProjectivePoint {
type Output = ProjectivePoint;

Expand All @@ -101,6 +115,20 @@ impl core::ops::SubAssign<&ProjectivePoint> for ProjectivePoint {
}
}

impl core::ops::Sub<ProjectivePoint> for ProjectivePoint {
type Output = ProjectivePoint;

fn sub(self, rhs: ProjectivePoint) -> ProjectivePoint {
&self - &rhs
}
}

impl core::ops::SubAssign<ProjectivePoint> for ProjectivePoint {
fn sub_assign(&mut self, rhs: ProjectivePoint) {
*self -= &rhs;
}
}

impl ops::Mul<Felt> for &ProjectivePoint {
type Output = ProjectivePoint;

Expand Down Expand Up @@ -325,7 +353,7 @@ mod test {
}

#[test]
fn sub_operations() {
fn sub_operations_pointers() {
let mut a = ProjectivePoint::new(
Felt::from_dec_str(
"685118385380464480289795596422487144864558069280897344382334516257395969277",
Expand All @@ -345,4 +373,26 @@ mod test {
a -= &b;
assert_eq!(a, ProjectivePoint::identity());
}

#[test]
fn sub_operations() {
let mut a = ProjectivePoint::new(
Felt::from_dec_str(
"685118385380464480289795596422487144864558069280897344382334516257395969277",
)
.unwrap(),
Felt::from_dec_str(
"2157469546853095472290556201984093730375838368522549154974787195581425752638",
)
.unwrap(),
Felt::from(1),
);
let b = a.clone();

assert_eq!(ProjectivePoint::identity() - a.clone(), -&a);
assert_eq!(a.clone() - a.clone(), ProjectivePoint::identity());
assert_eq!(a.clone() - a.clone() + a.clone(), a);
a -= b;
assert_eq!(a, ProjectivePoint::identity());
}
}

0 comments on commit 20742c8

Please sign in to comment.