1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::{construct_intermediate_sets, ChallengeV, Query};
use crate::arithmetic::{eval_polynomial, kate_division, powers, CurveAffine, FieldExt};
use crate::helpers::SerdeCurveAffine;
use crate::poly::commitment::ParamsProver;
use crate::poly::commitment::Prover;
use crate::poly::kzg::commitment::{KZGCommitmentScheme, ParamsKZG};
use crate::poly::query::ProverQuery;
use crate::poly::Rotation;
use crate::poly::{
commitment::{Blind, Params},
Coeff, Polynomial,
};
use crate::transcript::{EncodedChallenge, TranscriptWrite};
use ff::Field;
use group::Curve;
use halo2curves::pairing::Engine;
use rand_core::RngCore;
use std::fmt::Debug;
use std::io::{self, Write};
use std::marker::PhantomData;
#[derive(Debug)]
pub struct ProverGWC<'params, E: Engine> {
params: &'params ParamsKZG<E>,
}
impl<'params, E: Engine + Debug> Prover<'params, KZGCommitmentScheme<E>> for ProverGWC<'params, E>
where
E::G1Affine: SerdeCurveAffine,
E::G2Affine: SerdeCurveAffine,
{
const QUERY_INSTANCE: bool = false;
fn new(params: &'params ParamsKZG<E>) -> Self {
Self { params }
}
fn create_proof<
'com,
Ch: EncodedChallenge<E::G1Affine>,
T: TranscriptWrite<E::G1Affine, Ch>,
R,
I,
>(
&self,
_: R,
transcript: &mut T,
queries: I,
) -> io::Result<()>
where
I: IntoIterator<Item = ProverQuery<'com, E::G1Affine>> + Clone,
R: RngCore,
{
let v: ChallengeV<_> = transcript.squeeze_challenge_scalar();
let commitment_data = construct_intermediate_sets(queries);
for commitment_at_a_point in commitment_data.iter() {
let z = commitment_at_a_point.point;
let (poly_batch, eval_batch) = commitment_at_a_point
.queries
.iter()
.zip(powers(*v))
.map(|(query, power_of_v)| {
assert_eq!(query.get_point(), z);
let poly = query.get_commitment().poly;
let eval = query.get_eval();
(poly.clone() * power_of_v, eval * power_of_v)
})
.reduce(|(poly_acc, eval_acc), (poly, eval)| (poly_acc + &poly, eval_acc + eval))
.unwrap();
let poly_batch = &poly_batch - eval_batch;
let witness_poly = Polynomial {
values: kate_division(&poly_batch.values, z),
_marker: PhantomData,
};
let w = self
.params
.commit(&witness_poly, Blind::default())
.to_affine();
transcript.write_point(w)?;
}
Ok(())
}
}