11
11
#include "util.h"
12
12
#include "bench.h"
13
13
14
+ #define MAX_PROOF_SIZE 500
15
+
14
16
typedef struct {
15
17
secp256k1_context * ctx ;
16
18
secp256k1_bppp_generators * gens ;
17
19
secp256k1_scratch_space * scratch ;
18
20
secp256k1_pedersen_commitment commit ;
19
- unsigned char proof [ 1000 ] ;
21
+ unsigned char * proofs ;
20
22
unsigned char blind [32 ];
21
23
unsigned char nonce [32 ];
22
24
size_t proof_len ;
@@ -31,13 +33,13 @@ static void bench_bppp_setup(void* arg) {
31
33
32
34
data -> min_value = 0 ;
33
35
data -> value = 100 ;
34
- data -> proof_len = sizeof ( data -> proof ) ;
36
+ data -> proof_len = MAX_PROOF_SIZE ;
35
37
memset (data -> blind , 0x77 , 32 );
36
38
memset (data -> nonce , 0x0 , 32 );
37
39
CHECK (secp256k1_pedersen_commit (data -> ctx , & data -> commit , data -> blind , data -> value , secp256k1_generator_h ));
38
40
39
- CHECK (secp256k1_bppp_rangeproof_prove (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , data -> proof , & data -> proof_len , data -> n_bits , data -> base , data -> value , 0 , & data -> commit , data -> blind , data -> nonce , NULL , 0 ));
40
- CHECK (secp256k1_bppp_rangeproof_verify (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , data -> proof , data -> proof_len , data -> n_bits , data -> base , data -> min_value , & data -> commit , NULL , 0 ));
41
+ CHECK (secp256k1_bppp_rangeproof_prove (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , data -> proofs , & data -> proof_len , data -> n_bits , data -> base , data -> value , 0 , & data -> commit , data -> blind , data -> nonce , NULL , 0 ));
42
+ CHECK (secp256k1_bppp_rangeproof_verify (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , data -> proofs , data -> proof_len , data -> n_bits , data -> base , data -> min_value , & data -> commit , NULL , 0 ));
41
43
}
42
44
43
45
static void bench_bppp_prove (void * arg , int iters ) {
@@ -48,8 +50,8 @@ static void bench_bppp_prove(void* arg, int iters) {
48
50
data -> nonce [1 ] = i ;
49
51
data -> nonce [2 ] = i >> 8 ;
50
52
data -> nonce [3 ] = i >> 16 ;
51
- data -> proof_len = sizeof ( data -> proof ) ;
52
- CHECK (secp256k1_bppp_rangeproof_prove (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , data -> proof , & data -> proof_len , data -> n_bits , data -> base , data -> value , 0 , & data -> commit , data -> blind , data -> nonce , NULL , 0 ));
53
+ data -> proof_len = MAX_PROOF_SIZE ;
54
+ CHECK (secp256k1_bppp_rangeproof_prove (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , & data -> proofs [ i * MAX_PROOF_SIZE ] , & data -> proof_len , data -> n_bits , data -> base , data -> value , 0 , & data -> commit , data -> blind , data -> nonce , NULL , 0 ));
53
55
}
54
56
}
55
57
@@ -58,28 +60,30 @@ static void bench_bppp_verify(void* arg, int iters) {
58
60
int i ;
59
61
60
62
for (i = 0 ; i < iters ; i ++ ) {
61
- CHECK (secp256k1_bppp_rangeproof_verify (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , data -> proof , data -> proof_len , data -> n_bits , data -> base , data -> min_value , & data -> commit , NULL , 0 ));
63
+ CHECK (secp256k1_bppp_rangeproof_verify (data -> ctx , data -> scratch , data -> gens , secp256k1_generator_h , & data -> proofs [ i * MAX_PROOF_SIZE ] , data -> proof_len , data -> n_bits , data -> base , data -> min_value , & data -> commit , NULL , 0 ));
62
64
}
63
65
}
64
66
65
67
int main (void ) {
66
68
bench_bppp_data data ;
67
- int iters = get_iters (32 );
69
+ int iters = get_iters (64 );
68
70
char test_name [64 ];
69
71
70
72
data .ctx = secp256k1_context_create (SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY );
71
73
data .gens = secp256k1_bppp_generators_create (data .ctx , 24 );
72
- data .scratch = secp256k1_scratch_space_create (data .ctx , 8000 * 1024 );
74
+ data .scratch = secp256k1_scratch_space_create (data .ctx , 80 * 1024 );
75
+ data .proofs = (unsigned char * )malloc (iters * MAX_PROOF_SIZE );
73
76
74
77
data .n_bits = 1ul << 6 ;
75
78
data .base = 16 ;
76
79
sprintf (test_name , "bppp_prove_64bits_16base" );
77
- run_benchmark (test_name , bench_bppp_prove , bench_bppp_setup , NULL , & data , 20 , iters );
80
+ run_benchmark (test_name , bench_bppp_prove , bench_bppp_setup , NULL , & data , 4 , iters );
78
81
79
82
sprintf (test_name , "bppp_verify_64bits_16base" );
80
83
run_benchmark (test_name , bench_bppp_verify , bench_bppp_setup , NULL , & data , 20 , iters );
81
84
82
85
secp256k1_scratch_space_destroy (data .ctx , data .scratch );
86
+ free (data .proofs );
83
87
secp256k1_bppp_generators_destroy (data .ctx , data .gens );
84
88
secp256k1_context_destroy (data .ctx );
85
89
0 commit comments