barretenberg
Loading...
Searching...
No Matches
flavor.hpp
Go to the documentation of this file.
1
66#pragma once
67#include "barretenberg/common/ref_vector.hpp"
68#include "barretenberg/common/std_array.hpp"
69#include "barretenberg/common/std_vector.hpp"
70#include "barretenberg/common/zip_view.hpp"
71#include "barretenberg/polynomials/barycentric.hpp"
72#include "barretenberg/polynomials/evaluation_domain.hpp"
73#include "barretenberg/polynomials/univariate.hpp"
74#include "barretenberg/proof_system/types/circuit_type.hpp"
75#include <array>
76#include <concepts>
77#include <vector>
78
79namespace proof_system::honk::flavor {
80
86 public:
87 size_t circuit_size;
88 size_t log_circuit_size;
89 size_t num_public_inputs;
90 CircuitType circuit_type; // TODO(#392)
91};
92
100template <typename PrecomputedPolynomials, typename WitnessPolynomials>
101class ProvingKey_ : public PrecomputedPolynomials, public WitnessPolynomials {
102 public:
103 using Polynomial = typename PrecomputedPolynomials::DataType;
104 using FF = typename Polynomial::FF;
105
106 bool contains_recursive_proof;
107 std::vector<uint32_t> recursive_proof_public_input_indices;
109
110 std::vector<std::string> get_labels() const
111 {
112 return concatenate(PrecomputedPolynomials::get_labels(), WitnessPolynomials::get_labels());
113 }
114 // This order matters! must match get_unshifted in entity classes
115 RefVector<Polynomial> get_all() { return concatenate(get_precomputed_polynomials(), get_witness_polynomials()); }
116 RefVector<Polynomial> get_witness_polynomials() { return WitnessPolynomials::get_all(); }
117 RefVector<Polynomial> get_precomputed_polynomials() { return PrecomputedPolynomials::get_all(); }
118 ProvingKey_() = default;
119 ProvingKey_(const size_t circuit_size, const size_t num_public_inputs)
120 {
121 this->evaluation_domain = barretenberg::EvaluationDomain<FF>(circuit_size, circuit_size);
122 PrecomputedPolynomials::circuit_size = circuit_size;
123 this->log_circuit_size = numeric::get_msb(circuit_size);
124 this->num_public_inputs = num_public_inputs;
125 // Allocate memory for precomputed polynomials
126 for (auto& poly : PrecomputedPolynomials::get_all()) {
127 poly = Polynomial(circuit_size);
128 }
129 // Allocate memory for witness polynomials
130 for (auto& poly : WitnessPolynomials::get_all()) {
131 poly = Polynomial(circuit_size);
132 }
133 };
134};
135
141template <typename PrecomputedCommitments> class VerificationKey_ : public PrecomputedCommitments {
142 public:
143 VerificationKey_() = default;
144 VerificationKey_(const size_t circuit_size, const size_t num_public_inputs)
145 {
146 this->circuit_size = circuit_size;
147 this->log_circuit_size = numeric::get_msb(circuit_size);
148 this->num_public_inputs = num_public_inputs;
149 };
150};
151
152// Because of how Gemini is written, is importat to put the polynomials out in this order.
153auto get_unshifted_then_shifted(const auto& all_entities)
154{
155 return concatenate(all_entities.get_unshifted(), all_entities.get_shifted());
156};
157
164template <typename Tuple, std::size_t Index = 0> static constexpr size_t compute_max_partial_relation_length()
165{
166 if constexpr (Index >= std::tuple_size<Tuple>::value) {
167 return 0; // Return 0 when reach end of the tuple
168 } else {
169 constexpr size_t current_length = std::tuple_element<Index, Tuple>::type::RELATION_LENGTH;
170 constexpr size_t next_length = compute_max_partial_relation_length<Tuple, Index + 1>();
171 return (current_length > next_length) ? current_length : next_length;
172 }
173}
174
181template <typename Tuple, std::size_t Index = 0> static constexpr size_t compute_max_total_relation_length()
182{
183 if constexpr (Index >= std::tuple_size<Tuple>::value) {
184 return 0; // Return 0 when reach end of the tuple
185 } else {
186 constexpr size_t current_length = std::tuple_element<Index, Tuple>::type::TOTAL_RELATION_LENGTH;
187 constexpr size_t next_length = compute_max_total_relation_length<Tuple, Index + 1>();
188 return (current_length > next_length) ? current_length : next_length;
189 }
190}
191
196template <typename Tuple, std::size_t Index = 0> static constexpr size_t compute_number_of_subrelations()
197{
198 if constexpr (Index >= std::tuple_size<Tuple>::value) {
199 return 0;
200 } else {
201 constexpr size_t subrelations_in_relation =
202 std::tuple_element_t<Index, Tuple>::SUBRELATION_PARTIAL_LENGTHS.size();
203 return subrelations_in_relation + compute_number_of_subrelations<Tuple, Index + 1>();
204 }
205}
212template <typename Tuple, size_t NUM_INSTANCES, size_t Index = 0>
213static constexpr auto create_protogalaxy_tuple_of_tuples_of_univariates()
214{
215 if constexpr (Index >= std::tuple_size<Tuple>::value) {
216 return std::tuple<>{}; // Return empty when reach end of the tuple
217 } else {
218 using UnivariateTuple =
219 typename std::tuple_element_t<Index,
220 Tuple>::template ProtogalaxyTupleOfUnivariatesOverSubrelations<NUM_INSTANCES>;
221 return std::tuple_cat(std::tuple<UnivariateTuple>{},
222 create_protogalaxy_tuple_of_tuples_of_univariates<Tuple, NUM_INSTANCES, Index + 1>());
223 }
224}
225
232template <typename Tuple, std::size_t Index = 0> static constexpr auto create_sumcheck_tuple_of_tuples_of_univariates()
233{
234 if constexpr (Index >= std::tuple_size<Tuple>::value) {
235 return std::tuple<>{}; // Return empty when reach end of the tuple
236 } else {
237 using UnivariateTuple = typename std::tuple_element_t<Index, Tuple>::SumcheckTupleOfUnivariatesOverSubrelations;
238 return std::tuple_cat(std::tuple<UnivariateTuple>{},
239 create_sumcheck_tuple_of_tuples_of_univariates<Tuple, Index + 1>());
240 }
241}
242
248template <typename Tuple, std::size_t Index = 0> static constexpr auto create_tuple_of_arrays_of_values()
249{
250 if constexpr (Index >= std::tuple_size<Tuple>::value) {
251 return std::tuple<>{}; // Return empty when reach end of the tuple
252 } else {
253 using Values = typename std::tuple_element_t<Index, Tuple>::SumcheckArrayOfValuesOverSubrelations;
254 return std::tuple_cat(std::tuple<Values>{}, create_tuple_of_arrays_of_values<Tuple, Index + 1>());
255 }
256}
257
258} // namespace proof_system::honk::flavor
259
260// Forward declare honk flavors
261namespace proof_system::honk::flavor {
262class Ultra;
263class ECCVM;
264class GoblinUltra;
265template <typename BuilderType> class UltraRecursive_;
266template <typename BuilderType> class GoblinUltraRecursive_;
267} // namespace proof_system::honk::flavor
268
269// Forward declare plonk flavors
270namespace proof_system::plonk::flavor {
271class Standard;
272class Ultra;
273} // namespace proof_system::plonk::flavor
274
275// Establish concepts for testing flavor attributes
276namespace proof_system {
283// clang-format off
284
285template <typename T>
287
288template <typename T>
290
291template <typename T>
293
294template <typename T>
295concept IsGoblinFlavor = IsAnyOf<T, honk::flavor::GoblinUltra,
296 honk::flavor::GoblinUltraRecursive_<UltraCircuitBuilder>,
297 honk::flavor::GoblinUltraRecursive_<GoblinUltraCircuitBuilder>>;
298
299template <typename T>
301 honk::flavor::UltraRecursive_<GoblinUltraCircuitBuilder>,
302 honk::flavor::GoblinUltraRecursive_<UltraCircuitBuilder>,
303 honk::flavor::GoblinUltraRecursive_<GoblinUltraCircuitBuilder>>;
304
305template <typename T> concept IsGrumpkinFlavor = IsAnyOf<T, honk::flavor::ECCVM>;
306
308
309template <typename T> concept ECCVMFlavor = IsAnyOf<T, honk::flavor::ECCVM>;
310
311template <typename Container, typename Element>
312inline std::string flavor_get_label(Container&& container, const Element& element) {
313 for (auto [label, data] : zip_view(container.get_labels(), container.get_all())) {
314 if (&data == &element) {
315 return label;
316 }
317 }
318 return "(unknown label)";
319}
320
321// clang-format on
322} // namespace proof_system
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
Definition: ref_vector.hpp:20
Definition: evaluation_domain.hpp:8
Base class template containing circuit-specifying data.
Definition: flavor.hpp:85
Base proving key class.
Definition: flavor.hpp:101
Base verification key class.
Definition: flavor.hpp:141
Definition: zip_view.hpp:159
Definition: flavor.hpp:309
Definition: circuit_type.hpp:10
Definition: flavor.hpp:295
Definition: flavor.hpp:305
Definition: flavor.hpp:289
Test whether a type T lies in a list of types ...U.
Definition: flavor.hpp:286
Definition: flavor.hpp:300
Definition: flavor.hpp:292
Definition: flavor.hpp:307