EVM Opcodes

Complete reference of EVM bytecode instructions


Appendix C: EVM Opcodes

This appendix provides a reference of all EVM opcodes, their gas costs, and descriptions.

Opcode Categories

Stop and Arithmetic (0x00 - 0x0F)

OpcodeHexGasStackDescription
STOP0x0000 → 0Halts execution
ADD0x0132 → 1Addition
MUL0x0252 → 1Multiplication
SUB0x0332 → 1Subtraction
DIV0x0452 → 1Integer division
SDIV0x0552 → 1Signed integer division
MOD0x0652 → 1Modulo operation
SMOD0x0752 → 1Signed modulo
ADDMOD0x0883 → 1Modular addition
MULMOD0x0983 → 1Modular multiplication
EXP0x0A10*2 → 1Exponentiation
SIGNEXTEND0x0B52 → 1Sign extend

*EXP cost: 10 + 50 × (byte size of exponent)

Comparison & Bitwise (0x10 - 0x1F)

OpcodeHexGasStackDescription
LT0x1032 → 1Less than
GT0x1132 → 1Greater than
SLT0x1232 → 1Signed less than
SGT0x1332 → 1Signed greater than
EQ0x1432 → 1Equality
ISZERO0x1531 → 1Is zero
AND0x1632 → 1Bitwise AND
OR0x1732 → 1Bitwise OR
XOR0x1832 → 1Bitwise XOR
NOT0x1931 → 1Bitwise NOT
BYTE0x1A32 → 1Retrieve single byte
SHL0x1B32 → 1Shift left
SHR0x1C32 → 1Shift right
SAR0x1D32 → 1Arithmetic shift right

Keccak (0x20)

OpcodeHexGasStackDescription
KECCAK2560x2030*2 → 1Keccak-256 hash

*Plus 6 gas per word of data

Environmental (0x30 - 0x3F)

OpcodeHexGasStackDescription
ADDRESS0x3020 → 1Current contract address
BALANCE0x31100*1 → 1Balance of address
ORIGIN0x3220 → 1Transaction origin
CALLER0x3320 → 1Message caller
CALLVALUE0x3420 → 1Message value (wei)
CALLDATALOAD0x3531 → 1Load calldata word
CALLDATASIZE0x3620 → 1Calldata size
CALLDATACOPY0x373*3 → 0Copy calldata to memory
CODESIZE0x3820 → 1Code size
CODECOPY0x393*3 → 0Copy code to memory
GASPRICE0x3A20 → 1Transaction gas price
EXTCODESIZE0x3B100*1 → 1External code size
EXTCODECOPY0x3C100*4 → 0Copy external code
RETURNDATASIZE0x3D20 → 1Return data size
RETURNDATACOPY0x3E3*3 → 0Copy return data
EXTCODEHASH0x3F100*1 → 1External code hash

*Cold/warm access costs apply (EIP-2929)

Block Information (0x40 - 0x4F)

OpcodeHexGasStackDescription
BLOCKHASH0x40201 → 1Hash of recent block
COINBASE0x4120 → 1Block producer address
TIMESTAMP0x4220 → 1Block timestamp
NUMBER0x4320 → 1Block number
PREVRANDAO0x4420 → 1PoS random / PoW difficulty
GASLIMIT0x4520 → 1Block gas limit
CHAINID0x4620 → 1Chain ID
SELFBALANCE0x4750 → 1Contract balance
BASEFEE0x4820 → 1Block base fee

Stack, Memory, Storage (0x50 - 0x5F)

OpcodeHexGasStackDescription
POP0x5021 → 0Remove top item
MLOAD0x513*1 → 1Load from memory
MSTORE0x523*2 → 0Store to memory
MSTORE80x533*2 → 0Store byte to memory
SLOAD0x54100*1 → 1Load from storage
SSTORE0x55**2 → 0Store to storage
JUMP0x5681 → 0Jump to position
JUMPI0x57102 → 0Conditional jump
PC0x5820 → 1Program counter
MSIZE0x5920 → 1Memory size
GAS0x5A20 → 1Remaining gas
JUMPDEST0x5B10 → 0Valid jump destination

*Memory expansion costs apply **SSTORE: 20,000 (new) / 5,000 (update) / 100 (warm)

Push Operations (0x60 - 0x7F)

OpcodeHexGasStackDescription
PUSH10x6030 → 1Push 1 byte
PUSH20x6130 → 1Push 2 bytes
...............
PUSH320x7F30 → 1Push 32 bytes

Duplication (0x80 - 0x8F)

OpcodeHexGasStackDescription
DUP10x8031 → 2Duplicate 1st item
DUP20x8132 → 3Duplicate 2nd item
...............
DUP160x8F316 → 17Duplicate 16th item

Exchange (0x90 - 0x9F)

OpcodeHexGasStackDescription
SWAP10x9032 → 2Swap 1st and 2nd
SWAP20x9133 → 3Swap 1st and 3rd
...............
SWAP160x9F317 → 17Swap 1st and 17th

Logging (0xA0 - 0xA4)

OpcodeHexGasStackDescription
LOG00xA0375*2 → 0Log with 0 topics
LOG10xA1750*3 → 0Log with 1 topic
LOG20xA21125*4 → 0Log with 2 topics
LOG30xA31500*5 → 0Log with 3 topics
LOG40xA41875*6 → 0Log with 4 topics

*Plus 8 gas per byte of log data

System Operations (0xF0 - 0xFF)

OpcodeHexGasStackDescription
CREATE0xF032000*3 → 1Create contract
CALL0xF1100*7 → 1Call contract
CALLCODE0xF2100*7 → 1Call with own storage
RETURN0xF302 → 0Return from call
DELEGATECALL0xF4100*6 → 1Call keeping context
CREATE20xF532000*4 → 1Create with salt
STATICCALL0xFA100*6 → 1Read-only call
REVERT0xFD02 → 0Revert with data
INVALID0xFEall0 → 0Invalid instruction
SELFDESTRUCT0xFF5000*1 → 0Destroy contract

Gas Calculation Examples

// Simple addition: 3 gas
function add(uint a, uint b) public pure returns (uint) {
    return a + b;  // ADD: 3 gas
}
 
// Storage write: 20,000 gas (new) or 5,000 (update)
function store(uint x) public {
    value = x;  // SSTORE: 20,000 or 5,000 gas
}
 
// External call: ~2,600 gas minimum
function callOther(address target) public {
    target.call("");  // CALL: 100 base + 2,500 cold access
}

Resources