feat: BLS12-381 pairing#175
Open
nulltea wants to merge 24 commits intoaxiom-crypto:community-editionfrom
Open
Conversation
d92820e to
33f0250
Compare
33f0250 to
1a01328
Compare
halo2-base/src/utils/mod.rs
Outdated
| impl super::BigPrimeField for Fr { | ||
| #[inline(always)] | ||
| fn from_u64_digits(val: &[u64]) -> Self { | ||
| let mut raw = [0u64; 4]; |
Author
There was a problem hiding this comment.
used 4 for Fr here as BLS12-381 Scalar is 256 bits
ref: https://github.com/privacy-scaling-explorations/bls12_381/blob/main/src/scalar.rs#L19C1-L24C40
Contributor
jonathanpwang
left a comment
There was a problem hiding this comment.
Initial review just to address the carry_mod and check_carry_mod_to_zero implementations, which need to change for BLS12-381. We should make it fully general for any large field.
This is point #7 in the PR description.
* fix comment * fix comment line unequal * update comments * fix comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add pairing (miller_loop + final_exp) and pairing_check (multi_miller_loop + final_exp) for BLS12-381. Relies on axiom-crypto/halo2curves#8.
This implementation is over affine points , inspired by BN254 pairing in this repo. This variant performs better than https://github.com/DelphinusLab/halo2ecc-s (over projective points).
Originally implemented in dev/bls12_381.
Notable changes
previous_bit(based on BLS-X), Gt squaring and doubling step follows as usual.multi_miller_loopas it appears to make no difference (there). I wasn't able to find evidence, so am happy to be proven wrong!FieldExtConstructoris implemented for Fp2, and Fp12BigPrimeFieldwas replaced with per curve impls to account for bigger size of BLS12-381's Fq.halo2curves = "https://github.com/axiom-crypto/halo2curves"whenhalo2-psefeature is enabled and usehalo2curves::bls12_381instead one fromhalo2_proofs::halo2_curves. The reason is that PSE fork of halo2 still useshalo2curves v0.1.0, so patching is not an option.carry_mod.rs(1, 2) andcheck_carry_mod_to_zero.rs(1, 2).The last (7) change could be breaking. I could use some help to fix it more cleanly 🙏
Benchmarks
k=19lookup_bits=18:Using optimized
cyclotomic_pow_bls_xthat exploits structure of cyclotomic_pow for greater constraint efficiency: