@@ -9,22 +9,22 @@ extern "C" {
99
1010#include <stdint.h>
1111
12+ #include "include/secp256k1_generator.h"
13+
1214/** Opaque structure representing a large number of NUMS generators */
1315typedef struct secp256k1_bulletproofs_generators secp256k1_bulletproofs_generators ;
1416
1517/** Opaque structure representing a prover context used in bulletproofs++ prover */
1618typedef struct secp256k1_bulletproofs_pp_rangeproof_prover_context secp256k1_bulletproofs_pp_rangeproof_prover_context ;
1719
18- /** Returns a list of generators, or NULL if allocation failed.
20+ /** Allocates and initializes a list of NUMS generators
21+ * Returns a list of generators, or NULL if allocation failed.
1922 * Args: ctx: pointer to a context object
2023 * n: number of NUMS generators to produce. Should be 16 + 7 = 23
2124 * for a 64 bit range proof with base 16. In general, n = max(num_digits, base) + 7
2225 * where num_digits is the number of digits in base `base` representation of `n_bits`
2326 * base 2 number.
2427 *
25- * TODO: For the first version of PR, this is would still require 16 + 8 = 24 NUMS
26- * points. We will later use G = H0(required for compatibility with pedersen_commitment DS)
27- * in a separate commit to make review easier.
2828 */
2929SECP256K1_API secp256k1_bulletproofs_generators * secp256k1_bulletproofs_generators_create (
3030 const secp256k1_context * ctx ,
@@ -52,9 +52,6 @@ SECP256K1_API secp256k1_bulletproofs_generators* secp256k1_bulletproofs_generato
5252 * least 33 times the number of generators plus one(33 * (num_gens + 1));
5353 * will be ser to 33 times the number of generators plus one
5454 * on successful return
55- *
56- * TODO: For ease of review, this setting G = H0 is not included in this commit. We will
57- * add it in a separate commit.
5855 */
5956SECP256K1_API int secp256k1_bulletproofs_generators_serialize (
6057 const secp256k1_context * ctx ,
@@ -73,6 +70,97 @@ SECP256K1_API void secp256k1_bulletproofs_generators_destroy(
7370 secp256k1_bulletproofs_generators * gen
7471) SECP256K1_ARG_NONNULL (1 );
7572
73+ /** Returns the serialized size of an bulletproofs plus plus proof of a given number
74+ * of bits and the base. Both base and n_bits must be a power of two. The number
75+ * of digits required to represent number of bits in the given base must also be
76+ * a power of two. Specifically, all of n_bits, base and num_digits = (n_bits / log2(base))
77+ * must all be a power of two.
78+ * Args: ctx: pointer to a context object
79+ * Out: len: 0 if the parameters and num_digits (n_bits/log2(base)) are not a power of two
80+ * length of the serialized proof otherwise
81+ * In: n_bits: number of bits to prove (max 64, should usually be 64)
82+ * base: base representation to be used in proof construction (max 256, recommended 16)
83+ */
84+ SECP256K1_API size_t secp256k1_bulletproofs_pp_rangeproof_proof_length (
85+ const secp256k1_context * ctx ,
86+ size_t n_bits ,
87+ size_t base
88+ ) SECP256K1_ARG_NONNULL (1 );
89+
90+ /** Produces a Bulletproofs++ rangeproof. Returns 1 on success, 0 on failure.
91+ * Proof creation can only fail if the arguments are invalid. The documentation
92+ * below specifies the constraints on inputs and arguments under which this API
93+ * can fail.
94+ * Args: ctx: pointer to a context object
95+ * scratch: pointer to a scratch space
96+ * gens: pointer to the generator set to use, which must have exactly
97+ * `n = max(num_digits, base) + 7` generators, where num_digits is the number.
98+ * asset_gen: pointer to the asset generator for the Pedersen/CT commitment
99+ * Out: proof: pointer to a byte array to output the proof into
100+ * In/Out: plen: pointer to the size of the above array; will be set to the actual size of
101+ * the serialized proof. To learn this value in advance, to allocate a sufficient
102+ * buffer, call `secp256k1_bulletproofs_pp_rangeproof_proof_length`
103+ * In: n_bits: size of range being proven, in bits. Must be a power of two,
104+ * and at most 64.
105+ * base: base representation to be used in proof construction. Must be a power of two,
106+ * value: value committed in the Pedersen commitment. Must be less
107+ * than 2^n_bits.
108+ * min_value: minimum value of the range being proven. Must be less than value
109+ * commit: the Pedersen commitment being proven
110+ * blind: blinding factor for the Pedersen commitment. Must be a 32 byte
111+ * valid scalar within secp curve order.
112+ * nonce: seed for the RNG used to generate random data during proving
113+ * extra_commit: arbitrary extra data that the proof commits to (may be NULL if extra_commit_len is 0)
114+ * extra_commit_len: length of the arbitrary extra data
115+ */
116+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_bulletproofs_pp_rangeproof_prove (
117+ const secp256k1_context * ctx ,
118+ secp256k1_scratch_space * scratch ,
119+ const secp256k1_bulletproofs_generators * gens ,
120+ const secp256k1_generator * asset_gen ,
121+ unsigned char * proof ,
122+ size_t * plen ,
123+ const size_t n_bits ,
124+ const size_t base ,
125+ const uint64_t value ,
126+ const uint64_t min_value ,
127+ const secp256k1_pedersen_commitment * commit ,
128+ const unsigned char * blind ,
129+ const unsigned char * nonce ,
130+ const unsigned char * extra_commit ,
131+ size_t extra_commit_len
132+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 ) SECP256K1_ARG_NONNULL (11 ) SECP256K1_ARG_NONNULL (12 ) SECP256K1_ARG_NONNULL (13 );
133+
134+ /** Verifies an Bulletproofs++ rangeproof. Returns 1 on success, 0 on failure.
135+ * Args: ctx: pointer to a context object
136+ * scratch: pointer to a scratch space
137+ * gens: pointer to the generator set to use, which must have at least 2*n_bits generators
138+ * asset_gen: pointer to the asset generator for the CT commitment
139+ * In: proof: pointer to a byte array containing the serialized proof
140+ * plen: length of the serialized proof
141+ * n_bits: size of range being proven, in bits. Must be a power of two,
142+ * and at most 64.
143+ * base: base representation to be used in proof construction. Must be a power of two,
144+ * min_value: minimum value of the range being proven
145+ * commit: the Pedersen commitment being proven
146+ * extra_commit: arbitrary extra data that the proof commits to (may be NULL if extra_commit_len is 0)
147+ * extra_commit_len: length of the arbitrary extra data
148+ */
149+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_bulletproofs_pp_rangeproof_verify (
150+ const secp256k1_context * ctx ,
151+ secp256k1_scratch_space * scratch ,
152+ const secp256k1_bulletproofs_generators * gens ,
153+ const secp256k1_generator * asset_gen ,
154+ const unsigned char * proof ,
155+ const size_t plen ,
156+ const uint64_t n_bits ,
157+ const uint64_t base ,
158+ const uint64_t min_value ,
159+ const secp256k1_pedersen_commitment * commit ,
160+ const unsigned char * extra_commit ,
161+ size_t extra_commit_len
162+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 ) SECP256K1_ARG_NONNULL (10 );
163+
76164# ifdef __cplusplus
77165}
78166# endif
0 commit comments