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
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
314
315 static constexpr size_t NUM_BLOCKS = 11;
316
318 {
319 return { "ecc_op", "busread", "lookup", "pub_inputs", "arithmetic", "delta_range",
320 "elliptic", "memory", "nnf", "poseidon2_external", "poseidon2_internal" };
321 }
322
323 auto get()
324 {
326 &busread,
327 &lookup,
328 &pub_inputs,
329 &arithmetic,
331 &elliptic,
332 &memory,
333 &nnf,
336 }
337
338 auto get() const
339 {
341 &busread,
342 &lookup,
343 &pub_inputs,
344 &arithmetic,
346 &elliptic,
347 &memory,
348 &nnf,
351 }
352
353 auto get_gate_blocks() const
354 {
356 &busread,
357 &lookup,
358 &arithmetic,
360 &elliptic,
361 &memory,
362 &nnf,
365 });
366 }
367
368 bool operator==(const MegaTraceBlockData& other) const = default;
369};
370
372 public:
382 static constexpr size_t NUM_WIRES = MegaTraceBlock::NUM_WIRES;
383
384 using FF = fr;
385
387
389 {
390 uint32_t offset = 1; // start at 1 because the 0th row is unused for selectors for Honk
391 for (auto& block : this->get()) {
392 block.trace_offset_ = offset;
393 offset += static_cast<uint32_t>(block.size());
394 }
395 }
396
397 void summarize() const
398 {
399 info("Gate blocks summary:");
400 info("goblin ecc op :\t", this->ecc_op.size());
401 info("busread :\t", this->busread.size());
402 info("lookups :\t", this->lookup.size());
403 info("pub inputs :\t", this->pub_inputs.size(), " (populated in decider pk constructor)");
404 info("arithmetic :\t", this->arithmetic.size());
405 info("delta range :\t", this->delta_range.size());
406 info("elliptic :\t", this->elliptic.size());
407 info("memory :\t", this->memory.size());
408 info("nnf :\t", this->nnf.size());
409 info("poseidon ext :\t", this->poseidon2_external.size());
410 info("poseidon int :\t", this->poseidon2_internal.size());
411 info("");
412 info("Total size: ", get_total_size());
413 }
414
415 // Get cumulative size of all blocks
417 {
418 size_t total_size(0);
419 for (const auto& block : this->get()) {
420 total_size += block.size();
421 }
422 return total_size;
423 }
424
425 size_t get_total_size() const
426 {
427 size_t total_size = 1; // start at 1 because the 0th row is unused for selectors for Honk
428 for (const auto& block : this->get()) {
429 total_size += block.size();
430 }
431 return total_size;
432 }
433
434 bool operator==(const MegaExecutionTraceBlocks& other) const = default;
435};
436
437} // namespace bb
Basic structure for storing gate data in a builder.
bool operator==(const MegaExecutionTraceBlocks &other) const =default
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 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:75
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