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
15#include <cstdint>
16
17namespace bb {
18
19class MegaTraceBlock : public ExecutionTraceBlock<fr, /*NUM_WIRES_ */ 4> {
20 public:
22
23 virtual SelectorType& q_busread() { return this->zero_selectors[0]; };
24 virtual SelectorType& q_lookup() { return this->zero_selectors[1]; };
25 virtual SelectorType& q_arith() { return this->zero_selectors[2]; };
26 virtual SelectorType& q_delta_range() { return this->zero_selectors[3]; };
27 virtual SelectorType& q_elliptic() { return this->zero_selectors[4]; };
28 virtual SelectorType& q_memory() { return this->zero_selectors[5]; };
29 virtual SelectorType& q_nnf() { return this->zero_selectors[6]; };
30 virtual SelectorType& q_poseidon2_external() { return this->zero_selectors[7]; };
31 virtual SelectorType& q_poseidon2_internal() { return this->zero_selectors[8]; };
32
33 virtual const SelectorType& q_busread() const { return this->zero_selectors[0]; };
34 virtual const SelectorType& q_lookup() const { return this->zero_selectors[1]; };
35 virtual const SelectorType& q_arith() const { return this->zero_selectors[2]; };
36 virtual const SelectorType& q_delta_range() const { return this->zero_selectors[3]; };
37 virtual const SelectorType& q_elliptic() const { return this->zero_selectors[4]; };
38 virtual const SelectorType& q_memory() const { return this->zero_selectors[5]; };
39 virtual const SelectorType& q_nnf() const { return this->zero_selectors[6]; };
40 virtual const SelectorType& q_poseidon2_external() const { return this->zero_selectors[7]; };
41 virtual const SelectorType& q_poseidon2_internal() const { return this->zero_selectors[8]; };
42
44 {
45 return {
46 q_busread(),
47 q_lookup(),
48 q_arith(),
50 q_elliptic(),
51 q_memory(),
52 q_nnf(),
55 };
56 }
57
59 {
60 return RefVector{
61 q_m(),
62 q_c(),
63 q_1(),
64 q_2(),
65 q_3(),
66 q_4(),
67 q_busread(),
68 q_lookup(),
69 q_arith(),
71 q_elliptic(),
72 q_memory(),
73 q_nnf(),
76 };
77 }
78
86
93 void resize_additional(size_t new_size) { q_busread().resize(new_size); };
94
98 virtual void set_gate_selector([[maybe_unused]] const fr& value) {}
99
100 private:
102};
103
105
107 public:
108 SelectorType& q_busread() override { return gate_selector; }
109
122
123 private:
125};
126
128 public:
129 SelectorType& q_lookup() override { return gate_selector; }
130
143
144 private:
146};
147
149 public:
150 SelectorType& q_arith() override { return gate_selector; }
151
164
165 private:
167};
168
170 public:
172
173 void set_gate_selector(const fr& value) override
174 {
178 gate_selector.emplace_back(value);
181 q_nnf().emplace_back(0);
184 }
185
186 private:
188};
189
191 public:
192 SelectorType& q_elliptic() override { return gate_selector; }
193
194 void set_gate_selector(const fr& value) override
195 {
200 gate_selector.emplace_back(value);
202 q_nnf().emplace_back(0);
205 }
206
207 private:
209};
210
212 public:
213 SelectorType& q_memory() override { return gate_selector; }
214
227
228 private:
230};
231
233 public:
234 SelectorType& q_nnf() override { return gate_selector; }
235
248
249 private:
251};
252
254 public:
256
257 void set_gate_selector(const fr& value) override
258 {
265 q_nnf().emplace_back(0);
266 gate_selector.emplace_back(value);
268 }
269
270 private:
272};
273
275 public:
277
278 void set_gate_selector(const fr& value) override
279 {
286 q_nnf().emplace_back(0);
288 gate_selector.emplace_back(value);
289 }
290
291 private:
293};
294
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
388 {
389 uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
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 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.
void info(Args... args)
Definition log.hpp:89
ssize_t offset
Definition engine.cpp:36
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
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
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