Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
alu_event.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
9
10namespace bb::avm2::simulation {
11
12enum class AluOperation {
13 ADD,
14 SUB,
15 MUL,
16 DIV,
17 FDIV,
18 EQ,
19 LT,
20 LTE,
21 NOT,
22 SHL,
23 SHR,
25};
26
27enum class AluError {
30};
31
32inline std::string to_string(AluError e)
33{
34 switch (e) {
36 return "TAG_ERROR";
38 return "DIV_0_ERROR";
39 }
40
41 // We should be catching all the cases above.
42 __builtin_unreachable();
43}
44
45// Explanations on default values for b and c:
46// execution.register[X] == 0 and execution.mem_tag_reg[X] == 0 when we throw an error in execution, because
47// in the trace the default value is 0.
48// To have a correct lookup from Execution into ALU, we therefore need to set the default value to 0.
49// Note also that the default value for b allows to deduplicate events with only a being set. Otherwise, the key would
50// not be deterministic.
51struct AluEvent {
55 0); // Avoid unitialized values for ALU ops with one input such as NOT,
56 // TRUNCATE. Otherwise, deduplication is not guaranteed.
58 0); // Avoid unitialized values for ALU ops with one input and one output.
60 // To be used with deduplicating event emitters.
62 Key get_key() const { return { operation, a, b }; }
63
64 bool operator==(const AluEvent& other) const = default;
65};
66
67} // namespace bb::avm2::simulation
static TaggedValue from_tag(ValueTag tag, FF value)
std::string to_string(const std::array< FF, N > &arr)
Definition stringify.hpp:29
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::tuple< AluOperation, MemoryValue, MemoryValue > Key
Definition alu_event.hpp:61
std::optional< AluError > error
Definition alu_event.hpp:59
bool operator==(const AluEvent &other) const =default