Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_flavor.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
29
30namespace bb {
31
33 public:
39 using PCS = KZG<Curve>;
42 using Codec = FrCodec;
45
46 static constexpr size_t VIRTUAL_LOG_N = CONST_PROOF_SIZE_LOG_N;
47 // indicates when evaluating sumcheck, edges can be left as degree-1 monomials
48 static constexpr bool USE_SHORT_MONOMIALS = true;
49
50 // Indicates that this flavor runs with non-ZK Sumcheck.
51 static constexpr bool HasZK = false;
52 // To achieve fixed proof size and that the recursive verifier circuit is constant, we are using padding in Sumcheck
53 // and Shplemini
54 static constexpr bool USE_PADDING = true;
55 static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES;
56
57 // define the tuple of Relations that comprise the Sumcheck relation
58 // Note: made generic for use in MegaRecursive.
59 template <typename FF>
60
61 // List of relations reflecting the Ultra arithmetisation. WARNING: As UltraKeccak flavor inherits from
62 // Ultra flavor any change of ordering in this tuple needs to be reflected in the smart contract, otherwise
63 // relation accumulation will not match.
73
75
76 static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
77 static_assert(MAX_PARTIAL_RELATION_LENGTH == 7);
78 static constexpr size_t NUM_SUBRELATIONS = compute_number_of_subrelations<Relations>();
79 // A challenge whose powers are used to batch subrelation contributions during Sumcheck
81
82 // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
83 // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
84 // length = 3
87
88 static constexpr size_t num_frs_comm = FrCodec::calc_num_fields<Commitment>();
89 static constexpr size_t num_frs_fr = FrCodec::calc_num_fields<FF>();
90
95 template <typename DataType_> class PrecomputedEntities {
96 public:
97 bool operator==(const PrecomputedEntities&) const = default;
98 using DataType = DataType_;
100 q_m, // column 0
101 q_c, // column 1
102 q_l, // column 2
103 q_r, // column 3
104 q_o, // column 4
105 q_4, // column 5
106 q_lookup, // column 6
107 q_arith, // column 7
108 q_delta_range, // column 8
109 q_elliptic, // column 9
110 q_memory, // column 10
111 q_nnf, // column 11
112 q_poseidon2_external, // column 12
113 q_poseidon2_internal, // column 13
114 sigma_1, // column 14
115 sigma_2, // column 15
116 sigma_3, // column 16
117 sigma_4, // column 17
118 id_1, // column 18
119 id_2, // column 19
120 id_3, // column 20
121 id_4, // column 21
122 table_1, // column 22
123 table_2, // column 23
124 table_3, // column 24
125 table_4, // column 25
126 lagrange_first, // column 26
127 lagrange_last) // column 27
128
129 auto get_non_gate_selectors() { return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4 }; }
131 {
132 return RefArray{ q_lookup, q_arith, q_delta_range, q_elliptic,
133 q_memory, q_nnf, q_poseidon2_external, q_poseidon2_internal };
134 }
135 auto get_selectors() { return concatenate(get_non_gate_selectors(), get_gate_selectors()); }
136
137 auto get_sigmas() { return RefArray{ sigma_1, sigma_2, sigma_3, sigma_4 }; };
138 auto get_ids() { return RefArray{ id_1, id_2, id_3, id_4 }; };
139 auto get_tables() { return RefArray{ table_1, table_2, table_3, table_4 }; };
140 };
141
146 template <typename DataType, bool HasZK_ = HasZK> class MaskingEntities {
147 public:
148 // When ZK is disabled, this class is empty
149 auto get_all() { return RefArray<DataType, 0>{}; }
150 auto get_all() const { return RefArray<const DataType, 0>{}; }
151 static auto get_labels() { return std::vector<std::string>{}; }
152 };
153
154 // Specialization for when ZK is enabled
155 template <typename DataType> class MaskingEntities<DataType, true> {
156 public:
157 DEFINE_FLAVOR_MEMBERS(DataType, gemini_masking_poly)
158 };
159
163 template <typename DataType> class WitnessEntities {
164 public:
166 w_l, // column 0
167 w_r, // column 1
168 w_o, // column 2
169 w_4, // column 3
170 z_perm, // column 4
171 lookup_inverses, // column 5
172 lookup_read_counts, // column 6
173 lookup_read_tags) // column 7
174
175 auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; };
176 auto get_to_be_shifted() { return RefArray{ w_l, w_r, w_o, w_4, z_perm }; };
177 };
178
182 template <typename DataType> class ShiftedEntities {
183 public:
185 w_l_shift, // column 0
186 w_r_shift, // column 1
187 w_o_shift, // column 2
188 w_4_shift, // column 3
189 z_perm_shift) // column 4
190
191 auto get_shifted() { return RefArray{ w_l_shift, w_r_shift, w_o_shift, w_4_shift, z_perm_shift }; };
192 };
193
202 template <typename DataType, bool HasZK_ = HasZK>
223
224 // Default AllEntities alias (no ZK)
225 template <typename DataType> using AllEntities = AllEntities_<DataType, HasZK>;
226
227 // Derive entity counts from the actual struct definitions
233
234 // A container to be fed to ShpleminiVerifier to avoid redundant scalar muls
237
238 // Size of the final PCS MSM after KZG adds quotient commitment:
239 // 1 (Shplonk Q) + NUM_UNSHIFTED + (log_n - 1) Gemini folds + 1 (G1 identity) + 1 (KZG W)
240 // (shifted commitments are removed as duplicates)
241 static constexpr size_t FINAL_PCS_MSM_SIZE(size_t log_n = VIRTUAL_LOG_N)
242 {
243 return NUM_UNSHIFTED_ENTITIES + log_n + 2;
244 }
245
250 template <bool HasZK_ = HasZK> class AllValues_ : public AllEntities_<FF, HasZK_> {
251 public:
253 using Base::Base;
254 };
255
257
261 template <bool HasZK_ = HasZK>
263
265
267
273
275
279 template <bool HasZK_ = HasZK>
282
284
290
295
300
307 class CommitmentLabels : public AllEntities<std::string> {
308 public:
310 {
311 w_l = "W_L";
312 w_r = "W_R";
313 w_o = "W_O";
314 w_4 = "W_4";
315 z_perm = "Z_PERM";
316 lookup_inverses = "LOOKUP_INVERSES";
317 lookup_read_counts = "LOOKUP_READ_COUNTS";
318 lookup_read_tags = "LOOKUP_READ_TAGS";
319
320 q_c = "Q_C";
321 q_l = "Q_L";
322 q_r = "Q_R";
323 q_o = "Q_O";
324 q_4 = "Q_4";
325 q_m = "Q_M";
326 q_lookup = "Q_LOOKUP";
327 q_arith = "Q_ARITH";
328 q_delta_range = "Q_SORT";
329 q_elliptic = "Q_ELLIPTIC";
330 q_memory = "Q_MEMORY";
331 q_nnf = "Q_NNF";
332 q_poseidon2_external = "Q_POSEIDON2_EXTERNAL";
333 q_poseidon2_internal = "Q_POSEIDON2_INTERNAL";
334 sigma_1 = "SIGMA_1";
335 sigma_2 = "SIGMA_2";
336 sigma_3 = "SIGMA_3";
337 sigma_4 = "SIGMA_4";
338 id_1 = "ID_1";
339 id_2 = "ID_2";
340 id_3 = "ID_3";
341 id_4 = "ID_4";
342 table_1 = "TABLE_1";
343 table_2 = "TABLE_2";
344 table_3 = "TABLE_3";
345 table_4 = "TABLE_4";
346 lagrange_first = "LAGRANGE_FIRST";
347 lagrange_last = "LAGRANGE_LAST";
348 };
349 };
350
356 template <typename Commitment, typename VerificationKey, bool HasZK_ = HasZK>
357 class VerifierCommitments_ : public AllEntities_<Commitment, HasZK_> {
358 public:
359 VerifierCommitments_(const std::shared_ptr<VerificationKey>& verification_key,
360 const std::optional<WitnessEntities<Commitment>>& witness_commitments = std::nullopt)
361 {
362 // Copy the precomputed polynomial commitments into this
363 for (auto [precomputed, precomputed_in] : zip_view(this->get_precomputed(), verification_key->get_all())) {
364 precomputed = precomputed_in;
365 }
366
367 // If provided, copy the witness polynomial commitments into this
368 if (witness_commitments.has_value()) {
369 for (auto [witness, witness_in] :
370 zip_view(this->get_witness(), witness_commitments.value().get_all())) {
371 witness = witness_in;
372 }
373
374 // Set shifted commitments
375 this->w_l_shift = witness_commitments->w_l;
376 this->w_r_shift = witness_commitments->w_r;
377 this->w_o_shift = witness_commitments->w_o;
378 this->w_4_shift = witness_commitments->w_4;
379 this->z_perm_shift = witness_commitments->z_perm;
380 }
381 }
382 };
383 // Specialize for Ultra (general case used in UltraRecursive).
385};
386
387} // namespace bb
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
Base Native verification key class.
Definition flavor.hpp:135
A container for storing the partially evaluated multivariates produced by sumcheck.
A container for polynomials handles used by the prover.
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
static constexpr size_t NUM_WIRES
A base class labelling all entities (for instance, all of the polynomials used by the prover during s...
DEFINE_COMPOUND_GET_ALL(MaskingEntities< DataType, HasZK_ >, PrecomputedEntities< DataType >, WitnessEntities< DataType >, ShiftedEntities< DataType >) auto get_unshifted()
A field element for each entity of the flavor. These entities represent the prover polynomials evalua...
A container for commitment labels.
ZK-specific entities (only used when HasZK = true)
A base class labelling precomputed entities and (ordered) subsets of interest.
bool operator==(const PrecomputedEntities &) const =default
DEFINE_FLAVOR_MEMBERS(DataType, q_m, q_c, q_l, q_r, q_o, q_4, q_lookup, q_arith, q_delta_range, q_elliptic, q_memory, q_nnf, q_poseidon2_external, q_poseidon2_internal, sigma_1, sigma_2, sigma_3, sigma_4, id_1, id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first, lagrange_last) auto get_non_gate_selectors()
Class for ShiftedEntities, containing shifted witness polynomials.
DEFINE_FLAVOR_MEMBERS(DataType, w_l_shift, w_r_shift, w_o_shift, w_4_shift, z_perm_shift) auto get_shifted()
A container encapsulating all the commitments that the verifier receives (to precomputed polynomials ...
VerifierCommitments_(const std::shared_ptr< VerificationKey > &verification_key, const std::optional< WitnessEntities< Commitment > > &witness_commitments=std::nullopt)
DEFINE_FLAVOR_MEMBERS(DataType, w_l, w_r, w_o, w_4, z_perm, lookup_inverses, lookup_read_counts, lookup_read_tags) auto get_wires()
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > HashFunction
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH
static constexpr bool USE_PADDING
static constexpr size_t NUM_RELATIONS
static constexpr size_t NUM_PRECOMPUTED_ENTITIES
static constexpr bool HasZK
static constexpr bool USE_SHORT_MONOMIALS
static constexpr size_t FINAL_PCS_MSM_SIZE(size_t log_n=VIRTUAL_LOG_N)
static constexpr size_t num_frs_comm
Curve::ScalarField FF
Curve::AffineElement Commitment
static constexpr size_t num_frs_fr
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH
static constexpr size_t NUM_SUBRELATIONS
static constexpr size_t VIRTUAL_LOG_N
std::tuple< bb::ArithmeticRelation< FF >, bb::UltraPermutationRelation< FF >, bb::LogDerivLookupRelation< FF >, bb::DeltaRangeConstraintRelation< FF >, bb::EllipticRelation< FF >, bb::MemoryRelation< FF >, bb::NonNativeFieldRelation< FF >, bb::Poseidon2ExternalRelation< FF >, bb::Poseidon2InternalRelation< FF > > Relations_
Curve::Element GroupElement
Relations_< FF > Relations
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_UNSHIFTED_ENTITIES
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t NUM_WIRES
static constexpr size_t NUM_WITNESS_ENTITIES
Wrapper holding a verification key and its precomputed hash.
Definition flavor.hpp:541
typename Group::element Element
Definition bn254.hpp:21
typename Group::affine_element AffineElement
Definition bn254.hpp:22
bb::fr ScalarField
Definition bn254.hpp:18
Base class templates shared across Honk flavors.
#define DEFINE_FLAVOR_MEMBERS(DataType,...)
Define the body of a flavor class, included each member and a pointer view with which to iterate the ...
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
RefArray< T,(Ns+...)> constexpr concatenate(const RefArray< T, Ns > &... ref_arrays)
Concatenates multiple RefArray objects into a single RefArray.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
The precomputed data needed to compute a Honk VK.
Definition flavor.hpp:84