The LiquidityBasedTWAP contract attempts to accurately track the price of VADER and USDV while still being resistant to flash loan manipulation and short-term volatility. The previousPrices array is meant to track the last queried price for the two available paths, namely VADER and USDV.
The setupVader function configures the VADER token by setting previousPrices and adding a token pair. However, syncVaderPrice does not update previousPrices after syncing, causing currentLiquidityEvaluation to be dependent on the initial price for VADER. As a result, liquidity weightings do not accurately reflect the current and most up to date price for VADER.
This same issue also affects how USDV calculates currentLiquidityEvaluation.
This issue is of high risk and heavily impacts the accuracy of the TWAP implementation as the set price for VADER/USDV diverges from current market prices. For example, as the Chainlink oracle price and initial price for VADER diverge, currentLiquidityEvaluation will begin to favour either on-chain or off-chain price data depending on which price result is greater. The following calculation for currentLiquidityEvaluation outlines this behaviour.
Consider updating previousPrices[uint256(Paths.VADER)] and previousPrices[uint256(Paths.USDV)] after syncing the respective prices for the two tokens. This will ensure the most up to date price is used when evaluating liquidity for all available token pairs.
Handle
leastwood
Vulnerability details
Impact
The
LiquidityBasedTWAP
contract attempts to accurately track the price ofVADER
andUSDV
while still being resistant to flash loan manipulation and short-term volatility. ThepreviousPrices
array is meant to track the last queried price for the two available paths, namelyVADER
andUSDV
.The
setupVader
function configures theVADER
token by settingpreviousPrices
and adding a token pair. However,syncVaderPrice
does not updatepreviousPrices
after syncing, causingcurrentLiquidityEvaluation
to be dependent on the initial price forVADER
. As a result, liquidity weightings do not accurately reflect the current and most up to date price forVADER
.This same issue also affects how
USDV
calculatescurrentLiquidityEvaluation
.This issue is of high risk and heavily impacts the accuracy of the TWAP implementation as the set price for
VADER/USDV
diverges from current market prices. For example, as the Chainlink oracle price and initial price forVADER
diverge,currentLiquidityEvaluation
will begin to favour either on-chain or off-chain price data depending on which price result is greater. The following calculation forcurrentLiquidityEvaluation
outlines this behaviour.Proof of Concept
https://github.com/code-423n4/2021-12-vader/blob/main/contracts/lbt/LiquidityBasedTWAP.sol#L150-L189
https://github.com/code-423n4/2021-12-vader/blob/main/contracts/lbt/LiquidityBasedTWAP.sol#L221-L235
Tools Used
Manual code review.
Recommended Mitigation Steps
Consider updating
previousPrices[uint256(Paths.VADER)]
andpreviousPrices[uint256(Paths.USDV)]
after syncing the respective prices for the two tokens. This will ensure the most up to date price is used when evaluating liquidity for all available token pairs.