Overview
Opcode:0x5f
Introduced: Shanghai (EIP-3855)
PUSH0 pushes the constant value 0 onto the stack. Introduced in Shanghai hardfork as a gas optimization - previously required PUSH1 0x00 (3 gas).
Specification
Stack Input:Behavior
PUSH0 pushes constant zero without reading from bytecode. Unlike PUSH1-32, no immediate bytes follow the opcode. Key characteristics:- No bytecode reading (pure constant)
- Cheaper than PUSH1 0x00 (2 vs 3 gas)
- Only available Shanghai hardfork onwards
- InvalidOpcode error on earlier hardforks
- Most efficient way to push zero
Examples
Basic Usage
Solidity Compilation
Assembly Usage
Gas Cost
Cost: 2 gas (GasQuickStep) Comparison:
Savings:
- 1 gas per zero value
- 1 byte per zero value in bytecode
- Significant for contracts with many zero constants
Common Usage
Memory Initialization
Default Return Values
Array Length Initialization
Comparison Operations
Hardfork Compatibility
Shanghai Check
Safe Fallback
EIP-3855 Rationale
Problem:- PUSH1 0x00 wastes gas (3 instead of 2)
- PUSH1 0x00 wastes bytecode space (2 bytes instead of 1)
- Zero is extremely common in EVM code
- Dedicated opcode for pushing zero
- Same gas as other constant operations (ADDRESS, CALLER, etc.)
- Saves ~0.1% gas on typical contracts
Security
Hardfork Detection
Gas Calculation
Optimization
Replace PUSH1 0x00
Memory Clearing
Implementation
- TypeScript

