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

bls12381: Add support for point at infinity for G1 adds #37

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

wwared
Copy link
Contributor

@wwared wwared commented Feb 20, 2024

This PR adds some initial point at infinity handling for G1 points. (G2 points will be similar, but come in a future PR).

  • Add identity() method that returns (0, 0)
  • Check if value is identity inside alloc_elem: the native bls12_381 representation is (0, 1) instead of (0, 0), so we need to map it
  • Add alloc_is_identity() that checks whether the point is (0, 0)
  • Modify assert_collinear into assert_addition that can handle points at infinity. Function is called with assert_addition(a, b, c) and checks whether a + b = c is valid
    • Supports the case where a == 0 or b == 0, to support checking whether a + b = c: usually only one of a or b is 0, and in this case then c == 0 as well and the function works properly. The function only breaks if b == -a and c == 0.
    • The costs of this function are still under the costs of add_unified (~3800 vs ~5000 constraints per operation), so it makes sense to have it for certain applications for now.
    • The changes are implemented by chaining boolean conditions.
  • Add add_unified implementation that supports all input values. (p = 0, q = 0, p = q are all supported)
  • Add conditionally_select implementation for G1Point

Modify assert_collinear to assert_addition and add additional identity
point checks to it
@wwared wwared force-pushed the collinear_g1_infinity branch from 7ffc50d to 5a7424b Compare February 21, 2024 16:28
@wwared wwared force-pushed the collinear_g1_infinity branch from 5a7424b to 0a99886 Compare February 22, 2024 01:11
Copy link
Contributor

@Nramsrud Nramsrud left a comment

Choose a reason for hiding this comment

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

Other than the typo, good to go.

Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

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

This LGTM, I'll let @Nramsrud shepherd this one.

@huitseeker huitseeker merged commit be44888 into main Feb 23, 2024
12 checks passed
@huitseeker huitseeker deleted the collinear_g1_infinity branch February 23, 2024 22:05
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.

3 participants