4#include <gtest/gtest.h>
25 EXPECT_EQ(
a ==
b,
true);
26 EXPECT_EQ(
a ==
a,
true);
28 b.self_set_infinity();
30 EXPECT_EQ(
a ==
b,
false);
33 EXPECT_EQ(
a == c,
false);
35 a.self_set_infinity();
37 EXPECT_EQ(
a ==
b,
true);
40TEST(
g1, MixedAddCheckAgainstConstants)
42 fq a_x{ 0x92716caa6cac6d26, 0x1e6e234136736544, 0x1bb04588cde00af0, 0x9a2ac922d97e6f5 };
43 fq a_y{ 0x9e693aeb52d79d2d, 0xf0c1895a61e5e975, 0x18cd7f5310ced70f, 0xac67920a22939ad };
44 fq a_z{ 0xfef593c9ce1df132, 0xe0486f801303c27d, 0x9bbd01ab881dc08e, 0x2a589badf38ec0f9 };
45 fq b_x{ 0xa1ec5d1398660db8, 0x6be3e1f6fd5d8ab1, 0x69173397dd272e11, 0x12575bbfe1198886 };
46 fq b_y{ 0xcfbfd4441138823e, 0xb5f817e28a1ef904, 0xefb7c5629dcc1c42, 0x1a9ed3d6f846230e };
47 fq expected_x{ 0x2a9d0201fccca20, 0x36f969b294f31776, 0xee5534422a6f646, 0x911dbc6b02310b6 };
48 fq expected_y{ 0x14c30aaeb4f135ef, 0x9c27c128ea2017a1, 0xf9b7d80c8315eabf, 0x35e628df8add760 };
49 fq expected_z{ 0xa43fe96673d10eb3, 0x88fbe6351753d410, 0x45c21cc9d99cb7d, 0x3018020aa6e9ede5 };
57 rhs.
x = b_x.to_montgomery_form();
58 rhs.
y = b_y.to_montgomery_form();
64 EXPECT_EQ(result == expected,
true);
69 fq a_x{ 0x8d1703aa518d827f, 0xd19cc40779f54f63, 0xabc11ce30d02728c, 0x10938940de3cbeec };
70 fq a_y{ 0xcf1798994f1258b4, 0x36307a354ad90a25, 0xcd84adb348c63007, 0x6266b85241aff3f };
71 fq a_z{ 0xe213e18fd2df7044, 0xb2f42355982c5bc8, 0xf65cf5150a3a9da1, 0xc43bde08b03aca2 };
72 fq expected_x{ 0xd5c6473044b2e67c, 0x89b185ea20951f3a, 0x4ac597219cf47467, 0x2d00482f63b12c86 };
73 fq expected_y{ 0x4e7e6c06a87e4314, 0x906a877a71735161, 0xaa7b9893cc370d39, 0x62f206bef795a05 };
74 fq expected_z{ 0x8813bdca7b0b115a, 0x929104dffdfabd22, 0x3fff575136879112, 0x18a299c1f683bdca };
89 EXPECT_EQ(result == expected,
true);
94 fq a_x{ 0x184b38afc6e2e09a, 0x4965cd1c3687f635, 0x334da8e7539e71c4, 0xf708d16cfe6e14 };
95 fq a_y{ 0x2a6ff6ffc739b3b6, 0x70761d618b513b9, 0xbf1645401de26ba1, 0x114a1616c164b980 };
96 fq a_z{ 0x10143ade26bbd57a, 0x98cf4e1f6c214053, 0x6bfdc534f6b00006, 0x1875e5068ababf2c };
97 fq b_x{ 0xafdb8a15c98bf74c, 0xac54df622a8d991a, 0xc6e5ae1f3dad4ec8, 0x1bd3fb4a59e19b52 };
98 fq b_y{ 0x21b3bb529bec20c0, 0xaabd496406ffb8c1, 0xcd3526c26ac5bdcb, 0x187ada6b8693c184 };
99 fq b_z{ 0xffcd440a228ed652, 0x8a795c8f234145f1, 0xd5279cdbabb05b95, 0xbdf19ba16fc607a };
100 fq expected_x{ 0x18764da36aa4cd81, 0xd15388d1fea9f3d3, 0xeb7c437de4bbd748, 0x2f09b712adf6f18f };
101 fq expected_y{ 0x50c5f3cab191498c, 0xe50aa3ce802ea3b5, 0xd9d6125b82ebeff8, 0x27e91ba0686e54fe };
102 fq expected_z{ 0xe4b81ef75fedf95, 0xf608edef14913c75, 0xfd9e178143224c96, 0xa8ae44990c8accd };
120 EXPECT_EQ(result == expected,
true);
139 result = lhs + rhs_b;
141 EXPECT_EQ(lhs == result,
true);
146 EXPECT_EQ(rhs == result,
true);
168 expected = lhs.
dbl();
170 EXPECT_EQ(result == expected,
true);
201 dbl_result =
a.
dbl();
203 EXPECT_EQ(add_result == dbl_result,
true);
226 EXPECT_EQ(result == expected,
true);
246 EXPECT_EQ(rhs_c == result,
true);
259 expected = lhs.
dbl();
261 EXPECT_EQ(result == expected,
true);
273 add_result = lhs + rhs_b;
274 mixed_add_result = lhs + rhs;
276 EXPECT_EQ(add_result == mixed_add_result,
true);
281 size_t num_points = 2;
284 for (
size_t i = 0; i < num_points; ++i) {
288 normalized[i] = points[i];
290 g1::element::batch_normalize(&normalized[0], num_points);
292 for (
size_t i = 0; i < num_points; ++i) {
297 zz = points[i].z.
sqr();
298 zzz = points[i].z * zz;
299 result_x = normalized[i].x * zz;
300 result_y = normalized[i].y * zzz;
302 EXPECT_EQ((result_x == points[i].x),
true);
303 EXPECT_EQ((result_y == points[i].y),
true);
307TEST(
g1, GroupExponentiationCheckAgainstConstants)
309 fr a{ 0xb67299b792199cf0, 0xc1da7df1e7e12768, 0x692e427911532edf, 0x13dd85e87dc89978 };
312 fq expected_x{ 0x9bf840faf1b4ba00, 0xe81b7260d068e663, 0x7610c9a658d2c443, 0x278307cd3d0cddb0 };
313 fq expected_y{ 0xf6ed5fb779ebecb, 0x414ca771acbe183c, 0xe3692cb56dfbdb67, 0x3d3c5ed19b080a3 };
316 expected.
x = expected_x.to_montgomery_form();
317 expected.
y = expected_y.to_montgomery_form();
321 EXPECT_EQ(result == expected,
true);
329 fr scalar{ 0xcfbfd4441138823e, 0xb5f817e28a1ef904, 0xefb7c5629dcc1c42, 0x1a9ed3d6f846230e };
360TEST(
g1, GroupExponentiationConsistencyCheck)
374 EXPECT_EQ(result == expected,
true);
379 constexpr size_t num_generators = 128;
383 for (
size_t i = 0; i < result.size(); ++i) {
384 if ((i != j) && result[i] == y) {
391 for (
size_t k = 0; k < num_generators; ++k) {
392 EXPECT_EQ(is_unique(result[k], k),
true);
393 EXPECT_EQ(result[k].on_curve(),
true);
403 g1::affine_element::serialize_to_buffer(expected, &
buffer[0]);
407 EXPECT_EQ(result == expected,
true);
409template <
class T>
void write(
const T t)
411 FILE* fp = fopen(
"/dev/null",
"wb");
412 static_cast<void>(fwrite(&t,
sizeof(t), 1, fp));
413 static_cast<void>(fclose(fp));
416#if !defined(__wasm__)
420 EXPECT_NO_THROW(write<g1::affine_element>({}));
426 ASSERT_TRUE((bb::check_precomputed_generators<g1, "biggroup table offset generator", 1UL>()));
427 ASSERT_TRUE((bb::check_precomputed_generators<g1, "biggroup offset generator", 1UL>()));
428 ASSERT_TRUE((bb::check_precomputed_generators<g1, "ECCVM_OFFSET_GENERATOR", 1UL>()));
429 ASSERT_TRUE((bb::check_precomputed_generators<g1, "test generators", 2UL>()));
constexpr bool is_point_at_infinity() const noexcept
constexpr bool on_curve() const noexcept
element class. Implements ecc group arithmetic using Jacobian coordinates See https://hyperelliptic....
constexpr element dbl() const noexcept
constexpr element normalize() const noexcept
constexpr void self_dbl() noexcept
BB_INLINE constexpr bool on_curve() const noexcept
BB_INLINE constexpr void self_set_infinity() noexcept
BB_INLINE constexpr bool is_point_at_infinity() const noexcept
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
group_elements::affine_element< Fq, Fr, Params > affine_element
static constexpr element one
static constexpr affine_element affine_one
group_elements::element< Fq, Fr, Params > element
static std::vector< affine_element > derive_generators(const std::vector< uint8_t > &domain_separator_bytes, const size_t num_generators, const size_t starting_index=0)
Derives generator points via hash-to-curve.
uint8_t buffer[RANDOM_BUFFER_SIZE]
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr field one()
BB_INLINE constexpr field to_montgomery_form() const noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept
BB_INLINE constexpr field sqr() const noexcept
static BB_INLINE void __copy(const field &a, field &r) noexcept
BB_INLINE constexpr void self_to_montgomery_form() &noexcept
static constexpr field zero()