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: Complete, auditors: [Luke, Raju], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8
16#include <cstdint>
17
18namespace bb {
19
20class MegaTraceBlock : public ExecutionTraceBlock<fr, /*NUM_WIRES_ */ 4> {
21 public:
23
24 virtual SelectorType& q_busread() { return this->zero_selectors[0]; };
25 virtual SelectorType& q_lookup() { return this->zero_selectors[1]; };
26 virtual SelectorType& q_arith() { return this->zero_selectors[2]; };
27 virtual SelectorType& q_delta_range() { return this->zero_selectors[3]; };
28 virtual SelectorType& q_elliptic() { return this->zero_selectors[4]; };
29 virtual SelectorType& q_memory() { return this->zero_selectors[5]; };
30 virtual SelectorType& q_nnf() { return this->zero_selectors[6]; };
31 virtual SelectorType& q_poseidon2_external() { return this->zero_selectors[7]; };
32 virtual SelectorType& q_poseidon2_internal() { return this->zero_selectors[8]; };
33
34 virtual const SelectorType& q_busread() const { return this->zero_selectors[0]; };
35 virtual const SelectorType& q_lookup() const { return this->zero_selectors[1]; };
36 virtual const SelectorType& q_arith() const { return this->zero_selectors[2]; };
37 virtual const SelectorType& q_delta_range() const { return this->zero_selectors[3]; };
38 virtual const SelectorType& q_elliptic() const { return this->zero_selectors[4]; };
39 virtual const SelectorType& q_memory() const { return this->zero_selectors[5]; };
40 virtual const SelectorType& q_nnf() const { return this->zero_selectors[6]; };
41 virtual const SelectorType& q_poseidon2_external() const { return this->zero_selectors[7]; };
42 virtual const SelectorType& q_poseidon2_internal() const { return this->zero_selectors[8]; };
43
45 {
46 return {
47 q_busread(),
48 q_lookup(),
49 q_arith(),
51 q_elliptic(),
52 q_memory(),
53 q_nnf(),
56 };
57 }
58
60 {
61 return RefVector{
62 q_m(),
63 q_c(),
64 q_1(),
65 q_2(),
66 q_3(),
67 q_4(),
68 q_busread(),
69 q_lookup(),
70 q_arith(),
72 q_elliptic(),
73 q_memory(),
74 q_nnf(),
77 };
78 }
79
87
94 void resize_additional(size_t new_size) { q_busread().resize(new_size); };
95
99 virtual void set_gate_selector([[maybe_unused]] const fr& value) {}
100
101 private:
103};
104
106
108 public:
109 SelectorType& q_busread() override { return gate_selector; }
110
123
124 private:
126};
127
129 public:
130 SelectorType& q_lookup() override { return gate_selector; }
131
144
145 private:
147};
148
150 public:
151 SelectorType& q_arith() override { return gate_selector; }
152
165
166 private:
168};
169
171 public:
173
174 void set_gate_selector(const fr& value) override
175 {
179 gate_selector.emplace_back(value);
182 q_nnf().emplace_back(0);
185 }
186
187 private:
189};
190
192 public:
193 SelectorType& q_elliptic() override { return gate_selector; }
194
195 void set_gate_selector(const fr& value) override
196 {
201 gate_selector.emplace_back(value);
203 q_nnf().emplace_back(0);
206 }
207
208 private:
210};
211
213 public:
214 SelectorType& q_memory() override { return gate_selector; }
215
228
229 private:
231};
232
234 public:
235 SelectorType& q_nnf() override { return gate_selector; }
236
249
250 private:
252};
253
255 public:
257
258 void set_gate_selector(const fr& value) override
259 {
266 q_nnf().emplace_back(0);
267 gate_selector.emplace_back(value);
269 }
270
271 private:
273};
274
276 public:
278
279 void set_gate_selector(const fr& value) override
280 {
287 q_nnf().emplace_back(0);
289 gate_selector.emplace_back(value);
290 }
291
292 private:
294};
295
311 MegaTraceBlock ecc_op; // Must remain first
322
323 static constexpr size_t NUM_BLOCKS = 11;
324
326 {
327 return { "ecc_op", "busread", "lookup", "pub_inputs", "arithmetic", "delta_range",
328 "elliptic", "memory", "nnf", "poseidon2_external", "poseidon2_internal" };
329 }
330
331 auto get()
332 {
334 &busread,
335 &lookup,
336 &pub_inputs,
337 &arithmetic,
339 &elliptic,
340 &memory,
341 &nnf,
344 }
345
346 auto get() const
347 {
349 &busread,
350 &lookup,
351 &pub_inputs,
352 &arithmetic,
354 &elliptic,
355 &memory,
356 &nnf,
359 }
360
361 auto get_gate_blocks() const
362 {
364 &busread,
365 &lookup,
366 &arithmetic,
368 &elliptic,
369 &memory,
370 &nnf,
373 });
374 }
375
376 bool operator==(const MegaTraceBlockData& other) const = default;
377};
378
380 public:
381 static constexpr size_t NUM_WIRES = MegaTraceBlock::NUM_WIRES;
382
383 using FF = fr;
384
386
387 void compute_offsets(size_t trace_offset)
388 {
389 uint32_t offset = static_cast<uint32_t>(trace_offset + NUM_ZERO_ROWS);
390 for (auto& block : this->get()) {
391 block.trace_offset_ = offset;
392 offset += static_cast<uint32_t>(block.size());
393 }
394 }
395
396 void summarize() const
397 {
398 info("Gate blocks summary:");
399 info("goblin ecc op :\t", this->ecc_op.size());
400 info("busread :\t", this->busread.size());
401 info("lookups :\t", this->lookup.size());
402 info("pub inputs :\t", this->pub_inputs.size(), " (populated in decider pk constructor)");
403 info("arithmetic :\t", this->arithmetic.size());
404 info("delta range :\t", this->delta_range.size());
405 info("elliptic :\t", this->elliptic.size());
406 info("memory :\t", this->memory.size());
407 info("nnf :\t", this->nnf.size());
408 info("poseidon ext :\t", this->poseidon2_external.size());
409 info("poseidon int :\t", this->poseidon2_internal.size());
410 info("");
411 info("Total size: ", get_total_size());
412 }
413
414 // Get cumulative size of all blocks
416 {
417 size_t total_size(0);
418 for (const auto& block : this->get()) {
419 total_size += block.size();
420 }
421 return total_size;
422 }
423
424 size_t get_total_size() const
425 {
426 size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk
427 for (const auto& block : this->get()) {
428 total_size += block.size();
429 }
430 return total_size;
431 }
432
433 bool operator==(const MegaExecutionTraceBlocks& other) const = default;
434};
435
436} // namespace bb
Basic structure for storing gate data in a builder.
bool operator==(const MegaExecutionTraceBlocks &other) const =default
void compute_offsets(size_t trace_offset)
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 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_poseidon2_internal() const
virtual SelectorType & q_poseidon2_internal()
virtual SelectorType & q_lookup()
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 const SelectorType & q_lookup() 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() 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.
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.
Abstract interface for a generic selector.
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.
#define info(...)
Definition log.hpp:93
ssize_t offset
Definition engine.cpp:62
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
field< Bn254FrParams > fr
Definition fr.hpp:155
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
static constexpr size_t NUM_BLOCKS
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