4#include <gtest/gtest.h>
18 while (res >= test_fq_mod) {
28 for (
size_t i = 0; i < n; ++i) {
38 if (expected < a_raw) {
39 expected -= test_fq_mod;
42 EXPECT_EQ(result, expected);
49 for (
size_t i = 0; i < n; ++i) {
59 if (expected > a_raw) {
60 expected += test_fq_mod;
63 EXPECT_EQ(result, expected);
67TEST(secp256r1, TestToMontgomeryForm)
70 for (
size_t i = 0; i < n; ++i) {
74#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
83 montgomery_result.
data[0], montgomery_result.
data[1], montgomery_result.
data[2], montgomery_result.
data[3]
85 EXPECT_EQ(result, expected);
89TEST(secp256r1, TestFromMontgomeryForm)
92 for (
size_t i = 0; i < n; ++i) {
103 for (
size_t i = 0; i < n; ++i) {
117 EXPECT_EQ(result, expected);
124 for (
size_t i = 0; i < n; ++i) {
134 EXPECT_EQ(result, expected);
148TEST(secp256r1, GeneratorOnCurve)
160TEST(secp256r1, RandomAffineElement)
171 EXPECT_EQ(
a ==
b,
true);
172 EXPECT_EQ(
a ==
a,
true);
174 b.self_set_infinity();
176 EXPECT_EQ(
a ==
b,
false);
179 EXPECT_EQ(
a == c,
false);
181 a.self_set_infinity();
183 EXPECT_EQ(
a ==
b,
true);
186TEST(secp256r1, CheckGroupModulus)
197TEST(secp256r1, AddExceptionTestInfinity)
213 result = lhs + rhs_b;
215 EXPECT_EQ(lhs == result,
true);
220 EXPECT_EQ(rhs == result,
true);
223TEST(secp256r1, AddExceptionTestDbl)
233 expected = lhs.
dbl();
235 EXPECT_EQ(result == expected,
true);
238TEST(secp256r1, AddDblConsistency)
254TEST(secp256r1, AddDblConsistencyRepeated)
274 EXPECT_EQ(result == expected,
true);
277TEST(secp256r1, MixedAddExceptionTestInfinity)
294 EXPECT_EQ(rhs_c == result,
true);
297TEST(secp256r1, MixedAddExceptionTestDbl)
307 expected = lhs.
dbl();
309 EXPECT_EQ(result == expected,
true);
312TEST(secp256r1, AddMixedAddConsistencyCheck)
321 add_result = lhs + rhs_b;
322 mixed_add_result = lhs + rhs;
324 EXPECT_EQ(add_result == mixed_add_result,
true);
329 for (
size_t i = 0; i < 100; ++i) {
333 EXPECT_EQ(affine_test.
on_curve(),
true);
338 size_t num_points = 2;
341 for (
size_t i = 0; i < num_points; ++i) {
345 normalized[i] = points[i];
347 secp256r1::g1::element::batch_normalize(&normalized[0], num_points);
349 for (
size_t i = 0; i < num_points; ++i) {
354 zz = points[i].z.
sqr();
355 zzz = points[i].z * zz;
356 result_x = normalized[i].x * zz;
357 result_y = normalized[i].y * zzz;
359 EXPECT_EQ((result_x == points[i].x),
true);
360 EXPECT_EQ((result_y == points[i].y),
true);
364TEST(secp256r1, GroupExponentiationZeroAndOne)
379TEST(secp256r1, GroupExponentiationConsistencyCheck)
393 EXPECT_EQ(result == expected,
true);
401TEST(secp256r1, AdditionSubtractionRegressionCheck)
403 secp256r1::fq fq1(
uint256_t{ 0xfffffe0000000200, 0x200fffff9ff, 0xfffffbfffffffe00, 0xfffffbff00000400 });
412 EXPECT_EQ(fq1 + fq1,
fq2 +
fq2);
442#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
443TEST(secp256r1, MontgomeryMulBigBug)
446 a.
data[0] = 0xC5BF4F6AFF993D09;
447 a.data[1] = 0xA3361BDA67E62E0E;
448 a.data[2] = 0xAAAAAAAAAAAAAAAA;
449 a.data[3] = 0xFFFFFFFFE38E38E3;
451 secp256r1::fr expected(
uint256_t{ 0x57abc6aa0349c084, 0x65b21b232a4cb7a5, 0x5ba781948b0fcd6e, 0xd6e9e0644bda12f7 });
452 EXPECT_EQ((a_sqr == expected),
true);
456TEST(secp256r1, CheckPrecomputedGenerators)
458 ASSERT_TRUE((bb::check_precomputed_generators<secp256r1::g1, "biggroup offset generator", 1UL>()));
459 ASSERT_TRUE((bb::check_precomputed_generators<secp256r1::g1, "biggroup table offset generator", 1UL>()));
467GTEST_API_
int main(
int argc,
char** argv)
469 testing::InitGoogleTest(&argc, argv);
470 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
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
virtual uint256_t get_random_uint256()=0
uintx< uint256_t > uint512_t
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
uintx< uint512_t > uint1024_t
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
field2< fq, Bn254Fq2Params > fq2
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()
static constexpr uint64_t modulus_3
static constexpr uint64_t modulus_2
static constexpr uint64_t modulus_0
static constexpr uint64_t modulus_1