|
6 | 6 |
|
7 | 7 | #include <stdint.h>
|
8 | 8 |
|
| 9 | +#include "include/secp256k1.h" |
9 | 10 | #include "include/secp256k1_bppp.h"
|
10 | 11 | #include "util.h"
|
11 | 12 | #include "bench.h"
|
12 | 13 |
|
13 | 14 | typedef struct {
|
14 | 15 | secp256k1_context* ctx;
|
| 16 | + secp256k1_bppp_generators* gens; |
| 17 | + secp256k1_scratch_space *scratch; |
| 18 | + secp256k1_pedersen_commitment commit; |
| 19 | + unsigned char proof[1000]; |
| 20 | + unsigned char blind[32]; |
| 21 | + unsigned char nonce[32]; |
| 22 | + size_t proof_len; |
| 23 | + size_t n_bits; |
| 24 | + size_t base; |
| 25 | + uint64_t min_value; |
| 26 | + uint64_t value; |
15 | 27 | } bench_bppp_data;
|
16 | 28 |
|
17 | 29 | static void bench_bppp_setup(void* arg) {
|
18 |
| - (void) arg; |
| 30 | + bench_bppp_data *data = (bench_bppp_data*)arg; |
| 31 | + |
| 32 | + data->min_value = 0; |
| 33 | + data->value = 100; |
| 34 | + data->proof_len = sizeof(data->proof); |
| 35 | + memset(data->blind, 0x77, 32); |
| 36 | + memset(data->nonce, 0x0, 32); |
| 37 | + CHECK(secp256k1_pedersen_commit(data->ctx, &data->commit, data->blind, data->value, secp256k1_generator_h)); |
| 38 | + |
| 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)); |
19 | 41 | }
|
20 | 42 |
|
21 |
| -static void bench_bppp(void* arg, int iters) { |
| 43 | +static void bench_bppp_prove(void* arg, int iters) { |
22 | 44 | bench_bppp_data *data = (bench_bppp_data*)arg;
|
| 45 | + int i; |
23 | 46 |
|
24 |
| - (void) data; |
25 |
| - (void) iters; |
| 47 | + for (i = 0; i < iters; i++) { |
| 48 | + data->nonce[1] = i; |
| 49 | + data->nonce[2] = i >> 8; |
| 50 | + 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 | + } |
| 54 | +} |
| 55 | + |
| 56 | +static void bench_bppp_verify(void* arg, int iters) { |
| 57 | + bench_bppp_data *data = (bench_bppp_data*)arg; |
| 58 | + int i; |
| 59 | + |
| 60 | + 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)); |
| 62 | + } |
26 | 63 | }
|
27 | 64 |
|
28 | 65 | int main(void) {
|
29 | 66 | bench_bppp_data data;
|
30 | 67 | int iters = get_iters(32);
|
| 68 | + char test_name[64]; |
31 | 69 |
|
32 | 70 | data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
|
| 71 | + data.gens = secp256k1_bppp_generators_create(data.ctx, 24); |
| 72 | + data.scratch = secp256k1_scratch_space_create(data.ctx, 8000 * 1024); |
33 | 73 |
|
34 |
| - run_benchmark("bppp_verify_bit", bench_bppp, bench_bppp_setup, NULL, &data, 10, iters); |
| 74 | + data.n_bits = 1ul << 6; |
| 75 | + data.base = 16; |
| 76 | + sprintf(test_name, "bppp_prove_64bits_16base"); |
| 77 | + run_benchmark(test_name, bench_bppp_prove, bench_bppp_setup, NULL, &data, 20, iters); |
35 | 78 |
|
| 79 | + sprintf(test_name, "bppp_verify_64bits_16base"); |
| 80 | + run_benchmark(test_name, bench_bppp_verify, bench_bppp_setup, NULL, &data, 20, iters); |
| 81 | + |
| 82 | + secp256k1_scratch_space_destroy(data.ctx, data.scratch); |
| 83 | + secp256k1_bppp_generators_destroy(data.ctx, data.gens); |
36 | 84 | secp256k1_context_destroy(data.ctx);
|
| 85 | + |
37 | 86 | return 0;
|
38 | 87 | }
|
0 commit comments