Skip to content

Commit

Permalink
refactor code to remove unsafe and compute inverse once
Browse files Browse the repository at this point in the history
  • Loading branch information
jotabulacios committed Feb 28, 2025
1 parent 669e7a3 commit 6f0e40d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions math/src/elliptic_curve/short_weierstrass/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,18 @@ where
z = ByteConversion::from_bytes_le(&bytes[len * 2..])?;
}

if z == FieldElement::zero() {
let Ok(z_inv) = z.inv() else {
let point = Self::new([x, y, z])
.map_err(|_| DeserializationError::FieldFromBytesError)?;
if point.is_neutral_element() {
return if point.is_neutral_element() {
Ok(point)
} else {
Err(DeserializationError::FieldFromBytesError)
}
} else if E::defining_equation(unsafe { &(&x / &z).unwrap_unchecked() }, unsafe {
&(&y / &z).unwrap_unchecked()
}) == FieldElement::zero()
{
};
};
let x_affine = &x * &z_inv;
let y_affine = &y * &z_inv;
if E::defining_equation(&x_affine, &y_affine) == FieldElement::zero() {
Self::new([x, y, z]).map_err(|_| DeserializationError::FieldFromBytesError)
} else {
Err(DeserializationError::FieldFromBytesError)
Expand Down

0 comments on commit 6f0e40d

Please sign in to comment.