32using Curves = ::testing::Types<curve::BN254, curve::Grumpkin>;
38 using Curve = TypeParam;
47 Element expected = Group::one * scalar;
54 Element t1 = Group::affine_one * k1;
55 AffineElement generator = Group::affine_one;
57 generator.x = generator.x * beta;
58 generator.y = -generator.y;
62 EXPECT_EQ(result == expected,
true);
67 using Curve = TypeParam;
70 GTEST_SKIP() <<
"Skipping test for grumpkin";
79 size_t target_degree = 1200000;
82 Fr* scalars = (
Fr*)(aligned_alloc(64,
sizeof(
Fr) * target_degree));
85 Fr accumulator = source_scalar;
86 for (
size_t i = 0; i < target_degree; ++i) {
87 accumulator *= source_scalar;
91 Element first = scalar_multiplication::pippenger<Curve>({ 0, { scalars, target_degree } }, monomials);
92 first = first.normalize();
94 for (
size_t i = 0; i < target_degree; ++i) {
98 Element second = scalar_multiplication::pippenger<Curve>(
100 second = second.normalize();
102 EXPECT_EQ((first.z == second.z),
true);
103 EXPECT_EQ((first.z ==
Fq::one()),
true);
104 EXPECT_EQ((first.x == second.x),
true);
105 EXPECT_EQ((first.y == -second.y),
true);
107 aligned_free(scalars);
112 using Curve = TypeParam;
119 size_t num_points = 17;
121 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
123 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
125 for (
size_t i = 0; i < num_points; ++i) {
127 points[i] = AffineElement(Element::random_element());
131 expected.self_set_infinity();
132 for (
size_t i = 0; i < num_points; ++i) {
133 Element temp = points[i] * scalars[i];
136 expected = expected.normalize();
138 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
139 { points, num_points * 2 });
140 result = result.normalize();
142 aligned_free(scalars);
143 aligned_free(points);
145 EXPECT_EQ(result == expected,
true);
150 using Curve = TypeParam;
155 constexpr size_t num_points = 8192;
157 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
159 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
161 for (
size_t i = 0; i < num_points; ++i) {
163 points[i] = AffineElement(Element::random_element());
167 expected.self_set_infinity();
168 for (
size_t i = 0; i < num_points; ++i) {
169 Element temp = points[i] * scalars[i];
172 expected = expected.normalize();
174 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
175 { points, num_points });
176 result = result.normalize();
178 aligned_free(scalars);
179 aligned_free(points);
181 EXPECT_EQ(result == expected,
true);
186 using Curve = TypeParam;
191 constexpr size_t num_points = 128;
193 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
195 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
197 AffineElement point = AffineElement(Element::random_element());
198 for (
size_t i = 0; i < num_points; ++i) {
204 expected.self_set_infinity();
205 for (
size_t i = 0; i < num_points; ++i) {
206 Element temp = points[i] * scalars[i];
209 if (!expected.is_point_at_infinity()) {
210 expected = expected.normalize();
212 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
213 { points, num_points * 2 });
214 result = result.normalize();
216 aligned_free(scalars);
217 aligned_free(points);
219 EXPECT_EQ(result == expected,
true);
224 using Curve = TypeParam;
229 constexpr size_t num_points = 8192;
231 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
233 std::vector<AffineElement> points(num_points);
235 for (
size_t i = 0; i < num_points; ++i) {
236 points[i] = AffineElement(Element::random_element());
238 for (
size_t i = 0; i < (num_points / 4); ++i) {
244 scalars[i * 4 + 1].
data[0] = 0;
245 scalars[i * 4 + 1].
data[1] = 0;
246 scalars[i * 4 + 1].
data[2] = 0;
247 scalars[i * 4 + 1].
data[3] = 0;
251 scalars[i * 4 + 2].
data[2] = 0;
252 scalars[i * 4 + 2].
data[3] = 0;
255 scalars[i * 4 + 3].
data[1] = 0;
256 scalars[i * 4 + 3].
data[2] = 0;
257 scalars[i * 4 + 3].
data[3] = 0;
262 expected.self_set_infinity();
263 for (
size_t i = 0; i < num_points; ++i) {
264 Element temp = points[i] * scalars[i];
267 expected = expected.normalize();
269 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } }, points);
270 result = result.normalize();
272 aligned_free(scalars);
274 EXPECT_EQ(result == expected,
true);
279 using Curve = TypeParam;
284 constexpr size_t num_points = 8192;
286 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
288 std::vector<AffineElement> points(num_points);
290 for (
size_t i = 0; i < num_points; ++i) {
292 points[i] = AffineElement(Element::random_element());
296 expected.self_set_infinity();
297 for (
size_t i = 0; i < num_points; ++i) {
298 Element temp = points[i] * scalars[i];
301 expected = expected.normalize();
302 Element result = scalar_multiplication::pippenger_unsafe<Curve>({ 0, { scalars, num_points } }, points);
303 result = result.normalize();
305 aligned_free(scalars);
307 EXPECT_EQ(result == expected,
true);
312 using Curve = TypeParam;
317 constexpr size_t num_points = 8192;
319 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * num_points);
321 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
323 for (
size_t i = 0; i < num_points; ++i) {
324 points[i] = AffineElement(Element::random_element());
326 for (
size_t i = 0; i < (num_points / 4); ++i) {
332 scalars[i * 4 + 1].
data[0] = 0;
333 scalars[i * 4 + 1].
data[1] = 0;
334 scalars[i * 4 + 1].
data[2] = 0;
335 scalars[i * 4 + 1].
data[3] = 0;
339 scalars[i * 4 + 2].
data[2] = 0;
340 scalars[i * 4 + 2].
data[3] = 0;
343 scalars[i * 4 + 3].
data[1] = 0;
344 scalars[i * 4 + 3].
data[2] = 0;
345 scalars[i * 4 + 3].
data[3] = 0;
350 expected.self_set_infinity();
351 for (
size_t i = 0; i < num_points; ++i) {
352 Element temp = points[i] * scalars[i];
355 expected = expected.normalize();
357 Element result = scalar_multiplication::pippenger_unsafe<Curve>({ 0, { scalars, num_points } },
358 { points, num_points * 2 + 1 });
359 result = result.normalize();
361 aligned_free(scalars);
362 aligned_free(points);
364 EXPECT_EQ(result == expected,
true);
369 using Curve = TypeParam;
374 size_t num_points = 1;
376 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr) * 1);
378 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (num_points * 2 + 1));
380 for (
size_t i = 0; i < num_points; ++i) {
382 points[i] = AffineElement(Element::random_element());
386 expected.self_set_infinity();
387 for (
size_t i = 0; i < num_points; ++i) {
388 Element temp = points[i] * scalars[i];
391 expected = expected.normalize();
393 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, num_points } },
394 { points, num_points * 2 });
395 result = result.normalize();
397 aligned_free(scalars);
398 aligned_free(points);
400 EXPECT_EQ(result == expected,
true);
405 using Curve = TypeParam;
410 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr));
412 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (2 + 1));
414 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, 0 } }, { points, 0 });
416 aligned_free(scalars);
417 aligned_free(points);
419 EXPECT_EQ(result.is_point_at_infinity(),
true);
424 using Curve = TypeParam;
430 Fr* scalars = (
Fr*)aligned_alloc(32,
sizeof(
Fr));
432 AffineElement* points = (AffineElement*)aligned_alloc(32,
sizeof(AffineElement) * (2 + 1));
435 points[0] = Group::affine_one;
436 Element result = scalar_multiplication::pippenger<Curve>({ 0, { scalars, 1 } }, { points, 2 });
438 aligned_free(scalars);
439 aligned_free(points);
441 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
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
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(CommitmentKeyTest, Curves)
TYPED_TEST(CommitmentKeyTest, CommitToZeroPoly)
::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)
Full-width endomorphism decomposition: k ≡ k1 - k2·λ (mod r). Modifies the field elements k1 and k2.
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()