@@ -10,6 +10,15 @@ extern "C" {
10
10
11
11
#include <stdint.h>
12
12
13
+ /** Length of a message that can be embedded into a maximally-sized rangeproof
14
+ *
15
+ * It is not be possible to fit a message of this size into a non-maximally-sized
16
+ * rangeproof, but it is guaranteed that any embeddable message can fit into an
17
+ * array of this size. This constant is intended to be used for memory allocations
18
+ * and sanity checks.
19
+ */
20
+ #define SECP256K1_RANGEPROOF_MAX_MESSAGE_LEN 3968
21
+
13
22
/** Opaque data structure that stores a Pedersen commitment
14
23
*
15
24
* The exact representation of data inside is implementation defined and not
@@ -287,6 +296,33 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_rangeproof_info(
287
296
size_t plen
288
297
) SECP256K1_ARG_NONNULL (1 ) SECP256K1_ARG_NONNULL (2 ) SECP256K1_ARG_NONNULL (3 ) SECP256K1_ARG_NONNULL (4 ) SECP256K1_ARG_NONNULL (5 );
289
298
299
+ /** Returns an upper bound on the size of a rangeproof with the given parameters
300
+ *
301
+ * An actual rangeproof may be smaller, for example if the actual value
302
+ * is less than both the provided `max_value` and 2^`min_bits`, or if
303
+ * the `exp` parameter to `secp256k1_rangeproof_sign` is set such that
304
+ * the proven range is compressed. In particular this function will always
305
+ * overestimate the size of single-value proofs. Also, if `min_value`
306
+ * is set to 0 in the proof, the result will usually, but not always,
307
+ * be 8 bytes smaller than if a nonzero value had been passed.
308
+ *
309
+ * The goal of this function is to provide a useful upper bound for
310
+ * memory allocation or fee estimation purposes, without requiring
311
+ * too many parameters be fixed in advance.
312
+ *
313
+ * To obtain the size of largest possible proof, set `max_value` to
314
+ * `UINT64_MAX` (and `min_bits` to any valid value such as 0).
315
+ *
316
+ * In: ctx: pointer to a context object
317
+ * max_value: the maximum value that might be passed for `value` for the proof.
318
+ * min_bits: the value that will be passed as `min_bits` for the proof.
319
+ */
320
+ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT size_t secp256k1_rangeproof_max_size (
321
+ const secp256k1_context * ctx ,
322
+ uint64_t max_value ,
323
+ int min_bits
324
+ ) SECP256K1_ARG_NONNULL (1 );
325
+
290
326
# ifdef __cplusplus
291
327
}
292
328
# endif
0 commit comments