Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
decider_keys.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
11
12namespace bb {
13
14template <IsUltraOrMegaHonk Flavor_, size_t NUM_ = 2> struct DeciderProvingKeys_ {
15 public:
16 static_assert(NUM_ > 1, "Must have at least two decider proving keys.");
17 using Flavor = Flavor_;
18 using FF = typename Flavor::FF;
19 static constexpr size_t NUM = NUM_;
20 static constexpr size_t NUM_SUBRELATIONS = Flavor::NUM_SUBRELATIONS;
22
24 // The extended length here is the length of a composition of polynomials.
25 static constexpr size_t EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1) * (NUM - 1) + 1;
26 static constexpr size_t BATCHED_EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1 + NUM - 1) * (NUM - 1) + 1;
27
28 ArrayType _data; // we should not add any other data to this class
29
30 std::shared_ptr<DeciderPK> const& operator[](size_t idx) const { return _data[idx]; }
31 typename ArrayType::const_iterator begin() const { return _data.begin(); };
32 typename ArrayType::iterator begin() { return _data.begin(); };
33 typename ArrayType::const_iterator end() const { return _data.end(); };
34 typename ArrayType::iterator end() { return _data.end(); };
36 DeciderProvingKeys_(std::vector<std::shared_ptr<DeciderPK>> data)
37 {
38 BB_ASSERT_EQ(data.size(), NUM);
39 for (size_t idx = 0; idx < data.size(); idx++) {
40 _data[idx] = std::move(data[idx]);
41 }
42 };
43
63 template <size_t LENGTH, size_t skip_count = 0> auto row_to_univariates(size_t row_idx) const
64 {
65 auto prover_polynomials_views = get_polynomials_views();
66 std::array<Univariate<FF, LENGTH, 0, skip_count>, prover_polynomials_views[0].size()> results;
67 // Set the size corresponding to the number of rows in the execution trace
68 // Iterate over the prover polynomials' views corresponding to each proving key
69 for (size_t dpk_idx = 0; auto& get_all : prover_polynomials_views) {
70 // Iterate over all columns in the trace execution of an proving key and extract their value at row_idx.
71 for (auto [result, poly_ptr] : zip_view(results, get_all)) {
72 result.evaluations[dpk_idx] = poly_ptr[row_idx];
73 }
74 dpk_idx++;
75 }
76 return results;
77 }
78
79 typename Flavor::template ProverUnivariates<2> row_to_short_univariates(size_t row_idx) const
80 {
81 auto prover_polynomials_views = get_polynomials_views();
82 typename Flavor::template ProverUnivariates<2> results;
83 // Set the size corresponding to the number of rows in the execution trace
84 // Iterate over the prover polynomials' views corresponding to each proving key
85 for (size_t dpk_idx = 0; const auto& view : prover_polynomials_views) {
86 // Iterate over all columns in the trace execution of a proving key and extract their value at row_idx.
87 for (auto [result, poly_ptr] : zip_view(results.get_all(), view)) {
88 result.evaluations[dpk_idx] = poly_ptr[row_idx];
89 }
90 dpk_idx++;
91 }
92 return results;
93 }
94
95 private:
96 // Returns a vector containing pointer views to the prover polynomials corresponding to each proving key.
98 {
99 // As a practical measure, get the first proving key's view to deduce the array type
100 std::array<decltype(_data[0]->polynomials.get_all()), NUM> views;
101 for (size_t i = 0; i < NUM; i++) {
102 views[i] = _data[i]->polynomials.get_all();
103 }
104 return views;
105 }
106};
107
108template <IsUltraOrMegaHonk Flavor_, size_t NUM_ = 2> struct DeciderVerificationKeys_ {
109 static_assert(NUM_ > 1, "Must have at least two decider verification keys.");
110 using Flavor = Flavor_;
111 using FF = typename Flavor_::FF;
112 using Commitment = typename Flavor_::Commitment;
116
117 public:
118 static constexpr size_t NUM = NUM_;
119 static constexpr size_t BATCHED_EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1 + NUM - 1) * (NUM - 1) + 1;
121 std::shared_ptr<DeciderVK> const& operator[](size_t idx) const { return _data[idx]; }
122 typename ArrayType::iterator begin() { return _data.begin(); };
123 typename ArrayType::iterator end() { return _data.end(); };
124
126 DeciderVerificationKeys_(const std::vector<std::shared_ptr<DeciderVK>>& data)
127 {
128 BB_ASSERT_EQ(data.size(), NUM);
129 for (size_t idx = 0; idx < data.size(); idx++) {
130 _data[idx] = std::move(data[idx]);
131 }
132 };
133
147 {
148 const size_t num_commitments_to_fold = _data[0]->vk->get_all().size();
149 std::vector<std::vector<Commitment>> result(num_commitments_to_fold, std::vector<Commitment>(NUM));
150 for (size_t idx = 0; auto& commitment_at_idx : result) {
151 for (auto [elt, key] : zip_view(commitment_at_idx, _data)) {
152 elt = key->vk->get_all()[idx];
153 }
154 idx++;
155 }
156 return result;
157 }
158
164 {
165 const size_t num_commitments_to_fold = _data[0]->witness_commitments.get_all().size();
166 std::vector<std::vector<Commitment>> result(num_commitments_to_fold, std::vector<Commitment>(NUM));
167 for (size_t idx = 0; auto& commitment_at_idx : result) {
168 for (auto [elt, key] : zip_view(commitment_at_idx, _data)) {
169 elt = key->witness_commitments.get_all()[idx];
170 }
171 idx++;
172 }
173 return result;
174 }
175
181 {
182 const size_t num_alphas_to_fold = _data[0]->alphas.size();
183 std::vector<std::vector<FF>> result(num_alphas_to_fold, std::vector<FF>(NUM));
184 for (size_t idx = 0; auto& alpha_at_idx : result) {
185 for (auto [elt, key] : zip_view(alpha_at_idx, _data)) {
186 elt = key->alphas[idx];
187 }
188 idx++;
189 }
190 return result;
191 }
192
198 {
199 const size_t num_params_to_fold = _data[0]->relation_parameters.get_to_fold().size();
200 std::vector<std::vector<FF>> result(num_params_to_fold, std::vector<FF>(NUM));
201 for (size_t idx = 0; auto& params_at_idx : result) {
202 for (auto [elt, key] : zip_view(params_at_idx, _data)) {
203 elt = key->relation_parameters.get_to_fold()[idx];
204 }
205 idx++;
206 }
207 return result;
208 }
209};
210} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
The DeciderVerificationKey encapsulates all the necessary information for a Mega Honk Verifier to ver...
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
Curve::ScalarField FF
static constexpr size_t MAX_TOTAL_RELATION_LENGTH
static constexpr size_t NUM_SUBRELATIONS
const std::vector< FF > data
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static constexpr size_t BATCHED_EXTENDED_LENGTH
ArrayType::iterator begin()
Flavor::template ProverUnivariates< 2 > row_to_short_univariates(size_t row_idx) const
static constexpr size_t EXTENDED_LENGTH
typename Flavor::FF FF
auto get_polynomials_views() const
std::shared_ptr< DeciderPK > const & operator[](size_t idx) const
auto row_to_univariates(size_t row_idx) const
static constexpr size_t NUM_SUBRELATIONS
ArrayType::const_iterator end() const
static constexpr size_t NUM
ArrayType::const_iterator begin() const
ArrayType::iterator end()
std::array< std::shared_ptr< DeciderPK >, NUM_ > ArrayType
DeciderProvingKeys_(std::vector< std::shared_ptr< DeciderPK > > data)
DeciderVerificationKeys_(const std::vector< std::shared_ptr< DeciderVK > > &data)
std::vector< std::vector< Commitment > > get_witness_commitments() const
Get the witness commitments grouped by commitment index.
std::vector< std::vector< Commitment > > get_precomputed_commitments() const
static constexpr size_t BATCHED_EXTENDED_LENGTH
std::array< std::shared_ptr< DeciderVK >, NUM_ > ArrayType
ArrayType::iterator end()
std::vector< std::vector< FF > > get_alphas() const
Get the alphas grouped by commitment index.
std::vector< std::vector< FF > > get_relation_parameters() const
Get the relation parameters grouped by commitment index.
typename Flavor::VerificationKey VerificationKey
typename Flavor_::Commitment Commitment
static constexpr size_t NUM
std::shared_ptr< DeciderVK > const & operator[](size_t idx) const
ArrayType::iterator begin()