4#include <gtest/gtest.h>
13TEST(secp256r1, CurveCoefficients)
22TEST(secp256r1, GeneratorOnCurve)
28 EXPECT_EQ(result.
x, expected_x);
29 EXPECT_EQ(result.
y, expected_y);
33TEST(secp256r1, RandomElement)
39TEST(secp256r1, RandomAffineElement)
50 EXPECT_EQ(
a ==
b,
true);
51 EXPECT_EQ(
a ==
a,
true);
53 b.self_set_infinity();
55 EXPECT_EQ(
a ==
b,
false);
58 EXPECT_EQ(
a == c,
false);
60 a.self_set_infinity();
62 EXPECT_EQ(
a ==
b,
true);
65TEST(secp256r1, CheckGroupModulus)
76TEST(secp256r1, AddExceptionTestInfinity)
94 EXPECT_EQ(lhs == result,
true);
99 EXPECT_EQ(rhs == result,
true);
102TEST(secp256r1, AddExceptionTestDbl)
112 expected = lhs.
dbl();
114 EXPECT_EQ(result == expected,
true);
117TEST(secp256r1, AddDblConsistency)
133TEST(secp256r1, AddDblConsistencyRepeated)
153 EXPECT_EQ(result == expected,
true);
156TEST(secp256r1, MixedAddExceptionTestInfinity)
173 EXPECT_EQ(rhs_c == result,
true);
176TEST(secp256r1, MixedAddExceptionTestDbl)
186 expected = lhs.
dbl();
188 EXPECT_EQ(result == expected,
true);
191TEST(secp256r1, AddMixedAddConsistencyCheck)
200 add_result = lhs + rhs_b;
201 mixed_add_result = lhs + rhs;
203 EXPECT_EQ(add_result == mixed_add_result,
true);
208 for (
size_t i = 0; i < 100; ++i) {
212 EXPECT_EQ(affine_test.
on_curve(),
true);
217 size_t num_points = 2;
220 for (
size_t i = 0; i < num_points; ++i) {
224 normalized[i] = points[i];
226 secp256r1::g1::element::batch_normalize(&normalized[0], num_points);
228 for (
size_t i = 0; i < num_points; ++i) {
233 zz = points[i].z.
sqr();
234 zzz = points[i].z * zz;
235 result_x = normalized[i].x * zz;
236 result_y = normalized[i].y * zzz;
238 EXPECT_EQ((result_x == points[i].x),
true);
239 EXPECT_EQ((result_y == points[i].y),
true);
243TEST(secp256r1, GroupExponentiationZeroAndOne)
258TEST(secp256r1, GroupExponentiationConsistencyCheck)
272 EXPECT_EQ(result == expected,
true);
280TEST(secp256r1, AdditionSubtractionRegressionCheck)
282 secp256r1::fq fq1(
uint256_t{ 0xfffffe0000000200, 0x200fffff9ff, 0xfffffbfffffffe00, 0xfffffbff00000400 });
291 EXPECT_EQ(fq1 + fq1,
fq2 +
fq2);
321#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
322TEST(secp256r1, MontgomeryMulBigBug)
325 a.
data[0] = 0xC5BF4F6AFF993D09;
326 a.
data[1] = 0xA3361BDA67E62E0E;
327 a.
data[2] = 0xAAAAAAAAAAAAAAAA;
328 a.
data[3] = 0xFFFFFFFFE38E38E3;
330 secp256r1::fr expected(
uint256_t{ 0x57abc6aa0349c084, 0x65b21b232a4cb7a5, 0x5ba781948b0fcd6e, 0xd6e9e0644bda12f7 });
331 EXPECT_EQ((a_sqr == expected),
true);
335TEST(secp256r1, CheckPrecomputedGenerators)
337 ASSERT_TRUE((bb::check_precomputed_generators<secp256r1::g1, "biggroup offset generator", 1UL>()));
338 ASSERT_TRUE((bb::check_precomputed_generators<secp256r1::g1, "biggroup table offset generator", 1UL>()));
346GTEST_API_
int main(
int argc,
char** argv)
348 testing::InitGoogleTest(&argc, argv);
349 return RUN_ALL_TESTS();
int main(int argc, char **argv)
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
Entry point for Barretenberg command-line interface.
field2< fq, Bn254Fq2Params > fq2
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 one()
static field random_element(numeric::RNG *engine=nullptr) noexcept
BB_INLINE constexpr field sqr() const noexcept
static constexpr uint256_t modulus_minus_two
static BB_INLINE void __copy(const field &a, field &r) noexcept
static constexpr field zero()