ethereum.forks.berlin.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

CHAINID

96
    CHAINID = 0x46

SELFBALANCE

97
    SELFBALANCE = 0x47

STOP

100
    STOP = 0x00

JUMP

101
    JUMP = 0x56

JUMPI

102
    JUMPI = 0x57

PC

103
    PC = 0x58

GAS

104
    GAS = 0x5A

JUMPDEST

105
    JUMPDEST = 0x5B

SLOAD

108
    SLOAD = 0x54

SSTORE

109
    SSTORE = 0x55

POP

112
    POP = 0x50

PUSH1

115
    PUSH1 = 0x60

PUSH2

116
    PUSH2 = 0x61

PUSH3

117
    PUSH3 = 0x62

PUSH4

118
    PUSH4 = 0x63

PUSH5

119
    PUSH5 = 0x64

PUSH6

120
    PUSH6 = 0x65

PUSH7

121
    PUSH7 = 0x66

PUSH8

122
    PUSH8 = 0x67

PUSH9

123
    PUSH9 = 0x68

PUSH10

124
    PUSH10 = 0x69

PUSH11

125
    PUSH11 = 0x6A

PUSH12

126
    PUSH12 = 0x6B

PUSH13

127
    PUSH13 = 0x6C

PUSH14

128
    PUSH14 = 0x6D

PUSH15

129
    PUSH15 = 0x6E

PUSH16

130
    PUSH16 = 0x6F

PUSH17

131
    PUSH17 = 0x70

PUSH18

132
    PUSH18 = 0x71

PUSH19

133
    PUSH19 = 0x72

PUSH20

134
    PUSH20 = 0x73

PUSH21

135
    PUSH21 = 0x74

PUSH22

136
    PUSH22 = 0x75

PUSH23

137
    PUSH23 = 0x76

PUSH24

138
    PUSH24 = 0x77

PUSH25

139
    PUSH25 = 0x78

PUSH26

140
    PUSH26 = 0x79

PUSH27

141
    PUSH27 = 0x7A

PUSH28

142
    PUSH28 = 0x7B

PUSH29

143
    PUSH29 = 0x7C

PUSH30

144
    PUSH30 = 0x7D

PUSH31

145
    PUSH31 = 0x7E

PUSH32

146
    PUSH32 = 0x7F

DUP1

149
    DUP1 = 0x80

DUP2

150
    DUP2 = 0x81

DUP3

151
    DUP3 = 0x82

DUP4

152
    DUP4 = 0x83

DUP5

153
    DUP5 = 0x84

DUP6

154
    DUP6 = 0x85

DUP7

155
    DUP7 = 0x86

DUP8

156
    DUP8 = 0x87

DUP9

157
    DUP9 = 0x88

DUP10

158
    DUP10 = 0x89

DUP11

159
    DUP11 = 0x8A

DUP12

160
    DUP12 = 0x8B

DUP13

161
    DUP13 = 0x8C

DUP14

162
    DUP14 = 0x8D

DUP15

163
    DUP15 = 0x8E

DUP16

164
    DUP16 = 0x8F

SWAP1

167
    SWAP1 = 0x90

SWAP2

168
    SWAP2 = 0x91

SWAP3

169
    SWAP3 = 0x92

SWAP4

170
    SWAP4 = 0x93

SWAP5

171
    SWAP5 = 0x94

SWAP6

172
    SWAP6 = 0x95

SWAP7

173
    SWAP7 = 0x96

SWAP8

174
    SWAP8 = 0x97

SWAP9

175
    SWAP9 = 0x98

SWAP10

176
    SWAP10 = 0x99

SWAP11

177
    SWAP11 = 0x9A

SWAP12

178
    SWAP12 = 0x9B

SWAP13

179
    SWAP13 = 0x9C

SWAP14

180
    SWAP14 = 0x9D

SWAP15

181
    SWAP15 = 0x9E

SWAP16

182
    SWAP16 = 0x9F

MLOAD

185
    MLOAD = 0x51

MSTORE

186
    MSTORE = 0x52

MSTORE8

187
    MSTORE8 = 0x53

MSIZE

188
    MSIZE = 0x59

LOG0

191
    LOG0 = 0xA0

LOG1

192
    LOG1 = 0xA1

LOG2

193
    LOG2 = 0xA2

LOG3

194
    LOG3 = 0xA3

LOG4

195
    LOG4 = 0xA4

CREATE

198
    CREATE = 0xF0

CALL

199
    CALL = 0xF1

CALLCODE

200
    CALLCODE = 0xF2

RETURN

201
    RETURN = 0xF3

DELEGATECALL

202
    DELEGATECALL = 0xF4

CREATE2

203
    CREATE2 = 0xF5

STATICCALL

204
    STATICCALL = 0xFA

REVERT

205
    REVERT = 0xFD

SELFDESTRUCT

206
    SELFDESTRUCT = 0xFF

op_implementation

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