@@ -23,6 +23,7 @@ import (
2323// OpCode is an EVM opcode
2424type OpCode byte
2525
26+ // IsPush specifies if an opcode is a PUSH opcode.
2627func (op OpCode ) IsPush () bool {
2728 switch op {
2829 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 {
3132 return false
3233}
3334
35+ // IsStaticJump specifies if an opcode is JUMP.
3436func (op OpCode ) IsStaticJump () bool {
3537 return op == JUMP
3638}
3739
40+ // 0x0 range - arithmetic ops.
3841const (
39- // 0x0 range - arithmetic ops
4042 STOP OpCode = iota
4143 ADD
4244 MUL
@@ -51,6 +53,7 @@ const (
5153 SIGNEXTEND
5254)
5355
56+ // 0x10 range - comparison ops.
5457const (
5558 LT OpCode = iota + 0x10
5659 GT
@@ -70,8 +73,8 @@ const (
7073 SHA3 = 0x20
7174)
7275
76+ // 0x30 range - closure state.
7377const (
74- // 0x30 range - closure state
7578 ADDRESS OpCode = 0x30 + iota
7679 BALANCE
7780 ORIGIN
@@ -89,8 +92,8 @@ const (
8992 RETURNDATACOPY
9093)
9194
95+ // 0x40 range - block operations.
9296const (
93- // 0x40 range - block operations
9497 BLOCKHASH OpCode = 0x40 + iota
9598 COINBASE
9699 TIMESTAMP
@@ -99,8 +102,8 @@ const (
99102 GASLIMIT
100103)
101104
105+ // 0x50 range - 'storage' and execution.
102106const (
103- // 0x50 range - 'storage' and execution
104107 POP OpCode = 0x50 + iota
105108 MLOAD
106109 MSTORE
@@ -115,8 +118,8 @@ const (
115118 JUMPDEST
116119)
117120
121+ // 0x60 range.
118122const (
119- // 0x60 range
120123 PUSH1 OpCode = 0x60 + iota
121124 PUSH2
122125 PUSH3
@@ -183,6 +186,7 @@ const (
183186 SWAP16
184187)
185188
189+ // 0xa0 range - logging ops.
186190const (
187191 LOG0 OpCode = 0xa0 + iota
188192 LOG1
@@ -191,15 +195,15 @@ const (
191195 LOG4
192196)
193197
194- // unofficial opcodes used for parsing
198+ // unofficial opcodes used for parsing.
195199const (
196200 PUSH OpCode = 0xb0 + iota
197201 DUP
198202 SWAP
199203)
200204
205+ // 0xf0 range - closures.
201206const (
202- // 0xf0 range - closures
203207 CREATE OpCode = 0xf0 + iota
204208 CALL
205209 CALLCODE
@@ -211,9 +215,9 @@ const (
211215 SELFDESTRUCT = 0xff
212216)
213217
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.
215219var opCodeToString = map [OpCode ]string {
216- // 0x0 range - arithmetic ops
220+ // 0x0 range - arithmetic ops.
217221 STOP : "STOP" ,
218222 ADD : "ADD" ,
219223 MUL : "MUL" ,
@@ -232,7 +236,7 @@ var opCodeToString = map[OpCode]string{
232236 ISZERO : "ISZERO" ,
233237 SIGNEXTEND : "SIGNEXTEND" ,
234238
235- // 0x10 range - bit ops
239+ // 0x10 range - bit ops.
236240 AND : "AND" ,
237241 OR : "OR" ,
238242 XOR : "XOR" ,
@@ -243,10 +247,10 @@ var opCodeToString = map[OpCode]string{
243247 ADDMOD : "ADDMOD" ,
244248 MULMOD : "MULMOD" ,
245249
246- // 0x20 range - crypto
250+ // 0x20 range - crypto.
247251 SHA3 : "SHA3" ,
248252
249- // 0x30 range - closure state
253+ // 0x30 range - closure state.
250254 ADDRESS : "ADDRESS" ,
251255 BALANCE : "BALANCE" ,
252256 ORIGIN : "ORIGIN" ,
@@ -263,15 +267,15 @@ var opCodeToString = map[OpCode]string{
263267 RETURNDATASIZE : "RETURNDATASIZE" ,
264268 RETURNDATACOPY : "RETURNDATACOPY" ,
265269
266- // 0x40 range - block operations
270+ // 0x40 range - block operations.
267271 BLOCKHASH : "BLOCKHASH" ,
268272 COINBASE : "COINBASE" ,
269273 TIMESTAMP : "TIMESTAMP" ,
270274 NUMBER : "NUMBER" ,
271275 DIFFICULTY : "DIFFICULTY" ,
272276 GASLIMIT : "GASLIMIT" ,
273277
274- // 0x50 range - 'storage' and execution
278+ // 0x50 range - 'storage' and execution.
275279 POP : "POP" ,
276280 //DUP: "DUP",
277281 //SWAP: "SWAP",
@@ -287,7 +291,7 @@ var opCodeToString = map[OpCode]string{
287291 GAS : "GAS" ,
288292 JUMPDEST : "JUMPDEST" ,
289293
290- // 0x60 range - push
294+ // 0x60 range - push.
291295 PUSH1 : "PUSH1" ,
292296 PUSH2 : "PUSH2" ,
293297 PUSH3 : "PUSH3" ,
@@ -360,7 +364,7 @@ var opCodeToString = map[OpCode]string{
360364 LOG3 : "LOG3" ,
361365 LOG4 : "LOG4" ,
362366
363- // 0xf0 range
367+ // 0xf0 range.
364368 CREATE : "CREATE" ,
365369 CALL : "CALL" ,
366370 RETURN : "RETURN" ,
@@ -524,6 +528,7 @@ var stringToOp = map[string]OpCode{
524528 "SELFDESTRUCT" : SELFDESTRUCT ,
525529}
526530
531+ // StringToOp finds the opcode whose name is stored in `str`.
527532func StringToOp (str string ) OpCode {
528533 return stringToOp [str ]
529534}
0 commit comments