Closed wwared closed 9 months ago
@wwared I have pushed a rebased version of this branch to https://github.com/lurk-lab/bellpepper-gadgets/tree/blshashtog2_rebased, which I believe is just a plain vanilla rebase of this PR. I will stamp this PR the minute it's reset to that branch (or something better, in case I have made a mistake).
@wwared please also link with @samuelburnham to make sure you have the ability to merge your own PRs on this repo, you should absolutely not be blocked on somebody merging your (approved) PRs in any circumstance.
@wwared I have pushed a rebased version of this branch to https://github.com/lurk-lab/bellpepper-gadgets/tree/blshashtog2_rebased, which I believe is just a plain vanilla rebase of this PR. I will stamp this PR the minute it's reset to that branch (or something better, in case I have made a mistake).
I'm finishing rebasing the branch right now, running the tests to ensure I didn't screw anything up and double checking that I didn't reintroduce anything, will force push once everything is green.
@wwared please also link with @samuelburnham to make sure you have the ability to merge your own PRs on this repo, you should absolutely not be blocked on somebody merging your PRs in any circumstance.
Will do!
@wwared You're good to merge!
This PR adds a
map_to_g2
function following RFC 9380, with implementation heavily based on circom-pairing's bls12_381_hash_to_G2.The following pieces are included:
assert_subgroup_check()
for both G1 and G2clear_cofactor()
for G2assert_is_on_curve()
for both G1 and G2phi()
andpsi()
/psi2()
endomorphisms for G1 and G2 respectivelyscalar_mul_by_seed_square()
for G1 subgroup checkopt_simple_swu2()
andiso3_map()
functionssgn0()
function added to bellpepper-emulatedmap_to_g2()
function for turning a pair of Fp2 elements into a G2 pointAny constants added were either taken directly from the RFC or from circom-pairing's source code.
This PR requires this additional commit to the bls12_381 fork exposing a few extra private crate members, mainly to support the new tests. The feature
experimental
is necessary to include thehash_to_g2
module. This PR also adds short docstrings for most useful g1 and g2 functions and some minor refactors.Additional improvements and cleanup included in the PR:
Fp12Element::square()
that resulted in the majority of performance gainsThe current constraint count for one pairing is now 7.1M constraints (down from >20M), and two pairings take 17M constraints. A
map_to_g2()
call takes 1.4M constraints. :tada: (However, the pairing tests remain commented out because they take over 60 seconds to run, and themulti_pairing
test requires too much RAM, so CI fails trying to run them)Future work in upcoming PRs:
hash_to_curve
section of RFC 9380add_or_double
implementation based on gnark'sAddUnified
pairing()
,map_to_g2()
) will simply fail due to a division by zero, but these edge cases should be properly documented and tested (and fixed if they should not fail)