-
Notifications
You must be signed in to change notification settings - Fork 7
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
Feat/curve/jacobian scalar mul #38
Conversation
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.
lgtm! list out some notes and potential improvement directions, we can re-examine these
Jacobian jacobian_scalar_mul( | ||
Jacobian point, | ||
uint scalar | ||
) { |
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.
The scalar used here is constrained by the default GPU word size, which is 32-bit. Note that this function is suitable for MSM use cases because the scalar fragments involved in MSM are relatively small. However, for larger scalars, this may produce incorrect results.
if (is_jacobian_zero(a)) { | ||
return b; | ||
} | ||
if (is_jacobian_zero(b)) { | ||
return a; | ||
} | ||
if (a == b) return jacobian_dbl_2009_l(a, p); | ||
|
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.
Potential acceleration can be achieved by moving the condition checks directly into the MSM logic
// Handle special cases first | ||
if (scalar == 0 || is_bigint_zero(point.z)) { | ||
return get_bn254_zero_mont(); | ||
} | ||
if (scalar == 1) { | ||
return point; | ||
} |
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.
Potential acceleration can be achieved by moving the condition checks directly into the MSM logic
This pull request introduces several new functions and tests to improve the functionality and robustness of the Jacobian curve arithmetic in the Metal shader implementation. Key changes include the addition of new equality and zero-check functions, a new scalar multiplication function, and the restructuring and enhancement of existing tests.
New functions:
bigint_eq
andis_bigint_zero
functions tobigint.metal
for BigInt equality and zero checks.jacobian_dbl_2009_l
andjacobian_scalar_mul
functions injacobian.metal
to handle point doubling and scalar multiplication on Jacobian curves. [1] [2]jacobian_eq
andis_jacobian_zero
functions toutils.metal
for Jacobian equality and zero checks.Enhancements to operators:
==
operator forBigInt
andJacobian
types to use the newly added equality functions. [1] [2]New and updated tests:
jacobian_add_2007_b1.rs
.jacobian_scalar_mul.rs
for testing scalar multiplication on Jacobian curves.mod.rs
to include the new test module for scalar multiplication.These changes enhance the functionality and reliability of the Metal shader implementation for elliptic curve operations.