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 new_unchecked method for AffinePoint #53

Merged
merged 4 commits into from
Mar 29, 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
30 changes: 30 additions & 0 deletions crates/starknet-types-core/src/curve/affine_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ impl AffinePoint {
)?))
}

/// Constructs a new affine 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 const fn new_unchecked(x: Felt, y: Felt) -> AffinePoint {
0xLucqs marked this conversation as resolved.
Show resolved Hide resolved
Self(ShortWeierstrassProjectivePoint::new([
x.0,
y.0,
Felt::ONE.0,
]))
}

/// The point at infinity.
pub fn identity() -> AffinePoint {
Self(ShortWeierstrassProjectivePoint::neutral_element())
Expand Down Expand Up @@ -50,6 +61,25 @@ impl core::ops::Neg for &AffinePoint {
mod test {
use super::*;

#[test]
fn affine_point_new_unchecked() {
let a = AffinePoint::new(
Felt::from_hex_unchecked("0x2d39148a92f479fb077389d"),
Felt::from_hex_unchecked(
"0x11a2681208d7c128580162110d9e6ddb0bd34e42ace22dcc7f52f9939e11df6",
),
)
.unwrap();

let b = AffinePoint::new_unchecked(
Felt::from_hex_unchecked("0x2d39148a92f479fb077389d"),
Felt::from_hex_unchecked(
"0x11a2681208d7c128580162110d9e6ddb0bd34e42ace22dcc7f52f9939e11df6",
),
);
assert!(a.eq(&b));
}

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