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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Opcode(pub u8);
impl Opcode {
pub const STOP: Opcode = Opcode(0x00);
pub const ADD: Opcode = Opcode(0x01);
pub const MUL: Opcode = Opcode(0x02);
pub const SUB: Opcode = Opcode(0x03);
pub const DIV: Opcode = Opcode(0x04);
pub const SDIV: Opcode = Opcode(0x05);
pub const MOD: Opcode = Opcode(0x06);
pub const SMOD: Opcode = Opcode(0x07);
pub const ADDMOD: Opcode = Opcode(0x08);
pub const MULMOD: Opcode = Opcode(0x09);
pub const EXP: Opcode = Opcode(0x0a);
pub const SIGNEXTEND: Opcode = Opcode(0x0b);
pub const LT: Opcode = Opcode(0x10);
pub const GT: Opcode = Opcode(0x11);
pub const SLT: Opcode = Opcode(0x12);
pub const SGT: Opcode = Opcode(0x13);
pub const EQ: Opcode = Opcode(0x14);
pub const ISZERO: Opcode = Opcode(0x15);
pub const AND: Opcode = Opcode(0x16);
pub const OR: Opcode = Opcode(0x17);
pub const XOR: Opcode = Opcode(0x18);
pub const NOT: Opcode = Opcode(0x19);
pub const BYTE: Opcode = Opcode(0x1a);
pub const CALLDATALOAD: Opcode = Opcode(0x35);
pub const CALLDATASIZE: Opcode = Opcode(0x36);
pub const CALLDATACOPY: Opcode = Opcode(0x37);
pub const CODESIZE: Opcode = Opcode(0x38);
pub const CODECOPY: Opcode = Opcode(0x39);
pub const SHL: Opcode = Opcode(0x1b);
pub const SHR: Opcode = Opcode(0x1c);
pub const SAR: Opcode = Opcode(0x1d);
pub const POP: Opcode = Opcode(0x50);
pub const MLOAD: Opcode = Opcode(0x51);
pub const MSTORE: Opcode = Opcode(0x52);
pub const MSTORE8: Opcode = Opcode(0x53);
pub const JUMP: Opcode = Opcode(0x56);
pub const JUMPI: Opcode = Opcode(0x57);
pub const PC: Opcode = Opcode(0x58);
pub const MSIZE: Opcode = Opcode(0x59);
pub const JUMPDEST: Opcode = Opcode(0x5b);
pub const PUSH1: Opcode = Opcode(0x60);
pub const PUSH2: Opcode = Opcode(0x61);
pub const PUSH3: Opcode = Opcode(0x62);
pub const PUSH4: Opcode = Opcode(0x63);
pub const PUSH5: Opcode = Opcode(0x64);
pub const PUSH6: Opcode = Opcode(0x65);
pub const PUSH7: Opcode = Opcode(0x66);
pub const PUSH8: Opcode = Opcode(0x67);
pub const PUSH9: Opcode = Opcode(0x68);
pub const PUSH10: Opcode = Opcode(0x69);
pub const PUSH11: Opcode = Opcode(0x6a);
pub const PUSH12: Opcode = Opcode(0x6b);
pub const PUSH13: Opcode = Opcode(0x6c);
pub const PUSH14: Opcode = Opcode(0x6d);
pub const PUSH15: Opcode = Opcode(0x6e);
pub const PUSH16: Opcode = Opcode(0x6f);
pub const PUSH17: Opcode = Opcode(0x70);
pub const PUSH18: Opcode = Opcode(0x71);
pub const PUSH19: Opcode = Opcode(0x72);
pub const PUSH20: Opcode = Opcode(0x73);
pub const PUSH21: Opcode = Opcode(0x74);
pub const PUSH22: Opcode = Opcode(0x75);
pub const PUSH23: Opcode = Opcode(0x76);
pub const PUSH24: Opcode = Opcode(0x77);
pub const PUSH25: Opcode = Opcode(0x78);
pub const PUSH26: Opcode = Opcode(0x79);
pub const PUSH27: Opcode = Opcode(0x7a);
pub const PUSH28: Opcode = Opcode(0x7b);
pub const PUSH29: Opcode = Opcode(0x7c);
pub const PUSH30: Opcode = Opcode(0x7d);
pub const PUSH31: Opcode = Opcode(0x7e);
pub const PUSH32: Opcode = Opcode(0x7f);
pub const DUP1: Opcode = Opcode(0x80);
pub const DUP2: Opcode = Opcode(0x81);
pub const DUP3: Opcode = Opcode(0x82);
pub const DUP4: Opcode = Opcode(0x83);
pub const DUP5: Opcode = Opcode(0x84);
pub const DUP6: Opcode = Opcode(0x85);
pub const DUP7: Opcode = Opcode(0x86);
pub const DUP8: Opcode = Opcode(0x87);
pub const DUP9: Opcode = Opcode(0x88);
pub const DUP10: Opcode = Opcode(0x89);
pub const DUP11: Opcode = Opcode(0x8a);
pub const DUP12: Opcode = Opcode(0x8b);
pub const DUP13: Opcode = Opcode(0x8c);
pub const DUP14: Opcode = Opcode(0x8d);
pub const DUP15: Opcode = Opcode(0x8e);
pub const DUP16: Opcode = Opcode(0x8f);
pub const SWAP1: Opcode = Opcode(0x90);
pub const SWAP2: Opcode = Opcode(0x91);
pub const SWAP3: Opcode = Opcode(0x92);
pub const SWAP4: Opcode = Opcode(0x93);
pub const SWAP5: Opcode = Opcode(0x94);
pub const SWAP6: Opcode = Opcode(0x95);
pub const SWAP7: Opcode = Opcode(0x96);
pub const SWAP8: Opcode = Opcode(0x97);
pub const SWAP9: Opcode = Opcode(0x98);
pub const SWAP10: Opcode = Opcode(0x99);
pub const SWAP11: Opcode = Opcode(0x9a);
pub const SWAP12: Opcode = Opcode(0x9b);
pub const SWAP13: Opcode = Opcode(0x9c);
pub const SWAP14: Opcode = Opcode(0x9d);
pub const SWAP15: Opcode = Opcode(0x9e);
pub const SWAP16: Opcode = Opcode(0x9f);
pub const RETURN: Opcode = Opcode(0xf3);
pub const REVERT: Opcode = Opcode(0xfd);
pub const INVALID: Opcode = Opcode(0xfe);
}
impl Opcode {
pub const SHA3: Opcode = Opcode(0x20);
pub const ADDRESS: Opcode = Opcode(0x30);
pub const BALANCE: Opcode = Opcode(0x31);
pub const SELFBALANCE: Opcode = Opcode(0x47);
pub const ORIGIN: Opcode = Opcode(0x32);
pub const CALLER: Opcode = Opcode(0x33);
pub const CALLVALUE: Opcode = Opcode(0x34);
pub const GASPRICE: Opcode = Opcode(0x3a);
pub const EXTCODESIZE: Opcode = Opcode(0x3b);
pub const EXTCODECOPY: Opcode = Opcode(0x3c);
pub const EXTCODEHASH: Opcode = Opcode(0x3f);
pub const RETURNDATASIZE: Opcode = Opcode(0x3d);
pub const RETURNDATACOPY: Opcode = Opcode(0x3e);
pub const BLOCKHASH: Opcode = Opcode(0x40);
pub const COINBASE: Opcode = Opcode(0x41);
pub const TIMESTAMP: Opcode = Opcode(0x42);
pub const NUMBER: Opcode = Opcode(0x43);
pub const DIFFICULTY: Opcode = Opcode(0x44);
pub const GASLIMIT: Opcode = Opcode(0x45);
pub const SLOAD: Opcode = Opcode(0x54);
pub const SSTORE: Opcode = Opcode(0x55);
pub const GAS: Opcode = Opcode(0x5a);
pub const LOG0: Opcode = Opcode(0xa0);
pub const LOG1: Opcode = Opcode(0xa1);
pub const LOG2: Opcode = Opcode(0xa2);
pub const LOG3: Opcode = Opcode(0xa3);
pub const LOG4: Opcode = Opcode(0xa4);
pub const CREATE: Opcode = Opcode(0xf0);
pub const CREATE2: Opcode = Opcode(0xf5);
pub const CALL: Opcode = Opcode(0xf1);
pub const CALLCODE: Opcode = Opcode(0xf2);
pub const DELEGATECALL: Opcode = Opcode(0xf4);
pub const STATICCALL: Opcode = Opcode(0xfa);
pub const SUICIDE: Opcode = Opcode(0xff);
pub const CHAINID: Opcode = Opcode(0x46);
}
impl Opcode {
pub fn is_push(&self) -> Option<u8> {
let value = self.0;
if value >= 0x60 && value <= 0x7f {
Some(value - 0x60 + 1)
} else {
None
}
}
#[inline]
pub const fn as_u8(&self) -> u8 {
self.0
}
#[inline]
pub const fn as_usize(&self) -> usize {
self.0 as usize
}
}