PRCYCoin  2.0.0.7rc1
P2P Digital Currency
bench_bulletproof.c
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (c) 2017 Andrew Poelstra *
3  * Distributed under the MIT software license, see the accompanying *
4  * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5  **********************************************************************/
6 
7 #include <stdint.h>
8 
12 #include "util.h"
13 #include "bench.h"
14 
15 #define MAX_PROOF_SIZE 2000
16 #define CIRCUIT_DIR "src/modules/bulletproofs/bin_circuits/"
17 
18 typedef struct {
21  unsigned char nonce[32];
22  unsigned char **proof;
26  size_t n_proofs;
27  size_t plen;
28  size_t iters;
30 
31 typedef struct {
34  const unsigned char **blind;
35  size_t *value;
36  size_t n_commits;
37  size_t nbits;
39 
40 typedef struct {
42 
46 
47 static void bench_bulletproof_common_setup(bench_bulletproof_t *data) {
48  size_t i;
49  const unsigned char nonce[32] = "my kingdom for some randomness!!";
50  const unsigned char genbd[32] = "yet more blinding, for the asset";
51 
52  memcpy(data->nonce, nonce, 32);
53  data->proof = (unsigned char **)malloc(data->n_proofs * sizeof(*data->proof));
54  data->value_gen = (secp256k1_generator *)malloc(data->n_proofs * sizeof(*data->value_gen));
55  for (i = 0; i < data->n_proofs; i++) {
56  data->proof[i] = (unsigned char *)malloc(MAX_PROOF_SIZE);
57  CHECK(secp256k1_generator_generate(data->ctx, &data->value_gen[i], genbd));
58  }
59  data->plen = MAX_PROOF_SIZE;
60 }
61 
62 static void bench_bulletproof_rangeproof_setup(void* arg) {
64  size_t i;
65  size_t v;
66 
67  unsigned char blind[32] = "and my kingdom too for a blinder";
68 
69  bench_bulletproof_common_setup (data->common);
70 
71  data->commit = (secp256k1_pedersen_commitment **)malloc(data->common->n_proofs * sizeof(*data->commit));
72  data->blind = (const unsigned char **)malloc(data->n_commits * sizeof(*data->blind));
73  data->value = (size_t *)malloc(data->n_commits * sizeof(*data->commit));
74 
75  for (i = 0; i < data->common->n_proofs; i++) {
76  data->commit[i] = (secp256k1_pedersen_commitment *)malloc(data->n_commits * sizeof(*data->commit[i]));
77  }
78 
79  for (i = 0; i < data->n_commits; i++) {
80  data->blind[i] = malloc(32);
81  blind[0] = i;
82  blind[1] = i >> 8;
83  memcpy((unsigned char*) data->blind[i], blind, 32);
84  data->value[i] = i * 17;
85  CHECK(secp256k1_pedersen_commit(data->common->ctx, &data->commit[0][i], data->blind[i], data->value[i], &data->common->value_gen[0], &data->common->blind_gen));
86  }
87  for (i = 1; i < data->common->n_proofs; i++) {
88  memcpy(data->commit[i], data->commit[0], data->n_commits * sizeof(*data->commit[0]));
89  }
90 
91  CHECK(secp256k1_bulletproof_rangeproof_prove(data->common->ctx, data->common->scratch, data->common->generators, data->common->proof[0], &data->common->plen, data->value, NULL, data->blind, data->n_commits, data->common->value_gen, data->nbits, data->common->nonce, NULL, 0) == 1);
92  for (i = 1; i < data->common->n_proofs; i++) {
93  memcpy(data->common->proof[i], data->common->proof[0], data->common->plen);
94  CHECK(secp256k1_bulletproof_rangeproof_verify(data->common->ctx, data->common->scratch, data->common->generators, data->common->proof[i], data->common->plen, NULL, data->commit[i], data->n_commits, data->nbits, &data->common->value_gen[0], NULL, 0) == 1);
95  }
96  CHECK(secp256k1_bulletproof_rangeproof_verify(data->common->ctx, data->common->scratch, data->common->generators, data->common->proof[0], data->common->plen, NULL, data->commit[0], data->n_commits, data->nbits, data->common->value_gen, NULL, 0) == 1);
97  CHECK(secp256k1_bulletproof_rangeproof_verify_multi(data->common->ctx, data->common->scratch, data->common->generators, (const unsigned char **) data->common->proof, data->common->n_proofs, data->common->plen, NULL, (const secp256k1_pedersen_commitment **) data->commit, data->n_commits, data->nbits, data->common->value_gen, NULL, 0) == 1);
98  if (data->n_commits == 1) {
99  CHECK(secp256k1_bulletproof_rangeproof_rewind(data->common->ctx, data->common->generators, &v, blind, data->common->proof[0], data->common->plen, 0, data->commit[0], &data->common->value_gen[0], data->common->nonce, NULL, 0) == 1);
100  }
101 }
102 
103 static void bench_bulletproof_circuit_setup(void* arg) {
105  size_t i;
106 
107  bench_bulletproof_common_setup (data->common);
108 
109  CHECK(secp256k1_bulletproof_circuit_prove(data->common->ctx, data->common->scratch, data->common->generators, data->circ[0], data->common->proof[0], &data->common->plen, data->assn, NULL, 0, data->common->nonce, &data->common->value_gen[0], NULL, 0) == 1);
110  for (i = 1; i < data->common->n_proofs; i++) {
111  data->circ[i] = data->circ[0];
112  memcpy(data->common->proof[i], data->common->proof[0], data->common->plen);
113  }
114  CHECK(secp256k1_bulletproof_circuit_verify(data->common->ctx, data->common->scratch, data->common->generators, data->circ[0], data->common->proof[0], data->common->plen, NULL, 0, data->common->value_gen, NULL, 0) == 1);
115  CHECK(secp256k1_bulletproof_circuit_verify_multi(data->common->ctx, data->common->scratch, data->common->generators, (const secp256k1_bulletproof_circuit* const*) data->circ, (const unsigned char **) data->common->proof, data->common->n_proofs, data->common->plen, NULL, NULL, data->common->value_gen, NULL, 0) == 1);
116 }
117 
118 static void bench_bulletproof_common_teardown(bench_bulletproof_t *data) {
119  size_t i;
120 
121  for (i = 0; i < data->n_proofs; i++) {
122  free(data->proof[i]);
123  }
124  free(data->proof);
125  free(data->value_gen);
126 }
127 
128 static void bench_bulletproof_rangeproof_teardown(void* arg) {
130  size_t i;
131 
132  if (data->blind != NULL) {
133  for (i = 0; i < data->n_commits; i++) {
134  free((unsigned char*) data->blind[i]);
135  }
136  }
137  if (data->commit != NULL) {
138  for (i = 0; i < data->common->n_proofs; i++) {
139  free(data->commit[i]);
140  }
141  free(data->commit);
142  }
143  free(data->blind);
144  free(data->value);
145 
146  bench_bulletproof_common_teardown(data->common);
147 }
148 
149 static void bench_bulletproof_circuit_teardown(void* arg) {
151  bench_bulletproof_common_teardown(data->common);
152 }
153 
154 static void bench_bulletproof_rangeproof_prove(void* arg) {
156  size_t i;
157  for (i = 0; i < 25; i++) {
158  CHECK(secp256k1_bulletproof_rangeproof_prove(data->common->ctx, data->common->scratch, data->common->generators, data->common->proof[0], &data->common->plen, data->value, NULL, data->blind, data->n_commits, data->common->value_gen, data->nbits, data->common->nonce, NULL, 0) == 1);
159  }
160 }
161 
162 void simple_test_bench_bulletproof_rangeproof_prove(size_t nCommits, uint64_t* values) {
163  unsigned char proof[2000];
164  size_t len;
166  secp256k1_scratch_space2* scratch = secp256k1_scratch_space_create(context, 1024 * 1024 * 1024);
168  unsigned char blind[32] = "and my kingdom too for a blinder";
169  unsigned char nonce[32] = "and my kingdom too for a blinder";
170  unsigned char blinds[nCommits][32];
171  int i = 0;
172  secp256k1_pedersen_commitment commitments[nCommits];
173  const unsigned char *blind_ptr[nCommits];
174  for (i = 0; i < nCommits; i++) {
175  memcpy(blinds[i], blind, 32);
176  blind_ptr[i] = blinds[i];
177  secp256k1_pedersen_commit(context, &commitments[i], blind_ptr[i], values[i], &secp256k1_generator_const_h, &secp256k1_generator_const_g);
178  }
179  CHECK(secp256k1_bulletproof_rangeproof_prove(context, scratch, generators, proof, &len, values, NULL, blind_ptr, nCommits, &secp256k1_generator_const_h, 64, nonce, NULL, 0) == 1);
180 
181  CHECK(secp256k1_bulletproof_rangeproof_verify(context, scratch, generators, proof, len, NULL, commitments, nCommits, 64, &secp256k1_generator_const_h, NULL, 0) == 1);
182 }
183 
184 static void bench_bulletproof_rangeproof_verify(void* arg) {
185  size_t i;
187 
188  for (i = 0; i < data->common->iters; i++) {
189  CHECK(secp256k1_bulletproof_rangeproof_verify_multi(data->common->ctx, data->common->scratch, data->common->generators, (const unsigned char **) data->common->proof, data->common->n_proofs, data->common->plen, NULL, (const secp256k1_pedersen_commitment **) data->commit, data->n_commits, data->nbits, data->common->value_gen, NULL, 0) == 1);
190  }
191 }
192 
193 static void bench_bulletproof_rangeproof_rewind_succeed(void* arg) {
194  size_t i;
195  size_t v;
196  unsigned char blind[32];
198 
199  for (i = 0; i < data->common->iters; i++) {
200  CHECK(secp256k1_bulletproof_rangeproof_rewind(data->common->ctx, data->common->generators, &v, blind, data->common->proof[0], data->common->plen, 0, data->commit[0], &data->common->value_gen[0], data->common->nonce, NULL, 0) == 1);
201  }
202 }
203 
204 static void bench_bulletproof_rangeproof_rewind_fail(void* arg) {
205  size_t i;
206  size_t v;
207  unsigned char blind[32];
209 
210  data->common->nonce[0] ^= 1;
211  for (i = 0; i < data->common->iters; i++) {
212  CHECK(secp256k1_bulletproof_rangeproof_rewind(data->common->ctx, data->common->generators, &v, blind, data->common->proof[0], data->common->plen, 0, data->commit[0], &data->common->value_gen[0], data->common->nonce, NULL, 0) == 0);
213  }
214  data->common->nonce[0] ^= 1;
215 }
216 
217 static void bench_bulletproof_circuit_prove(void* arg) {
219  CHECK(secp256k1_bulletproof_circuit_prove(data->common->ctx, data->common->scratch, data->common->generators, data->circ[0], data->common->proof[0], &data->common->plen, data->assn, NULL, 0, data->common->nonce, data->common->value_gen, NULL, 0) == 1);
220 }
221 
222 static void bench_bulletproof_circuit_verify(void* arg) {
224  size_t i;
225  for (i = 0; i < 10; i++) {
226  CHECK(secp256k1_bulletproof_circuit_verify_multi(data->common->ctx, data->common->scratch, data->common->generators, (const secp256k1_bulletproof_circuit* const*) data->circ, (const unsigned char **) data->common->proof, data->common->n_proofs, data->common->plen, NULL, NULL, data->common->value_gen, NULL, 0) == 1);
227  }
228 }
229 
230 static void run_rangeproof_test(bench_bulletproof_rangeproof_t *data, size_t nbits, size_t n_commits) {
231  char str[64];
232 
233  data->nbits = nbits;
234  data->n_commits = n_commits;
235  data->common->iters = 100;
236 
237  data->common->n_proofs = 1;
238  sprintf(str, "bulletproof_prove, %i, %i, 0, ", (int)nbits, (int) n_commits);
239  run_benchmark(str, bench_bulletproof_rangeproof_prove, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, 25);
240 
241  data->common->n_proofs = 1;
242  sprintf(str, "bulletproof_verify, %i, %i, 1, ", (int)nbits, (int) n_commits);
243  run_benchmark(str, bench_bulletproof_rangeproof_verify, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
244 
245  if (n_commits == 1) {
246  sprintf(str, "bulletproof_rewind_succeed, %i, ", (int)nbits);
247  run_benchmark(str, bench_bulletproof_rangeproof_rewind_succeed, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
248  sprintf(str, "bulletproof_rewind_fail, %i, ", (int)nbits);
249  run_benchmark(str, bench_bulletproof_rangeproof_rewind_fail, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
250  }
251 
252  data->common->n_proofs = 2;
253  sprintf(str, "bulletproof_verify, %i, %i, 2, ", (int)nbits, (int) n_commits);
254  run_benchmark(str, bench_bulletproof_rangeproof_verify, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
255 
256  data->common->iters = 10;
257  data->common->n_proofs = 50;
258  sprintf(str, "bulletproof_verify, %i, %i, 50, ", (int)nbits, (int) n_commits);
259  run_benchmark(str, bench_bulletproof_rangeproof_verify, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
260 
261  data->common->iters = 1;
262  data->common->n_proofs = 100;
263  sprintf(str, "bulletproof_verify, %i, %i, 100, ", (int)nbits, (int) n_commits);
264  run_benchmark(str, bench_bulletproof_rangeproof_verify, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
265 
266  data->common->n_proofs = 500;
267  sprintf(str, "bulletproof_verify, %i, %i, 500, ", (int)nbits, (int) n_commits);
268  run_benchmark(str, bench_bulletproof_rangeproof_verify, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
269 
270  data->common->n_proofs = 1000;
271  sprintf(str, "bulletproof_verify, %i, %i, 1000, ", (int)nbits, (int) n_commits);
272  run_benchmark(str, bench_bulletproof_rangeproof_verify, bench_bulletproof_rangeproof_setup, bench_bulletproof_rangeproof_teardown, (void *)data, 5, data->common->iters);
273 }
274 
276  char fname[128];
277  size_t i;
278 
279  data->circ = (secp256k1_bulletproof_circuit **)malloc(500 * sizeof(*data->circ));
280 
281  sprintf(fname, CIRCUIT_DIR "%s.circ", name);
282  data->circ[0] = secp256k1_bulletproof_circuit_decode(data->common->ctx, fname);
283  CHECK(data->circ[0] != NULL);
284 
285  for (i = 1; i < 500; i++) {
286  data->circ[i] = data->circ[0];
287  }
288 
289  sprintf(fname, CIRCUIT_DIR "%s.assn", name);
291  CHECK(data->assn != NULL);
292 
293  data->common->n_proofs = 1;
294  sprintf(fname, "bulletproof_prove_%s, ", name);
295  run_benchmark(fname, bench_bulletproof_circuit_prove, bench_bulletproof_circuit_setup, bench_bulletproof_circuit_teardown, (void *)data, 1, 1);
296 
297  data->common->n_proofs = 1;
298  sprintf(fname, "bulletproof_verify_%s, %i, ", name, 1);
299  run_benchmark(fname, bench_bulletproof_circuit_verify, bench_bulletproof_circuit_setup, bench_bulletproof_circuit_teardown, (void *)data, 2, 10);
300 
301  data->common->n_proofs = 2;
302  sprintf(fname, "bulletproof_verify_%s, %i, ", name, 2);
303  run_benchmark(fname, bench_bulletproof_circuit_verify, bench_bulletproof_circuit_setup, bench_bulletproof_circuit_teardown, (void *)data, 2, 10);
304 
305  data->common->n_proofs = 100;
306  sprintf(fname, "bulletproof_verify_%s, %i, ", name, 100);
307  run_benchmark(fname, bench_bulletproof_circuit_verify, bench_bulletproof_circuit_setup, bench_bulletproof_circuit_teardown, (void *)data, 2, 10);
308 
309  secp256k1_bulletproof_circuit_destroy(data->common->ctx, data->circ[0]);
310  secp256k1_bulletproof_circuit_assignment_destroy(data->common->ctx, data->assn);
311 }
312 
313 int main(void) {
314  bench_bulletproof_t data;
317 
320  data.scratch = secp256k1_scratch_space_create(data.ctx, 1024 * 1024 * 1024);
321  data.generators = secp256k1_bulletproof_generators_create(data.ctx, &data.blind_gen, 64 * 1024);
322 
323  rp_data.common = &data;
324  data.generators = secp256k1_bulletproof_generators_create(data.ctx, &data.blind_gen, 64 * 1024);
325 
326  rp_data.common = &data;
327  c_data.common = &data;
328 
329  /*run_circuit_test(&c_data, "pedersen-3");
330  run_circuit_test(&c_data, "pedersen-6");
331  run_circuit_test(&c_data, "pedersen-12");
332  run_circuit_test(&c_data, "pedersen-24");
333  run_circuit_test(&c_data, "pedersen-48");
334  run_circuit_test(&c_data, "pedersen-96");
335  run_circuit_test(&c_data, "pedersen-192");
336  run_circuit_test(&c_data, "pedersen-384");
337  run_circuit_test(&c_data, "pedersen-768");
338  run_circuit_test(&c_data, "pedersen-1536");
339  run_circuit_test(&c_data, "pedersen-3072");
340  run_circuit_test(&c_data, "SHA2");*/
341  uint64_t values[5] = {300000000000000000, 300000000000000000, 300000000000000000, 400, 500};
343  run_rangeproof_test(&rp_data, 8, 1);
344  run_rangeproof_test(&rp_data, 16, 1);
345  run_rangeproof_test(&rp_data, 32, 1);
346 
347  run_rangeproof_test(&rp_data, 64, 1);
348  run_rangeproof_test(&rp_data, 64, 2);
349  run_rangeproof_test(&rp_data, 64, 4);
350  run_rangeproof_test(&rp_data, 64, 8);
351  run_rangeproof_test(&rp_data, 64, 16);
352  run_rangeproof_test(&rp_data, 64, 32);
353  run_rangeproof_test(&rp_data, 64, 64);
354  run_rangeproof_test(&rp_data, 64, 128);
355  run_rangeproof_test(&rp_data, 64, 256);
356  run_rangeproof_test(&rp_data, 64, 512);
357  /* to add more, increase the number of generators above in `data.generators = ...` */
358 
362  return 0;
363 }
secp256k1_pedersen_commit
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_pedersen_commit(const secp256k1_context2 *ctx, secp256k1_pedersen_commitment *commit, const unsigned char *blind, uint64_t value, const secp256k1_generator *value_gen, const secp256k1_generator *blind_gen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6)
Generate a Pedersen commitment.
Definition: main_impl.h:93
secp256k1_scratch_space_struct2
Definition: scratch.h:14
secp256k1_scratch_space_destroy
SECP256K1_API void secp256k1_scratch_space_destroy(secp256k1_scratch_space2 *scratch)
Destroy a secp256k1 scratch space.
Definition: secp256k1_2.c:140
secp256k1_bulletproof_rangeproof_rewind
SECP256K1_WARN_UNUSED_RESULT SECP256K1_API int secp256k1_bulletproof_rangeproof_rewind(const secp256k1_context2 *ctx, const secp256k1_bulletproof_generators *gens, uint64_t *value, unsigned char *blind, const unsigned char *proof, size_t plen, uint64_t min_value, const secp256k1_pedersen_commitment *commit, const secp256k1_generator *value_gen, const unsigned char *nonce, const unsigned char *extra_commit, size_t extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(8) SECP256K1_ARG_NONNULL(9)
Extracts the value and blinding factor from a single-commit rangeproof given a secret nonce Returns: ...
Definition: main_impl.h:561
bench.h
bench_bulletproof_t::generators
secp256k1_bulletproof_generators * generators
Definition: bench_bulletproof.c:23
bench_bulletproof_t::iters
size_t iters
Definition: bench_bulletproof.c:28
secp256k1_bulletproof_generators_create
SECP256K1_API secp256k1_bulletproof_generators * secp256k1_bulletproof_generators_create(const secp256k1_context2 *ctx, const secp256k1_generator *blinding_gen, size_t n) SECP256K1_ARG_NONNULL(1)
Allocates and initializes a list of NUMS generators, along with precomputation data Returns a list of...
Definition: main_impl.h:427
bench_bulletproof_rangeproof_t::commit
secp256k1_pedersen_commitment ** commit
Definition: bench_bulletproof.c:33
util.h
secp256k1_scratch_space_create
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space2 * secp256k1_scratch_space_create(const secp256k1_context2 *ctx, size_t max_size) SECP256K1_ARG_NONNULL(1)
Create a secp256k1 scratch space object.
Definition: secp256k1_2.c:135
memcpy
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:15
bench_bulletproof_t::blind_gen
secp256k1_generator blind_gen
Definition: bench_bulletproof.c:25
bench_bulletproof_circuit_t::assn
secp256k1_bulletproof_circuit_assignment * assn
Definition: bench_bulletproof.c:44
secp256k1_context_destroy
SECP256K1_API void secp256k1_context_destroy(secp256k1_context2 *ctx)
Destroy a secp256k1 context object.
Definition: secp256k1_2.c:110
simple_test_bench_bulletproof_rangeproof_prove
void simple_test_bench_bulletproof_rangeproof_prove(size_t nCommits, uint64_t *values)
Definition: bench_bulletproof.c:162
run_benchmark
void run_benchmark(char *name, void(*benchmark)(void *), void(*setup)(void *), void(*teardown)(void *), void *data, int count, int iter)
Definition: bench.h:34
secp256k1_generator
Opaque data structure that stores a base point.
Definition: secp256k1_generator.h:20
secp256k1_bulletproof_rangeproof_verify_multi
SECP256K1_WARN_UNUSED_RESULT SECP256K1_API int secp256k1_bulletproof_rangeproof_verify_multi(const secp256k1_context2 *ctx, secp256k1_scratch_space2 *scratch, const secp256k1_bulletproof_generators *gens, const unsigned char *const *proof, size_t n_proofs, size_t plen, const uint64_t *const *min_value, const secp256k1_pedersen_commitment *const *commit, size_t n_commits, size_t nbits, const secp256k1_generator *value_gen, const unsigned char *const *extra_commit, size_t *extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(8)
Batch-verifies multiple bulletproof (aggregate) rangeproofs of the same size using same generator Ret...
Definition: main_impl.h:516
bench_bulletproof_rangeproof_t::value
size_t * value
Definition: bench_bulletproof.c:35
bench_bulletproof_rangeproof_t::common
bench_bulletproof_t * common
Definition: bench_bulletproof.c:32
secp256k1_bulletproof_rangeproof_prove
SECP256K1_WARN_UNUSED_RESULT SECP256K1_API int secp256k1_bulletproof_rangeproof_prove(const secp256k1_context2 *ctx, secp256k1_scratch_space2 *scratch, const secp256k1_bulletproof_generators *gens, unsigned char *proof, size_t *plen, const uint64_t *value, const uint64_t *min_value, const unsigned char *const *blind, size_t n_commits, const secp256k1_generator *value_gen, size_t nbits, const unsigned char *nonce, const unsigned char *extra_commit, size_t extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(8) SECP256K1_ARG_NONNULL(10) SECP256K1_ARG_NONNULL(12)
Produces an aggregate Bulletproof rangeproof for a set of Pedersen commitments Returns: 1: rangeproof...
Definition: main_impl.h:582
bench_bulletproof_t::proof
unsigned char ** proof
Definition: bench_bulletproof.c:22
run_circuit_test
void run_circuit_test(bench_bulletproof_circuit_t *data, const char *name)
Definition: bench_bulletproof.c:275
secp256k1_bulletproofs.h
bench_bulletproof_t::ctx
secp256k1_context2 * ctx
Definition: bench_bulletproof.c:19
secp256k1_bulletproof_rangeproof_verify
SECP256K1_WARN_UNUSED_RESULT SECP256K1_API int secp256k1_bulletproof_rangeproof_verify(const secp256k1_context2 *ctx, secp256k1_scratch_space2 *scratch, const secp256k1_bulletproof_generators *gens, const unsigned char *proof, size_t plen, const uint64_t *min_value, const secp256k1_pedersen_commitment *commit, size_t n_commits, size_t nbits, const secp256k1_generator *value_gen, const unsigned char *extra_commit, size_t extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(10)
Verifies a single bulletproof (aggregate) rangeproof Returns: 1: rangeproof was valid 0: rangeproof w...
Definition: main_impl.h:477
bench_bulletproof_t::nonce
unsigned char nonce[32]
Definition: bench_bulletproof.c:21
bench_bulletproof_t
Definition: bench_bulletproof.c:18
bench_bulletproof_circuit_t::circ
secp256k1_bulletproof_circuit ** circ
Definition: bench_bulletproof.c:43
main
int main(void)
Definition: bench_bulletproof.c:313
bench_bulletproof_rangeproof_t
Definition: bench_bulletproof.c:31
secp256k1_bulletproof_circuit_verify
SECP256K1_API int secp256k1_bulletproof_circuit_verify(const secp256k1_context2 *ctx, secp256k1_scratch_space2 *scratch, const secp256k1_bulletproof_generators *gens, const secp256k1_bulletproof_circuit *circ, const unsigned char *proof, size_t plen, const secp256k1_pedersen_commitment *commit, size_t n_commits, const secp256k1_generator *value_gen, const unsigned char *extra_commit, size_t extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(9)
Verifies a single bulletproof zero-knowledge proof (zkp) Returns: 1: zkp accepted 0: zkp did not acce...
Definition: main_impl.h:705
secp256k1_bulletproof_circuit_assignment_decode
SECP256K1_API secp256k1_bulletproof_circuit_assignment * secp256k1_bulletproof_circuit_assignment_decode(const secp256k1_context2 *ctx, const char *fname) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Decodes an accepting wire assignment which is serialized in an opaque binary format Returns a circuit...
Definition: main_impl.h:877
secp256k1_bulletproof_circuit_destroy
SECP256K1_API void secp256k1_bulletproof_circuit_destroy(const secp256k1_context2 *ctx, secp256k1_bulletproof_circuit *circ) SECP256K1_ARG_NONNULL(1)
Destroys a circuit Args: ctx: pointer to a context object (cannot be NULL) gen: pointer to the circui...
Definition: main_impl.h:964
secp256k1_bulletproof_circuit_assignment
Definition: main_impl.h:45
name
const char * name
Definition: rest.cpp:34
bench_bulletproof_circuit_t
Definition: bench_bulletproof.c:40
secp256k1_context_struct2
Definition: secp256k1_types.h:15
CIRCUIT_DIR
#define CIRCUIT_DIR
Definition: bench_bulletproof.c:16
secp256k1_bulletproof_generators_destroy
SECP256K1_API void secp256k1_bulletproof_generators_destroy(const secp256k1_context2 *ctx, secp256k1_bulletproof_generators *gen) SECP256K1_ARG_NONNULL(1)
Destroys a list of NUMS generators, freeing allocated memory Args: ctx: pointer to a context object (...
Definition: main_impl.h:469
secp256k1_pedersen_commitment
Opaque data structure that stores a Pedersen commitment.
Definition: secp256k1_commitment.h:22
bench_bulletproof_rangeproof_t::blind
const unsigned char ** blind
Definition: bench_bulletproof.c:34
secp256k1_bulletproof_circuit_assignment_destroy
SECP256K1_API void secp256k1_bulletproof_circuit_assignment_destroy(const secp256k1_context2 *ctx, secp256k1_bulletproof_circuit_assignment *assn) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Destroys a circuit assignment Args: ctx: pointer to a context object (cannot be NULL) gen: pointer to...
Definition: main_impl.h:974
secp256k1_generator_const_g
const SECP256K1_API secp256k1_generator secp256k1_generator_const_g
Standard secp256k1 generator G.
Definition: main_impl.h:18
MAX_PROOF_SIZE
#define MAX_PROOF_SIZE
Definition: bench_bulletproof.c:15
secp256k1_generator_const_h
const SECP256K1_API secp256k1_generator secp256k1_generator_const_h
Alternate secp256k1 generator from Elements Alpha.
Definition: main_impl.h:32
secp256k1_generator.h
bench_bulletproof_t::value_gen
secp256k1_generator * value_gen
Definition: bench_bulletproof.c:24
secp256k1_context_create2
SECP256K1_API secp256k1_context2 * secp256k1_context_create2(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object.
Definition: secp256k1_2.c:75
bench_bulletproof_t::n_proofs
size_t n_proofs
Definition: bench_bulletproof.c:26
secp256k1_bulletproof_circuit
Definition: main_impl.h:31
bench_bulletproof_rangeproof_t::nbits
size_t nbits
Definition: bench_bulletproof.c:37
bench_bulletproof_circuit_t::common
bench_bulletproof_t * common
Definition: bench_bulletproof.c:41
SECP256K1_CONTEXT_VERIFY
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create2.
Definition: secp256k1_2.h:167
secp256k1_bulletproof_circuit_verify_multi
SECP256K1_API int secp256k1_bulletproof_circuit_verify_multi(const secp256k1_context2 *ctx, secp256k1_scratch_space2 *scratch, const secp256k1_bulletproof_generators *gens, const secp256k1_bulletproof_circuit *const *circ, const unsigned char *const *proof, size_t n_proofs, size_t plen, const secp256k1_pedersen_commitment **commit, size_t *n_commits, const secp256k1_generator *value_gen, const unsigned char **extra_commit, size_t *extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(10)
Batch-verifies multiple bulletproof zero-knowledge proofs of equally-sized circuits (zkp) Returns: 1:...
Definition: main_impl.h:750
CHECK
#define CHECK(cond)
Definition: util.h:43
secp256k1_bulletproof_circuit_decode
secp256k1_bulletproof_circuit * secp256k1_bulletproof_circuit_decode(const secp256k1_context2 *ctx, const char *fname)
Decodes a circuit which is serialized in an opaque binary format Returns a circuit,...
Definition: main_impl.h:813
secp256k1_bulletproof_circuit_prove
SECP256K1_API int secp256k1_bulletproof_circuit_prove(const secp256k1_context2 *ctx, secp256k1_scratch_space2 *scratch, const secp256k1_bulletproof_generators *gens, const secp256k1_bulletproof_circuit *circ, unsigned char *proof, size_t *plen, const secp256k1_bulletproof_circuit_assignment *assn, const unsigned char **blind, size_t n_commits, const unsigned char *nonce, const secp256k1_generator *value_gen, const unsigned char *extra_commit, size_t extra_commit_len) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(6) SECP256K1_ARG_NONNULL(7) SECP256K1_ARG_NONNULL(10) SECP256K1_ARG_NONNULL(11)
Produces a bulletproof zero-knowledge proof (zkp) Returns: 1: proof was successfully created 0: pro...
Definition: main_impl.h:639
secp256k1_commitment.h
secp256k1_bulletproof_generators
Definition: main_impl.h:54
secp256k1_generator_generate
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_generator_generate(const secp256k1_context2 *ctx, secp256k1_generator *gen, const unsigned char *seed32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Generate a generator for the curve.
Definition: main_impl.h:231
bench_bulletproof_t::scratch
secp256k1_scratch_space2 * scratch
Definition: bench_bulletproof.c:20
bench_bulletproof_rangeproof_t::n_commits
size_t n_commits
Definition: bench_bulletproof.c:36
SECP256K1_CONTEXT_SIGN
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1_2.h:168
bench_bulletproof_t::plen
size_t plen
Definition: bench_bulletproof.c:27