Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from_affine_unchecked operation for ProjectivePoint #55

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions crates/starknet-types-core/src/curve/projective_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ impl ProjectivePoint {
))
}

/// Constructs a new projective point without checking whether the coordinates specify a point in the subgroup.
/// This method should be used with caution, as it does not validate whether the provided coordinates
/// correspond to a valid point on the curve.
pub fn from_affine_unchecked(x: Felt, y: Felt) -> Self {
Self(ShortWeierstrassProjectivePoint::new([
x.0,
y.0,
Felt::ONE.0,
]))
}

/// Returns the `x` coordinate of the point.
pub fn x(&self) -> Felt {
Felt(*self.0.x())
Expand Down Expand Up @@ -180,6 +191,26 @@ where
mod test {
use super::*;

#[test]
fn from_affine_unchecked() {
let a = AffinePoint::new(
Felt::from_dec_str(
"3324833730090626974525872402899302150520188025637965566623476530814354734325",
)
.unwrap(),
Felt::from_dec_str(
"3147007486456030910661996439995670279305852583596209647900952752170983517249",
)
.unwrap(),
)
.unwrap();

assert_eq!(
ProjectivePoint::from_affine_unchecked(a.x(), a.y()),
ProjectivePoint::from_affine(a.x(), a.y()).unwrap()
);
}

#[test]
fn projective_point_identity() {
let identity = ProjectivePoint::identity();
Expand Down
Loading