Skip to content

Commit 38b24ee

Browse files
committed
Add testcases for bulletproofs++ norm arugment
1 parent 9062460 commit 38b24ee

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/modules/bulletproofs/tests_impl.h

+45
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,57 @@ void test_norm_util_helpers(void) {
276276
secp256k1_scalar_set_int(&res, 256); CHECK(secp256k1_scalar_eq(&res, &r_pows[3]));
277277
}
278278

279+
void norm_arg_test(unsigned int n, unsigned int m) {
280+
secp256k1_scalar n_vec[64], l_vec[64], c_vec[64];
281+
secp256k1_scalar r, q;
282+
secp256k1_ge commit;
283+
size_t i, plen;
284+
int res;
285+
secp256k1_bulletproofs_generators *gs = secp256k1_bulletproofs_generators_create(ctx, n + m);
286+
secp256k1_scratch *scratch = secp256k1_scratch_space_create(ctx, 1000*1000); /* shouldn't need much */
287+
unsigned char proof[1000], transcript32[32];
288+
for (i = 0; i < 32; i++) {
289+
transcript32[i] = i;
290+
}
291+
random_scalar_order(&r);
292+
secp256k1_scalar_sqr(&q, &r);
293+
294+
for (i = 0; i < n; i++) {
295+
random_scalar_order(&n_vec[i]);
296+
}
297+
298+
for (i = 0; i < m; i++) {
299+
random_scalar_order(&l_vec[i]);
300+
random_scalar_order(&c_vec[i]);
301+
}
302+
303+
res = secp256k1_bulletproofs_commit(ctx, scratch, &commit, gs, n_vec, n, l_vec, m, c_vec, m, &q);
304+
CHECK(res == 1);
305+
res = secp256k1_bulletproofs_pp_rangeproof_norm_product_prove(ctx, scratch, proof, &plen, transcript32, &r, gs, n_vec, n, l_vec, m, c_vec, m, &commit);
306+
CHECK(res == 1);
307+
308+
for (i = 0; i < 32; i++) {
309+
transcript32[i] = i;
310+
}
311+
312+
res = secp256k1_bulletproofs_pp_rangeproof_norm_product_verify(ctx, scratch, proof, plen, transcript32, &r, gs, n, c_vec, m, &commit);
313+
CHECK(res == 1);
314+
}
315+
279316
void run_bulletproofs_tests(void) {
280317
test_log_exp();
281318
test_norm_util_helpers();
282319
test_bulletproofs_generators_api();
283320
test_bulletproofs_generators_fixed();
284321
test_bulletproofs_rangeproof_uncompressed_api();
322+
323+
norm_arg_test(1, 1);
324+
norm_arg_test(1, 64);
325+
norm_arg_test(64, 1);
326+
norm_arg_test(32, 32);
327+
norm_arg_test(32, 64);
328+
norm_arg_test(64, 32);
329+
norm_arg_test(64, 64);
285330
}
286331

287332
#endif

0 commit comments

Comments
 (0)