Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pairing_points.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: complete, auditors: [Luke], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
12
13namespace bb {
14
22template <typename Curve_> class PairingPoints {
23 public:
24 using Curve = Curve_;
25 using Point = typename Curve::AffineElement;
26 using Fr = typename Curve::ScalarField;
27 using Fq = typename Curve::BaseField;
29
30 static constexpr size_t PUBLIC_INPUTS_SIZE = PAIRING_POINTS_SIZE;
31
32 // Array-like interface for Codec compatibility
34 static constexpr size_t SIZE = 2;
35
36 // Named accessors
37 Point& P0() { return _points[0]; }
38 Point& P1() { return _points[1]; }
39 const Point& P0() const { return _points[0]; }
40 const Point& P1() const { return _points[1]; }
41
42 PairingPoints() = default;
43 PairingPoints(const Point& p0, const Point& p1)
44 : _points{ p0, p1 }
45 {}
46
47 // Iterator support for range-based for (required by Codec)
48 auto begin() { return _points.begin(); }
49 auto end() { return _points.end(); }
50 auto begin() const { return _points.begin(); }
51 auto end() const { return _points.end(); }
52 static constexpr size_t size() { return SIZE; }
53
60 {
61 if (other.P0() == Point::infinity() || other.P1() == Point::infinity()) {
62 throw_or_abort("Cannot aggregate: incoming pairing points are at infinity (probably uninitialized).");
63 }
64 // If this is at infinity (default/uninitialized), just adopt the incoming points
65 if (P0() == Point::infinity() || P1() == Point::infinity()) {
66 *this = other;
67 return;
68 }
69 Fr aggregation_separator = Fr::random_element();
70 P0() = P0() + other.P0() * aggregation_separator;
71 P1() = P1() + other.P1() * aggregation_separator;
72 }
73
77 bool check() const
78 {
79 BB_BENCH_NAME("PairingPoints::check");
80 VerifierCK vck{};
81 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1423): Rename to verifier_pcs_key or vckey or
82 // something. Issue exists in many places besides just here.
83 return vck.pairing_check(P0(), P1());
84 }
85
86 private:
87 std::array<Point, 2> _points = { Point::infinity(), Point::infinity() };
88};
89
90} // namespace bb
91
92// Enable std::tuple_size for Codec compatibility (array-like deserialization)
93namespace std {
94template <typename Curve> struct tuple_size<bb::PairingPoints<Curve>> : std::integral_constant<size_t, 2> {};
95} // namespace std
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:225
An object storing two EC points that represent the inputs to a pairing check.
void aggregate(const PairingPoints< Curve > &other)
Aggregate the current pairing points with another set of pairing points using a random scalar.
static constexpr size_t size()
std::array< Point, 2 > _points
const Point & P1() const
static constexpr size_t PUBLIC_INPUTS_SIZE
static constexpr size_t SIZE
PairingPoints(const Point &p0, const Point &p1)
bool check() const
Verify the pairing equation e(P0, [1]₂) · e(P1, [x]₂) = 1.
typename Curve::BaseField Fq
typename Curve::AffineElement Point
PairingPoints()=default
const Point & P0() const
typename Curve::ScalarField Fr
bool pairing_check(const GroupElement &p0, const GroupElement &p1)
Verify the pairing equation e(P₀,[1]₂) · e(P₁,[x]₂) = [1]ₜ
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
typename Group::affine_element AffineElement
Definition grumpkin.hpp:65
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept
void throw_or_abort(std::string const &err)