Normal Behavior:
In Ethereum, block.timestamp
is commonly used for time-based logic, such as validating event start times, enforcing cooldowns, or determining if an event is active. However, block.timestamp
is not perfectly accurate: miners can manipulate it within a range of up to 30 seconds in either direction. For most applications, this is acceptable, but for high-value or time-sensitive operations, this can be exploited to gain unfair advantages or bypass restrictions.
Issue:
In the FestivalPass
contract, several functions use block.timestamp
for critical logic:
createPerformance
: Validates that the start time is in the future.
attendPerformance
: Checks cooldown periods between attendances.
isPerformanceActive
: Determines if a performance is currently active.
Because miners can manipulate block.timestamp
, users or validators may be able to attend performances outside intended windows or bypass cooldowns, especially if the contract is deployed on a chain with low block times or low miner diversity.
Relevant Code Example:
Likelihood:
This will occur whenever a miner or validator is incentivized to manipulate the timestamp to benefit themselves or a user, such as to attend a performance early, bypass a cooldown, or claim a reward.
The risk is present in all deployments, but is higher on chains with low miner/validator diversity or where time-based rewards are valuable.
Impact:
Bypass of Restrictions: Users may be able to attend performances or claim rewards outside the intended time windows.
Unfair Advantage: Validators or miners can give themselves or their friends an edge in time-sensitive operations, undermining fairness.
Potential MEV: In high-value scenarios, this can be exploited for maximal extractable value (MEV), especially if rewards are significant.
To observe the effect of timestamp manipulation, copy and paste the following test code into your test file (e.g., test/contract.t.sol
). This test simulates a user attending a performance slightly before the intended window by manipulating the block timestamp:
Explanation:
The test schedules a performance and manipulates the block timestamp to just before the start.
It attempts to attend the performance, which should fail, but may succeed if timestamp manipulation is possible.
For most festival use cases, the 30-second window is acceptable and should be documented as a known limitation. For higher-value or more sensitive applications, consider these mitigations:
Documentation:
Clearly document in the contract and user-facing materials that time-based logic is subject to a small window of miner manipulation.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.