OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: medium
Likelihood: low
Invalid

[L-2] Use of `block.timestamp` for Deadline Checks can introduce vulnerabilities due to Miner Manipulation

Description:
The use of block.timestamp to enforce order deadlines in the OrderBook contract is not entirely safe, as block timestamps can be slightly manipulated by miners. Although Ethereum protocol rules restrict the extent of this manipulation (typically within a range of a few seconds), it is still possible for miners to influence the timestamp of a block they are producing. This subtle control can be exploited in certain scenarios, particularly in time-sensitive applications such as decentralized exchanges or order books, where the precise timing of order expiration is critical. Relying on block.timestamp for deadline enforcement can therefore introduce a minor, but non-negligible, attack surface that may be abused to gain an unfair advantage or disrupt the intended operation of the protocol.

Impact:
Malicious miners could manipulate the block timestamp to prematurely expire or artificially extend the validity of orders, potentially disrupting the intended functionality of the order book and enabling unfair trading advantages. For example, a miner could cause a legitimate buy transaction to fail by advancing the timestamp just enough to make an order appear expired, or conversely, delay expiration to allow a favored party to fill an order that should have already lapsed. Over time, repeated exploitation of this vector could erode user trust in the fairness and reliability of the protocol, especially in high-frequency or competitive trading environments.

Proof of Concept:
The following scenario demonstrates the vulnerability in practice:

  1. A user creates a sell order with a deadline set to expire in 60 seconds (using block.timestamp + 60).

  2. Another user submits a buy transaction to fill this order just before the deadline is reached.

  3. A malicious miner, who is able to include this transaction in a block they mine, intentionally sets the block.timestamp forward by several seconds (within the allowed protocol range).

  4. As a result, the order's deadline is considered expired, and the buy transaction reverts, even though it was submitted in time.

  5. The miner or a favored user can then submit their own transaction in the next block, potentially filling the order themselves or preventing others from doing so.

  6. This demonstrates how even a small manipulation of block.timestamp can impact the fairness and reliability of the order book, especially in scenarios where timing is critical and users expect precise deadline enforcement.

  7. In more competitive or adversarial environments, this could be used to front-run, grief, or otherwise manipulate the outcome of trades, undermining the protocol's integrity.

Recommended Mitigation:
To mitigate this risk, consider using block.number for deadline checks instead of block.timestamp, as block numbers are deterministic and far less susceptible to manipulation by miners. If precise timing is required, block numbers can be converted to approximate timestamps using the average block time, though this introduces some granularity. Additionally, ensure that critical logic does not rely on exact timestamp precision, and document any timing assumptions clearly in the contract and user documentation. Where possible, design the protocol to tolerate small timing discrepancies, or provide a buffer period to reduce the impact of minor timestamp manipulation. Regularly review and test deadline logic to ensure it remains robust against miner manipulation and other edge cases.

Updates

Lead Judging Commences

yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Design choice

Appeal created

akronim26 Submitter
about 1 month ago
yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.