7#include <gtest/gtest.h>
27TEST(BatchAffineAddPacked, MatchesCurveAffineAdd)
29 constexpr size_t W = PushSpanFq::W;
30 for (
size_t n : {
size_t{ 1 },
size_t{ 4 },
size_t{ 5 },
size_t{ 6 },
size_t{ 9 },
size_t{ 25 },
size_t{ 31 } }) {
34 for (
size_t i = 0; i < n; ++i) {
35 Affine
a = Element::random_element(&
engine);
36 Affine
b = Element::random_element(&
engine);
38 b = Affine(Element::random_element(&
engine));
47 std::vector<VecFq> dx((n / W) + 1), dy((n / W) + 1), xsum((n / W) + 1), inv((n / W) + 1);
51 for (
size_t i = 0; i < n; ++i) {
52 lhs.push_point(L[i].x, L[i].y);
53 rhs.push_point(R[i].x, R[i].y);
62 ASSERT_EQ(
out.size(), n);
63 for (
size_t i = 0; i < n; ++i) {
64 const bool full = i <
out.num_full_vectors() * W;
65 const fq gx = full ?
out.x[i / W].to_array()[i % W] :
out.x.tail_data()[i % W];
66 const fq gy = full ?
out.y[i / W].to_array()[i % W] :
out.y.tail_data()[i % W];
67 EXPECT_EQ(gx, ref[i].x) <<
"n=" << n <<
" i=" << i;
68 EXPECT_EQ(gy, ref[i].y) <<
"n=" << n <<
" i=" << i;
76TEST(BatchAffineAddPacked, OutAliasesLhs)
78 constexpr size_t W = PushSpanFq::W;
79 for (
size_t n : {
size_t{ 1 },
size_t{ 5 },
size_t{ 6 },
size_t{ 25 },
size_t{ 31 } }) {
83 for (
size_t i = 0; i < n; ++i) {
84 Affine
a = Element::random_element(&
engine);
85 Affine
b = Element::random_element(&
engine);
87 b = Affine(Element::random_element(&
engine));
95 std::vector<VecFq> dx((n / W) + 1), dy((n / W) + 1), xsum((n / W) + 1), inv((n / W) + 1);
99 for (
size_t i = 0; i < n; ++i) {
100 lhs.push_point(L[i].x, L[i].y);
101 rhs.push_point(R[i].x, R[i].y);
110 ASSERT_EQ(
out.size(), n);
111 for (
size_t i = 0; i < n; ++i) {
112 const bool full = i <
out.num_full_vectors() * W;
113 const fq gx = full ?
out.x[i / W].to_array()[i % W] :
out.x.tail_data()[i % W];
114 const fq gy = full ?
out.y[i / W].to_array()[i % W] :
out.y.tail_data()[i % W];
115 EXPECT_EQ(gx, ref[i].x) <<
"n=" << n <<
" i=" << i;
116 EXPECT_EQ(gy, ref[i].y) <<
"n=" << n <<
" i=" << i;
123TEST(BatchAffineAddPacked, MatchesCurveDouble)
125 constexpr size_t W = PushSpanFq::W;
126 for (
size_t n : {
size_t{ 1 },
size_t{ 4 },
size_t{ 5 },
size_t{ 6 },
size_t{ 9 },
size_t{ 25 },
size_t{ 31 } }) {
129 for (
size_t i = 0; i < n; ++i) {
130 Affine
a = Element::random_element(&
engine);
142 for (
size_t i = 0; i < n; ++i) {
143 in.push_point(P[i].x, P[i].y);
151 ASSERT_EQ(
out.size(), n);
152 for (
size_t i = 0; i < n; ++i) {
153 const bool full = i <
out.num_full_vectors() * W;
154 const fq gx = full ?
out.x[i / W].to_array()[i % W] :
out.x.tail_data()[i % W];
155 const fq gy = full ?
out.y[i / W].to_array()[i % W] :
out.y.tail_data()[i % W];
156 EXPECT_EQ(gx, ref[i].x) <<
"n=" << n <<
" i=" << i;
157 EXPECT_EQ(gy, ref[i].y) <<
"n=" << n <<
" i=" << i;
167TEST(BatchAffineAddPacked, IndexedAddMatchesScalar)
169 constexpr size_t W = PushSpanFq::W;
170 constexpr size_t CAP_VFS = (64 / W) + 1;
171 for (
size_t np : {
size_t{ 1 },
181 for (
size_t k = 0; k < np; ++k) {
182 Affine
a = Element::random_element(&
engine);
183 Affine
b = Element::random_element(&
engine);
185 b = Affine(Element::random_element(&
engine));
189 pairs[k] = {
static_cast<uint32_t
>(k),
static_cast<uint32_t
>(np + k) };
194 bb::group_elements::batch_affine_add_indexed_impl<Affine, fq>(
195 scalar_buckets.data(),
pairs.data(), np, scalar_scratch.data());
200 for (
size_t i = 0; i < base.size(); ++i) {
201 col_x[i] = base[i].x;
202 col_y[i] = base[i].y;
205 std::vector<VecFq> lx(CAP_VFS), ly(CAP_VFS), rx(CAP_VFS), ry(CAP_VFS), ox(CAP_VFS), oy(CAP_VFS);
217 for (
size_t k = 0; k < np; ++k) {
218 EXPECT_EQ(col_x[k], scalar_buckets[k].x) <<
"np=" << np <<
" k=" << k;
219 EXPECT_EQ(col_y[k], scalar_buckets[k].y) <<
"np=" << np <<
" k=" << k;
226TEST(BatchAffineAddPacked, IndexedDoubleMatchesScalar)
228 constexpr size_t W = PushSpanFq::W;
229 constexpr size_t CAP_VFS = (64 / W) + 1;
231 {
size_t{ 1 },
size_t{ 5 },
size_t{ 6 },
size_t{ 31 },
size_t{ 65 },
size_t{ 130 },
size_t{ 300 } }) {
233 std::vector<uint32_t>
indices(np);
234 for (
size_t k = 0; k < np; ++k) {
235 base[k] = Affine(Element::random_element(&
engine));
236 indices[k] =
static_cast<uint32_t
>(k);
241 bb::group_elements::batch_affine_double_indexed_impl<Affine, fq>(
242 scalar_buckets.data(),
indices.data(), np, scalar_scratch.data());
246 for (
size_t i = 0; i < np; ++i) {
247 col_x[i] = base[i].x;
248 col_y[i] = base[i].y;
261 for (
size_t k = 0; k < np; ++k) {
262 EXPECT_EQ(col_x[k], scalar_buckets[k].x) <<
"np=" << np <<
" k=" << k;
263 EXPECT_EQ(col_y[k], scalar_buckets[k].y) <<
"np=" << np <<
" k=" << k;
270TEST(BatchAffineAddPacked, IndexedAddScalarSoaMatchesAos)
272 for (
size_t np : {
size_t{ 1 },
size_t{ 5 },
size_t{ 31 },
size_t{ 130 },
size_t{ 300 } }) {
275 for (
size_t k = 0; k < np; ++k) {
276 Affine
a = Element::random_element(&
engine);
277 Affine
b = Element::random_element(&
engine);
279 b = Affine(Element::random_element(&
engine));
283 pairs[k] = {
static_cast<uint32_t
>(k),
static_cast<uint32_t
>(np + k) };
288 bb::group_elements::batch_affine_add_indexed_impl<Affine, fq>(aos.data(),
pairs.data(), np, aos_scratch.data());
292 for (
size_t i = 0; i < base.size(); ++i) {
293 col_x[i] = base[i].x;
294 col_y[i] = base[i].y;
300 for (
size_t k = 0; k < np; ++k) {
301 EXPECT_EQ(col_x[k], aos[k].x) <<
"np=" << np <<
" k=" << k;
302 EXPECT_EQ(col_y[k], aos[k].y) <<
"np=" << np <<
" k=" << k;
307TEST(BatchAffineAddPacked, IndexedDoubleScalarSoaMatchesAos)
309 for (
size_t np : {
size_t{ 1 },
size_t{ 5 },
size_t{ 31 },
size_t{ 130 },
size_t{ 300 } }) {
311 std::vector<uint32_t>
indices(np);
312 for (
size_t k = 0; k < np; ++k) {
313 base[k] = Affine(Element::random_element(&
engine));
314 indices[k] =
static_cast<uint32_t
>(k);
319 bb::group_elements::batch_affine_double_indexed_impl<Affine, fq>(
320 aos.data(),
indices.data(), np, aos_scratch.data());
324 for (
size_t i = 0; i < np; ++i) {
325 col_x[i] = base[i].x;
326 col_y[i] = base[i].y;
332 for (
size_t k = 0; k < np; ++k) {
333 EXPECT_EQ(col_x[k], aos[k].x) <<
"np=" << np <<
" k=" << k;
334 EXPECT_EQ(col_y[k], aos[k].y) <<
"np=" << np <<
" k=" << k;
TEST(acir_formal_proofs, uint_terms_add)
Tests 128-bit unsigned addition Verifies that the ACIR implementation of addition is correct Executio...
Parameters defining the base field of the BN254 curve.
group_elements::affine_element< Fq, Fr, Params > affine_element
group_elements::element< Fq, Fr, Params > element
void batch_affine_add_indexed_scalar(AffineColumnSpan< Field > &buckets, const std::pair< uint32_t, uint32_t > *pairs, size_t num_pairs, Field *scratch) noexcept
void batch_affine_add(const VectorAffineElementPushSpan< Params > &lhs, const VectorAffineElementPushSpan< Params > &rhs, VectorAffineElementPushSpan< Params > &out, BatchAffineAddScratch< Params > &s) noexcept
void batch_affine_double(const VectorAffineElementPushSpan< Params > &in, VectorAffineElementPushSpan< Params > &out, BatchAffineDoubleScratch< Params > &s) noexcept
void batch_affine_double_indexed_scalar(AffineColumnSpan< Field > &buckets, const uint32_t *indices, size_t num_points, Field *scratch) noexcept
void batch_affine_double_indexed_packed(AffineColumnSpan< typename VectorField< Params >::Field > &buckets, const uint32_t *indices, size_t num_points, VectorAffineElementPushSpan< Params > &in, VectorAffineElementPushSpan< Params > &out, BatchAffineDoubleScratch< Params > &scratch) noexcept
const std::pair< uint32_t, uint32_t > * pairs
void batch_affine_add_indexed_packed(AffineColumnSpan< typename VectorField< Params >::Field > &buckets, const std::pair< uint32_t, uint32_t > *pairs, size_t num_pairs, VectorAffineElementPushSpan< Params > &lhs, VectorAffineElementPushSpan< Params > &rhs, VectorAffineElementPushSpan< Params > &out, BatchAffineAddScratch< Params > &scratch) noexcept
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
field< Bn254FqParams > fq
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
bb::VectorAffineElementPushSpan< BaseParams > lhs
bb::VectorAffineElementPushSpan< BaseParams > out
bb::VectorAffineElementPushSpan< BaseParams > rhs