Skip to content

Commit 6347c4d

Browse files
committed
Add benchmarks
1 parent 9f5cef2 commit 6347c4d

File tree

1 file changed

+59
-6
lines changed

1 file changed

+59
-6
lines changed

src/bench_bppp.c

+59-6
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,85 @@
77
#include <stdint.h>
88

99
#include "../include/secp256k1_bppp.h"
10+
#include "../include/secp256k1.h"
1011
#include "util.h"
1112
#include "bench.h"
1213

14+
#define MAX_PROOF_SIZE 500
15+
1316
typedef struct {
1417
secp256k1_context* ctx;
18+
secp256k1_bppp_generators* gens;
19+
secp256k1_scratch_space *scratch;
20+
secp256k1_pedersen_commitment commit;
21+
unsigned char *proofs;
22+
unsigned char blind[32];
23+
unsigned char nonce[32];
24+
size_t proof_len;
25+
size_t n_bits;
26+
size_t base;
27+
uint64_t min_value;
28+
uint64_t value;
1529
} bench_bppp_data;
1630

1731
static void bench_bppp_setup(void* arg) {
18-
(void) arg;
32+
bench_bppp_data *data = (bench_bppp_data*)arg;
33+
34+
data->min_value = 0;
35+
data->value = 100;
36+
data->proof_len = MAX_PROOF_SIZE;
37+
memset(data->blind, 0x77, 32);
38+
memset(data->nonce, 0x0, 32);
39+
CHECK(secp256k1_pedersen_commit(data->ctx, &data->commit, data->blind, data->value, secp256k1_generator_h));
40+
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));
43+
}
44+
45+
static void bench_bppp_prove(void* arg, int iters) {
46+
bench_bppp_data *data = (bench_bppp_data*)arg;
47+
int i;
48+
49+
for (i = 0; i < iters; i++) {
50+
data->nonce[1] = i;
51+
data->nonce[2] = i >> 8;
52+
data->nonce[3] = i >> 16;
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));
55+
}
1956
}
2057

21-
static void bench_bppp(void* arg, int iters) {
58+
static void bench_bppp_verify(void* arg, int iters) {
2259
bench_bppp_data *data = (bench_bppp_data*)arg;
60+
int i;
2361

24-
(void) data;
25-
(void) iters;
62+
for (i = 0; i < iters; i++) {
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));
64+
}
2665
}
2766

2867
int main(void) {
2968
bench_bppp_data data;
30-
int iters = get_iters(32);
69+
int iters = get_iters(64);
70+
char test_name[64];
3171

3272
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
73+
data.gens = secp256k1_bppp_generators_create(data.ctx, 24);
74+
data.scratch = secp256k1_scratch_space_create(data.ctx, 80 * 1024);
75+
data.proofs = (unsigned char *)malloc(iters * MAX_PROOF_SIZE);
3376

34-
run_benchmark("bppp_verify_bit", bench_bppp, bench_bppp_setup, NULL, &data, 10, iters);
77+
data.n_bits = 1ul << 6;
78+
data.base = 16;
79+
sprintf(test_name, "bppp_prove_64bits_16base");
80+
run_benchmark(test_name, bench_bppp_prove, bench_bppp_setup, NULL, &data, 4, iters);
3581

82+
sprintf(test_name, "bppp_verify_64bits_16base");
83+
run_benchmark(test_name, bench_bppp_verify, bench_bppp_setup, NULL, &data, 20, iters);
84+
85+
secp256k1_scratch_space_destroy(data.ctx, data.scratch);
86+
free(data.proofs);
87+
secp256k1_bppp_generators_destroy(data.ctx, data.gens);
3688
secp256k1_context_destroy(data.ctx);
89+
3790
return 0;
3891
}

0 commit comments

Comments
 (0)