Overview
Opcode:0x84
Introduced: Frontier (EVM genesis)
DUP5 duplicates the 5th stack item and pushes it to the top of the stack. The original 5th item remains in place.
Specification
Stack Input:Behavior
DUP5 copies the 5th-from-top stack item without removing it. Requires stack depth ≥ 5. Key characteristics:- Requires stack depth ≥ 5
- Original value unchanged
- New copy pushed to top
- StackUnderflow if depth < 5
- Stack depth increases by 1
Examples
Basic Usage
Solidity Compilation
Assembly Usage
Gas Cost
Cost: 3 gas (GasFastestStep) All DUP1-16 operations cost the same despite different stack depths accessed. Comparison:| Operation | Gas | Note |
|---|---|---|
| DUP5 | 3 | Duplicate 5th item |
| PUSH1-32 | 3 | Same cost tier |
| POP | 2 | Cheaper |
Common Usage
Deep Stack Access
Conditional Logic
Stack Depth Requirements
Minimum Depth
Safe Usage
Implementation
- TypeScript
Edge Cases
Stack Underflow
Stack Overflow
Out of Gas
Maximum Value
References
- Yellow Paper - Section 9.1 (Stack Operations)
- EVM Codes - DUP5
- Solidity Assembly - dup5

