Overview
Opcode:0x42
Introduced: Frontier (EVM genesis)
TIMESTAMP retrieves the Unix timestamp of the current block in seconds since epoch (January 1, 1970 00:00:00 UTC). Block producers set this value when creating blocks, subject to consensus rules.
Specification
Stack Input:Behavior
TIMESTAMP pushes the block timestamp as a 256-bit unsigned integer representing seconds since Unix epoch:Consensus Rules
Pre-Merge (PoW):- Miners could manipulate ±15 seconds
- Must be greater than parent timestamp
- Limited by network propagation
- Strictly enforced to
12 * slot_number + genesis_time - More predictable and regular
- 12-second slot times on Ethereum mainnet
Examples
Basic Usage
Time-Based Calculations
Timestamp Comparison
Gas Cost
Cost: 2 gas (GasQuickStep) TIMESTAMP is one of the cheapest operations in the EVM. Comparison:TIMESTAMP: 2 gasNUMBER,COINBASE,DIFFICULTY,GASLIMIT: 2 gasBLOCKHASH: 20 gasSLOAD(cold): 2100 gas
Common Usage
Time Locks
Vesting Schedules
Auction Deadlines
Cooldown Mechanisms
Time-Window Operations
Security Considerations
Timestamp Manipulation
Block producers can manipulate timestamps within bounds:Not Suitable for Randomness
Timestamps are predictable and should not be used for randomness:Short Time Windows
Avoid time windows shorter than block time:Overflow Considerations
Timestamps will overflow u256 in ~10^60 years (not a practical concern):Backwards Time Travel
While rare, timestamp must be > parent timestamp:Pre vs Post-Merge Differences
Implementation
- TypeScript
Edge Cases
Zero Timestamp
Far Future Timestamp
Post-Merge Slot Calculation
Stack Overflow
Out of Gas
Practical Patterns
Safe Time Ranges
Relative Time Checks
Timestamp to Date Conversion
Benchmarks
Performance:- Stack push: O(1)
- No computation required
- 2 gas per query
- ~500,000 queries per million gas
Related Instructions
- NUMBER (0x43) - Get block number
- BLOCKHASH (0x40) - Get block hash
- DIFFICULTY (0x44) - Get difficulty/PREVRANDAO
References
- Yellow Paper - Section 9.3 (Block Information)
- EVM Codes - TIMESTAMP
- Solidity Docs - block.timestamp
- Consensys Best Practices - Timestamp Dependence

