4#include <gtest/gtest.h>
12 EXPECT_EQ(seventeen, -
b);
15TEST(grumpkin, RandomElement)
21TEST(grumpkin, RandomAffineElement)
32 EXPECT_EQ(
a ==
b,
true);
33 EXPECT_EQ(
a ==
a,
true);
35 b.self_set_infinity();
37 EXPECT_EQ(
a ==
b,
false);
40 EXPECT_EQ(
a == c,
false);
42 a.self_set_infinity();
44 EXPECT_EQ(
a ==
b,
true);
47TEST(grumpkin, CheckGroupModulus)
58TEST(grumpkin, AddExceptionTestInfinity)
76 EXPECT_EQ(lhs == result,
true);
81 EXPECT_EQ(rhs == result,
true);
84TEST(grumpkin, AddExceptionTestDbl)
96 EXPECT_EQ(result == expected,
true);
99TEST(grumpkin, AddDblConsistency)
114 dbl_result =
a.
dbl();
116 EXPECT_EQ(add_result == dbl_result,
true);
119TEST(grumpkin, AddDblConsistencyRepeated)
139 EXPECT_EQ(result == expected,
true);
142TEST(grumpkin, MixedAddExceptionTestInfinity)
159 EXPECT_EQ(rhs_c == result,
true);
162TEST(grumpkin, MixedAddExceptionTestDbl)
172 expected = lhs.
dbl();
174 EXPECT_EQ(result == expected,
true);
177TEST(grumpkin, AddMixedAddConsistencyCheck)
186 add_result = lhs + rhs_b;
187 mixed_add_result = lhs + rhs;
189 EXPECT_EQ(add_result == mixed_add_result,
true);
194 for (
size_t i = 0; i < 100; ++i) {
198 EXPECT_EQ(affine_test.
on_curve(),
true);
203 size_t num_points = 2;
206 for (
size_t i = 0; i < num_points; ++i) {
210 normalized[i] = points[i];
212 grumpkin::g1::element::batch_normalize(&normalized[0], num_points);
214 for (
size_t i = 0; i < num_points; ++i) {
219 zz = points[i].z.
sqr();
220 zzz = points[i].z * zz;
221 result_x = normalized[i].x * zz;
222 result_y = normalized[i].y * zzz;
224 EXPECT_EQ((result_x == points[i].x),
true);
225 EXPECT_EQ((result_y == points[i].y),
true);
229TEST(grumpkin, GroupExponentiationZeroAndOne)
240TEST(grumpkin, GroupExponentiationConsistencyCheck)
254 EXPECT_EQ(result == expected,
true);
257TEST(grumpkin, DeriveGenerators)
259 constexpr size_t num_generators = 128;
262 for (
size_t i = 0; i < result.size(); ++i) {
263 if ((i != j) && result[i] == y) {
270 for (
size_t k = 0; k < num_generators; ++k) {
271 EXPECT_EQ(is_unique(result[k], k),
true);
272 EXPECT_EQ(result[k].on_curve(),
true);
278 constexpr size_t num_points = 1024;
281 for (
size_t i = 0; i < num_points; ++i) {
282 points.emplace_back(grumpkin::g1::element::random_element());
284 grumpkin::g1::element::batch_normalize(&points[0], num_points);
287 for (
size_t i = 0; i < num_points; ++i) {
288 affine_points.emplace_back(points[i]);
292 std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
295 expected.reserve(num_points);
296 for (
const auto& point : points) {
297 expected.emplace_back((point * exponent).normalize());
300 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
301 std::chrono::milliseconds diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
304 start = std::chrono::steady_clock::now();
306 const auto result = grumpkin::g1::element::batch_mul_with_endomorphism(affine_points, exponent);
307 end = std::chrono::steady_clock::now();
308 diff = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
311 for (
size_t i = 0; i < num_points; ++i) {
312 EXPECT_EQ(result[i].x, expected[i].x);
313 EXPECT_EQ(result[i].y, expected[i].y);
321 auto beta_sqr = beta * beta;
324 for (
size_t i = 0; i < 256; i++) {
326 if (val == beta || val == beta_sqr) {
334TEST(grumpkin, CheckPrecomputedGenerators)
336 ASSERT_TRUE((bb::check_precomputed_generators<grumpkin::g1, "pedersen_hash_length", 1UL>()));
337 ASSERT_TRUE((bb::check_precomputed_generators<grumpkin::g1, "DEFAULT_DOMAIN_SEPARATOR", 8UL>()));
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
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
static constexpr element one
static constexpr affine_element affine_one
group_elements::element< Fq, Fr, Params > element
static constexpr Fq curve_b
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.
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static constexpr field cube_root_of_unity()
static constexpr field one()
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
static constexpr field zero()