Skip to content

Commit

Permalink
Improve root calculation for KZG setup() (#211)
Browse files Browse the repository at this point in the history
* improve root calculation for KZG setup()

* Update halo2_proofs/src/poly/kzg/commitment.rs

Co-authored-by: Han <[email protected]>

* Fix rust format issue

---------

Co-authored-by: Han <[email protected]>
  • Loading branch information
chiro-hiro and han0110 authored Sep 21, 2023
1 parent 836792f commit 4455c2f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions halo2_proofs/src/poly/kzg/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ where
};

let mut g_lagrange_projective = vec![E::G1::identity(); n as usize];
let mut root = E::Scalar::ROOT_OF_UNITY_INV.invert().unwrap();
let mut root = E::Scalar::ROOT_OF_UNITY;
for _ in k..E::Scalar::S {
root = root.square();
}
let n_inv = Option::<E::Scalar>::from(E::Scalar::from(n).invert())
let n_inv = E::Scalar::from(n)
.invert()
.expect("inversion should be ok for n = 1<<k");
let multiplier = (s.pow_vartime([n]) - E::Scalar::ONE) * n_inv;
parallelize(&mut g_lagrange_projective, |g, start| {
Expand All @@ -106,11 +107,9 @@ where

let g_lagrange = {
let mut g_lagrange = vec![E::G1Affine::identity(); n as usize];
parallelize(&mut g_lagrange, |g_lagrange, starts| {
E::G1::batch_normalize(
&g_lagrange_projective[starts..(starts + g_lagrange.len())],
g_lagrange,
);
parallelize(&mut g_lagrange, |g_lagrange, start| {
let end = start + g_lagrange.len();
E::G1::batch_normalize(&g_lagrange_projective[start..end], g_lagrange);
});
drop(g_lagrange_projective);
g_lagrange
Expand Down Expand Up @@ -142,10 +141,9 @@ where
Self {
k,
n: 1 << k,
g_lagrange: if let Some(g_l) = g_lagrange {
g_l
} else {
g_to_lagrange(g.iter().map(PrimeCurveAffine::to_curve).collect(), k)
g_lagrange: match g_lagrange {
Some(g_l) => g_l,
None => g_to_lagrange(g.iter().map(PrimeCurveAffine::to_curve).collect(), k),
},
g,
g2,
Expand Down

0 comments on commit 4455c2f

Please sign in to comment.