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

feature: eliptic curves #589

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

Conversation

qalisander
Copy link
Member

@qalisander qalisander commented Mar 5, 2025

Resolves #343

PR Checklist

  • Tests
  • Documentation
  • Changelog

Copy link

netlify bot commented Mar 5, 2025

Deploy Preview for contracts-stylus ready!

Name Link
🔨 Latest commit 112946f
🔍 Latest deploy log https://app.netlify.com/sites/contracts-stylus/deploys/67daadd97279770008c3cce7
😎 Deploy Preview https://deploy-preview-589--contracts-stylus.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@qalisander qalisander force-pushed the openzeppelin-crypto/eliptic-curves branch from ad18d44 to 112946f Compare March 19, 2025 11:43
Copy link

codecov bot commented Mar 19, 2025

@qalisander
Copy link
Member Author

qalisander commented Mar 19, 2025

merge simple test cases (coverage)

@qalisander
Copy link
Member Author

fix clippy lints

Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass.


#[inline]
fn add(self, other: Self) -> Self {
let mut result = self;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you use just self + &other?

/// Elliptic curves can be represented via different "models" with varying
/// efficiency properties.
///
/// `CurveConfig` bundles together the types that are common
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// `CurveConfig` bundles together the types that are common
/// [`CurveConfig`] bundles together the types that are common

/// efficiency properties.
///
/// `CurveConfig` bundles together the types that are common
/// to all models of the given curve, namely the `BaseField` over which the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// to all models of the given curve, namely the `BaseField` over which the
/// to all models of the given curve, namely the [`BaseField`] over which the

///
/// `CurveConfig` bundles together the types that are common
/// to all models of the given curve, namely the `BaseField` over which the
/// curve is defined, and the `ScalarField` defined by the appropriate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// curve is defined, and the `ScalarField` defined by the appropriate
/// curve is defined, and the [`ScalarField`] defined by the appropriate


/// Returns `true` if the cofactor is one.
fn cofactor_is_one() -> bool {
Self::COFACTOR[0] == 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whag if Self::COFACTOR is an empty slice?

}

// Invert `tmp`.
tmp = tmp.inverse().unwrap(); // Guaranteed to be nonzero.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use expect

}

impl<P: SWCurveConfig> Affine<P> {
/// Constructs a group element from x and y coordinates.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Constructs a group element from x and y coordinates.
/// Constructs a group element from `x` and `y` coordinates.

point
}

/// Constructs a group element from x and y coordinates.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Constructs a group element from x and y coordinates.
/// Constructs a group element from `x` and `y`coordinates.


/// Checks if `self` is a valid point on the curve.
pub fn is_on_curve(&self) -> bool {
if !self.infinity {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy warning that makes sense.

impl<P: SWCurveConfig> Eq for Projective<P> {}
impl<P: SWCurveConfig> PartialEq for Projective<P> {
fn eq(&self, other: &Self) -> bool {
if self.is_zero() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like XOR operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Elliptic curve primitives
2 participants