Skip to content

Commit 6463ffb

Browse files
HalosGhostapoelstra
authored andcommitted
bulletproofs: expose a macro returning proof-size
This PR adds a convenience macro enabling callers to allocate the necessary and sufficient space for an uncompressed rangeproof. In particular, this makes it tractible to avoid pessimistically over-allocating the maximum possible space an uncompressed rangeproof might ever occupy. Also, SECP256K1_BULLETPROOFS_RANGEPROOF_UNCOMPRESSED_MAX_LENGTH_ is redefined as a short-cut leveraging the new convenience macro. This both makes clear from where the maximum length is derived, and should avoid the two macros drifting apart should the expected size change (e.g., if compression is supported in the future).
1 parent c1d6e95 commit 6463ffb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

include/secp256k1_bulletproofs.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ extern "C" {
1010

1111
#include <stdint.h>
1212

13+
/** A function-like macro returning the size, in bytes, of an uncompressed
14+
* Bulletproof proving that a value lies in the range [0, 2^(n_bits) - 1]
15+
*
16+
* A proof contains: 65 bytes for (A, S); 65 for (T1, T2); 64 for (tau_x, mu)
17+
* followed by n_bits-many scalar pairs (l(i), r(i)).
18+
*/
19+
#define SECP256K1_BULLETPROOFS_UNCOMPRESSED_SIZE(n_bits) (65UL + 65 + 64 + (n_bits) * 64)
20+
1321
/** Maximum size, in bytes, of an uncompressed rangeproof */
1422
extern const size_t SECP256K1_BULLETPROOFS_RANGEPROOF_UNCOMPRESSED_MAX_LENGTH;
1523

1624
/** The same value, as a C macro so it can be used as C89 array size */
17-
#define SECP256K1_BULLETPROOFS_RANGEPROOF_UNCOMPRESSED_MAX_LENGTH_ (194 + 4096)
25+
#define SECP256K1_BULLETPROOFS_RANGEPROOF_UNCOMPRESSED_MAX_LENGTH_ \
26+
SECP256K1_BULLETPROOFS_UNCOMPRESSED_SIZE(64)
1827

1928
/** Opaque data structure that holds the current state of an uncompressed
2029
* Bulletproof proof generation. This data is not secret and does not need

src/modules/bulletproofs/main_impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ size_t secp256k1_bulletproofs_rangeproof_uncompressed_proof_length(const secp256
130130
if (n_bits > 64) {
131131
return 0;
132132
}
133-
return 2 * 65 + 64 + n_bits * 64;
133+
return SECP256K1_BULLETPROOFS_UNCOMPRESSED_SIZE(n_bits);
134134
}
135135

136136
int secp256k1_bulletproofs_rangeproof_uncompressed_prove(

0 commit comments

Comments
 (0)