9
9
10
10
#include <stdint.h>
11
11
12
+ #include "group_impl.h"
12
13
#include "include/secp256k1_bulletproofs.h"
13
14
#include "bulletproofs_pp_norm_product_impl.h"
15
+ #include "bulletproofs_pp_rangeproof_impl.h"
14
16
#include "bulletproofs_util.h"
17
+ #include "modules/generator/main_impl.h"
15
18
16
19
static void test_bulletproofs_generators_api (void ) {
17
20
/* The BP generator API requires no precomp */
@@ -198,7 +201,40 @@ void norm_arg_test(unsigned int n, unsigned int m) {
198
201
CHECK (res == 1 );
199
202
}
200
203
204
+ void rangeproof_test (size_t digit_base , size_t num_bits , uint64_t value , uint64_t min_value ) {
205
+ secp256k1_generator asset_genp ;
206
+ size_t plen ;
207
+ size_t num_digits = num_bits /secp256k1_bulletproofs_pp_log2 (digit_base );
208
+ size_t n = num_digits > digit_base ? num_digits : digit_base ;
209
+ size_t res ;
210
+ secp256k1_pedersen_commitment commit ;
211
+ secp256k1_context * secp_ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
212
+ const unsigned char blind [32 ] = "help me! i'm bliiiiiiiiiiiiiiind" ;
213
+ const unsigned char nonce [32 ] = "nonce? non ce n'est vrai amirite" ;
214
+ /* Extra commit is a Joan Shelley lyric */
215
+ const unsigned char extra_commit [] = "Shock of teal blue beneath clouds gathering, and the light of empty black on the waves at the horizon" ;
216
+ const size_t extra_commit_len = sizeof (extra_commit );
217
+ secp256k1_sha256 transcript ;
218
+ const secp256k1_bulletproofs_generators * gs = secp256k1_bulletproofs_generators_create (secp_ctx , n + 8 );
219
+ secp256k1_scratch * scratch = secp256k1_scratch_space_create (secp_ctx , 1000 * 1000 ); /* shouldn't need much */
220
+ unsigned char proof [1000 ];
221
+ plen = 1000 ;
222
+ asset_genp = * secp256k1_generator_h ;
223
+ CHECK (secp256k1_pedersen_commit (secp_ctx , & commit , blind , value , & asset_genp ));
224
+ secp256k1_bulletproofs_generators_serialize (secp_ctx , gs , proof , & plen );
225
+ plen = 1000 ;
226
+ secp256k1_sha256_initialize (& transcript );
227
+
228
+
229
+ res = secp256k1_bulletproofs_pp_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 );
230
+ CHECK (res == 1 );
231
+
232
+ res = secp256k1_bulletproofs_pp_rangeproof_verify (secp_ctx , scratch , gs , & asset_genp , proof , plen , num_bits , digit_base , min_value , & commit , extra_commit , extra_commit_len );
233
+ CHECK (res == 1 );
234
+ }
235
+
201
236
void run_bulletproofs_tests (void ) {
237
+ size_t i ;
202
238
test_log_exp ();
203
239
test_norm_util_helpers ();
204
240
test_bulletproofs_generators_api ();
@@ -211,6 +247,18 @@ void run_bulletproofs_tests(void) {
211
247
norm_arg_test (32 , 64 );
212
248
norm_arg_test (64 , 32 );
213
249
norm_arg_test (64 , 64 );
250
+ for (i = 0 ; i < 16 ; i ++ ) {
251
+ rangeproof_test (2 , 4 , i , 0 );
252
+ }
253
+
254
+ rangeproof_test (16 , 4 , 7 , 0 );
255
+ rangeproof_test (16 , 8 , 243 , 0 );
256
+ rangeproof_test (16 , 16 , 12431 , 0 );
257
+ rangeproof_test (16 , 32 , 134132 , 0 );
258
+ for (i = 0 ; i < 100 ; i ++ ) {
259
+ uint64_t v = secp256k1_testrand64 ();
260
+ rangeproof_test (16 , 64 , v , 0 );
261
+ }
214
262
}
215
263
216
264
#endif
0 commit comments