Skip to content
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

Vanishing polynomial evaluator #35

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions halo2_proofs/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,8 @@ pub fn lagrange_interpolate<F: FieldExt>(points: &[F], evals: &[F]) -> Vec<F> {
}
}

/// Given roots [a_0, a_1, ... a_n] returns vanishing polynomials
/// (x - a_0) * (x - a_1) * ... * (x - a_n)
pub fn vanishing_polynomial<F: FieldExt>(roots: &[F]) -> Vec<F> {
fn mul_with<F: FieldExt>(coeffs: Vec<F>, root: &F) -> Vec<F> {
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<F: FieldExt>(roots: &[F], z: F) -> F {
roots.iter().fold(F::one(), |acc, point| (z - point) * acc)
}

#[cfg(test)]
Expand Down
11 changes: 5 additions & 6 deletions halo2_proofs/src/poly/multiopen/shplonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<C>| -> Polynomial<C::Scalar, Coeff> {
// 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
Expand Down
10 changes: 4 additions & 6 deletions halo2_proofs/src/poly/multiopen/shplonk/verifier.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<C> = 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<C> = ProjectiveMSM::new();
for commitment_data in rotation_set.commitments.iter() {
Expand Down