@@ -190,48 +190,37 @@ BOOST_AUTO_TEST_CASE(kzg_batched_basic_test) {
190
190
{{21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 }},
191
191
{{31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 }},
192
192
}};
193
-
194
193
const std::vector<polynomial<scalar_value_type>> gs{{
195
194
{{71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 }},
196
195
{{81 , 82 , 83 , 84 , 85 , 86 , 87 , 88 }},
197
196
{{91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 }},
198
197
}};
198
+ typename kzg_type::batch_of_batches_of_polynomials_type polys = {fs, gs};
199
199
200
- scalar_value_type z0 = 123 ;
201
- scalar_value_type z1 = 456 ;
202
- auto evals = kzg_type::evaluate_polynomials (fs, gs, z0, z1);
200
+ std::vector<scalar_value_type> zs = {123 , 456 };
201
+ auto evals = kzg_type::evaluate_polynomials (polys, zs);
203
202
204
203
auto srs = kzg_type::setup ({n, alpha});
205
204
206
- scalar_value_type gamma0 = 54321 ;
207
- scalar_value_type gamma1 = 98760 ;
205
+ std::vector<scalar_value_type> gammas = {54321 , 98760 };
208
206
209
- auto proof = kzg_type::proof_eval (srs, fs, gs, evals, z0, z1, gamma0, gamma1 );
207
+ auto proof = kzg_type::proof_eval (srs, polys, evals, zs, gammas );
210
208
211
- {
209
+ for ( size_t j = 0 ; j < proof. size (); ++j) {
212
210
scalar_value_type h0_x = scalar_value_type::zero ();
213
- for (size_t i = 0 ; i < fs .size (); ++i) {
214
- const polynomial<scalar_value_type> &f_i = fs [i];
215
- const scalar_value_type f_x_minus_f_z0 = f_i.evaluate (alpha) - f_i.evaluate (z0 );
216
- const scalar_value_type gamma_power = gamma0 .pow (i);
217
- h0_x += gamma_power * f_x_minus_f_z0 * ((alpha - z0 ).inversed ());
211
+ for (size_t i = 0 ; i < polys[j] .size (); ++i) {
212
+ const polynomial<scalar_value_type> &f_i = polys[j] [i];
213
+ const scalar_value_type f_x_minus_f_z0 = f_i.evaluate (alpha) - f_i.evaluate (zs[j] );
214
+ const scalar_value_type gamma_power = gammas[j] .pow (i);
215
+ h0_x += gamma_power * f_x_minus_f_z0 * ((alpha - zs[j] ).inversed ());
218
216
}
219
- BOOST_CHECK (h0_x * curve_type::template g1_type<>::value_type::one () == proof.commit0 );
220
-
221
- scalar_value_type h1_x = scalar_value_type::zero ();
222
- for (size_t i = 0 ; i < gs.size (); ++i) {
223
- const polynomial<scalar_value_type> &g_i = gs[i];
224
- const scalar_value_type g_x_minus_g_z1 = g_i.evaluate (alpha) - g_i.evaluate (z1);
225
- const scalar_value_type gamma_power = gamma1.pow (i);
226
- h1_x += gamma_power * g_x_minus_g_z1 * ((alpha - z1).inversed ());
227
- }
228
- BOOST_CHECK (h1_x * curve_type::template g1_type<>::value_type::one () == proof.commit1 );
217
+ BOOST_CHECK (h0_x * curve_type::template g1_type<>::value_type::one () == proof[j]);
229
218
}
230
219
231
220
scalar_value_type r = 23546 ;
232
221
auto c0 = kzg_type::commit (srs, fs);
233
222
auto c1 = kzg_type::commit (srs, gs);
234
- BOOST_CHECK (kzg_type::verify_eval (srs, proof, evals, c0, c1, z0, z1, gamma0, gamma1 , r));
223
+ BOOST_CHECK (kzg_type::verify_eval (srs, proof, evals, { c0, c1}, zs, gammas , r));
235
224
}
236
225
237
226
BOOST_AUTO_TEST_CASE (kzg_batched_random_test) {
@@ -245,54 +234,57 @@ BOOST_AUTO_TEST_CASE(kzg_batched_random_test) {
245
234
246
235
scalar_value_type alpha = algebra::random_element<scalar_field_type>();
247
236
std::size_t n = 298 ;
248
- const std::vector<polynomial<scalar_value_type>> fs {{
237
+ const std::vector<polynomial<scalar_value_type>> f0 {{
249
238
{{1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 }},
250
239
{{11 , 12 , 13 , 14 , 15 , 16 , 17 }},
251
240
{{21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 }},
252
241
{{31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 }},
253
242
}};
254
-
255
- const std::vector<polynomial<scalar_value_type>> gs{{
243
+ const std::vector<polynomial<scalar_value_type>> f1{{
256
244
{{71 , 72 }},
257
245
{{81 , 82 , 83 , 85 , 86 , 87 , 88 }},
258
246
{{91 , 92 , 93 , 94 , 95 , 96 , 97 , 98 , 99 , 100 }},
259
247
}};
260
-
261
- scalar_value_type z0 = algebra::random_element<scalar_field_type>();
262
- scalar_value_type z1 = algebra::random_element<scalar_field_type>();
263
- auto evals = kzg_type::evaluate_polynomials (fs, gs, z0, z1);
248
+ const std::vector<polynomial<scalar_value_type>> f2{{
249
+ {{73 , 74 , 25 }},
250
+ {{87 }},
251
+ {{91 , 92 , 93 , 94 , 95 , 96 , 97 , 100 , 1 , 2 , 3 }},
252
+ }};
253
+ const kzg_type::batch_of_batches_of_polynomials_type polys = {f0, f1, f2};
254
+ std::size_t num_polys = polys.size ();
255
+
256
+ std::vector<scalar_value_type> zs;
257
+ for (std::size_t i = 0 ; i < num_polys; ++i) {
258
+ zs.push_back (algebra::random_element<scalar_field_type>());
259
+ }
260
+ auto evals = kzg_type::evaluate_polynomials (polys, zs);
264
261
265
262
auto srs = kzg_type::setup ({n, alpha});
266
263
267
- scalar_value_type gamma0 = algebra::random_element<scalar_field_type>();
268
- scalar_value_type gamma1 = algebra::random_element<scalar_field_type>();
264
+ std::vector<scalar_value_type> gammas;
265
+ for (std::size_t i = 0 ; i < num_polys; ++i) {
266
+ gammas.push_back (algebra::random_element<scalar_field_type>());
267
+ }
269
268
270
- auto proof = kzg_type::proof_eval (srs, fs, gs, evals, z0, z1, gamma0, gamma1 );
269
+ auto proof = kzg_type::proof_eval (srs, polys, evals, zs, gammas );
271
270
272
- {
271
+ for (std:: size_t j = 0 ; j < proof. size (); ++j) {
273
272
scalar_value_type h0_x = scalar_value_type::zero ();
274
- for (size_t i = 0 ; i < fs .size (); ++i) {
275
- const polynomial<scalar_value_type> &f_i = fs [i];
276
- const scalar_value_type f_x_minus_f_z0 = f_i.evaluate (alpha) - f_i.evaluate (z0 );
277
- const scalar_value_type gamma_power = gamma0 .pow (i);
278
- h0_x += gamma_power * f_x_minus_f_z0 * ((alpha - z0 ).inversed ());
273
+ for (std:: size_t i = 0 ; i < polys[j] .size (); ++i) {
274
+ const polynomial<scalar_value_type> &f_i = polys[j] [i];
275
+ const scalar_value_type f_x_minus_f_z0 = f_i.evaluate (alpha) - f_i.evaluate (zs[j] );
276
+ const scalar_value_type gamma_power = gammas[j] .pow (i);
277
+ h0_x += gamma_power * f_x_minus_f_z0 * ((alpha - zs[j] ).inversed ());
279
278
}
280
- BOOST_CHECK (h0_x * curve_type::template g1_type<>::value_type::one () == proof.commit0 );
281
-
282
- scalar_value_type h1_x = scalar_value_type::zero ();
283
- for (size_t i = 0 ; i < gs.size (); ++i) {
284
- const polynomial<scalar_value_type> &g_i = gs[i];
285
- const scalar_value_type g_x_minus_g_z1 = g_i.evaluate (alpha) - g_i.evaluate (z1);
286
- const scalar_value_type gamma_power = gamma1.pow (i);
287
- h1_x += gamma_power * g_x_minus_g_z1 * ((alpha - z1).inversed ());
288
- }
289
- BOOST_CHECK (h1_x * curve_type::template g1_type<>::value_type::one () == proof.commit1 );
279
+ BOOST_CHECK (h0_x * curve_type::template g1_type<>::value_type::one () == proof[j]);
290
280
}
291
281
292
282
scalar_value_type r = algebra::random_element<scalar_field_type>();
293
- auto c0 = kzg_type::commit (srs, fs);
294
- auto c1 = kzg_type::commit (srs, gs);
295
- BOOST_CHECK (kzg_type::verify_eval (srs, proof, evals, c0, c1, z0, z1, gamma0, gamma1, r));
283
+ std::vector<std::vector<kzg_type::commitment_type>> cs;
284
+ for (std::size_t j = 0 ; j < num_polys; ++j) {
285
+ cs.push_back (kzg_type::commit (srs, polys[j]));
286
+ }
287
+ BOOST_CHECK (kzg_type::verify_eval (srs, proof, evals, cs, zs, gammas, r));
296
288
}
297
289
298
290
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments