diff --git a/halo2_proofs/src/arithmetic.rs b/halo2_proofs/src/arithmetic.rs index 700b37ad58..6f78dcd5c1 100644 --- a/halo2_proofs/src/arithmetic.rs +++ b/halo2_proofs/src/arithmetic.rs @@ -402,26 +402,8 @@ pub fn lagrange_interpolate(points: &[F], evals: &[F]) -> Vec { } } -/// Given roots [a_0, a_1, ... a_n] returns vanishing polynomials -/// (x - a_0) * (x - a_1) * ... * (x - a_n) -pub fn vanishing_polynomial(roots: &[F]) -> Vec { - fn mul_with(coeffs: Vec, root: &F) -> Vec { - let mut ret = vec![F::zero(); coeffs.len() + 1]; - - for (i, coeff) in coeffs.iter().enumerate() { - ret[i] -= *coeff * root; - ret[i + 1] += coeff; - } - - ret - } - - let mut coeffs = vec![F::one()]; - for root in roots { - coeffs = mul_with(coeffs, root); - } - - coeffs +pub(crate) fn evaluate_vanishing_polynomial(roots: &[F], z: F) -> F { + roots.iter().fold(F::one(), |acc, point| (z - point) * acc) } #[cfg(test)] diff --git a/halo2_proofs/src/poly/multiopen/shplonk/prover.rs b/halo2_proofs/src/poly/multiopen/shplonk/prover.rs index ebdddd87d7..2398df09ce 100644 --- a/halo2_proofs/src/poly/multiopen/shplonk/prover.rs +++ b/halo2_proofs/src/poly/multiopen/shplonk/prover.rs @@ -2,8 +2,8 @@ use super::{ construct_intermediate_sets, ChallengeU, ChallengeV, ChallengeY, Commitment, Query, RotationSet, }; use crate::arithmetic::{ - eval_polynomial, kate_division, lagrange_interpolate, vanishing_polynomial, CurveAffine, - FieldExt, + eval_polynomial, evaluate_vanishing_polynomial, kate_division, lagrange_interpolate, + CurveAffine, FieldExt, }; use crate::poly::multiopen::ProverQuery; use crate::poly::{commitment::Params, Coeff, Error, Polynomial}; @@ -156,14 +156,13 @@ where transcript.write_point(h)?; let u: ChallengeU<_> = transcript.squeeze_challenge_scalar(); - let zt_x = vanishing_polynomial(&super_point_set[..]); - let zt_eval = eval_polynomial(&zt_x[..], *u); + let zt_eval = evaluate_vanishing_polynomial(&super_point_set[..], *u); let linearisation_contribution = |rotation_set: RotationSetExtension| -> Polynomial { // calculate difference vanishing polynomial evaluation - let z_diff = vanishing_polynomial(&rotation_set.diffs[..]); - let z_i = eval_polynomial(&z_diff[..], *u); + + let z_i = evaluate_vanishing_polynomial(&rotation_set.diffs[..], *u); // inner linearisation contibutions are // [P_i_0(X) - r_i_0, P_i_1(X) - r_i_1, ... ] where diff --git a/halo2_proofs/src/poly/multiopen/shplonk/verifier.rs b/halo2_proofs/src/poly/multiopen/shplonk/verifier.rs index 7bbcba96f6..5c3ef5c56a 100644 --- a/halo2_proofs/src/poly/multiopen/shplonk/verifier.rs +++ b/halo2_proofs/src/poly/multiopen/shplonk/verifier.rs @@ -1,7 +1,7 @@ use super::{construct_intermediate_sets, ChallengeU, ChallengeV, ChallengeY}; use crate::arithmetic::{ - eval_polynomial, lagrange_interpolate, vanishing_polynomial, CurveAffine, Engine, FieldExt, - MillerLoopResult, MultiMillerLoop, + eval_polynomial, evaluate_vanishing_polynomial, lagrange_interpolate, CurveAffine, Engine, + FieldExt, MillerLoopResult, MultiMillerLoop, }; use crate::poly::{ commitment::{Params, ParamsVerifier}, @@ -47,14 +47,12 @@ where let u: ChallengeU<_> = transcript.squeeze_challenge_scalar(); let h2 = transcript.read_point().map_err(|_| Error::SamplingError)?; - let zt_x = vanishing_polynomial(&super_point_set[..]); - let zt_eval = eval_polynomial(&zt_x[..], *u); + let zt_eval = evaluate_vanishing_polynomial(&super_point_set[..], *u); let mut outer_msm: PreMSM = PreMSM::new(); for rotation_set in rotation_sets.iter() { - let z_diff = vanishing_polynomial(&rotation_set.diffs[..]); - let z_i = eval_polynomial(&z_diff[..], *u); + let z_i = evaluate_vanishing_polynomial(&rotation_set.diffs[..], *u); let mut inner_msm: ProjectiveMSM = ProjectiveMSM::new(); for commitment_data in rotation_set.commitments.iter() {