4#include <gtest/gtest.h>
12TEST(secp256k1, CurveCoefficients)
21TEST(secp256k1, GeneratorOnCurve)
27 EXPECT_EQ(result.
x, expected_x);
28 EXPECT_EQ(result.
y, expected_y);
32TEST(secp256k1, RandomElement)
38TEST(secp256k1, RandomAffineElement)
49 EXPECT_EQ(
a ==
b,
true);
50 EXPECT_EQ(
a ==
a,
true);
52 b.self_set_infinity();
54 EXPECT_EQ(
a ==
b,
false);
57 EXPECT_EQ(
a == c,
false);
59 a.self_set_infinity();
61 EXPECT_EQ(
a ==
b,
true);
64TEST(secp256k1, CheckGroupModulus)
75TEST(secp256k1, AddExceptionTestInfinity)
93 EXPECT_EQ(lhs == result,
true);
98 EXPECT_EQ(rhs == result,
true);
101TEST(secp256k1, AddExceptionTestDbl)
111 expected = lhs.
dbl();
113 EXPECT_EQ(result == expected,
true);
116TEST(secp256k1, AddDblConsistency)
131 dbl_result =
a.dbl();
133 EXPECT_EQ(add_result == dbl_result,
true);
136TEST(secp256k1, AddDblConsistencyRepeated)
156 EXPECT_EQ(result == expected,
true);
159TEST(secp256k1, MixedAddExceptionTestInfinity)
176 EXPECT_EQ(rhs_c == result,
true);
179TEST(secp256k1, MixedAddExceptionTestDbl)
189 expected = lhs.
dbl();
191 EXPECT_EQ(result == expected,
true);
194TEST(secp256k1, AddMixedAddConsistencyCheck)
203 add_result = lhs + rhs_b;
204 mixed_add_result = lhs + rhs;
206 EXPECT_EQ(add_result == mixed_add_result,
true);
211 for (
size_t i = 0; i < 100; ++i) {
215 EXPECT_EQ(affine_test.
on_curve(),
true);
220 size_t num_points = 2;
223 for (
size_t i = 0; i < num_points; ++i) {
227 normalized[i] = points[i];
229 secp256k1::g1::element::batch_normalize(&normalized[0], num_points);
231 for (
size_t i = 0; i < num_points; ++i) {
236 zz = points[i].z.
sqr();
237 zzz = points[i].z * zz;
238 result_x = normalized[i].x * zz;
239 result_y = normalized[i].y * zzz;
241 EXPECT_EQ((result_x == points[i].x),
true);
242 EXPECT_EQ((result_y == points[i].y),
true);
246TEST(secp256k1, GroupExponentiationZeroAndOne)
257TEST(secp256k1, GroupExponentiationConsistencyCheck)
271 EXPECT_EQ(result == expected,
true);
274TEST(secp256k1, DeriveGenerators)
276 constexpr size_t num_generators = 128;
280 for (
size_t i = 0; i < result.size(); ++i) {
281 if ((i != j) && result[i] == y) {
288 for (
size_t k = 0; k < num_generators; ++k) {
289 EXPECT_EQ(is_unique(result[k], k),
true);
290 EXPECT_EQ(result[k].on_curve(),
true);
294TEST(secp256k1, CheckPrecomputedGenerators)
296 ASSERT_TRUE((bb::check_precomputed_generators<secp256k1::g1, "biggroup offset generator", 1UL>()));
297 ASSERT_TRUE((bb::check_precomputed_generators<secp256k1::g1, "biggroup table offset generator", 1UL>()));
300TEST(secp256k1, GetEndomorphismScalars)
302 for (
size_t i = 0; i < 2048; i++) {
333 EXPECT_EQ(k, expected);
340TEST(secp256k1, TestEndomorphismScalars)
370 static const uint256_t secp256k1_const_lambda{
371 0xDF02967C1B23BD72ULL, 0x122E22EA20816678UL, 0xA5261C028812645AULL, 0x5363AD4CC05C30E0ULL
377 EXPECT_EQ(k, expected);
380TEST(secp256k1, NegAndSelfNeg0CmpRegression)
384 EXPECT_EQ((
a == a_neg),
true);
388 EXPECT_EQ((
a == a_neg),
true);
391TEST(secp256k1, MontgomeryMulBigBug)
396 EXPECT_EQ((a_sqr == expected),
true);
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
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 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.
constexpr uint64_t get_msb() const
Entry point for Barretenberg command-line interface.
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
General class for prime fields see Prime field documentation["field documentation"] for general imple...
static constexpr field cube_root_of_unity()
static constexpr field one()
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
BB_INLINE constexpr field sqr() const noexcept
constexpr uint256_t uint256_t_no_montgomery_conversion() const noexcept
static BB_INLINE void __copy(const field &a, field &r) noexcept
BB_INLINE constexpr void self_from_montgomery_form() &noexcept
BB_INLINE constexpr void self_to_montgomery_form() &noexcept
static constexpr field zero()