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: 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
14
15namespace bb {
16
24template <typename Curve_> class PairingPoints {
25 public:
26 using Curve = Curve_;
28 using Point = typename Curve::AffineElement;
29 using Fr = typename Curve::ScalarField;
30 using Fq = typename Curve::BaseField;
32
33 static constexpr size_t PUBLIC_INPUTS_SIZE = PAIRING_POINTS_SIZE;
34
35 Point P0 = Point::infinity();
36 Point P1 = Point::infinity();
37
38 PairingPoints() = default;
39 PairingPoints(const Point& P0, const Point& P1)
40 : P0(P0)
41 , P1(P1)
42 {}
43
45 : PairingPoints(points[0], points[1])
46 {}
47
48 Point& operator[](size_t idx)
49 {
50 BB_ASSERT(idx < 2, "Index out of bounds");
51 return idx == 0 ? P0 : P1;
52 }
53
54 const Point& operator[](size_t idx) const
55 {
56 BB_ASSERT(idx < 2, "Index out of bounds");
57 return idx == 0 ? P0 : P1;
58 }
59
65 {
66 const std::span<const bb::fr, Point::PUBLIC_INPUTS_SIZE> P0_limbs(limbs_in.data(), Point::PUBLIC_INPUTS_SIZE);
67 const std::span<const bb::fr, Point::PUBLIC_INPUTS_SIZE> P1_limbs(limbs_in.data() + Point::PUBLIC_INPUTS_SIZE,
68 Point::PUBLIC_INPUTS_SIZE);
69 Point P0 = Point::reconstruct_from_public(P0_limbs);
70 Point P1 = Point::reconstruct_from_public(P1_limbs);
71
72 return PairingPoints<Curve>{ P0, P1 };
73 }
74
79 {
80 if (P0 == Point::infinity() || P1 == Point::infinity() || other.P0 == Point::infinity() ||
81 other.P1 == Point::infinity()) {
82 throw_or_abort("WARNING: Shouldn't be aggregating with Point at infinity! The pairing points are probably "
83 "uninitialized.");
84 }
85 Fr aggregation_separator = Fr::random_element();
86 P0 = P0 + other.P0 * aggregation_separator;
87 P1 = P1 + other.P1 * aggregation_separator;
88 }
89
93 bool check() const
94 {
95 VerifierCK pcs_vkey{};
96 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1423): Rename to verifier_pcs_key or vckey or
97 // something. Issue exists in many places besides just here.
98 return pcs_vkey.pairing_check(P0, P1);
99 }
100
101 bool operator==(const PairingPoints<Curve>& other) const = default;
102};
103
104} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:67
CommitmentKey object over a pairing group 𝔾₁.
An object storing two EC points that represent the inputs to a pairing check.
const Point & operator[](size_t idx) const
PairingPoints(std::array< Point, 2 > const &points)
PairingPoints(const Point &P0, const Point &P1)
void aggregate(const PairingPoints< Curve > &other)
Aggregate the current pairing points with another set of pairing points using a random scalar.
static PairingPoints< Curve > reconstruct_from_public(const std::span< const Fr, PUBLIC_INPUTS_SIZE > &limbs_in)
Reconstruct the pairing points from limbs stored on the public inputs.
bool operator==(const PairingPoints< Curve > &other) const =default
static constexpr size_t PUBLIC_INPUTS_SIZE
bool check() const
Perform the pairing check.
Point & operator[](size_t idx)
typename Curve::BaseField Fq
typename Curve::AffineElement Point
PairingPoints()=default
typename Curve::ScalarField Fr
bool pairing_check(const GroupElement &p0, const GroupElement &p1)
verifies a pairing equation over 2 points using the verifier SRS
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
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
static field random_element(numeric::RNG *engine=nullptr) noexcept
void throw_or_abort(std::string const &err)