-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathopcodes.rb
91 lines (86 loc) · 1.99 KB
/
opcodes.rb
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
module Ethereum
class Opcodes
TABLE = {
0x00 => :STOP,
0x01 => :ADD,
0x02 => :MUL,
0x03 => :SUB,
0x04 => :DIV,
0x05 => :SDIV,
0x06 => :MOD,
0x07 => :SMOD,
0x08 => :ADDMOD,
0x09 => :MULMOD,
0x0a => :EXP,
0x0b => :SIGNEXTEND,
0x10 => :LT,
0x11 => :GT,
0x12 => :SLT,
0x13 => :SGT,
0x14 => :EQ,
0x15 => :ISZERO,
0x16 => :AND,
0x17 => :OR,
0x18 => :XOR,
0x19 => :NOT,
0x1a => :BYTE,
0x20 => :KECCAK256,
0x30 => :ADDRESS,
0x31 => :BALANCE,
0x32 => :ORIGIN,
0x33 => :CALLER,
0x34 => :CALLVALUE,
0x35 => :CALLDATALOAD,
0x36 => :CALLDATASIZE,
0x37 => :CALLDATACOPY,
0x38 => :CODESIZE,
0x39 => :CODECOPY,
0x3a => :GASPRICE,
0x3b => :EXTCODESIZE,
0x3c => :EXTCODECOPY,
0x40 => :BLOCKHASH,
0x41 => :COINBASE,
0x42 => :TIMESTAMP,
0x43 => :NUMBER,
0x44 => :DIFFICULTY,
0x45 => :GASLIMIT,
0x50 => :POP,
0x51 => :MLOAD,
0x52 => :MSTORE,
0x53 => :MSTORE8,
0x54 => :SLOAD,
0x55 => :SSTORE,
0x56 => :JUMP,
0x57 => :JUMPI,
0x58 => :PC,
0x59 => :MSIZE,
0x5a => :GAS,
0x5b => :JUMPDEST,
0xa0 => :LOG0,
0xa1 => :LOG1,
0xa2 => :LOG2,
0xa3 => :LOG3,
0xa4 => :LOG4,
0xf0 => :CREATE,
0xf1 => :CALL,
0xf2 => :CALLCODE,
0xf3 => :RETURN,
0xf4 => :DELEGATECALL,
0xf5 => :CREATE2,
0xff => :SUICIDE,
0xfd => :REVERT,
0xfe => :INVALID,
}
32.times do |i|
TABLE[0x60+i] = :"PUSH#{i+1}"
end
16.times do |i|
TABLE[0x80+i] = :"DUP#{i+1}"
TABLE[0x90+i] = :"SWAP#{i+1}"
end
REVERSE_TABLE = TABLE.reduce({}) do |table, (opcode, name)|
table[name] = opcode
table
end
end # class Opcodes
end # module Ethereum