Skip to content

Commit efd98c1

Browse files
committed
remove overflow check in aggregation
1 parent 58b129f commit efd98c1

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

src/modules/schnorrsig_halfagg/main_impl.h

+2-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ void secp256k1_schnorrsig_sha256_tagged_aggregation(secp256k1_sha256 *sha) {
2525
int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned char *aggsig, size_t *aggsig_len, const secp256k1_xonly_pubkey *all_pubkeys, const unsigned char *all_msgs32, const unsigned char *new_sigs64, size_t n_before, size_t n_new) {
2626
size_t i;
2727
size_t n;
28-
int overflow;
2928
secp256k1_sha256 hash;
3029
secp256k1_scalar s;
3130

@@ -64,12 +63,7 @@ int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned ch
6463
/* Compute s = s_old + sum_{i = n_before}^{n} z_i*s_i */
6564
/* where s_old = 0 if n_before = 0 */
6665
secp256k1_scalar_set_int(&s, 0);
67-
if (n_before > 0) {
68-
secp256k1_scalar_set_b32(&s, &aggsig[n_before*32], &overflow);
69-
if (overflow) {
70-
return 0;
71-
}
72-
}
66+
if (n_before > 0) secp256k1_scalar_set_b32(&s, &aggsig[n_before*32], NULL);
7367
for (i = n_before; i < n; ++i) {
7468
unsigned char pk_ser[32];
7569
unsigned char hashoutput[32];
@@ -96,10 +90,7 @@ int secp256k1_schnorrsig_inc_aggregate(const secp256k1_context *ctx, unsigned ch
9690

9791
/* Step 2: s := s + zi*si */
9892
/* except if i == 0, then zi = 1 implicitly */
99-
secp256k1_scalar_set_b32(&si, &new_sigs64[(i-n_before)*64+32], &overflow);
100-
if (overflow) {
101-
return 0;
102-
}
93+
secp256k1_scalar_set_b32(&si, &new_sigs64[(i-n_before)*64+32], NULL);
10394
if (i != 0) secp256k1_scalar_mul(&si, &si, &zi);
10495
secp256k1_scalar_add(&s, &s, &si);
10596
}

src/modules/schnorrsig_halfagg/tests_impl.h

+1-12
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,7 @@ static void test_schnorrsig_aggregate_overflow(void) {
304304
unsigned char aggsig[32*(N_MAX + 1)];
305305
size_t n = secp256k1_testrand_int(N_MAX + 1);
306306

307-
/* Test 1: We check that aggregation returns 0 if one s overflows. */
308-
test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n);
309-
if (n > 0) {
310-
size_t aggsig_len = sizeof(aggsig);
311-
size_t k = secp256k1_testrand_int(n);
312-
/* Make one randomly chosen s overflow */
313-
memset(&sigs64[k*64+32], 0xFF, 32);
314-
/* Check that aggregating fails */
315-
CHECK(secp256k1_schnorrsig_aggregate(CTX, aggsig, &aggsig_len, pubkeys, msgs32, sigs64, n) == 0);
316-
}
317-
318-
/* Test 2: We check that verification returns 0 if the s in aggsig overflows. */
307+
/* We check that verification returns 0 if the s in aggsig overflows. */
319308
test_schnorrsig_aggregate_input_helper(pubkeys, msgs32, sigs64, n);
320309
{
321310
size_t aggsig_len = sizeof(aggsig);

0 commit comments

Comments
 (0)