Skip to content

Commit 29a1b7e

Browse files
Remove the unused points and scalars allocation from secp256k1_ecmult_strauss_batch.
1 parent 8242379 commit 29a1b7e

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/ecmult_impl.h

+4-12
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
/* The number of objects allocated on the scratch space for ecmult_multi algorithms */
4949
#define PIPPENGER_SCRATCH_OBJECTS 6
50-
#define STRAUSS_SCRATCH_OBJECTS 5
50+
#define STRAUSS_SCRATCH_OBJECTS 3
5151

5252
#define PIPPENGER_MAX_BUCKET_WINDOW 12
5353

@@ -386,7 +386,7 @@ static void secp256k1_ecmult(secp256k1_gej *r, const secp256k1_gej *a, const sec
386386
}
387387

388388
static size_t secp256k1_strauss_scratch_size(size_t n_points) {
389-
static const size_t point_size = (sizeof(secp256k1_ge) + sizeof(secp256k1_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct secp256k1_strauss_point_state) + sizeof(secp256k1_gej) + sizeof(secp256k1_scalar);
389+
static const size_t point_size = (sizeof(secp256k1_ge) + sizeof(secp256k1_fe)) * ECMULT_TABLE_SIZE(WINDOW_A) + sizeof(struct secp256k1_strauss_point_state);
390390
return n_points*point_size;
391391
}
392392

@@ -408,8 +408,6 @@ static int secp256k1_ecmult_adaptor_cb(secp256k1_scalar *sc, secp256k1_gej *pt,
408408
}
409409

410410
static int secp256k1_ecmult_strauss_batch(const secp256k1_callback* error_callback, secp256k1_scratch *scratch, secp256k1_gej *r, const secp256k1_scalar *inp_g_sc, secp256k1_ecmult_multi_callback cb, void *cbdata, size_t n_points, size_t cb_offset) {
411-
secp256k1_gej* points;
412-
secp256k1_scalar* scalars;
413411
struct secp256k1_ecmult_adaptor_cb_data adaptor_data;
414412
struct secp256k1_strauss_state state;
415413
const size_t scratch_checkpoint = secp256k1_scratch_checkpoint(error_callback, scratch);
@@ -422,20 +420,14 @@ static int secp256k1_ecmult_strauss_batch(const secp256k1_callback* error_callba
422420
/* We allocate STRAUSS_SCRATCH_OBJECTS objects on the scratch space. If these
423421
* allocations change, make sure to update the STRAUSS_SCRATCH_OBJECTS
424422
* constant and strauss_scratch_size accordingly. */
425-
points = (secp256k1_gej*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_gej));
426-
scalars = (secp256k1_scalar*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_scalar));
427423
adaptor_data.cb = cb;
428424
adaptor_data.data = cbdata;
429425
state.aux = (secp256k1_fe*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_fe));
430426
state.pre_a = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));
431427
state.ps = (struct secp256k1_strauss_point_state*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(struct secp256k1_strauss_point_state));
432428

433-
if (points == NULL || scalars == NULL || state.aux == NULL || state.pre_a == NULL || state.ps == NULL) {
434-
secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);
435-
return 0;
436-
}
437-
438-
if (!secp256k1_ecmult_strauss_wnaf(&state, r, n_points, &secp256k1_ecmult_adaptor_cb, &adaptor_data, cb_offset, inp_g_sc)) {
429+
if (state.aux == NULL || state.pre_a == NULL || state.ps == NULL ||
430+
!secp256k1_ecmult_strauss_wnaf(&state, r, n_points, &secp256k1_ecmult_adaptor_cb, &adaptor_data, cb_offset, inp_g_sc)) {
439431
secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);
440432
return 0;
441433
}

0 commit comments

Comments
 (0)