|
|
@ -23,6 +23,7 @@ import ( |
|
|
|
// OpCode is an EVM opcode
|
|
|
|
// OpCode is an EVM opcode
|
|
|
|
type OpCode byte |
|
|
|
type OpCode byte |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IsPush specifies if an opcode is a PUSH opcode.
|
|
|
|
func (op OpCode) IsPush() bool { |
|
|
|
func (op OpCode) IsPush() bool { |
|
|
|
switch op { |
|
|
|
switch op { |
|
|
|
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: |
|
|
|
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 { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IsStaticJump specifies if an opcode is JUMP.
|
|
|
|
func (op OpCode) IsStaticJump() bool { |
|
|
|
func (op OpCode) IsStaticJump() bool { |
|
|
|
return op == JUMP |
|
|
|
return op == JUMP |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x0 range - arithmetic ops.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// 0x0 range - arithmetic ops
|
|
|
|
|
|
|
|
STOP OpCode = iota |
|
|
|
STOP OpCode = iota |
|
|
|
ADD |
|
|
|
ADD |
|
|
|
MUL |
|
|
|
MUL |
|
|
@ -51,6 +53,7 @@ const ( |
|
|
|
SIGNEXTEND |
|
|
|
SIGNEXTEND |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x10 range - comparison ops.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
LT OpCode = iota + 0x10 |
|
|
|
LT OpCode = iota + 0x10 |
|
|
|
GT |
|
|
|
GT |
|
|
@ -70,8 +73,8 @@ const ( |
|
|
|
SHA3 = 0x20 |
|
|
|
SHA3 = 0x20 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x30 range - closure state.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// 0x30 range - closure state
|
|
|
|
|
|
|
|
ADDRESS OpCode = 0x30 + iota |
|
|
|
ADDRESS OpCode = 0x30 + iota |
|
|
|
BALANCE |
|
|
|
BALANCE |
|
|
|
ORIGIN |
|
|
|
ORIGIN |
|
|
@ -89,8 +92,8 @@ const ( |
|
|
|
RETURNDATACOPY |
|
|
|
RETURNDATACOPY |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x40 range - block operations.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// 0x40 range - block operations
|
|
|
|
|
|
|
|
BLOCKHASH OpCode = 0x40 + iota |
|
|
|
BLOCKHASH OpCode = 0x40 + iota |
|
|
|
COINBASE |
|
|
|
COINBASE |
|
|
|
TIMESTAMP |
|
|
|
TIMESTAMP |
|
|
@ -99,8 +102,8 @@ const ( |
|
|
|
GASLIMIT |
|
|
|
GASLIMIT |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x50 range - 'storage' and execution.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// 0x50 range - 'storage' and execution
|
|
|
|
|
|
|
|
POP OpCode = 0x50 + iota |
|
|
|
POP OpCode = 0x50 + iota |
|
|
|
MLOAD |
|
|
|
MLOAD |
|
|
|
MSTORE |
|
|
|
MSTORE |
|
|
@ -115,8 +118,8 @@ const ( |
|
|
|
JUMPDEST |
|
|
|
JUMPDEST |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0x60 range.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// 0x60 range
|
|
|
|
|
|
|
|
PUSH1 OpCode = 0x60 + iota |
|
|
|
PUSH1 OpCode = 0x60 + iota |
|
|
|
PUSH2 |
|
|
|
PUSH2 |
|
|
|
PUSH3 |
|
|
|
PUSH3 |
|
|
@ -183,6 +186,7 @@ const ( |
|
|
|
SWAP16 |
|
|
|
SWAP16 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0xa0 range - logging ops.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
LOG0 OpCode = 0xa0 + iota |
|
|
|
LOG0 OpCode = 0xa0 + iota |
|
|
|
LOG1 |
|
|
|
LOG1 |
|
|
@ -191,15 +195,15 @@ const ( |
|
|
|
LOG4 |
|
|
|
LOG4 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// unofficial opcodes used for parsing
|
|
|
|
// unofficial opcodes used for parsing.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
PUSH OpCode = 0xb0 + iota |
|
|
|
PUSH OpCode = 0xb0 + iota |
|
|
|
DUP |
|
|
|
DUP |
|
|
|
SWAP |
|
|
|
SWAP |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 0xf0 range - closures.
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
// 0xf0 range - closures
|
|
|
|
|
|
|
|
CREATE OpCode = 0xf0 + iota |
|
|
|
CREATE OpCode = 0xf0 + iota |
|
|
|
CALL |
|
|
|
CALL |
|
|
|
CALLCODE |
|
|
|
CALLCODE |
|
|
@ -211,9 +215,9 @@ const ( |
|
|
|
SELFDESTRUCT = 0xff |
|
|
|
SELFDESTRUCT = 0xff |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Since the opcodes aren't all in order we can't use a regular slice
|
|
|
|
// Since the opcodes aren't all in order we can't use a regular slice.
|
|
|
|
var opCodeToString = map[OpCode]string{ |
|
|
|
var opCodeToString = map[OpCode]string{ |
|
|
|
// 0x0 range - arithmetic ops
|
|
|
|
// 0x0 range - arithmetic ops.
|
|
|
|
STOP: "STOP", |
|
|
|
STOP: "STOP", |
|
|
|
ADD: "ADD", |
|
|
|
ADD: "ADD", |
|
|
|
MUL: "MUL", |
|
|
|
MUL: "MUL", |
|
|
@ -232,7 +236,7 @@ var opCodeToString = map[OpCode]string{ |
|
|
|
ISZERO: "ISZERO", |
|
|
|
ISZERO: "ISZERO", |
|
|
|
SIGNEXTEND: "SIGNEXTEND", |
|
|
|
SIGNEXTEND: "SIGNEXTEND", |
|
|
|
|
|
|
|
|
|
|
|
// 0x10 range - bit ops
|
|
|
|
// 0x10 range - bit ops.
|
|
|
|
AND: "AND", |
|
|
|
AND: "AND", |
|
|
|
OR: "OR", |
|
|
|
OR: "OR", |
|
|
|
XOR: "XOR", |
|
|
|
XOR: "XOR", |
|
|
@ -243,10 +247,10 @@ var opCodeToString = map[OpCode]string{ |
|
|
|
ADDMOD: "ADDMOD", |
|
|
|
ADDMOD: "ADDMOD", |
|
|
|
MULMOD: "MULMOD", |
|
|
|
MULMOD: "MULMOD", |
|
|
|
|
|
|
|
|
|
|
|
// 0x20 range - crypto
|
|
|
|
// 0x20 range - crypto.
|
|
|
|
SHA3: "SHA3", |
|
|
|
SHA3: "SHA3", |
|
|
|
|
|
|
|
|
|
|
|
// 0x30 range - closure state
|
|
|
|
// 0x30 range - closure state.
|
|
|
|
ADDRESS: "ADDRESS", |
|
|
|
ADDRESS: "ADDRESS", |
|
|
|
BALANCE: "BALANCE", |
|
|
|
BALANCE: "BALANCE", |
|
|
|
ORIGIN: "ORIGIN", |
|
|
|
ORIGIN: "ORIGIN", |
|
|
@ -263,7 +267,7 @@ var opCodeToString = map[OpCode]string{ |
|
|
|
RETURNDATASIZE: "RETURNDATASIZE", |
|
|
|
RETURNDATASIZE: "RETURNDATASIZE", |
|
|
|
RETURNDATACOPY: "RETURNDATACOPY", |
|
|
|
RETURNDATACOPY: "RETURNDATACOPY", |
|
|
|
|
|
|
|
|
|
|
|
// 0x40 range - block operations
|
|
|
|
// 0x40 range - block operations.
|
|
|
|
BLOCKHASH: "BLOCKHASH", |
|
|
|
BLOCKHASH: "BLOCKHASH", |
|
|
|
COINBASE: "COINBASE", |
|
|
|
COINBASE: "COINBASE", |
|
|
|
TIMESTAMP: "TIMESTAMP", |
|
|
|
TIMESTAMP: "TIMESTAMP", |
|
|
@ -271,7 +275,7 @@ var opCodeToString = map[OpCode]string{ |
|
|
|
DIFFICULTY: "DIFFICULTY", |
|
|
|
DIFFICULTY: "DIFFICULTY", |
|
|
|
GASLIMIT: "GASLIMIT", |
|
|
|
GASLIMIT: "GASLIMIT", |
|
|
|
|
|
|
|
|
|
|
|
// 0x50 range - 'storage' and execution
|
|
|
|
// 0x50 range - 'storage' and execution.
|
|
|
|
POP: "POP", |
|
|
|
POP: "POP", |
|
|
|
//DUP: "DUP",
|
|
|
|
//DUP: "DUP",
|
|
|
|
//SWAP: "SWAP",
|
|
|
|
//SWAP: "SWAP",
|
|
|
@ -287,7 +291,7 @@ var opCodeToString = map[OpCode]string{ |
|
|
|
GAS: "GAS", |
|
|
|
GAS: "GAS", |
|
|
|
JUMPDEST: "JUMPDEST", |
|
|
|
JUMPDEST: "JUMPDEST", |
|
|
|
|
|
|
|
|
|
|
|
// 0x60 range - push
|
|
|
|
// 0x60 range - push.
|
|
|
|
PUSH1: "PUSH1", |
|
|
|
PUSH1: "PUSH1", |
|
|
|
PUSH2: "PUSH2", |
|
|
|
PUSH2: "PUSH2", |
|
|
|
PUSH3: "PUSH3", |
|
|
|
PUSH3: "PUSH3", |
|
|
@ -360,7 +364,7 @@ var opCodeToString = map[OpCode]string{ |
|
|
|
LOG3: "LOG3", |
|
|
|
LOG3: "LOG3", |
|
|
|
LOG4: "LOG4", |
|
|
|
LOG4: "LOG4", |
|
|
|
|
|
|
|
|
|
|
|
// 0xf0 range
|
|
|
|
// 0xf0 range.
|
|
|
|
CREATE: "CREATE", |
|
|
|
CREATE: "CREATE", |
|
|
|
CALL: "CALL", |
|
|
|
CALL: "CALL", |
|
|
|
RETURN: "RETURN", |
|
|
|
RETURN: "RETURN", |
|
|
@ -524,6 +528,7 @@ var stringToOp = map[string]OpCode{ |
|
|
|
"SELFDESTRUCT": SELFDESTRUCT, |
|
|
|
"SELFDESTRUCT": SELFDESTRUCT, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StringToOp finds the opcode whose name is stored in `str`.
|
|
|
|
func StringToOp(str string) OpCode { |
|
|
|
func StringToOp(str string) OpCode { |
|
|
|
return stringToOp[str] |
|
|
|
return stringToOp[str] |
|
|
|
} |
|
|
|
} |
|
|
|