Oracle periodSize is very low allowing the TWAP price to be easily manipulated
The TWAP oracle's periodSize was set to zero, causing it to update every block and effectively become a spot price oracle. An attacker could manipulate the price within a single block, affecting the lending market's price feed.
Submitted by 0x52, also found by 141345, Chom, csanuragjain, and ladboy233
TWAP oracle easily manipulated.
Proof of Concept
periodSize is set to 0 meaning that the oracle will take a new observation every single block, which would allow an attacker to easily flood the TWAP oracle and manipulate the price.
Recommended Mitigation Steps
Increase periodSize to be greater than 0, 1800 is typically standard.
Alex the Entreprenerd (judge) commented:
The warden has identified a constant set to zero for the time in between TWAP observations.
Because the code change:
- Is a mistake (evidenced by the comments)
- Causes the TWAP (already put into question in previous contest) to become a Spot Oracle
- There’s no way to remediate as the variable is constant
- The change will end up resulting in a manipulatable
quotewhich will impactgetUnderlyingPriceI agree with High Severity.
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 periodSize constant was mistakenly set to zero instead of a positive value, causing the oracle to record an observation every block and lose its time-averaging property.
Impact
The oracle becomes a spot oracle, so an attacker could manipulate the price used by the lending market, potentially leading to incorrect valuations and financial loss.
What the attacker needed
Ability to trade on the pool; manipulate price within one block
The fix
The periodSize should be increased to a value greater than zero, with 1800 being a typical standard.
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.
A TWAP oracle is a way to get an average price over time, making it harder to manipulate than a single price. Here, the time between price updates was set to zero, so the average was taken over no time at all, making it as easy to manipulate as a single price. An attacker could then push the price around to their advantage.