TWAPOracle might register with wrong token order #171
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
TwapOracle
Handle
cmichel
Vulnerability details
The
TWAPOracle.registerPair
function takes in afactory
and (token0, token1)
.The function accepts a
_factory
argument which means any Uniswap-like factory can be used.When using the actual Uniswap factory's
IUniswapV2Factory(factory).getPair(token0, token1)
call, it could be that thetoken0
andtoken1
are reversed as it ignores the order.Meaning, the
price0/1CumulativeLast
could also be reversed as it matches the internal order.The code however pushes the
_pairs
assuming that the internalprice0CumulativeLast, price1CumulativeLast
order matches the order of the function argumentstoken0, token1
.Impact
The prices could be inverted which leads to the oracle providing wrong prices.
Recommended Mitigation Steps
It should be checked if Uniswap's internal order matches the order of the
token0/1
function arguments.If not, the cumulative prices must be swapped.
The text was updated successfully, but these errors were encountered: