Skip to content

Conversation

jotabulacios
Copy link
Contributor

Use new_unchecked

Description

This PR replaces the use of new with new_unchecked in cases where the points are already known to be valid.
It also applies new_unchecked to the generator point in StarkCurve, since it is a verified valid point

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.16%. Comparing base (160bb5c) to head (f411abd).

Files with missing lines Patch % Lines
...ptic_curve/short_weierstrass/curves/stark_curve.rs 0.00% 5 Missing ⚠️
...math/src/elliptic_curve/short_weierstrass/point.rs 77.27% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1024      +/-   ##
==========================================
- Coverage   70.17%   70.16%   -0.01%     
==========================================
  Files         165      165              
  Lines       32770    32773       +3     
==========================================
- Hits        22996    22995       -1     
- Misses       9774     9778       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jotabulacios jotabulacios marked this pull request as ready for review September 22, 2025 16:03
@jotabulacios jotabulacios requested a review from a team as a code owner September 22, 2025 16:03
@Oppen
Copy link
Contributor

Oppen commented Sep 22, 2025

Do we have a benchmark?

@gabrielbosio
Copy link
Collaborator

Do we have a benchmark?

I've run the Pedersen benchmark locally (MacOS, Apple M3 Pro, 18 GB of RAM):

Command

make benchmark BENCH=criterion_pedersen

Results

  • Lambdaworks 0.11.0: ~12.2 µs
  • Lambdaworks 0.12.0: ~30.6 µs
  • Lambdaworks in d94f91f: ~11.9 µs

Comment on lines 19 to 20
// SAFETY: The values `x_hex, y_hex`` should be constants valid for the curve.
ShortWeierstrassProjectivePoint::new_unchecked([
Copy link
Contributor

Choose a reason for hiding this comment

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

There's nothing in the method stating that. The name doesn't confer that this might silently give wrong results. I don't this is correct without also adding _unchecked to the method's name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, renamed the function in f411abd also improved the SAFETY comment

Comment on lines 45 to 55
/// Creates an elliptic curve point giving the projective [x: y: z] coordinates without
/// checking that the point satisfies the curve equation.
pub const fn new_unchecked(value: [FieldElement<E::BaseField>; 3]) -> Self {
Self(ProjectivePoint::new(value))
}

/// Changes the point coordinates without checking that it satisfies the curve equation.
pub fn set_unchecked(&mut self, value: [FieldElement<E::BaseField>; 3]) {
self.0.value = value
}

Copy link
Contributor

@Oppen Oppen Sep 23, 2025

Choose a reason for hiding this comment

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

These should also have the following (or similar) SAFETY comment:

// SAFETY: the caller MUST be sure the arguments correspond to a point in the curve.
// Failing to do so will result in silently wrong values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added SAFETY comment in f411abd

Comment on lines 461 to 465
/// Creates an elliptic curve point giving the projective [x: y: z] coordinates without
/// checking that the point satisfies the curve equation.
pub const fn new_unchecked(value: [FieldElement<E::BaseField>; 3]) -> Self {
Self(JacobianPoint::new(value))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This also needs a SAFETY comment explaining the requirements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added SAFETY comment in f411abd

@ColoCarletti ColoCarletti added this pull request to the merge queue Sep 26, 2025
Merged via the queue into main with commit 060dbf6 Sep 26, 2025
8 checks passed
@ColoCarletti ColoCarletti deleted the add_new_unchecked branch September 26, 2025 12:46
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.

7 participants