Skip to content

Commit d016756

Browse files
authored
chore: shrink msm test size while maintaining coverage (#23226)
see title
1 parent 45283a1 commit d016756

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

barretenberg/cpp/src/barretenberg/ecc/scalar_multiplication/scalar_multiplication.test.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,27 @@ template <class Curve> class ScalarMultiplicationTest : public ::testing::Test {
2323
using AffineElement = typename Curve::AffineElement;
2424
using ScalarField = typename Curve::ScalarField;
2525

26-
static constexpr size_t num_points = 201123;
26+
static constexpr size_t num_points = 31013;
27+
28+
// Bounds used by test_batch_multi_scalar_mul. Kept small so num_points (and therefore
29+
// SetUpTestSuite, which builds num_points random EC points) stays cheap — especially under wasm,
30+
// where the fixture build previously dominated the whole ecc_tests run.
31+
static constexpr size_t kMaxBatchMSMs = 32;
32+
static constexpr size_t kMaxBatchPointsPerMSM = 400;
33+
34+
// Used by test_consume_point_batch{,_and_accumulate}, which read generators[0..kMaxBucketTestPoints).
35+
static constexpr size_t kMaxBucketTestPoints = 30071;
36+
37+
// Pinning invariants: these tests walk generators[]/scalars[] without bounds checks beyond an
38+
// occasional runtime ASSERT_LT. Pin the relationships at compile time so changing any one of
39+
// these constants in isolation cannot regress into an out-of-bounds walk.
40+
static_assert(kMaxBatchMSMs * kMaxBatchPointsPerMSM < num_points,
41+
"test_batch_multi_scalar_mul can exceed num_points; "
42+
"raise num_points or lower kMaxBatchMSMs / kMaxBatchPointsPerMSM");
43+
static_assert(kMaxBucketTestPoints <= num_points,
44+
"test_consume_point_batch* reads past end of generators; "
45+
"raise num_points or lower kMaxBucketTestPoints");
46+
2747
static inline std::vector<AffineElement> generators{};
2848
static inline std::vector<ScalarField> scalars{};
2949

@@ -117,7 +137,7 @@ template <class Curve> class ScalarMultiplicationTest : public ::testing::Test {
117137

118138
void test_consume_point_batch()
119139
{
120-
const size_t total_points = 30071;
140+
const size_t total_points = kMaxBucketTestPoints;
121141
const size_t num_buckets = 128;
122142

123143
std::vector<uint64_t> input_point_schedule;
@@ -152,7 +172,7 @@ template <class Curve> class ScalarMultiplicationTest : public ::testing::Test {
152172

153173
void test_consume_point_batch_and_accumulate()
154174
{
155-
const size_t total_points = 30071;
175+
const size_t total_points = kMaxBucketTestPoints;
156176
const size_t num_buckets = 128;
157177

158178
std::vector<uint64_t> input_point_schedule;
@@ -298,7 +318,7 @@ template <class Curve> class ScalarMultiplicationTest : public ::testing::Test {
298318
{
299319
BB_BENCH_NAME("BatchMultiScalarMul");
300320

301-
const size_t num_msms = static_cast<size_t>(engine.get_random_uint8());
321+
const size_t num_msms = static_cast<size_t>(engine.get_random_uint8()) % kMaxBatchMSMs;
302322
std::vector<AffineElement> expected(num_msms);
303323

304324
std::vector<std::vector<ScalarField>> batch_scalars_copies(num_msms);
@@ -307,7 +327,7 @@ template <class Curve> class ScalarMultiplicationTest : public ::testing::Test {
307327

308328
size_t vector_offset = 0;
309329
for (size_t k = 0; k < num_msms; ++k) {
310-
const size_t num_pts = static_cast<size_t>(engine.get_random_uint16()) % 400;
330+
const size_t num_pts = static_cast<size_t>(engine.get_random_uint16()) % kMaxBatchPointsPerMSM;
311331

312332
ASSERT_LT(vector_offset + num_pts, num_points);
313333
std::span<const AffineElement> batch_points(&generators[vector_offset], num_pts);

0 commit comments

Comments
 (0)