Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
mega_execution_trace.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
15#include <cstdint>
16
17namespace bb {
18
31 uint32_t overflow; // block gates of arbitrary type that overflow their designated block
32
38
44
45 size_t size() const
46 {
47 size_t result{ 0 };
48 for (const auto& block_size : get()) {
49 result += block_size;
50 }
51 return static_cast<size_t>(result);
52 }
53};
54
57 // The size of the overflow block. Specified separately because it is allowed to be determined at runtime in the
58 // context of VK computation
59 uint32_t overflow_capacity = 0;
60
61 // This size is used as a hint to the BN254 Commitment Key needed in the CIVC.
62 // TODO(https://github.com/AztecProtocol/barretenberg/issues/1319): This can be removed once the prover knows all
63 // the circuit sizes in advance.
64 size_t size() const { return (structure ? structure->size() : 0) + static_cast<size_t>(overflow_capacity); }
65
66 size_t dyadic_size() const { return numeric::round_up_power_2(size()); }
67};
68
69class MegaTraceBlock : public ExecutionTraceBlock<fr, /*NUM_WIRES_ */ 4> {
70 public:
72
73 virtual SelectorType& q_busread() { return this->zero_selectors[0]; };
74 virtual SelectorType& q_lookup_type() { return this->zero_selectors[1]; };
75 virtual SelectorType& q_arith() { return this->zero_selectors[2]; };
76 virtual SelectorType& q_delta_range() { return this->zero_selectors[3]; };
77 virtual SelectorType& q_elliptic() { return this->zero_selectors[4]; };
78 virtual SelectorType& q_memory() { return this->zero_selectors[5]; };
79 virtual SelectorType& q_nnf() { return this->zero_selectors[6]; };
80 virtual SelectorType& q_poseidon2_external() { return this->zero_selectors[7]; };
81 virtual SelectorType& q_poseidon2_internal() { return this->zero_selectors[8]; };
82
83 virtual const SelectorType& q_busread() const { return this->zero_selectors[0]; };
84 virtual const SelectorType& q_lookup_type() const { return this->zero_selectors[1]; };
85 virtual const SelectorType& q_arith() const { return this->zero_selectors[2]; };
86 virtual const SelectorType& q_delta_range() const { return this->zero_selectors[3]; };
87 virtual const SelectorType& q_elliptic() const { return this->zero_selectors[4]; };
88 virtual const SelectorType& q_memory() const { return this->zero_selectors[5]; };
89 virtual const SelectorType& q_nnf() const { return this->zero_selectors[6]; };
90 virtual const SelectorType& q_poseidon2_external() const { return this->zero_selectors[7]; };
91 virtual const SelectorType& q_poseidon2_internal() const { return this->zero_selectors[8]; };
92
101
103 {
104 return RefVector{
105 q_m(),
106 q_c(),
107 q_1(),
108 q_2(),
109 q_3(),
110 q_4(),
111 q_busread(),
113 q_arith(),
115 q_elliptic(),
116 q_memory(),
117 q_nnf(),
120 };
121 }
122
130
137 void resize_additional(size_t new_size) { q_busread().resize(new_size); };
138
139 private:
141};
142
144
146 public:
147 SelectorType& q_busread() override { return gate_selector; }
148
149 private:
151};
152
154 public:
156
157 private:
159};
160
162 public:
163 SelectorType& q_arith() override { return gate_selector; }
164
165 private:
167};
168
170 public:
172
173 private:
175};
176
178 public:
179 SelectorType& q_elliptic() override { return gate_selector; }
180
181 private:
183};
184
186 public:
187 SelectorType& q_memory() override { return gate_selector; }
188
189 private:
191};
192
194 public:
195 SelectorType& q_nnf() override { return gate_selector; }
196
197 private:
199};
200
208
216
218 public:
219 SelectorType& q_busread() override { return gate_selectors[0]; };
220 SelectorType& q_lookup_type() override { return gate_selectors[1]; };
221 SelectorType& q_arith() override { return gate_selectors[2]; }
222 SelectorType& q_delta_range() override { return gate_selectors[3]; }
223 SelectorType& q_elliptic() override { return gate_selectors[4]; }
224 SelectorType& q_memory() override { return gate_selectors[5]; }
225 SelectorType& q_nnf() override { return gate_selectors[6]; }
228
229 private:
231};
232
252 MegaTraceOverflowBlock overflow; // block gates of arbitrary type that overflow their designated block
253
255 {
256 return { "ecc_op", "busread", "lookup", "pub_inputs", "arithmetic", "delta_range",
257 "elliptic", "memory", "nnf", "poseidon2_external", "poseidon2_internal", "overflow" };
258 }
259
260 auto get()
261 {
263 &busread,
264 &lookup,
265 &pub_inputs,
266 &arithmetic,
268 &elliptic,
269 &memory,
270 &nnf,
273 &overflow });
274 }
275
276 auto get() const
277 {
279 &busread,
280 &lookup,
281 &pub_inputs,
282 &arithmetic,
284 &elliptic,
285 &memory,
286 &nnf,
289 &overflow });
290 }
291
292 auto get_gate_blocks() const
293 {
295 &busread,
296 &lookup,
297 &arithmetic,
299 &elliptic,
300 &memory,
301 &nnf,
304 });
305 }
306
307 bool operator==(const MegaTraceBlockData& other) const = default;
308};
309
311 public:
321 static constexpr size_t NUM_WIRES = MegaTraceBlock::NUM_WIRES;
322
323 using FF = fr;
324
325 bool has_overflow = false; // indicates whether the overflow block has non-zero fixed or actual size
326
328
330 {
331 if (settings.structure) {
332 for (auto [block, size] : zip_view(this->get(), settings.structure.value().get())) {
333 block.fixed_size = size;
334 }
335 }
336
337 this->overflow.fixed_size = settings.overflow_capacity;
338 }
339
340 void compute_offsets(bool is_structured)
341 {
342 uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
343 for (auto& block : this->get()) {
344 block.trace_offset_ = offset;
345 offset += block.get_fixed_size(is_structured);
346 }
347 }
348
349 void summarize() const
350 {
351 info("Gate blocks summary: (actual gates / fixed capacity)");
352 info("goblin ecc op :\t", this->ecc_op.size(), "/", this->ecc_op.get_fixed_size());
353 info("busread :\t", this->busread.size(), "/", this->busread.get_fixed_size());
354 info("lookups :\t", this->lookup.size(), "/", this->lookup.get_fixed_size());
355 info("pub inputs :\t",
356 this->pub_inputs.size(),
357 "/",
358 this->pub_inputs.get_fixed_size(),
359 " (populated in decider pk constructor)");
360 info("arithmetic :\t", this->arithmetic.size(), "/", this->arithmetic.get_fixed_size());
361 info("delta range :\t", this->delta_range.size(), "/", this->delta_range.get_fixed_size());
362 info("elliptic :\t", this->elliptic.size(), "/", this->elliptic.get_fixed_size());
363 info("memory :\t", this->memory.size(), "/", this->memory.get_fixed_size());
364 info("nnf :\t", this->nnf.size(), "/", this->nnf.get_fixed_size());
365 info("poseidon ext :\t", this->poseidon2_external.size(), "/", this->poseidon2_external.get_fixed_size());
366 info("poseidon int :\t", this->poseidon2_internal.size(), "/", this->poseidon2_internal.get_fixed_size());
367 info("overflow :\t", this->overflow.size(), "/", this->overflow.get_fixed_size());
368 info("");
369 info("Total structured size: ", get_structured_size());
370 }
371
372 // Get cumulative size of all blocks
374 {
375 size_t total_size(0);
376 for (const auto& block : this->get()) {
377 total_size += block.size();
378 }
379 return total_size;
380 }
381
382 size_t get_structured_size() const
383 {
384 size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk
385 for (const auto& block : this->get()) {
386 total_size += block.get_fixed_size();
387 }
388 return total_size;
389 }
390
392 {
394
395 auto log2_n = static_cast<size_t>(numeric::get_msb(total_size));
396 if ((1UL << log2_n) != (total_size)) {
397 ++log2_n;
398 }
399 return 1UL << log2_n;
400 }
401
402 bool operator==(const MegaExecutionTraceBlocks& other) const = default;
403};
404
408static constexpr TraceStructure TINY_TEST_STRUCTURE{ .ecc_op = 18,
409 .busread = 3,
410 .lookup = 2,
411 .pub_inputs = 52, // Accomodate 4 + HidingKernelIO = 4 + 48
412 .arithmetic = 1 << 14,
413 .delta_range = 5,
414 .elliptic = 2,
415 .memory = 10,
416 .nnf = 2,
417 .poseidon2_external = 2,
418 .poseidon2_internal = 2,
419 .overflow = 0 };
420
425static constexpr TraceStructure SMALL_TEST_STRUCTURE{ .ecc_op = 1 << 14,
426 .busread = 1 << 14,
427 .lookup = 1 << 14,
428 .pub_inputs = 1 << 14,
429 .arithmetic = 1 << 15,
430 .delta_range = 1 << 14,
431 .elliptic = 1 << 14,
432 .memory = 1 << 14,
433 .nnf = 1 << 7,
434 .poseidon2_external = 1 << 14,
435 .poseidon2_internal = 1 << 15,
436 .overflow = 0 };
437
441static constexpr TraceStructure EXAMPLE_18{ .ecc_op = 1 << 10,
442 .busread = 1 << 6,
443 .lookup = 36000,
444 .pub_inputs = 1 << 6,
445 .arithmetic = 84000,
446 .delta_range = 45000,
447 .elliptic = 9000,
448 .memory = 67000,
449 .nnf = 1000,
450 .poseidon2_external = 2500,
451 .poseidon2_internal = 14000,
452 .overflow = 0 };
453
457static constexpr TraceStructure EXAMPLE_20{ .ecc_op = 1 << 11,
458 .busread = 1 << 8,
459 .lookup = 144000,
460 .pub_inputs = 1 << 8,
461 .arithmetic = 396000,
462 .delta_range = 180000,
463 .elliptic = 18000,
464 .memory = 268000,
465 .nnf = 4000,
466 .poseidon2_external = 5000,
467 .poseidon2_internal = 28000,
468 .overflow = 0 };
469
473static constexpr TraceStructure AZTEC_TRACE_STRUCTURE{ .ecc_op = 1000,
474 .busread = 3000,
475 .lookup = 13000,
476 .pub_inputs = 2000,
477 .arithmetic = 59000,
478 .delta_range = 18000,
479 .elliptic = 6500,
480 .memory = 25000,
481 .nnf = 19000,
482 .poseidon2_external = 17000,
483 .poseidon2_internal = 96500,
484 .overflow = 0 };
485
486template <typename T>
488} // namespace bb
Basic structure for storing gate data in a builder.
void compute_offsets(bool is_structured)
bool operator==(const MegaExecutionTraceBlocks &other) const =default
void set_fixed_block_sizes(const TraceSettings &settings)
static constexpr size_t NUM_WIRES
Defines the circuit block types for the Mega arithmetization.
SlabVectorSelector< fr > gate_selector
SelectorType & q_arith() override
virtual SelectorType & q_poseidon2_external()
virtual SelectorType & q_lookup_type()
virtual SelectorType & q_elliptic()
virtual SelectorType & q_delta_range()
RefVector< Selector< fr > > get_selectors() override
virtual const SelectorType & q_delta_range() const
virtual const SelectorType & q_lookup_type() const
virtual const SelectorType & q_poseidon2_internal() const
virtual SelectorType & q_poseidon2_internal()
std::array< ZeroSelector< fr >, 9 > zero_selectors
virtual const SelectorType & q_nnf() const
void resize_additional(size_t new_size)
Resizes all selectors which are not part of the conventional Ultra arithmetization.
RefVector< SelectorType > get_gate_selectors()
virtual const SelectorType & q_arith() const
virtual const SelectorType & q_elliptic() const
void pad_additional()
Add zeros to all selectors which are not part of the conventional Ultra arithmetization.
virtual const SelectorType & q_poseidon2_external() const
virtual SelectorType & q_nnf()
virtual const SelectorType & q_busread() const
virtual SelectorType & q_arith()
virtual const SelectorType & q_memory() const
virtual SelectorType & q_memory()
virtual SelectorType & q_busread()
SlabVectorSelector< fr > gate_selector
SelectorType & q_busread() override
SelectorType & q_delta_range() override
SlabVectorSelector< fr > gate_selector
SlabVectorSelector< fr > gate_selector
SelectorType & q_elliptic() override
SlabVectorSelector< fr > gate_selector
SelectorType & q_lookup_type() override
SelectorType & q_memory() override
SlabVectorSelector< fr > gate_selector
SelectorType & q_nnf() override
SelectorType & q_poseidon2_internal() override
SelectorType & q_arith() override
SelectorType & q_busread() override
SelectorType & q_poseidon2_external() override
std::array< SlabVectorSelector< fr >, 9 > gate_selectors
SelectorType & q_memory() override
SelectorType & q_lookup_type() override
SelectorType & q_elliptic() override
SelectorType & q_delta_range() override
SelectorType & q_poseidon2_external() override
SelectorType & q_poseidon2_internal() override
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Definition ref_array.hpp:22
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
virtual void resize(size_t new_size)=0
Resize the selector.
void emplace_back(const FF &value)
Append a field element to the selector.
Selector backed by a slab allocator vector.
void info(Args... args)
Definition log.hpp:70
ssize_t offset
Definition engine.cpp:36
constexpr T get_msb(const T in)
Definition get_msb.hpp:47
constexpr T round_up_power_2(const T in)
Definition get_msb.hpp:52
Entry point for Barretenberg command-line interface.
field< Bn254FrParams > fr
Definition fr.hpp:174
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
A container indexed by the types of the blocks in the execution trace.
MegaTraceDeltaRangeBlock delta_range
MegaTraceNonNativeFieldBlock nnf
MegaTraceArithmeticBlock arithmetic
MegaTracePublicInputBlock pub_inputs
MegaTraceEllipticBlock elliptic
bool operator==(const MegaTraceBlockData &other) const =default
MegaTraceBusReadBlock busread
MegaTracePoseidon2ExternalBlock poseidon2_external
MegaTracePoseidon2InternalBlock poseidon2_internal
std::vector< std::string_view > get_labels() const
MegaTraceOverflowBlock overflow
std::optional< TraceStructure > structure