-
Notifications
You must be signed in to change notification settings - Fork 151
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
Change elliptic curve new point function #970
Merged
Merged
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a3dd313
change edwards new
a78db2f
fix edwards, montgomery and weierstrass new
c22c917
fix short weierstrass new
480b6f1
fix ate pairing test. change new point at infinity
0958021
change edwards new
6ce5dc2
change jacobian new short weierstrass
4208567
fix lint
2be539a
change debug assert jacobian weierstrass
b8e1125
fix defining_equation_jacobian
jotabulacios a6c166b
fix operate_with for jacobian coordinates
jotabulacios bd51922
fix babybear benches
jotabulacios 0fcc8c2
Merge branch 'main' into fix-curve-new
jotabulacios 142d2fc
solve p3 new version conflicts
jotabulacios ac51469
fix edwards new: tiny jubjub working
ab5d9b2
Add safety comments for edwards
2c1faad
add safety docs
jotabulacios d6bac13
remove duplicated comments
jotabulacios 2e25e16
fix rust doc formatting
jotabulacios 41f453b
Remove unchecked from wrap to compare performancesave work
jotabulacios 052af98
Revert "Remove unchecked from wrap to compare performancesave work"
jotabulacios 4c7a1ec
fix clippy
jotabulacios 0475dea
remove unchecked from unwrap. Save work
jotabulacios f93ce93
fix bug in bn254 bench
jotabulacios 1a3e82f
add Oppen comments
jotabulacios 0e90bb0
fix comments and remove redundant debug_assert
jotabulacios a4ef57d
fix comment
jotabulacios File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,18 +12,39 @@ impl IsEllipticCurve for BandersnatchCurve { | |||||
type BaseField = BaseBandersnatchFieldElement; | ||||||
type PointRepresentation = EdwardsProjectivePoint<Self>; | ||||||
|
||||||
// Values are from https://github.com/arkworks-rs/curves/blob/5a41d7f27a703a7ea9c48512a4148443ec6c747e/ed_on_bls12_381_bandersnatch/src/curves/mod.rs#L120 | ||||||
// Converted to Hex | ||||||
/// Returns the generator point of the Bandersnatch curve. | ||||||
/// | ||||||
/// The generator point is defined with coordinates `(x, y, 1)`, where `x` and `y` | ||||||
/// are precomputed constants that belong to the curve. | ||||||
/// | ||||||
/// # Safety | ||||||
/// | ||||||
/// - The generator values are taken from the [Arkworks implementation](https://github.com/arkworks-rs/curves/blob/5a41d7f27a703a7ea9c48512a4148443ec6c747e/ed_on_bls12_381_bandersnatch/src/curves/mod.rs#L120) | ||||||
/// and have been converted to hexadecimal. | ||||||
/// - `unwrap_unchecked()` is safe because: | ||||||
/// - The generator point is **known to be valid** on the curve. | ||||||
/// - The function only uses **hardcoded** and **verified** constants. | ||||||
/// - This function should **never** be modified unless the new generator is fully verified. | ||||||
fn generator() -> Self::PointRepresentation { | ||||||
Self::PointRepresentation::new([ | ||||||
FieldElement::<Self::BaseField>::new_base( | ||||||
"29C132CC2C0B34C5743711777BBE42F32B79C022AD998465E1E71866A252AE18", | ||||||
), | ||||||
FieldElement::<Self::BaseField>::new_base( | ||||||
"2A6C669EDA123E0F157D8B50BADCD586358CAD81EEE464605E3167B6CC974166", | ||||||
), | ||||||
FieldElement::one(), | ||||||
]) | ||||||
// SAFETY: | ||||||
// - The generator point coordinates (x, y) are taken from a well-tested, | ||||||
// verified implementation. | ||||||
// - The constructor will only fail if the values are invalid, which is | ||||||
// impossible given that they are constants taken from a trusted source. | ||||||
// - `unwrap_unchecked()` avoids unnecessary checks, as we guarantee | ||||||
// correctness based on external verification. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No longer relevant, we now use the regular |
||||||
unsafe { | ||||||
Oppen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
Self::PointRepresentation::new([ | ||||||
FieldElement::<Self::BaseField>::new_base( | ||||||
"29C132CC2C0B34C5743711777BBE42F32B79C022AD998465E1E71866A252AE18", | ||||||
), | ||||||
FieldElement::<Self::BaseField>::new_base( | ||||||
"2A6C669EDA123E0F157D8B50BADCD586358CAD81EEE464605E3167B6CC974166", | ||||||
), | ||||||
FieldElement::one(), | ||||||
]) | ||||||
.unwrap_unchecked() | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ pub trait IsEdwards: IsEllipticCurve + Clone + Debug { | |
|
||
fn d() -> FieldElement<Self::BaseField>; | ||
|
||
// Edwards equation in affine coordinates: | ||
// ax^2 + y^2 - 1 = d * x^2 * y^2 | ||
fn defining_equation( | ||
x: &FieldElement<Self::BaseField>, | ||
y: &FieldElement<Self::BaseField>, | ||
|
@@ -15,4 +17,16 @@ pub trait IsEdwards: IsEllipticCurve + Clone + Debug { | |
- FieldElement::<Self::BaseField>::one() | ||
- Self::d() * x.pow(2_u16) * y.pow(2_u16) | ||
} | ||
|
||
// Edwards equation in projective coordinates. | ||
// a * x^2 * z^2 + y^2 * z^2 - z^4 = d * x^2 * y^2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be more efficient just by factoring out z^2. We can update that in future PR |
||
fn defining_equation_projective( | ||
x: &FieldElement<Self::BaseField>, | ||
y: &FieldElement<Self::BaseField>, | ||
z: &FieldElement<Self::BaseField>, | ||
) -> FieldElement<Self::BaseField> { | ||
Self::a() * x.square() * z.square() + y.square() * z.square() | ||
- z.square().square() | ||
- Self::d() * x.square() * y.square() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.