-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathopcode.hpp
140 lines (124 loc) · 3.05 KB
/
opcode.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include "barretenberg/numeric/uint128/uint128.hpp"
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <sstream>
#include <string>
namespace bb::avm_trace {
/**
* All AVM opcodes (Keep in sync with TS counterpart code opcodes.ts)
* TODO: Once opcode values are definitive, we should assign them explicitly in the enum below
* and typescript code. This would increase robustness against unintended modifications.
* i.e.: ADD = 0, SUB = 1, etc, ....
* CAUTION: Any change in the list below needs to be carefully followed by
* a potential adaptation of Bytecode::is_valid method.
*/
enum class OpCode : uint8_t {
// Compute
// Compute - Arithmetic
ADD,
SUB,
MUL,
DIV,
FDIV,
// Compute - Comparators
EQ,
LT,
LTE,
// Compute - Bitwise
AND,
OR,
XOR,
NOT,
SHL,
SHR,
// Compute - Type Conversions
CAST,
// Execution Environment
ADDRESS,
STORAGEADDRESS,
SENDER,
FUNCTIONSELECTOR,
TRANSACTIONFEE,
// Execution Environment - Globals
CHAINID,
VERSION,
BLOCKNUMBER,
TIMESTAMP,
COINBASE,
FEEPERL2GAS,
FEEPERDAGAS,
BLOCKL2GASLIMIT,
BLOCKDAGASLIMIT,
// Execution Environment - Calldata
CALLDATACOPY,
// Machine State
// Machine State - Gas
L2GASLEFT,
DAGASLEFT,
// Machine State - Internal Control Flow
JUMP,
JUMPI,
INTERNALCALL,
INTERNALRETURN,
// Machine State - Memory
SET,
MOV,
CMOV,
// World State
SLOAD, // Public Storage
SSTORE, // Public Storage
NOTEHASHEXISTS, // Notes & Nullifiers
EMITNOTEHASH, // Notes & Nullifiers
NULLIFIEREXISTS, // Notes & Nullifiers
EMITNULLIFIER, // Notes & Nullifiers
L1TOL2MSGEXISTS, // Messages
GETCONTRACTINSTANCE,
// Accrued Substate
EMITUNENCRYPTEDLOG,
SENDL2TOL1MSG, // Messages
// Control Flow - Contract Calls
CALL,
STATICCALL,
DELEGATECALL,
RETURN,
REVERT,
// Misc
DEBUGLOG,
// Gadgets
KECCAK,
POSEIDON2,
SHA256,
PEDERSEN,
ECADD,
MSM,
PEDERSENCOMMITMENT,
// Conversions
TORADIXLE,
// Future Gadgets -- pending changes in noir
SHA256COMPRESSION,
KECCAKF1600, // Here for when we eventually support this
// Sentinel
LAST_OPCODE_SENTINEL,
};
class Bytecode {
public:
static bool is_valid(uint8_t byte);
};
// Look into whether we can do something with concepts here to enable OpCode as a parameter
template <typename T>
requires(std::unsigned_integral<T>)
std::string to_hex(T value)
{
std::ostringstream stream;
auto num_bytes = static_cast<uint64_t>(sizeof(T));
auto mask = static_cast<uint64_t>((static_cast<uint128_t>(1) << (num_bytes * 8)) - 1);
auto padding = static_cast<int>(num_bytes * 2);
stream << std::setfill('0') << std::setw(padding) << std::hex << (value & mask);
return stream.str();
}
std::string to_hex(OpCode opcode);
std::string to_string(OpCode opcode);
} // namespace bb::avm_trace