forked from ethereum/pyethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopcodes.py
146 lines (131 loc) · 4.26 KB
/
opcodes.py
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
# schema: [opcode, ins, outs, gas]
opcodes = {
0x00: ['STOP', 0, 0, 0],
0x01: ['ADD', 2, 1, 3],
0x02: ['MUL', 2, 1, 5],
0x03: ['SUB', 2, 1, 3],
0x04: ['DIV', 2, 1, 5],
0x05: ['SDIV', 2, 1, 5],
0x06: ['MOD', 2, 1, 5],
0x07: ['SMOD', 2, 1, 5],
0x08: ['ADDMOD', 3, 1, 8],
0x09: ['MULMOD', 3, 1, 8],
0x0a: ['EXP', 2, 1, 10],
0x0b: ['SIGNEXTEND', 2, 1, 5],
0x10: ['LT', 2, 1, 3],
0x11: ['GT', 2, 1, 3],
0x12: ['SLT', 2, 1, 3],
0x13: ['SGT', 2, 1, 3],
0x14: ['EQ', 2, 1, 3],
0x15: ['ISZERO', 1, 1, 3],
0x16: ['AND', 2, 1, 3],
0x17: ['OR', 2, 1, 3],
0x18: ['XOR', 2, 1, 3],
0x19: ['NOT', 1, 1, 3],
0x1a: ['BYTE', 2, 1, 3],
0x20: ['SHA3', 2, 1, 30],
0x30: ['ADDRESS', 0, 1, 2],
0x31: ['BALANCE', 1, 1, 20], # now 400
0x32: ['ORIGIN', 0, 1, 2],
0x33: ['CALLER', 0, 1, 2],
0x34: ['CALLVALUE', 0, 1, 2],
0x35: ['CALLDATALOAD', 1, 1, 3],
0x36: ['CALLDATASIZE', 0, 1, 2],
0x37: ['CALLDATACOPY', 3, 0, 3],
0x38: ['CODESIZE', 0, 1, 2],
0x39: ['CODECOPY', 3, 0, 3],
0x3a: ['GASPRICE', 0, 1, 2],
0x3b: ['EXTCODESIZE', 1, 1, 20], # now 700
0x3c: ['EXTCODECOPY', 4, 0, 20], # now 700
0x40: ['BLOCKHASH', 1, 1, 20],
0x41: ['COINBASE', 0, 1, 2],
0x42: ['TIMESTAMP', 0, 1, 2],
0x43: ['NUMBER', 0, 1, 2],
0x44: ['DIFFICULTY', 0, 1, 2],
0x45: ['GASLIMIT', 0, 1, 2],
0x50: ['POP', 1, 0, 2],
0x51: ['MLOAD', 1, 1, 3],
0x52: ['MSTORE', 2, 0, 3],
0x53: ['MSTORE8', 2, 0, 3],
0x54: ['SLOAD', 1, 1, 50], # 200 now
0x55: ['SSTORE', 2, 0, 0], # actual cost 5000-20000 depending on circumstance
0x56: ['JUMP', 1, 0, 8],
0x57: ['JUMPI', 2, 0, 10],
0x58: ['PC', 0, 1, 2],
0x59: ['MSIZE', 0, 1, 2],
0x5a: ['GAS', 0, 1, 2],
0x5b: ['JUMPDEST', 0, 0, 1],
0xa0: ['LOG0', 2, 0, 375],
0xa1: ['LOG1', 3, 0, 750],
0xa2: ['LOG2', 4, 0, 1125],
0xa3: ['LOG3', 5, 0, 1500],
0xa4: ['LOG4', 6, 0, 1875],
0xe1: ['SLOADBYTES', 3, 0, 50], # to be discontinued
0xe2: ['SSTOREBYTES', 3, 0, 0], # to be discontinued
0xe3: ['SSIZE', 1, 1, 50], # to be discontinued
0xf0: ['CREATE', 3, 1, 32000],
0xf1: ['CALL', 7, 1, 40], # 700 now
0xf2: ['CALLCODE', 7, 1, 40], # 700 now
0xf3: ['RETURN', 2, 0, 0],
0xf4: ['DELEGATECALL', 6, 1, 40], # 700 now
0xf5: ['CALLBLACKBOX', 7, 1, 40],
0xfa: ['STATICCALL', 6, 1, 40],
0xfd: ['REVERT', 2, 0, 0],
0xff: ['SUICIDE', 1, 0, 0], # 5000 now
}
for i in range(1, 33):
opcodes[0x5f + i] = ['PUSH' + str(i), 0, 1, 3]
for i in range(1, 17):
opcodes[0x7f + i] = ['DUP' + str(i), i, i + 1, 3]
opcodes[0x8f + i] = ['SWAP' + str(i), i + 1, i + 1, 3]
reverse_opcodes = {}
for o in opcodes:
vars()[opcodes[o][0]] = opcodes[o]
reverse_opcodes[opcodes[o][0]] = o
# Non-opcode gas prices
GDEFAULT = 1
GMEMORY = 3
GQUADRATICMEMDENOM = 512 # 1 gas per 512 quadwords
GEXPONENTBYTE = 10 # cost of EXP exponent per byte
GCOPY = 3 # cost to copy one 32 byte word
GCONTRACTBYTE = 200 # one byte of code in contract creation
GCALLVALUETRANSFER = 9000 # non-zero-valued call
GLOGBYTE = 8 # cost of a byte of logdata
GTXCOST = 21000 # TX BASE GAS COST
GTXDATAZERO = 4 # TX DATA ZERO BYTE GAS COST
GTXDATANONZERO = 68 # TX DATA NON ZERO BYTE GAS COST
GSHA3WORD = 6 # Cost of SHA3 per word
GSHA256BASE = 60 # Base c of SHA256
GSHA256WORD = 12 # Cost of SHA256 per word
GRIPEMD160BASE = 600 # Base cost of RIPEMD160
GRIPEMD160WORD = 120 # Cost of RIPEMD160 per word
GIDENTITYBASE = 15 # Base cost of indentity
GIDENTITYWORD = 3 # Cost of identity per word
GECRECOVER = 3000 # Cost of ecrecover op
GSTIPEND = 2300
GCALLNEWACCOUNT = 25000
GSUICIDEREFUND = 24000
GSTORAGEBASE = 2500
GSTORAGEBYTESTORAGE = 250
GSTORAGEBYTECHANGE = 40
GSTORAGEMIN = 2500
GSSIZE = 50
GSLOADBYTES = 50
GSTORAGEREFUND = 15000
GSTORAGEKILL = 5000
GSTORAGEMOD = 5000
GSTORAGEADD = 20000
GMODEXPQUADDIVISOR = 100
GECADD = 500
GECMUL = 2000
GPAIRINGBASE = 100000
GPAIRINGPERPOINT = 80000
EXP_SUPPLEMENTAL_GAS = 40
# Anti-DoS HF changes
SLOAD_SUPPLEMENTAL_GAS = 150
CALL_SUPPLEMENTAL_GAS = 660
EXTCODELOAD_SUPPLEMENTAL_GAS = 680
BALANCE_SUPPLEMENTAL_GAS = 380
CALL_CHILD_LIMIT_NUM = 63
CALL_CHILD_LIMIT_DENOM = 64
SUICIDE_SUPPLEMENTAL_GAS = 5000