-
Notifications
You must be signed in to change notification settings - Fork 195
feat: BLS12-381 pairing #175
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
base: community-edition
Are you sure you want to change the base?
feat: BLS12-381 pairing #175
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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be 6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
jonathanpwang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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: