Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article explains the security risks associated with timestamps in Solidity.
The widely used block.timestamp global variable can introduce vulnerabilities when a contract relies on it under inappropriate assumptions. Solidity developers and bug bounty researchers should understand these limitations.
For an introduction to bug bounties, see:
Introduction to Solidity Bug Bounties
The following article covers additional risks of using block timestamps for randomness:
Understanding Pseudorandom Number Generation Vulnerabilities
What is a timestamp?

Definition
A timestamp represents the date and time at which an event occurred. Historically, the term also referred to postal markings; in computing, timestamps are commonly used to record events.
Source: Timestamp (Japanese Wikipedia)
Operating systems, for example, record timestamps when files are created or modified.
Timestamps in Solidity
The Solidity documentation defines block.timestamp as an unsigned integer containing the current block's Unix timestamp in seconds.
Unix time is a representation of time based on seconds since midnight UTC on January 1, 1970, the Unix epoch, without counting leap seconds as additional elapsed seconds. It is widely supported by operating systems. Older implementations that use signed 32-bit integers encounter an overflow after 2,147,483,647 seconds, known as the Year 2038 problem. Modern systems commonly use larger representations.
Source: Unix time (Japanese Wikipedia)
The following Solidity example stores a block timestamp:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Timestamp {
uint public time;
function updateTimestamp() public {
time = block.timestamp;
}
}Running the example produced the following value in the time variable:
1672451295To convert it into a readable date and time, the original example used this converter:
2022-12-31 10:48:15The displayed time corresponds to Japan Standard Time (UTC+9).
What is timestamp manipulation?

Historically, proof-of-work miners could exercise limited discretion over the timestamps of the blocks they produced. Miners validate transactions and include them in blocks. For background on mining, see:
Historical proof-of-work constraints included the following:
- A block timestamp had to be later than its parent's timestamp.
- Nodes could reject or defer blocks whose timestamps were too far in the future.
Within the applicable limits, miners could influence timestamp-dependent contract behavior.
Consensus context: Ethereum mainnet transitioned to proof of stake in September 2022. Its execution payload timestamp is determined by the consensus slot, not freely selected within a proof-of-work-style tolerance. Proposers may still influence transaction inclusion, and other EVM networks have different timestamp rules. The historical mining model must not be treated as a universal description of current Ethereum or EVM chains.
Timestamp-dependent contract example

The following educational example demonstrates why a contract should not use a block timestamp as an unpredictable source of randomness.
Code
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Roulette {
constructor() payable {}
/// @notice block.timestampが7で割り切れる場合コントラクト内の資金を取得できる関数。
function judgment() external payable {
require(msg.value == 1 ether);
if (block.timestamp % 7 == 0) {
(bool sent, ) = msg.sender.call{value: address(this).balance}("");
require(sent, "Failed to send Ether");
}
}
}Explanation
The judgment function requires a payment of 1 ether. If the executing block's timestamp is divisible by 7, the caller receives the entire contract balance.
Under a historical proof-of-work model, a miner able to select an eligible timestamp could influence this condition. Even on networks where timestamps are determined by consensus slots, the condition remains predictable and can be affected by transaction inclusion decisions.
Consequently, the timestamp does not provide secure randomness, and the contract may expose its funds to unintended payouts.
For another explanation of timestamp-based randomness, see:
Understanding Pseudorandom Number Generation Vulnerabilities
Mitigation
There are two design considerations in the original discussion.
Avoid using block.timestamp as a randomness source
Do not use block.timestamp to determine unpredictable outcomes or valuable payouts. Use a randomness mechanism appropriate to the application's threat model instead.
Timestamps can still be useful for deadlines and time-based conditions when the contract accounts for the network's consensus rules.
The historical 15-second rule
The original article refers to a historical rule of thumb that applications should tolerate approximately 15 seconds of timestamp variation. Some proof-of-work clients applied limits to future-dated blocks.
This is not a universal consensus guarantee, and a 15-second tolerance alone does not make a contract safe. On modern Ethereum, assess slot-derived timestamps, transaction inclusion delays, and missed slots. For other networks, review their own timestamp constraints.
Conclusion

This article covered timestamps, the risks of timestamp-dependent contract behavior, and precautions when using timestamps in Solidity.
Key points:
- Understand what a block timestamp represents.
- Recognize the risks of using predictable timestamps for security-sensitive outcomes.
- Account for the consensus rules and timing assumptions of the target network.
Questions are welcome via Twitter. I regularly publish and share articles about Solidity, blockchain, and Web3.





