@@ -23,6 +23,7 @@ import (
23
23
// OpCode is an EVM opcode
24
24
type OpCode byte
25
25
26
+ // IsPush specifies if an opcode is a PUSH opcode.
26
27
func (op OpCode ) IsPush () bool {
27
28
switch op {
28
29
case PUSH1 , PUSH2 , PUSH3 , PUSH4 , PUSH5 , PUSH6 , PUSH7 , PUSH8 , PUSH9 , PUSH10 , PUSH11 , PUSH12 , PUSH13 , PUSH14 , PUSH15 , PUSH16 , PUSH17 , PUSH18 , PUSH19 , PUSH20 , PUSH21 , PUSH22 , PUSH23 , PUSH24 , PUSH25 , PUSH26 , PUSH27 , PUSH28 , PUSH29 , PUSH30 , PUSH31 , PUSH32 :
@@ -31,12 +32,13 @@ func (op OpCode) IsPush() bool {
31
32
return false
32
33
}
33
34
35
+ // IsStaticJump specifies if an opcode is JUMP.
34
36
func (op OpCode ) IsStaticJump () bool {
35
37
return op == JUMP
36
38
}
37
39
40
+ // 0x0 range - arithmetic ops.
38
41
const (
39
- // 0x0 range - arithmetic ops
40
42
STOP OpCode = iota
41
43
ADD
42
44
MUL
@@ -51,6 +53,7 @@ const (
51
53
SIGNEXTEND
52
54
)
53
55
56
+ // 0x10 range - comparison ops.
54
57
const (
55
58
LT OpCode = iota + 0x10
56
59
GT
@@ -70,8 +73,8 @@ const (
70
73
SHA3 = 0x20
71
74
)
72
75
76
+ // 0x30 range - closure state.
73
77
const (
74
- // 0x30 range - closure state
75
78
ADDRESS OpCode = 0x30 + iota
76
79
BALANCE
77
80
ORIGIN
@@ -89,8 +92,8 @@ const (
89
92
RETURNDATACOPY
90
93
)
91
94
95
+ // 0x40 range - block operations.
92
96
const (
93
- // 0x40 range - block operations
94
97
BLOCKHASH OpCode = 0x40 + iota
95
98
COINBASE
96
99
TIMESTAMP
@@ -99,8 +102,8 @@ const (
99
102
GASLIMIT
100
103
)
101
104
105
+ // 0x50 range - 'storage' and execution.
102
106
const (
103
- // 0x50 range - 'storage' and execution
104
107
POP OpCode = 0x50 + iota
105
108
MLOAD
106
109
MSTORE
@@ -115,8 +118,8 @@ const (
115
118
JUMPDEST
116
119
)
117
120
121
+ // 0x60 range.
118
122
const (
119
- // 0x60 range
120
123
PUSH1 OpCode = 0x60 + iota
121
124
PUSH2
122
125
PUSH3
@@ -183,6 +186,7 @@ const (
183
186
SWAP16
184
187
)
185
188
189
+ // 0xa0 range - logging ops.
186
190
const (
187
191
LOG0 OpCode = 0xa0 + iota
188
192
LOG1
@@ -191,15 +195,15 @@ const (
191
195
LOG4
192
196
)
193
197
194
- // unofficial opcodes used for parsing
198
+ // unofficial opcodes used for parsing.
195
199
const (
196
200
PUSH OpCode = 0xb0 + iota
197
201
DUP
198
202
SWAP
199
203
)
200
204
205
+ // 0xf0 range - closures.
201
206
const (
202
- // 0xf0 range - closures
203
207
CREATE OpCode = 0xf0 + iota
204
208
CALL
205
209
CALLCODE
@@ -211,9 +215,9 @@ const (
211
215
SELFDESTRUCT = 0xff
212
216
)
213
217
214
- // Since the opcodes aren't all in order we can't use a regular slice
218
+ // Since the opcodes aren't all in order we can't use a regular slice.
215
219
var opCodeToString = map [OpCode ]string {
216
- // 0x0 range - arithmetic ops
220
+ // 0x0 range - arithmetic ops.
217
221
STOP : "STOP" ,
218
222
ADD : "ADD" ,
219
223
MUL : "MUL" ,
@@ -232,7 +236,7 @@ var opCodeToString = map[OpCode]string{
232
236
ISZERO : "ISZERO" ,
233
237
SIGNEXTEND : "SIGNEXTEND" ,
234
238
235
- // 0x10 range - bit ops
239
+ // 0x10 range - bit ops.
236
240
AND : "AND" ,
237
241
OR : "OR" ,
238
242
XOR : "XOR" ,
@@ -243,10 +247,10 @@ var opCodeToString = map[OpCode]string{
243
247
ADDMOD : "ADDMOD" ,
244
248
MULMOD : "MULMOD" ,
245
249
246
- // 0x20 range - crypto
250
+ // 0x20 range - crypto.
247
251
SHA3 : "SHA3" ,
248
252
249
- // 0x30 range - closure state
253
+ // 0x30 range - closure state.
250
254
ADDRESS : "ADDRESS" ,
251
255
BALANCE : "BALANCE" ,
252
256
ORIGIN : "ORIGIN" ,
@@ -263,15 +267,15 @@ var opCodeToString = map[OpCode]string{
263
267
RETURNDATASIZE : "RETURNDATASIZE" ,
264
268
RETURNDATACOPY : "RETURNDATACOPY" ,
265
269
266
- // 0x40 range - block operations
270
+ // 0x40 range - block operations.
267
271
BLOCKHASH : "BLOCKHASH" ,
268
272
COINBASE : "COINBASE" ,
269
273
TIMESTAMP : "TIMESTAMP" ,
270
274
NUMBER : "NUMBER" ,
271
275
DIFFICULTY : "DIFFICULTY" ,
272
276
GASLIMIT : "GASLIMIT" ,
273
277
274
- // 0x50 range - 'storage' and execution
278
+ // 0x50 range - 'storage' and execution.
275
279
POP : "POP" ,
276
280
//DUP: "DUP",
277
281
//SWAP: "SWAP",
@@ -287,7 +291,7 @@ var opCodeToString = map[OpCode]string{
287
291
GAS : "GAS" ,
288
292
JUMPDEST : "JUMPDEST" ,
289
293
290
- // 0x60 range - push
294
+ // 0x60 range - push.
291
295
PUSH1 : "PUSH1" ,
292
296
PUSH2 : "PUSH2" ,
293
297
PUSH3 : "PUSH3" ,
@@ -360,7 +364,7 @@ var opCodeToString = map[OpCode]string{
360
364
LOG3 : "LOG3" ,
361
365
LOG4 : "LOG4" ,
362
366
363
- // 0xf0 range
367
+ // 0xf0 range.
364
368
CREATE : "CREATE" ,
365
369
CALL : "CALL" ,
366
370
RETURN : "RETURN" ,
@@ -524,6 +528,7 @@ var stringToOp = map[string]OpCode{
524
528
"SELFDESTRUCT" : SELFDESTRUCT ,
525
529
}
526
530
531
+ // StringToOp finds the opcode whose name is stored in `str`.
527
532
func StringToOp (str string ) OpCode {
528
533
return stringToOp [str ]
529
534
}
0 commit comments