Skip to content
Smart contracts Audit finding Intermediate

TWAP Oracle inflexible _updatePeriod

The TWAP oracle contract has a fixed update period that cannot be changed after deployment and is the same for all assets, which may lead to price manipulation or inaccurate pricing. An attacker could potentially exploit this to manipulate prices or cause mispricing.

elprofesor Follow

Originally disclosed on Code4rena

Submitted by elprofesor

Impact

Update periods in TWAP oracles reflect risk of an asset. Updating more frequently accurately prices an asset but increases capabilities of manipulation (which should be harder with more stable assets), whereas longer update periods prevent manipulation but does not accurately price assets (due to the time difference between updates). Volatility of an asset should be considered when calculating update periods. However, in Vader’s TwapOracle.sol no such considerations are made, the _updatePeriod cannot be changed after deployment of the contract. Additionally, each asset uses the same _updatePeriod which does not adequately account for the differences in risk for each asset. This could lead to price manipulation or inadequate pricing of assets.

Proof of Concept

the only chance to set _updatePeriod

_updatePeriod used in time elapsed calculation

Recommended Mitigation Steps

Add the following function

function setUpdatePeriod(uint256 newUpdatePeriod) external onlyOwner {
    require(newUpdatePeriod > minimumUpdatePeriod, "Update period must be larger than threshold"); // Optional validation based on some risk tolerance
    _updatePeriod = newUpdatePeriod;
}

CloudEllie (organizer) commented:

Warden has requested that we add a second mitigation step/strategy to his submission:

  1. Consider adding a configurable update period per asset, this way we are not incorrectly assuming the same risk profile per asset.

SamSteinGG (Vader) diagreed with severity:

This finding is accurate as the update period should change per oracle, however, it is not of high risk severity.

alcueca (judge) commented:

Agree with sponsor, assets are not directly at risk. Severity 2.

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 elprofesor. 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 contract lacks a function to update the update period after deployment and does not allow per-asset configuration.

Impact

This could lead to price manipulation or inadequate pricing of assets, but the sponsor and judge agreed that assets are not directly at risk.

What the attacker needed

None

The fix

The TWAP oracle module 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 TWAP oracle is a tool that provides a price for an asset by averaging prices over time. The update period is how often it updates. If this period is fixed and the same for all assets, it might be too short for risky assets (making manipulation easier) or too long for stable assets (making prices inaccurate).

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by elprofesor

View all

3 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.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.