Oracle’s two-day feature can be gamed
The oracle's two-day price averaging feature can be bypassed by manipulating the oracle only around the boundary between two days, because the day is computed by integer division of the timestamp. An attacker could manipulate the price for just two blocks instead of the intended two days.
Submitted by Ruhum
The two-day feature of the oracle can be gamed where you only have to manipulate the oracle for ~2 blocks.
Proof of Concept
The oracle computes the day using:
uint day = block.timestamp / 1 days;
Since we’re working with uint values here, the following is true:
1728799 / 86400 = 1
172800 / 86400 = 2
Meaning, if you manipulate the oracle at the last block of day X, e.g. 23:59:50, and at the first block of day X + 1, e.g. 00:00:02, you bypass the two-day feature of the oracle. You only have to manipulate the oracle for two blocks.
This is quite hard to pull off. I’m also not sure whether there were any instances of Chainlink oracle manipulation before. But, since you designed this feature to prevent small timeframe oracle manipulation I think it’s valid to point this out.
Recommended Mitigation Steps
If you increase it to a three-day interval you can fix this issue. Then, the oracle has to be manipulated for at least 24 hours.
08xmt (Inverse) acknowledged and commented:
This is an issue if a 24 hour period elapses without any calls to the oracle and the underlying oracle is manipulable. The two day low is meant to be an added layer of security, but not bullet proof.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the day boundary is calculated with integer division of the timestamp, so two timestamps just before and just after midnight fall into different days, allowing the two-day window to be spanned with only two blocks.
Impact
If a 24-hour period passes without oracle calls and the underlying oracle is manipulable, an attacker could bypass the two-day protection, though the report notes this is hard to pull off.
What the attacker needed
24 hours without oracle calls; underlying oracle is manipulable
The fix
The issue should be fixed by increasing the interval to three days, so the oracle must be manipulated for at least 24 hours.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
An oracle is a service that feeds outside price data to a smart contract. This contract tried to make price manipulation harder by averaging prices over two days, but the way it counted days could be tricked at midnight. An attacker who can influence the price could then affect the average with only a couple of quick changes.