@@ -529,8 +529,41 @@ void norm_arg_verify_vectors(void) {
529529}
530530#undef IDX_TO_TEST
531531
532+ void rangeproof_test (size_t digit_base , size_t num_bits , uint64_t value , uint64_t min_value ) {
533+ secp256k1_generator asset_genp ;
534+ size_t plen ;
535+ size_t num_digits = num_bits /secp256k1_bppp_log2 (digit_base );
536+ size_t n = num_digits > digit_base ? num_digits : digit_base ;
537+ size_t res ;
538+ secp256k1_pedersen_commitment commit ;
539+ secp256k1_context * secp_ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
540+ const unsigned char blind [32 ] = "help me! i'm bliiiiiiiiiiiiiiind" ;
541+ const unsigned char nonce [32 ] = "nonce? non ce n'est vrai amirite" ;
542+ /* Extra commit is a Joan Shelley lyric */
543+ const unsigned char extra_commit [] = "Shock of teal blue beneath clouds gathering, and the light of empty black on the waves at the horizon" ;
544+ const size_t extra_commit_len = sizeof (extra_commit );
545+ secp256k1_sha256 transcript ;
546+ const secp256k1_bppp_generators * gs = secp256k1_bppp_generators_create (secp_ctx , n + 8 );
547+ secp256k1_scratch * scratch = secp256k1_scratch_space_create (secp_ctx , 1000 * 1000 ); /* shouldn't need much */
548+ unsigned char proof [1000 ];
549+ plen = 1000 ;
550+ asset_genp = * secp256k1_generator_h ;
551+ CHECK (secp256k1_pedersen_commit (secp_ctx , & commit , blind , value , & asset_genp ));
552+ secp256k1_bppp_generators_serialize (secp_ctx , gs , proof , & plen );
553+ plen = 1000 ;
554+ secp256k1_sha256_initialize (& transcript );
555+
556+
557+ 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 );
558+ CHECK (res == 1 );
559+
560+ 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 );
561+ CHECK (res == 1 );
562+ }
563+
532564void run_bppp_tests (void ) {
533565 /* Update the global context for all bppp tests*/
566+ size_t i ;
534567 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
535568 test_log_exp ();
536569 test_norm_util_helpers ();
@@ -547,6 +580,19 @@ void run_bppp_tests(void) {
547580 norm_arg_test (64 , 32 );
548581 norm_arg_test (64 , 64 );
549582 norm_arg_verify_vectors ();
583+
584+ for (i = 0 ; i < 16 ; i ++ ) {
585+ rangeproof_test (2 , 4 , i , i /2 );
586+ }
587+
588+ rangeproof_test (16 , 4 , 7 , 3 );
589+ rangeproof_test (16 , 8 , 243 , 129 );
590+ rangeproof_test (16 , 16 , 12431 , 6332 );
591+ rangeproof_test (16 , 32 , 134132 , 57251 );
592+ for (i = 0 ; i < 100 ; i ++ ) {
593+ uint64_t v = secp256k1_testrand64 ();
594+ rangeproof_test (16 , 64 , v , 0 );
595+ }
550596}
551597
552598#endif
0 commit comments