halo2_proofs/poly/multiopen/
verifier.rsuse ff::Field;
use rand_core::RngCore;
use super::super::{
commitment::{Guard, Params, MSM},
Error,
};
use super::{
construct_intermediate_sets, ChallengeX1, ChallengeX2, ChallengeX3, ChallengeX4,
CommitmentReference, Query, VerifierQuery,
};
use crate::arithmetic::{eval_polynomial, lagrange_interpolate, CurveAffine, FieldExt};
use crate::transcript::{EncodedChallenge, TranscriptRead};
pub fn verify_proof<
'r,
'params: 'r,
I,
C: CurveAffine,
E: EncodedChallenge<C>,
T: TranscriptRead<C, E>,
>(
params: &'params Params<C>,
transcript: &mut T,
queries: I,
mut msm: MSM<'params, C>,
) -> Result<Guard<'params, C, E>, Error>
where
I: IntoIterator<Item = VerifierQuery<'r, 'params, C>> + Clone,
{
let x_1: ChallengeX1<_> = transcript.squeeze_challenge_scalar();
let x_2: ChallengeX2<_> = transcript.squeeze_challenge_scalar();
let (commitment_map, point_sets) = construct_intermediate_sets(queries);
let mut q_commitments: Vec<_> = vec![params.empty_msm(); point_sets.len()];
let mut q_eval_sets = Vec::with_capacity(point_sets.len());
for point_set in point_sets.iter() {
q_eval_sets.push(vec![C::Scalar::zero(); point_set.len()]);
}
{
let mut accumulate = |set_idx: usize, new_commitment, evals: Vec<C::Scalar>| {
q_commitments[set_idx].scale(*x_1);
match new_commitment {
CommitmentReference::Commitment(c) => {
q_commitments[set_idx].append_term(C::Scalar::one(), *c);
}
CommitmentReference::MSM(msm) => {
q_commitments[set_idx].add_msm(msm);
}
}
for (eval, set_eval) in evals.iter().zip(q_eval_sets[set_idx].iter_mut()) {
*set_eval *= &(*x_1);
*set_eval += eval;
}
};
for commitment_data in commitment_map.into_iter() {
accumulate(
commitment_data.set_index, commitment_data.commitment, commitment_data.evals, );
}
}
let q_prime_commitment = transcript.read_point().map_err(|_| Error::SamplingError)?;
let x_3: ChallengeX3<_> = transcript.squeeze_challenge_scalar();
let mut u = Vec::with_capacity(q_eval_sets.len());
for _ in 0..q_eval_sets.len() {
u.push(transcript.read_scalar().map_err(|_| Error::SamplingError)?);
}
let msm_eval = point_sets
.iter()
.zip(q_eval_sets.iter())
.zip(u.iter())
.fold(
C::Scalar::zero(),
|msm_eval, ((points, evals), proof_eval)| {
let r_poly = lagrange_interpolate(points, evals);
let r_eval = eval_polynomial(&r_poly, *x_3);
let eval = points.iter().fold(*proof_eval - &r_eval, |eval, point| {
eval * &(*x_3 - point).invert().unwrap()
});
msm_eval * &(*x_2) + &eval
},
);
let x_4: ChallengeX4<_> = transcript.squeeze_challenge_scalar();
msm.append_term(C::Scalar::one(), q_prime_commitment);
let (msm, v) = q_commitments.into_iter().zip(u.iter()).fold(
(msm, msm_eval),
|(mut msm, msm_eval), (q_commitment, q_eval)| {
msm.scale(*x_4);
msm.add_msm(&q_commitment);
(msm, msm_eval * &(*x_4) + q_eval)
},
);
super::commitment::verify_proof(params, msm, transcript, *x_3, v)
}
impl<'a, 'b, C: CurveAffine> Query<C::Scalar> for VerifierQuery<'a, 'b, C> {
type Commitment = CommitmentReference<'a, 'b, C>;
type Eval = C::Scalar;
fn get_point(&self) -> C::Scalar {
self.point
}
fn get_eval(&self) -> C::Scalar {
self.eval
}
fn get_commitment(&self) -> Self::Commitment {
self.commitment
}
}