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.
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.
The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.
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.