Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
flavor.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Federico], commit: 0e37cb8}
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6#pragma once
7
8#include <array>
9#include <span>
10
17
22
23#include "barretenberg/aztec/aztec_constants.hpp"
28
31
32namespace bb::avm2 {
33
34// Metaprogramming to concatenate tuple types.
35template <typename... input_t> using tuple_cat_t = decltype(flat_tuple::tuple_cat(std::declval<input_t>()...));
36
37class AvmFlavor {
38 public:
42
51
52 // To help BB check if a flavor is AVM, even without including this flavor.
53 static constexpr bool IS_AVM = true;
54 // indicates when evaluating sumcheck, edges must be extended to be MAX_PARTIAL_RELATION_LENGTH
55 static constexpr bool USE_SHORT_MONOMIALS = false;
56 // This flavor would not be used with ZK Sumcheck
57 static constexpr bool HasZK = false;
58 static constexpr size_t TRACE_OFFSET = 0;
59 // Padding in Sumcheck and Shplemini
60 static constexpr bool USE_PADDING = true;
61
65 static constexpr size_t NUM_WIRES = AvmFlavorVariables::NUM_WIRES;
67
68 // Need to be templated for recursive verifier
70
72
73 // Need to be templated for recursive verifier
75
77
78 // Need to be templated for recursive verifier
81
82 static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
83
84 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
85
86 static_assert(MAX_PARTIAL_RELATION_LENGTH < 8, "MAX_PARTIAL_RELATION_LENGTH must be less than 8");
87
88 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
89 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
90 // length = 3
93
94 static constexpr size_t NUM_FRS_COM = FrCodec::calc_num_fields<Commitment>();
95 static constexpr size_t NUM_FRS_FR = FrCodec::calc_num_fields<FF>();
96
97 // The formula must match the serialization in Transcript::serialize_full_transcript(). The static_assert below
98 // catches drift between AVM_V2_PROOF_LENGTH_IN_FIELDS (the protocol-shared mirror in constants.nr) and the
99 // computed length. When it fires, follow the diagnostic and run scripts/bump_avm_proof_length.sh.
100 static constexpr size_t COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS =
101 NUM_WITNESS_ENTITIES * NUM_FRS_COM + // witness commitments
102 NUM_ALL_ENTITIES * NUM_FRS_FR + // sumcheck evaluations
104 (MAX_AVM_TRACE_LOG_SIZE - 1) * NUM_FRS_COM + // gemini fold comms
105 MAX_AVM_TRACE_LOG_SIZE * NUM_FRS_FR + // gemini fold evals
106 2 * NUM_FRS_COM; // shplonk + kzg
107
108 static_assert(AVM_V2_PROOF_LENGTH_IN_FIELDS == COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS,
109 "AVM_V2_PROOF_LENGTH_IN_FIELDS (constants.nr) != COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS. "
110 "Update AVM_V2_PROOF_LENGTH_IN_FIELDS in constants.nr to the computed value and "
111 "run barretenberg/cpp/scripts/bump_avm_proof_length.sh.");
112
113 public:
135
136 // Even though we only need the witness entities, we hold all entities because it's
137 // easier and will not make much of a difference.
138 template <typename DataType> class WitnessEntities : public AllEntities<DataType> {
139 private:
140 // Obscure get_all since we redefine it.
143
144 public:
148 };
149
150 // Even though we only need the precomputed entities, we hold all entities because it's
151 // easier and will not make much of a difference.
152 template <typename DataType> class PrecomputedEntities : public AllEntities<DataType> {
153 private:
154 // Obscure get_all since we redefine it.
157
158 public:
162 };
163
165 public:
167
168 std::array<Commitment, NUM_WITNESS_ENTITIES> commitments;
169
171 std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
172 std::vector<Commitment> gemini_fold_comms;
173 std::vector<FF> gemini_fold_evals;
176
177 Transcript() = default;
178
181 };
182
183 class ProvingKey : public AllEntities<Polynomial> {
184 private:
185 // Obscure get_all since it would be incorrect.
188
189 public:
190 using FF = typename Polynomial::FF;
191
192 static constexpr size_t circuit_size = MAX_AVM_TRACE_SIZE; // Fixed size
193 static constexpr size_t log_circuit_size = MAX_AVM_TRACE_LOG_SIZE;
194
195 ProvingKey();
196
200
202
203 // The number of public inputs has to be the same for all instances because they are
204 // folded element by element.
205 std::vector<FF> public_inputs;
206 };
207
214
215 // Used by sumcheck.
217
218 template <typename Polynomials> class PolynomialEntitiesAtFixedRow {
219 public:
222 , pp(pp)
223 {}
224
225 // Only const-access is allowed here. That's all that the logderivative library requires.
226 const auto& get(ColumnAndShifts c) const { return pp.get(c)[row_idx]; }
227
228 private:
229 const size_t row_idx;
231 };
232
236 class ProverPolynomials : public AllEntities<Polynomial> {
237 public:
238 // Define all operations as default, except copy construction/assignment
239 ProverPolynomials() = default;
242 ProverPolynomials(ProverPolynomials&& o) noexcept = default;
245
246 ProverPolynomials(ProvingKey& proving_key);
247 // For partially evaluated multivariates.
248 // TODO(fcarreiro): Reconsider its place.
249 ProverPolynomials(const ProverPolynomials& full_polynomials, size_t circuit_size);
250
251 // Only const-access is allowed here. That's all that the logderivative library requires.
252 // https://github.com/AztecProtocol/aztec-packages/blob/e50d8e0/barretenberg/cpp/src/barretenberg/honk/proof_system/logderivative_library.hpp#L44.
253 PolynomialEntitiesAtFixedRow<ProverPolynomials> get_row(size_t row_idx) const { return { row_idx, *this }; }
254 };
255
257
263 : private AllEntities<std::unique_ptr<bb::Univariate<FF, MAX_PARTIAL_RELATION_LENGTH>>> {
264 public:
268
269 void set_current_edge(size_t edge_idx);
271
272 private:
273 size_t current_edge = 0;
274 mutable bool dirty = false;
276 };
277
282 // TODO(fcarreiro): This is only required because of the Flavor::USE_SHORT_MONOMIALS conditional in
283 // SumcheckProverRound. The conditional should be improved to not require this.
284 template <size_t LENGTH> using ProverUnivariates = int;
285
291
292 // Templated for use in recursive verifier
293 template <typename Commitment_, typename VerificationKey>
294 class VerifierCommitments_ : public AllEntities<Commitment_> {
295 private:
297
298 public:
299 VerifierCommitments_(const std::shared_ptr<VerificationKey>& verification_key)
300 {
301 for (auto [commitment, vk_commitment] : zip_view(this->get_precomputed(), verification_key->get_all())) {
302 commitment = vk_commitment;
303 }
304 }
305 };
306
307 // Native version of the verifier commitments
309};
310
311} // namespace bb::avm2
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:104
std::span< DataType, NUM_WITNESS_ENTITIES > get_witness()
std::span< DataType, NUM_UNSHIFTED_ENTITIES > get_unshifted()
std::span< DataType, NUM_PRECOMPUTED_ENTITIES > get_precomputed()
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
DEFINE_AVM_GETTER(unshifted, UNSHIFTED_START_IDX, NUM_UNSHIFTED_ENTITIES)
DEFINE_AVM_GETTER(precomputed, PRECOMPUTED_START_IDX, NUM_PRECOMPUTED_ENTITIES)
std::span< DataType > get_all()
Definition flavor.hpp:119
std::span< const DataType > get_all() const
Definition flavor.hpp:120
std::span< const std::string > get_labels() const
Definition flavor.hpp:121
DEFINE_AVM_GETTER(witness, WITNESS_START_IDX, NUM_WITNESS_ENTITIES)
DEFINE_AVM_GETTER(wires, WIRE_START_IDX, NUM_WIRE_ENTITIES)
DataType & get(ColumnAndShifts c)
Definition flavor.hpp:132
const DataType & get(ColumnAndShifts c) const
Definition flavor.hpp:133
DEFINE_AVM_GETTER(to_be_shifted, WIRES_TO_BE_SHIFTED_START_IDX, NUM_WIRES_TO_BE_SHIFTED)
DEFINE_AVM_GETTER(derived, DERIVED_START_IDX, NUM_DERIVED_ENTITIES)
std::array< DataType, NUM_ALL_ENTITIES > entities
Definition flavor.hpp:117
DEFINE_AVM_GETTER(shifted, SHIFTED_START_IDX, NUM_SHIFTED_ENTITIES)
A container for univariates used during sumcheck.
Definition flavor.hpp:263
const bb::Univariate< FF, MAX_PARTIAL_RELATION_LENGTH > & get(ColumnAndShifts c) const
Definition flavor.cpp:107
LazilyExtendedProverUnivariates(const ProverPolynomials &multivariates)
Definition flavor.hpp:265
PolynomialEntitiesAtFixedRow(const size_t row_idx, const Polynomials &pp)
Definition flavor.hpp:220
const auto & get(ColumnAndShifts c) const
Definition flavor.hpp:226
std::span< const std::string > get_labels() const
Definition flavor.hpp:161
std::span< DataType > get_all()
Definition flavor.hpp:159
std::span< const DataType > get_all() const
Definition flavor.hpp:160
A container for the prover polynomials handles.
Definition flavor.hpp:236
PolynomialEntitiesAtFixedRow< ProverPolynomials > get_row(size_t row_idx) const
Definition flavor.hpp:253
ProverPolynomials & operator=(ProverPolynomials &&o) noexcept=default
ProverPolynomials & operator=(const ProverPolynomials &)=delete
ProverPolynomials(const ProverPolynomials &o)=delete
ProverPolynomials(ProverPolynomials &&o) noexcept=default
std::vector< FF > public_inputs
Definition flavor.hpp:205
std::span< const Polynomial > get_all() const
Definition flavor.hpp:198
std::span< Polynomial > get_all()
Definition flavor.hpp:197
static constexpr size_t log_circuit_size
Definition flavor.hpp:193
static constexpr size_t circuit_size
Definition flavor.hpp:192
std::span< const std::string > get_labels() const
Definition flavor.hpp:199
typename Polynomial::FF FF
Definition flavor.hpp:190
std::vector< Commitment > gemini_fold_comms
Definition flavor.hpp:172
std::array< FF, NUM_ALL_ENTITIES > sumcheck_evaluations
Definition flavor.hpp:171
std::array< Commitment, NUM_WITNESS_ENTITIES > commitments
Definition flavor.hpp:168
std::vector< bb::Univariate< FF, BATCHED_RELATION_PARTIAL_LENGTH > > sumcheck_univariates
Definition flavor.hpp:170
std::vector< FF > gemini_fold_evals
Definition flavor.hpp:173
VerifierCommitments_(const std::shared_ptr< VerificationKey > &verification_key)
Definition flavor.hpp:299
std::span< const std::string > get_labels() const
Definition flavor.hpp:147
std::span< DataType > get_all()
Definition flavor.hpp:145
std::span< const DataType > get_all() const
Definition flavor.hpp:146
AvmFlavorSettings::GroupElement GroupElement
Definition flavor.hpp:46
static constexpr bool IS_AVM
Definition flavor.hpp:53
static constexpr size_t TRACE_OFFSET
Definition flavor.hpp:58
tuple_cat_t< MainRelations_< FF_ >, LookupRelations_< FF_ > > Relations_
Definition flavor.hpp:79
static constexpr size_t COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS
Definition flavor.hpp:100
AvmFlavorSettings::PolynomialHandle PolynomialHandle
Definition flavor.hpp:45
static constexpr size_t NUM_SUBRELATIONS
Definition flavor.hpp:82
static constexpr size_t NUM_SHIFTED_ENTITIES
Definition flavor.hpp:64
AvmFlavorSettings::CommitmentHandle CommitmentHandle
Definition flavor.hpp:48
AvmFlavorSettings::FF FF
Definition flavor.hpp:43
static constexpr size_t NUM_FRS_FR
Definition flavor.hpp:95
static constexpr bool USE_PADDING
Definition flavor.hpp:60
static constexpr bool HasZK
Definition flavor.hpp:57
static constexpr size_t NUM_RELATIONS
Definition flavor.hpp:92
static constexpr size_t NUM_WITNESS_ENTITIES
Definition flavor.hpp:63
AvmFlavorSettings::G1 G1
Definition flavor.hpp:40
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
Definition flavor.hpp:84
static constexpr size_t NUM_WIRES
Definition flavor.hpp:65
static constexpr bool USE_SHORT_MONOMIALS
Definition flavor.hpp:55
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
Definition flavor.hpp:91
static constexpr size_t NUM_FRS_COM
Definition flavor.hpp:94
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
Definition flavor.hpp:62
AvmFlavorSettings::Commitment Commitment
Definition flavor.hpp:47
static constexpr size_t NUM_ALL_ENTITIES
Definition flavor.hpp:66
Relations_< FF > Relations
Definition flavor.hpp:80
bb::VerifierCommitmentKey< Curve > VerifierCommitmentKey
G1::affine_element CommitmentHandle
bb::Polynomial< FF > Polynomial
bb::CommitmentKey< Curve > CommitmentKey
Stores the fixed AVM VK commitments (to precomputed polynomials) that depend only on the precomputed ...
Base class templates shared across Honk flavors.
constexpr auto NUM_WIRE_ENTITIES
Definition columns.hpp:43
decltype(flat_tuple::tuple_cat(std::declval< input_t >()...)) tuple_cat_t
Definition flavor.hpp:35
constexpr auto NUM_UNSHIFTED_ENTITIES
Definition columns.hpp:48
const std::vector< std::string > & COLUMN_NAMES
Definition columns.cpp:26
constexpr std::size_t MAX_AVM_TRACE_SIZE
Definition constants.hpp:14
constexpr auto WITNESS_START_IDX
Definition columns.hpp:73
constexpr auto NUM_WIRES_TO_BE_SHIFTED
Definition columns.hpp:46
constexpr std::size_t MAX_AVM_TRACE_LOG_SIZE
Definition constants.hpp:13
constexpr auto NUM_DERIVED_ENTITIES
Definition columns.hpp:44
ColumnAndShifts
Definition columns.hpp:35
constexpr auto WIRES_TO_BE_SHIFTED_START_IDX
Definition columns.hpp:67
constexpr auto DERIVED_START_IDX
Definition columns.hpp:69
constexpr auto PRECOMPUTED_START_IDX
Definition columns.hpp:63
constexpr auto UNSHIFTED_START_IDX
Definition columns.hpp:75
constexpr auto WIRE_START_IDX
Definition columns.hpp:65
constexpr auto SHIFTED_START_IDX
Definition columns.hpp:71
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
constexpr auto tuple_cat(T &&... ts)
Definition tuplet.hpp:1101
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t NUM_WIRES
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES