ethereum.forks.constantinople.vm.instructions

EVM Instruction Encoding (Opcodes).

.. contents:: Table of Contents :backlinks: none :local:

Introduction

Machine readable representations of EVM instructions, and a mapping to their implementations.

Ops

Enum for EVM Opcodes.

class Ops:

ADD

38
    ADD = 0x01

MUL

39
    MUL = 0x02

SUB

40
    SUB = 0x03

DIV

41
    DIV = 0x04

SDIV

42
    SDIV = 0x05

MOD

43
    MOD = 0x06

SMOD

44
    SMOD = 0x07

ADDMOD

45
    ADDMOD = 0x08

MULMOD

46
    MULMOD = 0x09

EXP

47
    EXP = 0x0A

SIGNEXTEND

48
    SIGNEXTEND = 0x0B

LT

51
    LT = 0x10

GT

52
    GT = 0x11

SLT

53
    SLT = 0x12

SGT

54
    SGT = 0x13

EQ

55
    EQ = 0x14

ISZERO

56
    ISZERO = 0x15

AND

59
    AND = 0x16

OR

60
    OR = 0x17

XOR

61
    XOR = 0x18

NOT

62
    NOT = 0x19

BYTE

63
    BYTE = 0x1A

SHL

64
    SHL = 0x1B

SHR

65
    SHR = 0x1C

SAR

66
    SAR = 0x1D

KECCAK

69
    KECCAK = 0x20

ADDRESS

72
    ADDRESS = 0x30

BALANCE

73
    BALANCE = 0x31

ORIGIN

74
    ORIGIN = 0x32

CALLER

75
    CALLER = 0x33

CALLVALUE

76
    CALLVALUE = 0x34

CALLDATALOAD

77
    CALLDATALOAD = 0x35

CALLDATASIZE

78
    CALLDATASIZE = 0x36

CALLDATACOPY

79
    CALLDATACOPY = 0x37

CODESIZE

80
    CODESIZE = 0x38

CODECOPY

81
    CODECOPY = 0x39

GASPRICE

82
    GASPRICE = 0x3A

EXTCODESIZE

83
    EXTCODESIZE = 0x3B

EXTCODECOPY

84
    EXTCODECOPY = 0x3C

RETURNDATASIZE

85
    RETURNDATASIZE = 0x3D

RETURNDATACOPY

86
    RETURNDATACOPY = 0x3E

EXTCODEHASH

87
    EXTCODEHASH = 0x3F

BLOCKHASH

90
    BLOCKHASH = 0x40

COINBASE

91
    COINBASE = 0x41

TIMESTAMP

92
    TIMESTAMP = 0x42

NUMBER

93
    NUMBER = 0x43

DIFFICULTY

94
    DIFFICULTY = 0x44

GASLIMIT

95
    GASLIMIT = 0x45

STOP

98
    STOP = 0x00

JUMP

99
    JUMP = 0x56

JUMPI

100
    JUMPI = 0x57

PC

101
    PC = 0x58

GAS

102
    GAS = 0x5A

JUMPDEST

103
    JUMPDEST = 0x5B

SLOAD

106
    SLOAD = 0x54

SSTORE

107
    SSTORE = 0x55

POP

110
    POP = 0x50

PUSH1

113
    PUSH1 = 0x60

PUSH2

114
    PUSH2 = 0x61

PUSH3

115
    PUSH3 = 0x62

PUSH4

116
    PUSH4 = 0x63

PUSH5

117
    PUSH5 = 0x64

PUSH6

118
    PUSH6 = 0x65

PUSH7

119
    PUSH7 = 0x66

PUSH8

120
    PUSH8 = 0x67

PUSH9

121
    PUSH9 = 0x68

PUSH10

122
    PUSH10 = 0x69

PUSH11

123
    PUSH11 = 0x6A

PUSH12

124
    PUSH12 = 0x6B

PUSH13

125
    PUSH13 = 0x6C

PUSH14

126
    PUSH14 = 0x6D

PUSH15

127
    PUSH15 = 0x6E

PUSH16

128
    PUSH16 = 0x6F

PUSH17

129
    PUSH17 = 0x70

PUSH18

130
    PUSH18 = 0x71

PUSH19

131
    PUSH19 = 0x72

PUSH20

132
    PUSH20 = 0x73

PUSH21

133
    PUSH21 = 0x74

PUSH22

134
    PUSH22 = 0x75

PUSH23

135
    PUSH23 = 0x76

PUSH24

136
    PUSH24 = 0x77

PUSH25

137
    PUSH25 = 0x78

PUSH26

138
    PUSH26 = 0x79

PUSH27

139
    PUSH27 = 0x7A

PUSH28

140
    PUSH28 = 0x7B

PUSH29

141
    PUSH29 = 0x7C

PUSH30

142
    PUSH30 = 0x7D

PUSH31

143
    PUSH31 = 0x7E

PUSH32

144
    PUSH32 = 0x7F

DUP1

147
    DUP1 = 0x80

DUP2

148
    DUP2 = 0x81

DUP3

149
    DUP3 = 0x82

DUP4

150
    DUP4 = 0x83

DUP5

151
    DUP5 = 0x84

DUP6

152
    DUP6 = 0x85

DUP7

153
    DUP7 = 0x86

DUP8

154
    DUP8 = 0x87

DUP9

155
    DUP9 = 0x88

DUP10

156
    DUP10 = 0x89

DUP11

157
    DUP11 = 0x8A

DUP12

158
    DUP12 = 0x8B

DUP13

159
    DUP13 = 0x8C

DUP14

160
    DUP14 = 0x8D

DUP15

161
    DUP15 = 0x8E

DUP16

162
    DUP16 = 0x8F

SWAP1

165
    SWAP1 = 0x90

SWAP2

166
    SWAP2 = 0x91

SWAP3

167
    SWAP3 = 0x92

SWAP4

168
    SWAP4 = 0x93

SWAP5

169
    SWAP5 = 0x94

SWAP6

170
    SWAP6 = 0x95

SWAP7

171
    SWAP7 = 0x96

SWAP8

172
    SWAP8 = 0x97

SWAP9

173
    SWAP9 = 0x98

SWAP10

174
    SWAP10 = 0x99

SWAP11

175
    SWAP11 = 0x9A

SWAP12

176
    SWAP12 = 0x9B

SWAP13

177
    SWAP13 = 0x9C

SWAP14

178
    SWAP14 = 0x9D

SWAP15

179
    SWAP15 = 0x9E

SWAP16

180
    SWAP16 = 0x9F

MLOAD

183
    MLOAD = 0x51

MSTORE

184
    MSTORE = 0x52

MSTORE8

185
    MSTORE8 = 0x53

MSIZE

186
    MSIZE = 0x59

LOG0

189
    LOG0 = 0xA0

LOG1

190
    LOG1 = 0xA1

LOG2

191
    LOG2 = 0xA2

LOG3

192
    LOG3 = 0xA3

LOG4

193
    LOG4 = 0xA4

CREATE

196
    CREATE = 0xF0

CALL

197
    CALL = 0xF1

CALLCODE

198
    CALLCODE = 0xF2

RETURN

199
    RETURN = 0xF3

DELEGATECALL

200
    DELEGATECALL = 0xF4

CREATE2

201
    CREATE2 = 0xF5

STATICCALL

202
    STATICCALL = 0xFA

REVERT

203
    REVERT = 0xFD

SELFDESTRUCT

204
    SELFDESTRUCT = 0xFF

op_implementation

