Opcodes
OPCODES FOR THE EVM
OVERVIEW
This is an updated version of the EVM reference page at wolflo/evm-opcodes↗. Also drawn from the Ethereum's Yellow Paper↗, the Jello Paper↗, and the etn-sc implementation. This is intended to be an accessible reference, but it is not particularly rigorous. If you want to be certain of correctness and aware of every edge case, using the Jello Paper or a client implementation is advisable.
Looking for an interactive reference? Check out evm.codes↗.
For operations with dynamic gas costs, see gas.md↗.
💡 Quick tip: To view entire lines, use [shift] + scroll
to scroll horizontally on desktop.
Stack | Name | Gas | Initial Stack | Resulting Stack | Mem / Storage | Notes | |
---|---|---|---|---|---|---|---|
00 | STOP | 0 | halt execution | ||||
01 | ADD | 3 |
|
| (u)int256 addition modulo 2**256 | ||
02 | MUL | 5 |
|
| (u)int256 multiplication modulo 2**256 | ||
03 | SUB | 3 |
|
| (u)int256 addition modulo 2**256 | ||
04 | DIV | 5 |
|
| uint256 division | ||
05 | SDIV | 5 |
|
| int256 division | ||
06 | MOD | 5 |
|
| uint256 modulus | ||
07 | SMOD | 5 |
|
| int256 modulus | ||
08 | ADDMOD | 8 |
|
| (u)int256 addition modulo N | ||
09 | MULMOD | 8 |
|
| (u)int256 multiplication modulo N | ||
0A | EXP |
|
| uint256 exponentiation modulo 2**256 | |||
0B | SIGNEXTEND | 5 |
|
| sign extend(opens in a new tab)↗ | ||
0C-0F | invalid | ||||||
10 | LT | 3 |
|
| uint256 less-than | ||
11 | GT | 3 |
|
| uint256 greater-than | ||
12 | SLT | 3 |
|
| int256 less-than | ||
13 | SGT | 3 |
|
| int256 greater-than | ||
14 | EQ | 3 |
|
| (u)int256 equality | ||
15 | ISZERO | 3 |
|
| (u)int256 iszero | ||
16 | AND | 3 |
|
| bitwise AND | ||
17 | OR | 3 |
|
| bitwise OR | ||
18 | XOR | 3 |
|
| bitwise XOR | ||
19 | NOT | 3 |
|
| bitwise NOT | ||
1A | BYTE | 3 |
|
|
| ||
1B | SHL | 3 |
|
| shift left | ||
1C | SHR | 3 |
|
| logical shift right | ||
1D | SAR | 3 |
|
| arithmetic shift right | ||
1E-1F | invalid | ||||||
20 | KECCAK256 |
|
| keccak256 | |||
21-2F | invalid | ||||||
30 | ADDRESS | 2 |
|
| address of executing contract | ||
31 | BALANCE |
|
| balance, in wei | |||
32 | ORIGIN | 2 |
|
| address that originated the tx | ||
33 | CALLER | 2 |
|
| address of msg sender | ||
34 | CALLVALUE | 2 |
|
| msg value, in wei | ||
35 | CALLDATALOAD | 3 |
|
| read word from msg data at index | ||
36 | CALLDATASIZE | 2 |
|
| length of msg data, in bytes | ||
37 | CALLDATACOPY |
|
| mem[dstOst:dstOst+len-1] := msg.data[ost:ost+len-1] | copy msg data | ||
38 | CODESIZE | 2 |
|
| length of executing contract's code, in bytes | ||
39 | CODECOPY |
|
| mem[dstOst:dstOst+len-1] := this.code[ost:ost+len-1] | copy executing contract's bytecode | ||
3A | GASPRICE | 2 |
|
| gas price of tx, in wei per unit gas **(opens in a new tab)↗ | ||
3B | EXTCODESIZE |
|
| size of code at addr, in bytes | |||
3C | EXTCODECOPY |
|
| mem[dstOst:dstOst+len-1] := addr.code[ost:ost+len-1] | copy code from | ||
3D | RETURNDATASIZE | 2 |
|
| size of returned data from last external call, in bytes | ||
3E | RETURNDATACOPY |
|
| mem[dstOst:dstOst+len-1] := returndata[ost:ost+len-1] | copy returned data from last external call | ||
3F | EXTCODEHASH |
|
| hash = addr.exists ? keccak256(addr.code) : 0 | |||
40 | BLOCKHASH | 20 |
|
| |||
41 | COINBASE | 2 |
|
| address of miner of current block | ||
42 | TIMESTAMP | 2 |
|
| timestamp of current block | ||
43 | NUMBER | 2 |
|
| number of current block | ||
44 | PREVRANDAO | 2 |
|
| randomness beacon | ||
45 | GASLIMIT | 2 |
|
| gas limit of current block | ||
46 | CHAINID | 2 |
|
| push current chain id(opens in a new tab)↗ onto stack | ||
47 | SELFBALANCE | 5 |
|
| balance of executing contract, in wei | ||
48 | BASEFEE | 2 |
|
| base fee of current block | ||
49-4F | invalid | ||||||
50 | POP | 2 |
|
| remove item from top of stack and discard it | ||
51 | MLOAD |
|
| read word from memory at offset | |||
52 | MSTORE |
|
| mem[ost:ost+32] := val | write a word to memory | ||
53 | MSTORE8 |
|
| mem[ost] := val && 0xFF | write a single byte to memory | ||
54 | SLOAD |
|
| read word from storage | |||
55 | SSTORE |
|
| storage[key] := val | write word to storage | ||
56 | JUMP | 8 |
|
|
| ||
57 | JUMPI | 10 |
|
|
| ||
58 | PC | 2 |
|
| program counter | ||
59 | MSIZE | 2 |
|
| size of memory in current execution context, in bytes | ||
5A | GAS | 2 |
|
| |||
5B | JUMPDEST | 1 | mark valid jump destination | a valid jump destination for example a jump destination not inside the push data | |||
5C-5E | invalid | ||||||
5F | PUSH0 | 2 |
|
| push the constant value 0 onto stack | ||
60 | PUSH1 | 3 |
|
| push 1-byte value onto stack | ||
61 | PUSH2 | 3 |
|
| push 2-byte value onto stack | ||
62 | PUSH3 | 3 |
|
| push 3-byte value onto stack | ||
63 | PUSH4 | 3 |
|
| push 4-byte value onto stack | ||
64 | PUSH5 | 3 |
|
| push 5-byte value onto stack | ||
65 | PUSH6 | 3 |
|
| push 6-byte value onto stack | ||
66 | PUSH7 | 3 |
|
| push 7-byte value onto stack | ||
67 | PUSH8 | 3 |
|
| push 8-byte value onto stack | ||
68 | PUSH9 | 3 |
|
| push 9-byte value onto stack | ||
69 | PUSH10 | 3 |
|
| push 10-byte value onto stack | ||
6A | PUSH11 | 3 |
|
| push 11-byte value onto stack | ||
6B | PUSH12 | 3 |
|
| push 12-byte value onto stack | ||
6C | PUSH13 | 3 |
|
| push 13-byte value onto stack | ||
6D | PUSH14 | 3 |
|
| push 14-byte value onto stack | ||
6E | PUSH15 | 3 |
|
| push 15-byte value onto stack | ||
6F | PUSH16 | 3 |
|
| push 16-byte value onto stack | ||
70 | PUSH17 | 3 |
|
| push 17-byte value onto stack | ||
71 | PUSH18 | 3 |
|
| push 18-byte value onto stack | ||
72 | PUSH19 | 3 |
|
| push 19-byte value onto stack | ||
73 | PUSH20 | 3 |
|
| push 20-byte value onto stack | ||
74 | PUSH21 | 3 |
|
| push 21-byte value onto stack | ||
75 | PUSH22 | 3 |
|
| push 22-byte value onto stack | ||
76 | PUSH23 | 3 |
|
| push 23-byte value onto stack | ||
77 | PUSH24 | 3 |
|
| push 24-byte value onto stack | ||
78 | PUSH25 | 3 |
|
| push 25-byte value onto stack | ||
79 | PUSH26 | 3 |
|
| push 26-byte value onto stack | ||
7A | PUSH27 | 3 |
|
| push 27-byte value onto stack | ||
7B | PUSH28 | 3 |
|
| push 28-byte value onto stack | ||
7C | PUSH29 | 3 |
|
| push 29-byte value onto stack | ||
7D | PUSH30 | 3 |
|
| push 30-byte value onto stack | ||
7E | PUSH31 | 3 |
|
| push 31-byte value onto stack | ||
7F | PUSH32 | 3 |
|
| push 32-byte value onto stack | ||
80 | DUP1 | 3 |
|
| clone 1st value on stack | ||
81 | DUP2 | 3 |
|
| clone 2nd value on stack | ||
82 | DUP3 | 3 |
|
| clone 3rd value on stack | ||
83 | DUP4 | 3 |
|
| clone 4th value on stack | ||
84 | DUP5 | 3 |
|
| clone 5th value on stack | ||
85 | DUP6 | 3 |
|
| clone 6th value on stack | ||
86 | DUP7 | 3 |
|
| clone 7th value on stack | ||
87 | DUP8 | 3 |
|
| clone 8th value on stack | ||
88 | DUP9 | 3 |
|
| clone 9th value on stack | ||
89 | DUP10 | 3 |
|
| clone 10th value on stack | ||
8A | DUP11 | 3 |
|
| clone 11th value on stack | ||
8B | DUP12 | 3 |
|
| clone 12th value on stack | ||
8C | DUP13 | 3 |
|
| clone 13th value on stack | ||
8D | DUP14 | 3 |
|
| clone 14th value on stack | ||
8E | DUP15 | 3 |
|
| clone 15th value on stack | ||
8F | DUP16 | 3 |
|
| clone 16th value on stack | ||
90 | SWAP1 | 3 |
|
| |||
91 | SWAP2 | 3 |
|
| |||
92 | SWAP3 | 3 |
|
| |||
93 | SWAP4 | 3 |
|
| |||
94 | SWAP5 | 3 |
|
| |||
95 | SWAP6 | 3 |
|
| |||
96 | SWAP7 | 3 |
|
| |||
97 | SWAP8 | 3 |
|
| |||
98 | SWAP9 | 3 |
|
| |||
99 | SWAP10 | 3 |
|
| |||
9A | SWAP11 | 3 |
|
| |||
9B | SWAP12 | 3 |
|
| |||
9C | SWAP13 | 3 |
|
| |||
9D | SWAP14 | 3 |
|
| |||
9E | SWAP15 | 3 |
|
| |||
9F | SWAP16 | 3 |
|
| |||
A0 | LOG0 |
|
| LOG0(memory[ost:ost+len-1]) | |||
A1 | LOG1 |
|
| LOG1(memory[ost:ost+len-1], topic0) | |||
A2 | LOG2 |
|
| LOG1(memory[ost:ost+len-1], topic0, topic1) | |||
A3 | LOG3 |
|
| LOG1(memory[ost:ost+len-1], topic0, topic1, topic2) | |||
A4 | LOG4 |
|
| LOG1(memory[ost:ost+len-1], topic0, topic1, topic2, topic3) | |||
A5-EF | invalid | ||||||
F0 | CREATE |
|
| addr = keccak256(rlp([address(this), this.nonce])) | |||
F1 | CALL |
|
| mem[retOst:retOst+retLen-1] := returndata | |||
F2 | CALLCODE |
|
| mem[retOst:retOst+retLen-1] = returndata | same as DELEGATECALL, but does not propagate original msg.sender and msg.value | ||
F3 | RETURN |
|
| return mem[ost:ost+len-1] | |||
F4 | DELEGATECALL |
|
| mem[retOst:retOst+retLen-1] := returndata | |||
F5 | CREATE2 |
|
| addr = keccak256(0xff ++ address(this) ++ salt ++ keccak256(mem[ost:ost+len-1]))[12:] | |||
F6-F9 | invalid | ||||||
FA | STATICCALL |
|
| mem[retOst:retOst+retLen-1] := returndata | |||
FB-FC | invalid | ||||||
FD | REVERT |
|
| revert(mem[ost:ost+len-1]) | |||
FE | INVALID | designated invalid opcode - EIP-141(opens in a new tab)↗ | |||||
FF | SELFDESTRUCT |
|
| destroy contract and sends all funds to |
Last updated