Skip to content

Commit 7dc6e3f

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 d1b3f79 commit 7dc6e3f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

include/secp256k1_bulletproofs.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ 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+
#define SECP256K1_BULLETPROOFS_UNCOMPRESSED_SIZE(n_bits) (194UL + (n_bits) * 64)
17+
1318
/** Maximum size, in bytes, of an uncompressed rangeproof */
1419
extern const size_t SECP256K1_BULLETPROOFS_RANGEPROOF_UNCOMPRESSED_MAX_LENGTH;
1520

1621
/** 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)
22+
#define SECP256K1_BULLETPROOFS_RANGEPROOF_UNCOMPRESSED_MAX_LENGTH_ \
23+
SECP256K1_BULLETPROOFS_UNCOMPRESSED_SIZE(64)
1824

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

0 commit comments

Comments
 (0)