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
142 virtual void set_gate_selector([[maybe_unused]] const fr& value) {}
143
144 private:
146};
147
149
170
191
212
233
254
275
296
317
338
340 public:
341 SelectorType& q_busread() override { return gate_selectors[0]; };
342 SelectorType& q_lookup_type() override { return gate_selectors[1]; };
343 SelectorType& q_arith() override { return gate_selectors[2]; }
344 SelectorType& q_delta_range() override { return gate_selectors[3]; }
345 SelectorType& q_elliptic() override { return gate_selectors[4]; }
346 SelectorType& q_memory() override { return gate_selectors[5]; }
347 SelectorType& q_nnf() override { return gate_selectors[6]; }
350
351 private:
353};
354
374 MegaTraceOverflowBlock overflow; // block gates of arbitrary type that overflow their designated block
375
377 {
378 return { "ecc_op", "busread", "lookup", "pub_inputs", "arithmetic", "delta_range",
379 "elliptic", "memory", "nnf", "poseidon2_external", "poseidon2_internal", "overflow" };
380 }
381
382 auto get()
383 {
385 &busread,
386 &lookup,
387 &pub_inputs,
388 &arithmetic,
390 &elliptic,
391 &memory,
392 &nnf,
395 &overflow });
396 }
397
398 auto get() const
399 {
401 &busread,
402 &lookup,
403 &pub_inputs,
404 &arithmetic,
406 &elliptic,
407 &memory,
408 &nnf,
411 &overflow });
412 }
413
414 auto get_gate_blocks() const
415 {
417 &busread,
418 &lookup,
419 &arithmetic,
421 &elliptic,
422 &memory,
423 &nnf,
426 });
427 }
428
429 bool operator==(const MegaTraceBlockData& other) const = default;
430};
431
433 public:
443 static constexpr size_t NUM_WIRES = MegaTraceBlock::NUM_WIRES;
444
445 using FF = fr;
446
447 bool has_overflow = false; // indicates whether the overflow block has non-zero fixed or actual size
448
450
452 {
453 if (settings.structure) {
454 for (auto [block, size] : zip_view(this->get(), settings.structure.value().get())) {
455 block.fixed_size = size;
456 }
457 }
458
459 this->overflow.fixed_size = settings.overflow_capacity;
460 }
461
462 void compute_offsets(bool is_structured)
463 {
464 uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
465 for (auto& block : this->get()) {
466 block.trace_offset_ = offset;
467 offset += block.get_fixed_size(is_structured);
468 }
469 }
470
471 void summarize() const
472 {
473 info("Gate blocks summary: (actual gates / fixed capacity)");
474 info("goblin ecc op :\t", this->ecc_op.size(), "/", this->ecc_op.get_fixed_size());
475 info("busread :\t", this->busread.size(), "/", this->busread.get_fixed_size());
476 info("lookups :\t", this->lookup.size(), "/", this->lookup.get_fixed_size());
477 info("pub inputs :\t",
478 this->pub_inputs.size(),
479 "/",
480 this->pub_inputs.get_fixed_size(),
481 " (populated in decider pk constructor)");
482 info("arithmetic :\t", this->arithmetic.size(), "/", this->arithmetic.get_fixed_size());
483 info("delta range :\t", this->delta_range.size(), "/", this->delta_range.get_fixed_size());
484 info("elliptic :\t", this->elliptic.size(), "/", this->elliptic.get_fixed_size());
485 info("memory :\t", this->memory.size(), "/", this->memory.get_fixed_size());
486 info("nnf :\t", this->nnf.size(), "/", this->nnf.get_fixed_size());
487 info("poseidon ext :\t", this->poseidon2_external.size(), "/", this->poseidon2_external.get_fixed_size());
488 info("poseidon int :\t", this->poseidon2_internal.size(), "/", this->poseidon2_internal.get_fixed_size());
489 info("overflow :\t", this->overflow.size(), "/", this->overflow.get_fixed_size());
490 info("");
491 info("Total structured size: ", get_structured_size());
492 }
493
494 // Get cumulative size of all blocks
496 {
497 size_t total_size(0);
498 for (const auto& block : this->get()) {
499 total_size += block.size();
500 }
501 return total_size;
502 }
503
504 size_t get_structured_size() const
505 {
506 size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk
507 for (const auto& block : this->get()) {
508 total_size += block.get_fixed_size();
509 }
510 return total_size;
511 }
512
514 {
516
517 auto log2_n = static_cast<size_t>(numeric::get_msb(total_size));
518 if ((1UL << log2_n) != (total_size)) {
519 ++log2_n;
520 }
521 return 1UL << log2_n;
522 }
523
524 bool operator==(const MegaExecutionTraceBlocks& other) const = default;
525};
526
530static constexpr TraceStructure TINY_TEST_STRUCTURE{ .ecc_op = 18,
531 .busread = 3,
532 .lookup = 2,
533 .pub_inputs = 52, // Accomodate 4 + HidingKernelIO = 4 + 48
534 .arithmetic = 1 << 14,
535 .delta_range = 5,
536 .elliptic = 2,
537 .memory = 10,
538 .nnf = 2,
539 .poseidon2_external = 2,
540 .poseidon2_internal = 2,
541 .overflow = 0 };
542
547static constexpr TraceStructure SMALL_TEST_STRUCTURE{ .ecc_op = 1 << 14,
548 .busread = 1 << 14,
549 .lookup = 1 << 14,
550 .pub_inputs = 1 << 14,
551 .arithmetic = 1 << 15,
552 .delta_range = 1 << 14,
553 .elliptic = 1 << 14,
554 .memory = 1 << 14,
555 .nnf = 1 << 7,
556 .poseidon2_external = 1 << 14,
557 .poseidon2_internal = 1 << 15,
558 .overflow = 0 };
559
563static constexpr TraceStructure EXAMPLE_18{ .ecc_op = 1 << 10,
564 .busread = 1 << 6,
565 .lookup = 36000,
566 .pub_inputs = 1 << 6,
567 .arithmetic = 84000,
568 .delta_range = 45000,
569 .elliptic = 9000,
570 .memory = 67000,
571 .nnf = 1000,
572 .poseidon2_external = 2500,
573 .poseidon2_internal = 14000,
574 .overflow = 0 };
575
579static constexpr TraceStructure EXAMPLE_20{ .ecc_op = 1 << 11,
580 .busread = 1 << 8,
581 .lookup = 144000,
582 .pub_inputs = 1 << 8,
583 .arithmetic = 396000,
584 .delta_range = 180000,
585 .elliptic = 18000,
586 .memory = 268000,
587 .nnf = 4000,
588 .poseidon2_external = 5000,
589 .poseidon2_internal = 28000,
590 .overflow = 0 };
591
595static constexpr TraceStructure AZTEC_TRACE_STRUCTURE{ .ecc_op = 1000,
596 .busread = 4000,
597 .lookup = 13000,
598 .pub_inputs = 3500,
599 .arithmetic = 59000,
600 .delta_range = 15500,
601 .elliptic = 6500,
602 .memory = 25000,
603 .nnf = 19000,
604 .poseidon2_external = 17000,
605 .poseidon2_internal = 96500,
606 .overflow = 0 };
607
608} // 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.
void set_gate_selector(const fr &value) override
Default implementation does nothing.
SlabVectorSelector< fr > gate_selector
SelectorType & q_arith() override
virtual SelectorType & q_poseidon2_external()
virtual SelectorType & q_lookup_type()
virtual void set_gate_selector(const fr &value)
Default implementation does nothing.
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
void set_gate_selector(const fr &value) override
Default implementation does nothing.
SelectorType & q_busread() override
SelectorType & q_delta_range() override
SlabVectorSelector< fr > gate_selector
void set_gate_selector(const fr &value) override
Default implementation does nothing.
SlabVectorSelector< fr > gate_selector
SelectorType & q_elliptic() override
void set_gate_selector(const fr &value) override
Default implementation does nothing.
SlabVectorSelector< fr > gate_selector
SelectorType & q_lookup_type() override
void set_gate_selector(const fr &value) override
Default implementation does nothing.
SelectorType & q_memory() override
SlabVectorSelector< fr > gate_selector
void set_gate_selector(const fr &value) override
Default implementation does nothing.
void set_gate_selector(const fr &value) override
Default implementation does nothing.
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
void set_gate_selector(const fr &value) override
Default implementation does nothing.
SelectorType & q_poseidon2_external() override
SelectorType & q_poseidon2_internal() override
void set_gate_selector(const fr &value) override
Default implementation does nothing.
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 emplace_back(int i) override
Append an integer value to the selector.
void info(Args... args)
Definition log.hpp:74
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