An issue arises from the reliance on block.timestamp
for control flow decisions in the refundSwap
function of the StabilityBranch
contract. Although using time-based checks is common, block.timestamp
(like other environment variables) can be manipulated by malicious miners within a limited range, potentially impacting logic that depends on strict timing guarantees.
Location:
File:
/2025-01-zaros-part-2/src/market-making/branches/StabilityBranch.sol
Line: 450
Finding:
The contract enforces an expiration check on a swap request via if (deadlineCache > block.timestamp)
. Miners can slightly manipulate block.timestamp
to either extend or reduce the window for a refund. While the scope of manipulation is generally bounded (e.g., a few seconds or minutes), this still introduces trust in miners to behave correctly.
Minor Time Manipulation:
Miners can adjust timestamps within a narrow range to game time-based logic. This can be used—albeit usually with difficulty—to create edge-case conditions where a request is considered expired or not expired.
Not Secure as Randomness:
While the function is not using block.timestamp
as a source of randomness, any reliance on a miner-influenced variable for critical logic or large sums of money should be handled carefully.
Manual Review: Confirmed line of code and the reliance on an environment variable subject to minor manipulation by miners.
Accept Minor Timestamp Inaccuracy
If a small deviation of a few seconds (or up to ~900 seconds in extreme cases) does not materially affect the system, then document these assumptions explicitly. This is often adequate for typical “deadline” or “expiry” checks.
Use an Oracle or External Time Source
For critical scenarios requiring high integrity or minimal manipulation, consider using a trusted off-chain oracle. This eliminates or reduces the reliance on miner-provided timestamps.
Add Time Buffer
If strict timing is important, use a short buffer or grace period around deadlines to mitigate the effect of minor timestamp 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.