Skip to content

Commit 565f247

Browse files
committed
Add testcases for bulletproofs++ norm arugment
1 parent f7e2980 commit 565f247

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/modules/bulletproofs/tests_impl.h

+48
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,59 @@ void test_norm_util_helpers(void) {
170170
secp256k1_scalar_set_int(&res, 256); CHECK(secp256k1_scalar_eq(&res, &r_pows[3]));
171171
}
172172

173+
void norm_arg_test(unsigned int n, unsigned int m) {
174+
secp256k1_scalar n_vec[64], l_vec[64], c_vec[64];
175+
secp256k1_scalar r, q;
176+
secp256k1_ge commit;
177+
size_t i, plen;
178+
int res;
179+
secp256k1_bulletproofs_generators *gs = secp256k1_bulletproofs_generators_create(ctx, n + m);
180+
secp256k1_scratch *scratch = secp256k1_scratch_space_create(ctx, 1000*1000); /* shouldn't need much */
181+
unsigned char proof[1000], transcript32[32];
182+
plen = 1000;
183+
for (i = 0; i < 32; i++) {
184+
transcript32[i] = i;
185+
}
186+
random_scalar_order(&r);
187+
secp256k1_scalar_sqr(&q, &r);
188+
189+
for (i = 0; i < n; i++) {
190+
random_scalar_order(&n_vec[i]);
191+
}
192+
193+
for (i = 0; i < m; i++) {
194+
random_scalar_order(&l_vec[i]);
195+
random_scalar_order(&c_vec[i]);
196+
}
197+
198+
res = secp256k1_bulletproofs_commit(ctx, scratch, &commit, gs, n_vec, n, l_vec, m, c_vec, m, &q);
199+
CHECK(res == 1);
200+
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);
201+
CHECK(res == 1);
202+
203+
for (i = 0; i < 32; i++) {
204+
transcript32[i] = i;
205+
}
206+
207+
res = secp256k1_bulletproofs_pp_rangeproof_norm_product_verify(ctx, scratch, proof, plen, transcript32, &r, gs, n, c_vec, m, &commit);
208+
CHECK(res == 1);
209+
210+
secp256k1_bulletproofs_generators_destroy(ctx, gs);
211+
}
212+
173213
void run_bulletproofs_tests(void) {
174214
test_log_exp();
175215
test_norm_util_helpers();
176216
test_bulletproofs_generators_api();
177217
test_bulletproofs_generators_fixed();
218+
219+
norm_arg_test(1, 1);
220+
norm_arg_test(1, 64);
221+
norm_arg_test(64, 1);
222+
norm_arg_test(32, 32);
223+
norm_arg_test(32, 64);
224+
norm_arg_test(64, 32);
225+
norm_arg_test(64, 64);
178226
}
179227

180228
#endif

0 commit comments

Comments
 (0)