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

Feat/curve/jacobian scalar mul #38

Merged
merged 6 commits into from
Jan 17, 2025
Merged

Conversation

FoodChain1028
Copy link
Collaborator

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:

  • Added bigint_eq and is_bigint_zero functions to bigint.metal for BigInt equality and zero checks.
  • Introduced jacobian_dbl_2009_l and jacobian_scalar_mul functions in jacobian.metal to handle point doubling and scalar multiplication on Jacobian curves. [1] [2]
  • Added jacobian_eq and is_jacobian_zero functions to utils.metal for Jacobian equality and zero checks.

Enhancements to operators:

  • Overloaded the == operator for BigInt and Jacobian types to use the newly added equality functions. [1] [2]

New and updated tests:

  • Created new tests for zero and equality cases in jacobian_add_2007_b1.rs.
  • Added jacobian_scalar_mul.rs for testing scalar multiplication on Jacobian curves.
  • Updated 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.

Copy link
Collaborator

@moven0831 moven0831 left a 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

Comment on lines +176 to +179
Jacobian jacobian_scalar_mul(
Jacobian point,
uint scalar
) {
Copy link
Collaborator

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.

Comment on lines +53 to +60
if (is_jacobian_zero(a)) {
return b;
}
if (is_jacobian_zero(b)) {
return a;
}
if (a == b) return jacobian_dbl_2009_l(a, p);

Copy link
Collaborator

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

Comment on lines +180 to +186
// Handle special cases first
if (scalar == 0 || is_bigint_zero(point.z)) {
return get_bn254_zero_mont();
}
if (scalar == 1) {
return point;
}
Copy link
Collaborator

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

@FoodChain1028 FoodChain1028 merged commit 9e97c78 into main Jan 17, 2025
1 check passed
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.

2 participants