Skip to content
Audit finding Intermediate

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.

0x52 Follow

Originally disclosed on Code4rena

Submitted by 0x52, also found by 141345, Chom, csanuragjain, and ladboy233

https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/Stableswap/BaseV1-core.sol#L72

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.

nivasan1 (Canto) confirmed

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 quote which will impact getUnderlyingPrice

I agree with High Severity.


The original report as published on Code4rena, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by 0x52

View all

211 more disclosed reports, best first.

More from Canto v2 contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.