4#include <gtest/gtest.h>
13TEST(secp256r1, GeneratorOnCurve)
19TEST(secp256r1, RandomElement)
25TEST(secp256r1, RandomAffineElement)
36 EXPECT_EQ(
a ==
b,
true);
37 EXPECT_EQ(
a ==
a,
true);
39 b.self_set_infinity();
41 EXPECT_EQ(
a ==
b,
false);
44 EXPECT_EQ(
a == c,
false);
46 a.self_set_infinity();
48 EXPECT_EQ(
a ==
b,
true);
51TEST(secp256r1, CheckGroupModulus)
62TEST(secp256r1, AddExceptionTestInfinity)
80 EXPECT_EQ(lhs == result,
true);
85 EXPECT_EQ(rhs == result,
true);
88TEST(secp256r1, AddExceptionTestDbl)
100 EXPECT_EQ(result == expected,
true);
103TEST(secp256r1, AddDblConsistency)
119TEST(secp256r1, AddDblConsistencyRepeated)
139 EXPECT_EQ(result == expected,
true);
142TEST(secp256r1, MixedAddExceptionTestInfinity)
159 EXPECT_EQ(rhs_c == result,
true);
162TEST(secp256r1, MixedAddExceptionTestDbl)
172 expected = lhs.
dbl();
174 EXPECT_EQ(result == expected,
true);
177TEST(secp256r1, 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 secp256r1::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(secp256r1, GroupExponentiationZeroAndOne)
244TEST(secp256r1, GroupExponentiationConsistencyCheck)
258 EXPECT_EQ(result == expected,
true);
266TEST(secp256r1, AdditionSubtractionRegressionCheck)
268 secp256r1::fq fq1(
uint256_t{ 0xfffffe0000000200, 0x200fffff9ff, 0xfffffbfffffffe00, 0xfffffbff00000400 });
277 EXPECT_EQ(fq1 + fq1,
fq2 +
fq2);
307#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
308TEST(secp256r1, MontgomeryMulBigBug)
311 a.
data[0] = 0xC5BF4F6AFF993D09;
312 a.
data[1] = 0xA3361BDA67E62E0E;
313 a.
data[2] = 0xAAAAAAAAAAAAAAAA;
314 a.
data[3] = 0xFFFFFFFFE38E38E3;
316 secp256r1::fr expected(
uint256_t{ 0x57abc6aa0349c084, 0x65b21b232a4cb7a5, 0x5ba781948b0fcd6e, 0xd6e9e0644bda12f7 });
317 EXPECT_EQ((a_sqr == expected),
true);
321TEST(secp256r1, CheckPrecomputedGenerators)
323 ASSERT_TRUE((bb::check_precomputed_generators<secp256r1::g1, "biggroup offset generator", 1UL>()));
324 ASSERT_TRUE((bb::check_precomputed_generators<secp256r1::g1, "biggroup table offset generator", 1UL>()));
332GTEST_API_
int main(
int argc,
char** argv)
334 testing::InitGoogleTest(&argc, argv);
335 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
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()