argumentcomputer / bellpepper-gadgets

A library of gadgets compatible with bellpepper and bellperson (contact: @huitseeker)
Apache License 2.0
17 stars 13 forks source link

bls12381: Add map_to_g2 implementation #35

Closed wwared closed 9 months ago

wwared commented 9 months ago

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:

Any 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 the hash_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:

The 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 the multi_pairing test requires too much RAM, so CI fails trying to run them)

Future work in upcoming PRs:

huitseeker commented 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 commented 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).

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!

huitseeker commented 9 months ago

@wwared You're good to merge!