Skip to content

Commit

Permalink
fix add_assign for ProjectivePoint (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Feb 15, 2024
1 parent acdbeae commit 56fe578
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions starknet-curve/src/ec_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,22 @@ impl ops::AddAssign<&AffinePoint> for AffinePoint {
return;
}
if self.infinity {
self.x = rhs.x;
self.y = rhs.y;
self.infinity = rhs.infinity;
*self = *rhs;
return;
}
if self.x == rhs.x {
if self.y == -rhs.y {
self.x = FieldElement::ZERO;
self.y = FieldElement::ZERO;
self.infinity = true;
return;
if self.y == rhs.y {
self.double_assign();
} else {
*self = AffinePoint::identity();
}
self.double_assign();
return;
}

// l = (y2-y1)/(x2-x1)
let lambda = {
let dividend = rhs.y - self.y;
let divisor_inv = (rhs.x - self.x).invert().unwrap();
dividend * divisor_inv
};
let lambda = (rhs.y - self.y) * (rhs.x - self.x).invert().unwrap();

let result_x = lambda * lambda - self.x - rhs.x;

let result_x = (lambda * lambda) - self.x - rhs.x;
self.y = lambda * (self.x - result_x) - self.y;
self.x = result_x;
}
Expand Down Expand Up @@ -247,16 +239,17 @@ impl ops::AddAssign<&ProjectivePoint> for ProjectivePoint {
return;
}
if self.infinity {
self.x = rhs.x;
self.y = rhs.y;
self.z = rhs.z;
self.infinity = rhs.infinity;
*self = *rhs;
return;
}
let u0 = self.x * rhs.z;
let u1 = rhs.x * self.z;
if u0 == u1 {
self.double_assign();
if self.y == rhs.y {
self.double_assign();
} else {
*self = ProjectivePoint::identity();
}
return;
}

Expand Down

0 comments on commit 56fe578

Please sign in to comment.