@@ -88,42 +88,66 @@ static polynomial<FieldT> polynomial_accumulate_with_power_factors(
8888} // namespace internal
8989
9090template <typename ppT>
91- kzg10_batched_2_point<ppT>::multi_point_evaluation_challenge::
92- multi_point_evaluation_challenge (
93- const Field &z_1,
94- const Field &z_2,
95- const Field &gamma_1,
96- const Field &gamma_2)
97- : z_1(z_1), z_2(z_2), gamma_1(gamma_1), gamma_2(gamma_2)
91+ kzg10_batched_2_point<ppT>::evaluations::evaluations(
92+ std::vector<Field> &&s_1s, std::vector<Field> &&s_2s)
93+ : s_1s(s_1s), s_2s(s_2s)
9894{
9995}
10096
10197template <typename ppT>
102- kzg10_batched_2_point<ppT>::multi_point_evaluation_witness::
103- multi_point_evaluation_witness (
104- const std::vector<Field> &&s_1s,
105- const std::vector<Field> &&s_2s,
106- const libff::G1<ppT> &W_1,
107- const libff::G1<ppT> &W_2)
108- : s_1s(s_1s), s_2s(s_2s), W_1(W_1), W_2(W_2)
98+ kzg10_batched_2_point<ppT>::evaluation_witness::evaluation_witness(
99+ const libff::G1<ppT> &W_1, const libff::G1<ppT> &W_2)
100+ : W_1(W_1), W_2(W_2)
109101{
110102}
111103
112104template <typename ppT>
113- typename kzg10_batched_2_point<ppT>::multi_point_evaluation_witness
114- kzg10_batched_2_point<ppT>::create_witness (
115- const srs &srs ,
116- const multi_point_evaluation_challenge &challenge ,
117- const std::vector<polynomial< Field>> &fs ,
118- const std::vector<polynomial< Field>> &gs )
105+ typename kzg10_batched_2_point<ppT>::evaluations kzg10_batched_2_point<ppT>::
106+ evaluate_polynomials (
107+ const std::vector<polynomial<Field>> &fs ,
108+ const std::vector<polynomial<Field>> &gs ,
109+ const Field &z_1 ,
110+ const Field &z_2 )
119111{
120112 // Denote the numbers of polynomials as t1 and t2, consistent with [GWC19].
121113 const size_t t1 = fs.size ();
122114 const size_t t2 = gs.size ();
123115
124- // For convenience of variable naming, let $f_i \in fs$ and $g_i in gs$ to
125- // be the two sets of polynomials. These are denoted $f_i$ and $f^\prime_i$
126- // in [GWC19]. Similarly, $h_1$ and $h_2$ are used in place of $h$ and
116+ std::vector<Field> s_1s;
117+ s_1s.reserve (t1);
118+ for (const polynomial<Field> &f_i : fs) {
119+ s_1s.push_back (libfqfft::evaluate_polynomial (f_i.size (), f_i, z_1));
120+ }
121+
122+ std::vector<Field> s_2s;
123+ s_2s.reserve (t2);
124+ for (const polynomial<Field> &g_i : gs) {
125+ s_2s.push_back (libfqfft::evaluate_polynomial (g_i.size (), g_i, z_2));
126+ }
127+
128+ return evaluations (std::move (s_1s), std::move (s_2s));
129+ }
130+
131+ template <typename ppT>
132+ typename kzg10_batched_2_point<ppT>::evaluation_witness kzg10_batched_2_point<
133+ ppT>::
134+ create_evaluation_witness (
135+ const std::vector<polynomial<Field>> &fs,
136+ const std::vector<polynomial<Field>> &gs,
137+ const Field &z_1,
138+ const Field &z_2,
139+ const evaluations &evaluations,
140+ const srs &srs,
141+ const Field &gamma_1,
142+ const Field &gamma_2)
143+ {
144+ assert (fs.size () == evaluations.s_1s .size ());
145+ assert (gs.size () == evaluations.s_2s .size ());
146+ libff::UNUSED (evaluations);
147+
148+ // For convenience of variable naming, let $f_i \in fs$ and $g_i in gs$ be
149+ // the two sets of polynomials. These are denoted $f_i$ and $f^\prime_i$ in
150+ // [GWC19]. Similarly, $h_1$ and $h_2$ are used in place of $h$ and
127151 // $h^\prime$ in the paper, and $\gamma_1$ and $\gamma_2$ in place of
128152 // $\gamma$ and $\gamma^\prime$.
129153 //
@@ -137,71 +161,59 @@ kzg10_batched_2_point<ppT>::create_witness(
137161 //
138162 // W_1 = [h_1(x)]_1
139163 // W_2 = [h_2(x)]_2
140- // sf_i = f_i(z_1) for i = 1, ..., t1
141- // sg_i = g_i(z_2) for i = 1, ..., t2
142164
143165 // Compute the sum of $\gamma_1^{i=1} f_i$ polynomials, and pass this
144166 // polynomial into the kzg10 create_witness function, to yield $W_1$ and
145167 // $sf_1$.
146168
147- // Evaluations
148- std::vector<Field> s_1s;
149- s_1s.reserve (t1);
150- for (const polynomial<Field> &f_i : fs) {
151- s_1s.push_back (
152- libfqfft::evaluate_polynomial (f_i.size (), f_i, challenge.z_1 ));
153- }
154-
155- std::vector<Field> s_2s;
156- s_2s.reserve (t2);
157- for (const polynomial<Field> &g_i : gs) {
158- s_2s.push_back (
159- libfqfft::evaluate_polynomial (g_i.size (), g_i, challenge.z_2 ));
160- }
169+ // TODO: Use the evaluations object to compute f_accum_eval and
170+ // g_accum_eval, instead of evaluating the accumulated polynomial.
161171
162172 // Accumulate polynomials and get the witnesses
163173 const polynomial<Field> f_accum =
164- internal::polynomial_accumulate_with_power_factors (
165- fs, challenge.gamma_1 );
166- const evaluation_and_witness<ppT, kzg10<ppT>> f_accum_witness =
167- kzg10<ppT>::create_witness (srs, f_accum, challenge.z_1 );
174+ internal::polynomial_accumulate_with_power_factors (fs, gamma_1);
175+ const libff::Fr<ppT> f_accum_eval =
176+ kzg10<ppT>::evaluate_polynomial (f_accum, z_1);
177+ const libff::G1<ppT> f_accum_witness =
178+ kzg10<ppT>::create_evaluation_witness (f_accum, z_1, f_accum_eval, srs);
168179
169180 const polynomial<Field> g_accum =
170- internal::polynomial_accumulate_with_power_factors (
171- gs, challenge.gamma_2 );
172- const evaluation_and_witness<ppT, kzg10<ppT>> g_accum_witness =
173- kzg10<ppT>::create_witness (srs, g_accum, challenge.z_2 );
181+ internal::polynomial_accumulate_with_power_factors (gs, gamma_2);
182+ const libff::Fr<ppT> g_accum_eval =
183+ kzg10<ppT>::evaluate_polynomial (g_accum, z_2);
184+ const libff::G1<ppT> g_accum_witness =
185+ kzg10<ppT>::create_evaluation_witness (g_accum, z_2, g_accum_eval, srs);
174186
175- return multi_point_evaluation_witness (
176- std::move (s_1s), std::move (s_2s), f_accum_witness.w , g_accum_witness.w );
187+ return evaluation_witness (f_accum_witness, g_accum_witness);
177188}
178189
179190template <typename ppT>
180- bool kzg10_batched_2_point<ppT>::verify_eval(
191+ bool kzg10_batched_2_point<ppT>::verify_evaluations(
192+ const Field &z_1,
193+ const Field &z_2,
194+ const evaluations &evaluations,
181195 const srs &srs,
182- const multi_point_evaluation_challenge &challenge,
196+ const Field &gamma_1,
197+ const Field &gamma_2,
198+ const evaluation_witness &witness,
183199 const std::vector<commitment> &cm_1s,
184200 const std::vector<commitment> &cm_2s,
185- const multi_point_evaluation_witness &witness,
186- const libff::Fr<ppT> &r)
201+ const Field &r)
187202{
188203 // See Section 3, p13 of [GWC19].
189204
190- assert (cm_1s.size () == witness.s_1s .size ());
191- assert (cm_2s.size () == witness.s_2s .size ());
192-
193205 const size_t t1 = cm_1s.size ();
194206 const size_t t2 = cm_2s.size ();
207+ assert (t1 == evaluations.s_1s .size ());
208+ assert (t2 == evaluations.s_2s .size ());
195209
196210 // Compute:
197211 //
198212 // F = \sum_{i=1}^{t1} \gamma_1^{i-1} (cm_1[i] - [s_1[i]]_1) + (G)
199213 // r \sum_{i=1}^{t2} \gamma_2^{i-1} (cm_2[i] - [s_2[i]]_1) (H)
200214
201- const std::vector<Field> &s_1s = witness.s_1s ;
202- const std::vector<Field> &s_2s = witness.s_2s ;
203- const Field gamma_1 = challenge.gamma_1 ;
204- const Field gamma_2 = challenge.gamma_2 ;
215+ const std::vector<Field> &s_1s = evaluations.s_1s ;
216+ const std::vector<Field> &s_2s = evaluations.s_2s ;
205217
206218 // Compute:
207219 //
@@ -252,8 +264,6 @@ bool kzg10_batched_2_point<ppT>::verify_eval(
252264
253265 const libff::G1<ppT> &W_1 = witness.W_1 ;
254266 const libff::G1<ppT> &W_2 = witness.W_2 ;
255- const Field &z_1 = challenge.z_1 ;
256- const Field &z_2 = challenge.z_2 ;
257267
258268 const libff::G1<ppT> r_W_2 = r * W_2;
259269 const libff::G1<ppT> A = F + z_1 * W_1 + z_2 * r_W_2;
0 commit comments