13#include <gtest/gtest.h>
27#if defined(__SIZEOF_INT128__) && !defined(__wasm__)
28TEST(BN254Fr, CompileTimeMultiplication)
30 constexpr fr a{ 0x20565a572c565a66, 0x7bccd0f01f5f7bff, 0x63ec2beaad64711f, 0x624953caaf44a814 };
31 constexpr fr b{ 0xa17307a2108adeea, 0x74629976c14c5e2b, 0x9ce6f072ab1740ee, 0x398c753702b2bef0 };
32 constexpr fr expected{ 0xe8cdd06343386834, 0x8cbb3f556258a9af, 0x5aef2f34f2d66fd4, 0x2d8263c7e10213ca };
34 constexpr fr result =
a *
b;
35 static_assert(result == expected);
38TEST(BN254Fr, CompileTimeSquaring)
40 constexpr fr a{ 0x20565a572c565a66, 0x7bccd0f01f5f7bff, 0x63ec2beaad64711f, 0x624953caaf44a814 };
41 constexpr fr expected{ 0x3e928bdb06267b99, 0x1e5834571f52dfbf, 0x3d63bdf9bf7d0d4b, 0x353bb31adaa033c7 };
43 constexpr fr result =
a.
sqr();
44 static_assert(result == expected);
47TEST(BN254Fr, CompileTimeAddition)
49 constexpr fr a{ 0x20565a572c565a66, 0x7bccd0f01f5f7bff, 0x63ec2beaad64711f, 0x624953caaf44a814 };
50 constexpr fr b{ 0xa17307a2108adeea, 0x74629976c14c5e2b, 0x9ce6f072ab1740ee, 0x398c753702b2bef0 };
51 constexpr fr expected{ 0x3a0576d15ce1394e, 0x9fc799d5ed38f908, 0x903290f055790153, 0x3b0d2c1bef9426b1 };
53 constexpr fr result =
a +
b;
54 static_assert(result == expected);
57TEST(BN254Fr, CompileTimeSubtraction)
59 constexpr fr a{ 0xcfbcfcf457cf2d38, 0x7b27af26ce62aa61, 0xf0378e90d48f2b92, 0x4734b22cb21ded };
60 constexpr fr b{ 0x569fdb1db5198770, 0x446ddccef8347d52, 0xef215227182d22a, 0x8281b4fb109306 };
61 constexpr fr expected{ 0xe10cfe82b5a5ca, 0x8721a2e8c9a10e32, 0x51e604db660f0a22, 0x608d4fe2f404cb3b };
63 constexpr fr result =
a -
b;
64 static_assert(result == expected);
68TEST(BN254Fr, CompileTimeInversion)
70 constexpr fr a{ 0x20565a572c565a66, 0x7bccd0f01f5f7bff, 0x63ec2beaad64711f, 0x624953caaf44a814 };
80TEST(BN254Fr, MultiplicativeGenerator)
85TEST(BN254Fr, SplitIntoEndomorphismScalars)
88 fr k1 = { 0, 0, 0, 0 };
89 fr k2 = { 0, 0, 0, 0 };
93 fr result{ 0, 0, 0, 0 };
100 result = k1 - result;
103 EXPECT_EQ(result, k);
106TEST(BN254Fr, SplitIntoEndomorphismScalarsSimple)
108 fr input = { 1, 0, 0, 0 };
109 fr k = { 0, 0, 0, 0 };
110 fr k1 = { 0, 0, 0, 0 };
111 fr k2 = { 0, 0, 0, 0 };
116 fr result{ 0, 0, 0, 0 };
121 result = k2 * lambda;
122 result = k1 - result;
125 for (
size_t i = 0; i < 4; ++i) {
126 EXPECT_EQ(result.data[i], k.
data[i]);
136TEST(BN254Fr, EquivalentRandomness)
139 auto random_lo =
fr(random_uint512.
lo);
140 auto random_hi =
fr(random_uint512.
hi);
143 EXPECT_EQ(random_lo + pow_2_256 * random_hi,
fr((random_uint512 % r).lo));
uint512_t get_random_uint512()
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Entry point for Barretenberg command-line interface.
field< Bn254FrParams > fr
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
static constexpr field cube_root_of_unity()
static constexpr field one()
static constexpr uint256_t modulus
static void split_into_endomorphism_scalars(const field &k, field &k1, field &k2)
constexpr field invert() const noexcept
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
BB_INLINE constexpr void self_from_montgomery_form() &noexcept
static constexpr field multiplicative_generator() noexcept
BB_INLINE constexpr void self_to_montgomery_form() &noexcept