@@ -35,9 +35,8 @@ static void test_bulletproof_api(void) {
35
35
uint64_t value [4 ] = { 1234 , 4567 , 8910 , 1112 } ;
36
36
uint64_t min_value [4 ] = { 1000 , 4567 , 0 , 5000 } ;
37
37
const uint64_t * mv_ptr = min_value ;
38
-
39
- const char circ_desc_good [] = "2,0,0,4; L0 = 17; 2*L1 - L0 = 21; O0 = 1; O1 = 1;" ;
40
- const char circ_desc_bad [] = "2,0,0,4; L0 = 17; 2*L1 - L0 = 21; O0 = 1; O1 x 1;" ;
38
+ unsigned char rewind_blind [32 ];
39
+ size_t rewind_v ;
41
40
42
41
int32_t ecount = 0 ;
43
42
@@ -223,6 +222,35 @@ static void test_bulletproof_api(void) {
223
222
CHECK (secp256k1_bulletproof_rangeproof_verify_multi (both , scratch , gens , & proof_ptr , 1 , plen , & mv_ptr , pcommit_arr , 4 , 64 , & value_gen , blind_ptr , & blindlen ) == 0 );
224
223
CHECK (ecount == 14 );
225
224
225
+ /* Rewind */
226
+ ecount = 0 ;
227
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , blind , blind , 32 ) == 1 );
228
+ CHECK (ecount == 0 );
229
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , NULL , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , blind , blind , 32 ) == 0 );
230
+ CHECK (ecount == 1 );
231
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , NULL , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , blind , blind , 32 ) == 0 );
232
+ CHECK (ecount == 2 );
233
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , NULL , proof , plen , min_value [0 ], pcommit , & value_gen , blind , blind , 32 ) == 0 );
234
+ CHECK (ecount == 3 );
235
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , NULL , plen , min_value [0 ], pcommit , & value_gen , blind , blind , 32 ) == 0 );
236
+ CHECK (ecount == 4 );
237
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , 0 , min_value [0 ], pcommit , & value_gen , blind , blind , 32 ) == 0 );
238
+ CHECK (ecount == 4 );
239
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , 0 , pcommit , & value_gen , blind , blind , 32 ) == 0 );
240
+ CHECK (ecount == 4 );
241
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], NULL , & value_gen , blind , blind , 32 ) == 0 );
242
+ CHECK (ecount == 5 );
243
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , NULL , blind , blind , 32 ) == 0 );
244
+ CHECK (ecount == 6 );
245
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , NULL , blind , 32 ) == 0 );
246
+ CHECK (ecount == 7 );
247
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , blind , NULL , 32 ) == 0 );
248
+ CHECK (ecount == 8 );
249
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , blind , blind , 0 ) == 0 );
250
+ CHECK (ecount == 8 );
251
+ CHECK (secp256k1_bulletproof_rangeproof_rewind (none , gens , & rewind_v , rewind_blind , proof , plen , min_value [0 ], pcommit , & value_gen , blind , NULL , 0 ) == 0 );
252
+ CHECK (ecount == 8 );
253
+
226
254
secp256k1_bulletproof_generators_destroy (none , gens );
227
255
secp256k1_bulletproof_generators_destroy (none , NULL );
228
256
secp256k1_scratch_destroy (scratch );
@@ -438,15 +466,18 @@ void test_bulletproof_inner_product(size_t n, const secp256k1_bulletproof_genera
438
466
439
467
void test_bulletproof_rangeproof (size_t nbits , size_t expected_size , const secp256k1_bulletproof_generators * gens ) {
440
468
secp256k1_scalar blind ;
469
+ secp256k1_scalar blind_recovered ;
441
470
unsigned char proof [1024 ];
442
471
unsigned char proof2 [1024 ];
443
472
unsigned char proof3 [1024 ];
444
473
const unsigned char * proof_ptr [3 ];
445
474
size_t plen = sizeof (proof );
446
475
uint64_t v = 123456 ;
476
+ uint64_t v_recovered ;
447
477
secp256k1_gej commitj ;
448
478
secp256k1_ge commitp ;
449
479
secp256k1_ge commitp2 ;
480
+ secp256k1_pedersen_commitment pcommit ;
450
481
const secp256k1_ge * commitp_ptr [3 ];
451
482
secp256k1_ge value_gen [3 ];
452
483
unsigned char nonce [32 ] = "my kingdom for some randomness!!" ;
@@ -472,6 +503,7 @@ void test_bulletproof_rangeproof(size_t nbits, size_t expected_size, const secp2
472
503
secp256k1_ge_set_gej (& commitp2 , & commitj );
473
504
commitp_ptr [0 ] = commitp_ptr [1 ] = & commitp ;
474
505
commitp_ptr [2 ] = & commitp2 ;
506
+ secp256k1_pedersen_commitment_save (& pcommit , & commitp );
475
507
476
508
CHECK (secp256k1_bulletproof_rangeproof_prove_impl (& ctx -> ecmult_ctx , scratch , proof , & plen , nbits , & v , NULL , & blind , & commitp , 1 , & value_gen [0 ], gens , nonce , NULL , 0 ) == 1 );
477
509
CHECK (plen == expected_size );
@@ -489,6 +521,14 @@ void test_bulletproof_rangeproof(size_t nbits, size_t expected_size, const secp2
489
521
/* Verify thrice at once where one has a different asset type */
490
522
CHECK (secp256k1_bulletproof_rangeproof_verify_impl (& ctx -> ecmult_ctx , scratch , proof_ptr , 3 , plen , nbits , NULL , commitp_ptr , 1 , value_gen , gens , NULL , 0 ) == 1 );
491
523
524
+ /* Rewind */
525
+ CHECK (secp256k1_bulletproof_rangeproof_rewind_impl (& v_recovered , & blind_recovered , proof , plen , 0 , & pcommit , & secp256k1_generator_const_g , gens -> blinding_gen , nonce , NULL , 0 ) == 1 );
526
+ CHECK (v_recovered == v );
527
+ CHECK (secp256k1_scalar_eq (& blind_recovered , & blind ) == 1 );
528
+
529
+ nonce [0 ] ^= 111 ;
530
+ CHECK (secp256k1_bulletproof_rangeproof_rewind_impl (& v_recovered , & blind_recovered , proof , plen , 0 , & pcommit , & secp256k1_generator_const_g , gens -> blinding_gen , nonce , NULL , 0 ) == 0 );
531
+
492
532
secp256k1_scratch_destroy (scratch );
493
533
}
494
534
0 commit comments