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// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
11#include <cstddef>
12#include <cstdint>
13
14namespace bb {
15
23template <typename Curve> class BatchedAffineAddition {
24 using G1 = typename Curve::AffineElement;
25 using Fr = typename Curve::ScalarField;
26 using Fq = typename Curve::BaseField;
27
28 // Struct describing a set of points to be reduced to num-sequence-counts-many points via summation of each sequence
30 std::vector<size_t> sequence_counts;
31 std::span<G1> points;
32 std::span<Fq> scratch_space;
33 };
34
35 // Collection of addition sequences to be handled by each thread
36 struct ThreadData {
38 std::vector<std::vector<size_t>> sequence_tags; // allows for the recombining of sequences split across threads
39 };
40
41 public:
66 static std::vector<G1> add_in_place(const std::span<G1>& points, const std::vector<size_t>& sequence_counts);
67
68 private:
81 static ThreadData construct_thread_data(const std::span<G1>& points,
82 const std::vector<size_t>& sequence_counts,
83 const std::span<Fq>& scratch_space);
84
93 static std::span<Fq> batch_compute_point_addition_slope_inverses(const AdditionSequences& add_sequences);
94
101 static void batched_affine_add_in_place(AdditionSequences add_sequences);
102
116 static inline G1 affine_add_with_denominator(const G1& point_1, const G1& point_2, const Fq& denominator)
117 {
118 const auto& x1 = point_1.x;
119 const auto& y1 = point_1.y;
120 const auto& x2 = point_2.x;
121 const auto& y2 = point_2.y;
122
123 const Fq lambda = denominator * (y2 - y1);
124 Fq x3 = lambda.sqr() - x2 - x1;
125 Fq y3 = lambda * (x1 - x3) - y1;
126 return { x3, y3 };
127 }
128};
129
130} // 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:56
Entry point for Barretenberg command-line interface.
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