32using Curves = ::testing::Types<curve::BN254, curve::Grumpkin>;
38 using Curve = TypeParam;
43 constexpr size_t num_points = 20;
44 AffineElement* points = (AffineElement*)(aligned_alloc(64,
sizeof(AffineElement) * (num_points)));
45 Fq* scratch_space = (
Fq*)(aligned_alloc(64,
sizeof(
Fq) * (num_points * 2)));
46 Fq* lambda = (
Fq*)(aligned_alloc(64,
sizeof(
Fq) * (num_points * 2)));
49 for (
size_t i = 0; i < num_points; ++i) {
50 points[i] = AffineElement(Element::random_element());
51 points_copy[i].x = points[i].x;
52 points_copy[i].y = points[i].y;
56 size_t count = num_points - 1;
57 for (
size_t i = num_points - 2; i < num_points; i -= 2) {
58 points_copy[count--] = points_copy[i] + points_copy[i + 1];
59 points_copy[count + 1] = points_copy[count + 1].normalize();
63 for (
size_t i = num_points - 1; i > num_points - 1 - (num_points / 2); --i) {
64 EXPECT_EQ((points[i].x == points_copy[i].x),
true);
65 EXPECT_EQ((points[i].y == points_copy[i].y),
true);
69 aligned_free(points_copy);
70 aligned_free(scratch_space);
75 using Curve = TypeParam;
84 Element expected = Group::one * scalar;
91 Fr k1{ (*k1_t).
data[0], (*k1_t).data[1], 0, 0 };
92 Fr k2{ (*k2_t).
data[0], (*k2_t).data[1], 0, 0 };
93#if !defined(__clang__) && defined(__GNUC__)
94#pragma GCC diagnostic pop
97 Element t1 = Group::affine_one * k1;
98 AffineElement generator = Group::affine_one;
100 generator.x = generator.x * beta;
101 generator.y = -generator.y;
105 EXPECT_EQ(result == expected,
true);
110 using Curve = TypeParam;
114 constexpr size_t target_degree = 1 << 8;
116 Fr* scalars = (
Fr*)(aligned_alloc(64,
sizeof(
Fr) * target_degree));
119 for (
size_t i = 0; i < target_degree; ++i) {
126 for (
size_t i = 0; i < num_rounds; ++i) {
128 std::vector<uint64_t> scalar_slices(target_degree);
129 std::vector<uint64_t> sorted_scalar_slices(target_degree);
131 for (
size_t j = 0; j < target_degree; ++j) {
133 sorted_scalar_slices[j] = scalar_slices[j];
136 &sorted_scalar_slices[0], target_degree,
static_cast<uint32_t
>(bits_per_slice));
138 const auto find_entry = [scalar_slices, num_entries = target_degree](
auto x) {
139 for (
size_t k = 0; k < num_entries; ++k) {
140 if (scalar_slices[k] == x) {
146 for (
size_t j = 0; j < target_degree; ++j) {
147 EXPECT_EQ(find_entry(sorted_scalar_slices[j]),
true);
149 EXPECT_EQ((sorted_scalar_slices[j] & 0x7fffffffU) >= (sorted_scalar_slices[j - 1] & 0x7fffffffU),
true);
159 using Curve = TypeParam;
162 GTEST_SKIP() <<
"Skipping test for grumpkin";
171 size_t target_degree = 1200000;
174 Fr* scalars = (
Fr*)(aligned_alloc(64,
sizeof(
Fr) * target_degree));
177 Fr accumulator = source_scalar;
178 for (
size_t i = 0; i < target_degree; ++i) {
179 accumulator *= source_scalar;
183 Element first = scalar_multiplication::pippenger<Curve>({ 0, { scalars, target_degree } }, monomials);
184 first = first.normalize();
186 for (
size_t i = 0; i < target_degree; ++i) {
190 Element second = scalar_multiplication::pippenger<Curve>(
192 second = second.normalize();
194 EXPECT_EQ((first.z == second.z),
true);
195 EXPECT_EQ((first.z ==
Fq::one()),
true);
196 EXPECT_EQ((first.x == second.x),
true);
197 EXPECT_EQ((first.y == -second.y),
true);
199 aligned_free(scalars);
204 using Curve = TypeParam;
211 size_t num_points = 17;
213 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
215 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
217 for (
size_t i = 0; i < num_points; ++i) {
219 points[i] = AffineElement(Element::random_element());
223 expected.self_set_infinity();
224 for (
size_t i = 0; i < num_points; ++i) {
225 Element temp = points[i] * scalars[i];
228 expected = expected.normalize();
230 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
231 { points, num_points * 2 });
232 result = result.normalize();
234 aligned_free(scalars);
235 aligned_free(points);
237 EXPECT_EQ(result == expected,
true);
242 using Curve = TypeParam;
247 constexpr size_t num_points = 8192;
249 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
251 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
253 for (
size_t i = 0; i < num_points; ++i) {
255 points[i] = AffineElement(Element::random_element());
259 expected.self_set_infinity();
260 for (
size_t i = 0; i < num_points; ++i) {
261 Element temp = points[i] * scalars[i];
264 expected = expected.normalize();
266 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
267 { points, num_points });
268 result = result.normalize();
270 aligned_free(scalars);
271 aligned_free(points);
273 EXPECT_EQ(result == expected,
true);
278 using Curve = TypeParam;
283 constexpr size_t num_points = 128;
285 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
287 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
289 AffineElement point = AffineElement(Element::random_element());
290 for (
size_t i = 0; i < num_points; ++i) {
296 expected.self_set_infinity();
297 for (
size_t i = 0; i < num_points; ++i) {
298 Element temp = points[i] * scalars[i];
301 if (!expected.is_point_at_infinity()) {
302 expected = expected.normalize();
304 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
305 { points, num_points * 2 });
306 result = result.normalize();
308 aligned_free(scalars);
309 aligned_free(points);
311 EXPECT_EQ(result == expected,
true);
316 using Curve = TypeParam;
321 constexpr size_t num_points = 8192;
323 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
325 std::vector<AffineElement> points(num_points);
327 for (
size_t i = 0; i < num_points; ++i) {
328 points[i] = AffineElement(Element::random_element());
330 for (
size_t i = 0; i < (num_points / 4); ++i) {
336 scalars[i * 4 + 1].
data[0] = 0;
337 scalars[i * 4 + 1].
data[1] = 0;
338 scalars[i * 4 + 1].
data[2] = 0;
339 scalars[i * 4 + 1].
data[3] = 0;
343 scalars[i * 4 + 2].
data[2] = 0;
344 scalars[i * 4 + 2].
data[3] = 0;
347 scalars[i * 4 + 3].
data[1] = 0;
348 scalars[i * 4 + 3].
data[2] = 0;
349 scalars[i * 4 + 3].
data[3] = 0;
354 expected.self_set_infinity();
355 for (
size_t i = 0; i < num_points; ++i) {
356 Element temp = points[i] * scalars[i];
359 expected = expected.normalize();
361 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } }, points);
362 result = result.normalize();
364 aligned_free(scalars);
366 EXPECT_EQ(result == expected,
true);
371 using Curve = TypeParam;
376 constexpr size_t num_points = 8192;
378 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
380 std::vector<AffineElement> points(num_points);
382 for (
size_t i = 0; i < num_points; ++i) {
384 points[i] = AffineElement(Element::random_element());
388 expected.self_set_infinity();
389 for (
size_t i = 0; i < num_points; ++i) {
390 Element temp = points[i] * scalars[i];
393 expected = expected.normalize();
394 Element result = scalar_multiplication::pippenger_unsafe<Curve>({ 0, { scalars, num_points } }, points);
395 result = result.normalize();
397 aligned_free(scalars);
399 EXPECT_EQ(result == expected,
true);
404 using Curve = TypeParam;
409 constexpr size_t num_points = 8192;
411 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
413 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
415 for (
size_t i = 0; i < num_points; ++i) {
416 points[i] = AffineElement(Element::random_element());
418 for (
size_t i = 0; i < (num_points / 4); ++i) {
424 scalars[i * 4 + 1].
data[0] = 0;
425 scalars[i * 4 + 1].
data[1] = 0;
426 scalars[i * 4 + 1].
data[2] = 0;
427 scalars[i * 4 + 1].
data[3] = 0;
431 scalars[i * 4 + 2].
data[2] = 0;
432 scalars[i * 4 + 2].
data[3] = 0;
435 scalars[i * 4 + 3].
data[1] = 0;
436 scalars[i * 4 + 3].
data[2] = 0;
437 scalars[i * 4 + 3].
data[3] = 0;
442 expected.self_set_infinity();
443 for (
size_t i = 0; i < num_points; ++i) {
444 Element temp = points[i] * scalars[i];
447 expected = expected.normalize();
449 Element result = scalar_multiplication::pippenger_unsafe<Curve>({ 0, { scalars, num_points } },
450 { points, num_points * 2 + 1 });
451 result = result.normalize();
453 aligned_free(scalars);
454 aligned_free(points);
456 EXPECT_EQ(result == expected,
true);
461 using Curve = TypeParam;
466 size_t num_points = 1;
468 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * 1);
470 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
472 for (
size_t i = 0; i < num_points; ++i) {
474 points[i] = AffineElement(Element::random_element());
478 expected.self_set_infinity();
479 for (
size_t i = 0; i < num_points; ++i) {
480 Element temp = points[i] * scalars[i];
483 expected = expected.normalize();
485 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
486 { points, num_points * 2 });
487 result = result.normalize();
489 aligned_free(scalars);
490 aligned_free(points);
492 EXPECT_EQ(result == expected,
true);
497 using Curve = TypeParam;
502 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr));
504 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (2 + 1));
506 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, 0 } }, { points, 0 });
508 aligned_free(scalars);
509 aligned_free(points);
511 EXPECT_EQ(result.is_point_at_infinity(),
true);
516 using Curve = TypeParam;
522 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr));
524 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (2 + 1));
527 points[0] = Group::affine_one;
528 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, 1 } }, { points, 2 });
530 aligned_free(scalars);
531 aligned_free(points);
533 EXPECT_EQ(result.is_point_at_infinity(),
true);
static void SetUpTestSuite()
typename Group::element Element
typename grumpkin::g1 Group
typename Group::affine_element AffineElement
virtual uint32_t get_random_uint32()=0
static size_t get_num_rounds(size_t num_points) noexcept
static uint32_t get_scalar_slice(const ScalarField &scalar, size_t round, size_t normal_slice_size) noexcept
Given a scalar that is NOT in Montgomery form, extract a slice_size-bit chunk.
static void add_affine_points(AffineElement *points, const size_t num_points, typename Curve::BaseField *scratch_space) noexcept
static size_t get_optimal_log_num_buckets(const size_t num_points) noexcept
For a given number of points, compute the optimal Pippenger bucket size.
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
size_t process_buckets_count_zero_entries(uint64_t *wnaf_entries, const size_t num_entries, const uint32_t num_bits) noexcept
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
::testing::Types< curve::BN254, curve::Grumpkin > Curves
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr field cube_root_of_unity()
static constexpr field one()
BB_INLINE constexpr field to_montgomery_form() const noexcept
static void split_into_endomorphism_scalars(const field &k, field &k1, field &k2)
BB_INLINE constexpr void self_sqr() &noexcept
BB_INLINE constexpr void self_neg() &noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept
static BB_INLINE void __copy(const field &a, field &r) noexcept
static constexpr field zero()