7#include <gtest/gtest.h>
22 v = fq::random_element(&
engine);
23 }
while (v.is_zero());
29template <
size_t W>
void check_compute_lane_inverses()
32 fq product = fq::one();
34 v = fq::random_element(&
engine);
37 const fq inv_product = product.
invert();
39 for (
size_t k = 0; k < W; ++k) {
40 EXPECT_EQ(inv[k],
a[k].invert());
41 EXPECT_EQ(inv[k] *
a[k], fq::one());
45TEST(BatchInversion, ComputeLaneInversesWidth5)
47 check_compute_lane_inverses<5>();
50TEST(BatchInversion, ComputeLaneInversesWidth1)
52 check_compute_lane_inverses<1>();
55TEST(BatchInversion, ComputeLaneInversesWidth8)
57 check_compute_lane_inverses<8>();
62TEST(BatchInversion, BatchInvertSpan)
64 constexpr size_t W = PushSpanFq::W;
66 {
size_t{ 0 },
size_t{ 1 },
size_t{ 4 },
size_t{ 5 },
size_t{ 6 },
size_t{ 9 },
size_t{ 25 },
size_t{ 31 } }) {
75 for (
const auto& v : src) {
81 ASSERT_EQ(
out.size(), n);
82 for (
size_t i = 0; i < n; ++i) {
83 const fq got = (i <
out.num_full_vectors() * W) ?
out[i / W].to_array()[i % W] :
out.tail_data()[i % W];
84 EXPECT_EQ(got, src[i].invert()) <<
"n=" << n <<
" i=" << i;
85 EXPECT_EQ(got * src[i], fq::one());
87 const fq in_i = (i < in.num_full_vectors() * W) ? in[i / W].to_array()[i % W] : in.tail_data()[i % W];
88 EXPECT_EQ(in_i, src[i]) <<
"in mutated at n=" << n <<
" i=" << i;
97TEST(BatchInversionDeath, ZeroInputAborts)
99 constexpr size_t W = PushSpanFq::W;
100 for (
size_t zero_at : {
size_t{ 2 },
size_t{ 6 } }) {
106 for (
size_t i = 0; i < n; ++i) {
107 in.push(i == zero_at ? fq::zero() : random_nonzero());
115TEST(BatchInversionDeath, AliasedOutputAborts)
117 constexpr size_t W = PushSpanFq::W;
121 for (
size_t i = 0; i < n; ++i) {
122 span.push(random_nonzero());
TEST(acir_formal_proofs, uint_terms_add)
Tests 128-bit unsigned addition Verifies that the ACIR implementation of addition is correct Executio...
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
field< Bn254FqParams > fq
void batch_invert(const VectorFieldPushSpan< Params > &in, VectorFieldPushSpan< Params > &out) noexcept
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
bb::VectorAffineElementPushSpan< BaseParams > out
constexpr field invert() const noexcept