@@ -570,8 +570,41 @@ void norm_arg_verify_vectors(void) {
570570}
571571#undef IDX_TO_TEST
572572
573+ void rangeproof_test (size_t digit_base , size_t num_bits , uint64_t value , uint64_t min_value ) {
574+ secp256k1_generator asset_genp ;
575+ size_t plen ;
576+ size_t num_digits = num_bits /secp256k1_bppp_log2 (digit_base );
577+ size_t n = num_digits > digit_base ? num_digits : digit_base ;
578+ size_t res ;
579+ secp256k1_pedersen_commitment commit ;
580+ secp256k1_context * secp_ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
581+ const unsigned char blind [32 ] = "help me! i'm bliiiiiiiiiiiiiiind" ;
582+ const unsigned char nonce [32 ] = "nonce? non ce n'est vrai amirite" ;
583+ /* Extra commit is a Joan Shelley lyric */
584+ const unsigned char extra_commit [] = "Shock of teal blue beneath clouds gathering, and the light of empty black on the waves at the horizon" ;
585+ const size_t extra_commit_len = sizeof (extra_commit );
586+ secp256k1_sha256 transcript ;
587+ const secp256k1_bppp_generators * gs = secp256k1_bppp_generators_create (secp_ctx , n + 8 );
588+ secp256k1_scratch * scratch = secp256k1_scratch_space_create (secp_ctx , 1000 * 1000 ); /* shouldn't need much */
589+ unsigned char proof [1000 ];
590+ plen = 1000 ;
591+ asset_genp = * secp256k1_generator_h ;
592+ CHECK (secp256k1_pedersen_commit (secp_ctx , & commit , blind , value , & asset_genp ));
593+ secp256k1_bppp_generators_serialize (secp_ctx , gs , proof , & plen );
594+ plen = 1000 ;
595+ secp256k1_sha256_initialize (& transcript );
596+
597+
598+ 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 );
599+ CHECK (res == 1 );
600+
601+ 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 );
602+ CHECK (res == 1 );
603+ }
604+
573605void run_bppp_tests (void ) {
574606 /* Update the global context for all bppp tests*/
607+ size_t i ;
575608 ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
576609 test_log_exp ();
577610 test_norm_util_helpers ();
@@ -588,6 +621,19 @@ void run_bppp_tests(void) {
588621 norm_arg_test (64 , 32 );
589622 norm_arg_test (64 , 64 );
590623 norm_arg_verify_vectors ();
624+
625+ for (i = 0 ; i < 16 ; i ++ ) {
626+ rangeproof_test (2 , 4 , i , i /2 );
627+ }
628+
629+ rangeproof_test (16 , 4 , 7 , 3 );
630+ rangeproof_test (16 , 8 , 243 , 129 );
631+ rangeproof_test (16 , 16 , 12431 , 6332 );
632+ rangeproof_test (16 , 32 , 134132 , 57251 );
633+ for (i = 0 ; i < 100 ; i ++ ) {
634+ uint64_t v = secp256k1_testrand64 ();
635+ rangeproof_test (16 , 64 , v , 0 );
636+ }
591637}
592638
593639#endif
0 commit comments