@@ -552,8 +552,41 @@ void norm_arg_verify_vectors(void) {
552
552
}
553
553
#undef IDX_TO_TEST
554
554
555
+ void rangeproof_test (size_t digit_base , size_t num_bits , uint64_t value , uint64_t min_value ) {
556
+ secp256k1_generator asset_genp ;
557
+ size_t plen ;
558
+ size_t num_digits = num_bits /secp256k1_bppp_log2 (digit_base );
559
+ size_t n = num_digits > digit_base ? num_digits : digit_base ;
560
+ size_t res ;
561
+ secp256k1_pedersen_commitment commit ;
562
+ secp256k1_context * secp_ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
563
+ const unsigned char blind [32 ] = "help me! i'm bliiiiiiiiiiiiiiind" ;
564
+ const unsigned char nonce [32 ] = "nonce? non ce n'est vrai amirite" ;
565
+ /* Extra commit is a Joan Shelley lyric */
566
+ const unsigned char extra_commit [] = "Shock of teal blue beneath clouds gathering, and the light of empty black on the waves at the horizon" ;
567
+ const size_t extra_commit_len = sizeof (extra_commit );
568
+ secp256k1_sha256 transcript ;
569
+ const secp256k1_bppp_generators * gs = secp256k1_bppp_generators_create (secp_ctx , n + 8 );
570
+ secp256k1_scratch * scratch = secp256k1_scratch_space_create (secp_ctx , 1000 * 1000 ); /* shouldn't need much */
571
+ unsigned char proof [1000 ];
572
+ plen = 1000 ;
573
+ asset_genp = * secp256k1_generator_h ;
574
+ CHECK (secp256k1_pedersen_commit (secp_ctx , & commit , blind , value , & asset_genp ));
575
+ secp256k1_bppp_generators_serialize (secp_ctx , gs , proof , & plen );
576
+ plen = 1000 ;
577
+ secp256k1_sha256_initialize (& transcript );
578
+
579
+
580
+ res = secp256k1_bppp_rangeproof_prove (secp_ctx , scratch , gs , & asset_genp , proof , & plen , num_bits , digit_base , value , min_value , & commit , blind , nonce , extra_commit , extra_commit_len );
581
+ CHECK (res == 1 );
582
+
583
+ res = secp256k1_bppp_rangeproof_verify (secp_ctx , scratch , gs , & asset_genp , proof , plen , num_bits , digit_base , min_value , & commit , extra_commit , extra_commit_len );
584
+ CHECK (res == 1 );
585
+ }
586
+
555
587
void run_bppp_tests (void ) {
556
588
/* Update the global context for all bppp tests*/
589
+ size_t i ;
557
590
ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
558
591
test_log_exp ();
559
592
test_norm_util_helpers ();
@@ -570,6 +603,19 @@ void run_bppp_tests(void) {
570
603
norm_arg_test (64 , 32 );
571
604
norm_arg_test (64 , 64 );
572
605
norm_arg_verify_vectors ();
606
+
607
+ for (i = 0 ; i < 16 ; i ++ ) {
608
+ rangeproof_test (2 , 4 , i , i /2 );
609
+ }
610
+
611
+ rangeproof_test (16 , 4 , 7 , 3 );
612
+ rangeproof_test (16 , 8 , 243 , 129 );
613
+ rangeproof_test (16 , 16 , 12431 , 6332 );
614
+ rangeproof_test (16 , 32 , 134132 , 57251 );
615
+ for (i = 0 ; i < 100 ; i ++ ) {
616
+ uint64_t v = secp256k1_testrand64 ();
617
+ rangeproof_test (16 , 64 , v , 0 );
618
+ }
573
619
}
574
620
575
621
#endif
0 commit comments