Skip to content
Business logic Audit finding Advanced

Unclear TwapOracle.consult algorithm

The TWAPOracle.consult function's algorithm is unclear and appears to compute an average price by summing foreign token pair prices and dividing by summed USD prices, which weights large prices more heavily. An attacker could potentially manipulate the oracle by skewing pool prices of low-priced pairs without significantly affecting the final result.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The TWAPOracle.consult function is unclear to the auditor. It seems to iterate through all registered pairs that share the token parameter (USDV or VADER) and then sums up the foreign token pair per token price. And divides this sum (sumNative) by the summed-up USD price of these foreign token pairs (sumUSD).

I think the idea is to create some kind of average price but doing it like this does not seem to be effective because large prices are weighted a lot stronger than low prices.

Example

Assume there are 3 USDV pairs registered: (ETH, DAI, USDC).

Oracle Price: USDV/ETH 4500, USDV/DAI 1, USDV/USDC 1 Pool price: USDV/ETH 4500, USDV/DAI 10, USDV/USDC 10

Even though the DAI and USDC pool prices are off by 10x, the final result is 4502/4520 = 0.996017699 very close to a price of 1.0 which seems strange.

Recommended Mitigation Steps

Document how the algorithm works and make sure it’s correct. Resolve the TODO.

SamSteinGG (Vader) confirmed

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 cmichel. 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 algorithm sums foreign token prices and divides by summed USD prices, which weights large prices more heavily and does not produce a robust average.

Impact

The oracle could be manipulated by skewing the prices of low-priced pairs, potentially leading to incorrect price feeds.

What the attacker needed

Access to oracle price feeds; ability to manipulate pool prices

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 price oracle is a service that provides price data to a smart contract. This report says the oracle's method for averaging prices is unclear and might be flawed because it gives too much weight to high-priced tokens, so an attacker could change the prices of low-priced tokens without changing the final average much.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by cmichel

View all

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

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.