Skip to content

Commit c6e29a7

Browse files
committed
fix: max-value overflow and explicit fast path for n_pts == 1
1 parent b99782e commit c6e29a7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/bulletproof_aggregated.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,15 @@ static int calculate_commitment_term(
11361136
pts[n_pts++] = &tH;
11371137
}
11381138

1139-
return secp256k1_ec_pubkey_combine(ctx, out, pts, n_pts);
1139+
if (n_pts == 1) {
1140+
*out = *pts[0];
1141+
return 1;
1142+
}
1143+
1144+
if (!secp256k1_ec_pubkey_combine(ctx, out, pts, n_pts))
1145+
return 0;
1146+
1147+
return 1;
11401148
}
11411149

11421150
/**

tests/test_bulletproof_agg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ void run_test_case(secp256k1_context* ctx, const char* name, uint64_t* values, s
129129
EXPECT(secp256k1_bulletproof_create_commitment(
130130
ctx,
131131
&bad_commitments[num_values - 1],
132-
values[num_values - 1] + 1,
132+
(values[num_values - 1] == UINT64_MAX)
133+
? values[num_values - 1] - 1
134+
: values[num_values - 1] + 1,
133135
bad_blinding,
134136
&pk_base));
135137

0 commit comments

Comments
 (0)