The TWAPOracle.registerPair function takes in a factory 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 the token0 and token1 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 internal price0CumulativeLast, price1CumulativeLast order matches the order of the function arguments token0, token1.
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.