Skip to content

Commit 2515fa2

Browse files
committed
rangeproof: fix Jonas' bug
Copied some more logic from the 2015-era code.
1 parent 75a5781 commit 2515fa2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/modules/rangeproof/rangeproof_impl.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int secp256k1_rangeproof_header_set_for_value(
113113
secp256k1_rangeproof_header* header,
114114
uint64_t* proven_value,
115115
const uint64_t min_value,
116-
const uint64_t min_bits,
116+
uint64_t min_bits,
117117
const int exp,
118118
const uint64_t value
119119
) {
@@ -149,9 +149,17 @@ static int secp256k1_rangeproof_header_set_for_value(
149149
*/
150150
header->exp = 0;
151151
}
152+
/* Reduce min_bits to keep within a uint64_t's range (essentially copied from 2015 code) */
153+
{
154+
const unsigned int max_bits = min_value ? secp256k1_clz64_var(min_value) : 64;
155+
if (min_bits > max_bits) {
156+
header->mantissa = max_bits;
157+
min_bits = max_bits;
158+
}
159+
}
152160
{
153161
/* If the user has asked for more bits of proof then there is room for in the exponent, reduce the exponent. */
154-
uint64_t max = min_bits ? (UINT64_MAX >> (64 - min_bits)) : 0;
162+
uint64_t max = min_bits ? (UINT64_MAX >> (64 - header->mantissa)) : 0;
155163
int i;
156164
for (i = 0; i < header->exp && max <= UINT64_MAX / 10; i++) {
157165
max *= 10;

0 commit comments

Comments
 (0)