Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
verification_key.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
22
23#include <cstddef>
24#include <memory>
25#include <string_view>
26
27namespace bb {
28
29template <class Curve> class VerifierCommitmentKey;
30
36template <> class VerifierCommitmentKey<curve::BN254> {
37 public:
39 using GroupElement = typename Curve::Element;
41
43
45 {
46 if (!srs) {
47 srs = srs::get_crs_factory<Curve>()->get_verifier_crs();
48 }
49 };
50 bool operator==(const VerifierCommitmentKey&) const = default;
51
52 bool initialized() const { return srs != nullptr; }
53
55 {
56 initialize();
57 return srs->get_g1_identity();
58 }
59
67 bool pairing_check(const GroupElement& p0, const GroupElement& p1)
68 {
69 initialize();
70 Commitment pairing_points[2]{ p0, p1 };
71 // The final pairing check of step 12.
72 Curve::TargetField result =
73 bb::pairing::reduced_ate_pairing_batch_precomputed(pairing_points, srs->get_precomputed_g2_lines(), 2);
74
75 return (result == Curve::TargetField::one());
76 }
77
78 private:
80};
81
87template <> class VerifierCommitmentKey<curve::Grumpkin> {
88 public:
90 using GroupElement = typename Curve::Element;
92
100 VerifierCommitmentKey(size_t num_points, const std::shared_ptr<bb::srs::factories::CrsFactory<Curve>>& crs_factory)
101 : srs(crs_factory->get_crs(num_points))
102 {}
103
104 VerifierCommitmentKey(size_t num_points) { srs = srs::get_crs_factory<Curve>()->get_crs(num_points); }
105
107
108 bool operator==(const VerifierCommitmentKey&) const = default;
109
110 bool initialized() const { return srs != nullptr; }
111
112 Commitment get_g1_identity() const { return srs->get_g1_identity(); }
113
114 std::span<const Commitment> get_monomial_points() const { return srs->get_monomial_points(); }
115
116 private:
118};
119
120} // namespace bb
bool operator==(const VerifierCommitmentKey &) const =default
std::shared_ptr< bb::srs::factories::Crs< Curve > > srs
bool pairing_check(const GroupElement &p0, const GroupElement &p1)
verifies a pairing equation over 2 points using the verifier SRS
typename Curve::AffineElement Commitment
std::span< const Commitment > get_monomial_points() const
VerifierCommitmentKey(size_t num_points, const std::shared_ptr< bb::srs::factories::CrsFactory< Curve > > &crs_factory)
Construct a new IPA Verification Key object from existing SRS.
bool operator==(const VerifierCommitmentKey &) const =default
std::shared_ptr< bb::srs::factories::Crs< Curve > > srs
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
typename Group::element Element
Definition grumpkin.hpp:55
typename Group::affine_element AffineElement
Definition grumpkin.hpp:56
fq12 reduced_ate_pairing_batch_precomputed(const g1::affine_element *P_affines, const miller_lines *lines, size_t num_points)
Entry point for Barretenberg command-line interface.
@ BN254
Definition types.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13