Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
batched_affine_addition.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <cstdint>
7
8namespace bb {
9
17template <typename Curve> class BatchedAffineAddition {
18 using G1 = typename Curve::AffineElement;
19 using Fr = typename Curve::ScalarField;
20 using Fq = typename Curve::BaseField;
21
22 // Struct describing a set of points to be reduced to num-sequence-counts-many points via summation of each sequence
24 std::vector<size_t> sequence_counts;
25 std::span<G1> points;
26 std::span<Fq> scratch_space;
27 };
28
29 // Collection of addition sequences to be handled by each thread
30 struct ThreadData {
32 std::vector<std::vector<size_t>> sequence_tags; // allows for the recombining of sequences split across threads
33 };
34
35 public:
60 static std::vector<G1> add_in_place(const std::span<G1>& points, const std::vector<size_t>& sequence_counts);
61
62 private:
75 static ThreadData construct_thread_data(const std::span<G1>& points,
76 const std::vector<size_t>& sequence_counts,
77 const std::span<Fq>& scratch_space);
78
87 static std::span<Fq> batch_compute_point_addition_slope_inverses(const AdditionSequences& add_sequences);
88
95 static void batched_affine_add_in_place(AdditionSequences add_sequences);
96
110 static inline G1 affine_add_with_denominator(const G1& point_1, const G1& point_2, const Fq& denominator)
111 {
112 const auto& x1 = point_1.x;
113 const auto& y1 = point_1.y;
114 const auto& x2 = point_2.x;
115 const auto& y2 = point_2.y;
116
117 const Fq lambda = denominator * (y2 - y1);
118 Fq x3 = lambda.sqr() - x2 - x1;
119 Fq y3 = lambda * (x1 - x3) - y1;
120 return { x3, y3 };
121 }
122};
123
124} // namespace bb
Class for handling fast batched affine addition of large sets of EC points.
static std::vector< G1 > add_in_place(const std::span< G1 > &points, const std::vector< size_t > &sequence_counts)
Given a set of points and sequence counts, peform addition to reduce each sequence to a single point.
static void batched_affine_add_in_place(AdditionSequences add_sequences)
Internal method for in-place summation of a single set of addition sequences.
static ThreadData construct_thread_data(const std::span< G1 > &points, const std::vector< size_t > &sequence_counts, const std::span< Fq > &scratch_space)
Construct the set of AdditionSequences to be handled by each thread.
typename Curve::ScalarField Fr
typename Curve::AffineElement G1
static G1 affine_add_with_denominator(const G1 &point_1, const G1 &point_2, const Fq &denominator)
Add two affine elements with the inverse in the slope term \lambda provided as input.
static std::span< Fq > batch_compute_point_addition_slope_inverses(const AdditionSequences &add_sequences)
Batch compute inverses needed for a set of affine point addition sequences.
typename Group::affine_element AffineElement
Definition grumpkin.hpp:63
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::vector< AdditionSequences > addition_sequences
std::vector< std::vector< size_t > > sequence_tags