207
op_implementation: Dict[Ops, Callable] = {
208
    Ops.STOP: control_flow_instructions.stop,
209
    Ops.ADD: arithmetic_instructions.add,
210
    Ops.MUL: arithmetic_instructions.mul,
211
    Ops.SUB: arithmetic_instructions.sub,
212
    Ops.DIV: arithmetic_instructions.div,
213
    Ops.SDIV: arithmetic_instructions.sdiv,
214
    Ops.MOD: arithmetic_instructions.mod,
215
    Ops.SMOD: arithmetic_instructions.smod,
216
    Ops.ADDMOD: arithmetic_instructions.addmod,
217
    Ops.MULMOD: arithmetic_instructions.mulmod,
218
    Ops.EXP: arithmetic_instructions.exp,
219
    Ops.SIGNEXTEND: arithmetic_instructions.signextend,
220
    Ops.LT: comparison_instructions.less_than,
221
    Ops.GT: comparison_instructions.greater_than,
222
    Ops.SLT: comparison_instructions.signed_less_than,
223
    Ops.SGT: comparison_instructions.signed_greater_than,
224
    Ops.EQ: comparison_instructions.equal,
225
    Ops.ISZERO: comparison_instructions.is_zero,
226
    Ops.AND: bitwise_instructions.bitwise_and,
227
    Ops.OR: bitwise_instructions.bitwise_or,
228
    Ops.XOR: bitwise_instructions.bitwise_xor,
229
    Ops.NOT: bitwise_instructions.bitwise_not,
230
    Ops.BYTE: bitwise_instructions.get_byte,
231
    Ops.SHL: bitwise_instructions.bitwise_shl,
232
    Ops.SHR: bitwise_instructions.bitwise_shr,
233
    Ops.SAR: bitwise_instructions.bitwise_sar,
234
    Ops.KECCAK: keccak_instructions.keccak,
235
    Ops.SLOAD: storage_instructions.sload,
236
    Ops.BLOCKHASH: block_instructions.block_hash,
237
    Ops.COINBASE: block_instructions.coinbase,
238
    Ops.TIMESTAMP: block_instructions.timestamp,
239
    Ops.NUMBER: block_instructions.number,
240
    Ops.DIFFICULTY: block_instructions.difficulty,
241
    Ops.GASLIMIT: block_instructions.gas_limit,
242
    Ops.MLOAD: memory_instructions.mload,
243
    Ops.MSTORE: memory_instructions.mstore,
244
    Ops.MSTORE8: memory_instructions.mstore8,
245
    Ops.MSIZE: memory_instructions.msize,
246
    Ops.ADDRESS: environment_instructions.address,
247
    Ops.BALANCE: environment_instructions.balance,
248
    Ops.ORIGIN: environment_instructions.origin,
249
    Ops.CALLER: environment_instructions.caller,
250
    Ops.CALLVALUE: environment_instructions.callvalue,
251
    Ops.CALLDATALOAD: environment_instructions.calldataload,
252
    Ops.CALLDATASIZE: environment_instructions.calldatasize,
253
    Ops.CALLDATACOPY: environment_instructions.calldatacopy,
254
    Ops.CODESIZE: environment_instructions.codesize,
255
    Ops.CODECOPY: environment_instructions.codecopy,
256
    Ops.GASPRICE: environment_instructions.gasprice,
257
    Ops.EXTCODESIZE: environment_instructions.extcodesize,
258
    Ops.EXTCODECOPY: environment_instructions.extcodecopy,
259
    Ops.RETURNDATASIZE: environment_instructions.returndatasize,
260
    Ops.RETURNDATACOPY: environment_instructions.returndatacopy,
261
    Ops.EXTCODEHASH: environment_instructions.extcodehash,
262
    Ops.SSTORE: storage_instructions.sstore,
263
    Ops.JUMP: control_flow_instructions.jump,
264
    Ops.JUMPI: control_flow_instructions.jumpi,
265
    Ops.PC: control_flow_instructions.pc,
266
    Ops.GAS: control_flow_instructions.gas_left,
267
    Ops.JUMPDEST: control_flow_instructions.jumpdest,
268
    Ops.POP: stack_instructions.pop,
269
    Ops.PUSH1: stack_instructions.push1,
270
    Ops.PUSH2: stack_instructions.push2,
271
    Ops.PUSH3: stack_instructions.push3,
272
    Ops.PUSH4: stack_instructions.push4,
273
    Ops.PUSH5: stack_instructions.push5,
274
    Ops.PUSH6: stack_instructions.push6,
275
    Ops.PUSH7: stack_instructions.push7,
276
    Ops.PUSH8: stack_instructions.push8,
277
    Ops.PUSH9: stack_instructions.push9,
278
    Ops.PUSH10: stack_instructions.push10,
279
    Ops.PUSH11: stack_instructions.push11,
280
    Ops.PUSH12: stack_instructions.push12,
281
    Ops.PUSH13: stack_instructions.push13,
282
    Ops.PUSH14: stack_instructions.push14,
283
    Ops.PUSH15: stack_instructions.push15,
284
    Ops.PUSH16: stack_instructions.push16,
285
    Ops.PUSH17: stack_instructions.push17,
286
    Ops.PUSH18: stack_instructions.push18,
287
    Ops.PUSH19: stack_instructions.push19,
288
    Ops.PUSH20: stack_instructions.push20,
289
    Ops.PUSH21: stack_instructions.push21,
290
    Ops.PUSH22: stack_instructions.push22,
291
    Ops.PUSH23: stack_instructions.push23,
292
    Ops.PUSH24: stack_instructions.push24,
293
    Ops.PUSH25: stack_instructions.push25,
294
    Ops.PUSH26: stack_instructions.push26,
295
    Ops.PUSH27: stack_instructions.push27,
296
    Ops.PUSH28: stack_instructions.push28,
297
    Ops.PUSH29: stack_instructions.push29,
298
    Ops.PUSH30: stack_instructions.push30,
299
    Ops.PUSH31: stack_instructions.push31,
300
    Ops.PUSH32: stack_instructions.push32,
301
    Ops.DUP1: stack_instructions.dup1,
302
    Ops.DUP2: stack_instructions.dup2,
303
    Ops.DUP3: stack_instructions.dup3,
304
    Ops.DUP4: stack_instructions.dup4,
305
    Ops.DUP5: stack_instructions.dup5,
306
    Ops.DUP6: stack_instructions.dup6,
307
    Ops.DUP7: stack_instructions.dup7,
308
    Ops.DUP8: stack_instructions.dup8,
309
    Ops.DUP9: stack_instructions.dup9,
310
    Ops.DUP10: stack_instructions.dup10,
311
    Ops.DUP11: stack_instructions.dup11,
312
    Ops.DUP12: stack_instructions.dup12,
313
    Ops.DUP13: stack_instructions.dup13,
314
    Ops.DUP14: stack_instructions.dup14,
315
    Ops.DUP15: stack_instructions.dup15,
316
    Ops.DUP16: stack_instructions.dup16,
317
    Ops.SWAP1: stack_instructions.swap1,
318
    Ops.SWAP2: stack_instructions.swap2,
319
    Ops.SWAP3: stack_instructions.swap3,
320
    Ops.SWAP4: stack_instructions.swap4,
321
    Ops.SWAP5: stack_instructions.swap5,
322
    Ops.SWAP6: stack_instructions.swap6,
323
    Ops.SWAP7: stack_instructions.swap7,
324
    Ops.SWAP8: stack_instructions.swap8,
325
    Ops.SWAP9: stack_instructions.swap9,
326
    Ops.SWAP10: stack_instructions.swap10,
327
    Ops.SWAP11: stack_instructions.swap11,
328
    Ops.SWAP12: stack_instructions.swap12,
329
    Ops.SWAP13: stack_instructions.swap13,
330
    Ops.SWAP14: stack_instructions.swap14,
331
    Ops.SWAP15: stack_instructions.swap15,
332
    Ops.SWAP16: stack_instructions.swap16,
333
    Ops.LOG0: log_instructions.log0,
334
    Ops.LOG1: log_instructions.log1,
335
    Ops.LOG2: log_instructions.log2,
336
    Ops.LOG3: log_instructions.log3,
337
    Ops.LOG4: log_instructions.log4,
338
    Ops.CREATE: system_instructions.create,
339
    Ops.RETURN: system_instructions.return_,
340
    Ops.CALL: system_instructions.call,
341
    Ops.CALLCODE: system_instructions.callcode,
342
    Ops.DELEGATECALL: system_instructions.delegatecall,
343
    Ops.SELFDESTRUCT: system_instructions.selfdestruct,
344
    Ops.STATICCALL: system_instructions.staticcall,
345
    Ops.REVERT: system_instructions.revert,
346
    Ops.CREATE2: system_instructions.create2,
347
}