Skip to content
DoS Audit finding Intermediate

Unbounded loop in TwapOracle.update can result in oracle being locked

The TwapOracle contract allows an unlimited number of pairs to be registered, and its update function iterates over all pairs. If too many pairs are added, the update function can run out of gas and become permanently unusable, locking the oracle.

TomFrenchBlockchain Follow

Originally disclosed on Code4rena

Submitted by TomFrenchBlockchain, also found by pauliax

Impact

Loss of ability of TwapOracle to update should too many pools be added.

Proof of Concept

TwapOracle allows an unlimited number of pairs to be added and has no way of removing pairs after the fact. At the same time TwapOracle.update iterates through all pairs in order to update value for each pair.

https://github.com/code-423n4/2021-11-vader/blob/3a43059e33d549f03b021d6b417b7eeba66cf62e/contracts/twap/TwapOracle.sol#L322-L369

TwapOracle.registerPair is a permissioned function so that only the owner can add new pairs however should the owner account be compromised or not mindful of the number of pairs being added it is possible to put the oracle into a state in which it is unable to update. The oracle cannot recover from this state.

Recommended Mitigation Steps

Possible options:

  • Add a method to stop tracking a particular pair
  • Allow updating a subset of all pairs at a time.

SamSteinGG (Vader) disagreed with severity:

The severity of the finding should be reduced as it relies on ill behavior from its owner which is a multisignature address.

alcueca (judge) commented:

The severity rating is valid since the signers might not be aware of the limitation, or the limitation might be reached by natural means.

SamSteinGG (Vader) commented:

The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.

The original report as published on Code4rena, by TomFrenchBlockchain. 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 update function loops over an unbounded array of pairs, and there is no mechanism to remove pairs, so the loop can exceed the block gas limit.

Impact

The oracle could become unable to update, causing a loss of functionality, but this requires the owner to add an excessive number of pairs or the owner account to be compromised.

What the attacker needed

Owner adds many pairs; or owner account compromised

The fix

The oracle was completely removed and redesigned from scratch as LBTwap.

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 smart contract has a function that updates prices for all trading pairs it tracks. If there are too many pairs, the function takes too long and runs out of gas, so it can never complete. Since there is no way to remove pairs, the contract gets stuck.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by TomFrenchBlockchain

View all

28 more disclosed reports, best first.

More from Vader Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.