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
45class AluException : public std::runtime_error {
46 public:
47 explicit AluException(const std::string& message)
48 : std::runtime_error("ALU Exception: " + message)
49 {}
50};
51
52// Explanations on default values for b and c:
53// execution.register[X] == 0 and execution.mem_tag_reg[X] == 0 when we throw an error in execution, because
54// in the trace the default value is 0.
55// To have a correct lookup from Execution into ALU, we therefore need to set the default value to 0.
56// Note also that the default value for b allows to deduplicate events with only a being set. Otherwise, the key would
57// not be deterministic.
58struct AluEvent {
62 0); // Avoid unitialized values for ALU ops with one input such as NOT,
63 // TRUNCATE. Otherwise, deduplication is not guaranteed.
65 0); // Avoid unitialized values for ALU ops with one input and one output.
67 // To be used with deduplicating event emitters.
69 Key get_key() const { return { operation, a, b }; }
70
71 bool operator==(const AluEvent& other) const = default;
72};
73
74} // namespace bb::avm2::simulation
static TaggedValue from_tag(ValueTag tag, FF value)
AluException(const std::string &message)
Definition alu_event.hpp:47
std::string to_string(AddressingEventError e)
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::tuple< AluOperation, MemoryValue, MemoryValue > Key
Definition alu_event.hpp:68
std::optional< AluError > error
Definition alu_event.hpp:66
bool operator==(const AluEvent &other) const =default