The UniswapV2Pair cumulative price variables are designed to eventually overflow, i.e. price0CumulativeLast and price1CumulativeLast and blockTimestampLast will overflow through 0.
It means that blockTimestampLast can be lower than blockTimestamp, and the new price0Cumulative can be less than price0CumulativeLast, and so on...
In that case, the current implementation of refreshedAssetPerBaseInUQ() will revert due to underflow.
As a result, price0Average and price1Average will not be updated for a long time, any other contracts or functions that rely on this price will be affected.
Lines of code
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PriceOracle.sol#L61-L75
Vulnerability details
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PriceOracle.sol#L61-L75
According to Uniswap official docs:
Ref: https://docs.uniswap.org/protocol/V2/guides/smart-contract-integration/building-an-oracle
It means that
blockTimestampLast
can be lower thanblockTimestamp
, and the newprice0Cumulative
can be less thanprice0CumulativeLast
, and so on...In that case, the current implementation of
refreshedAssetPerBaseInUQ()
will revert due to underflow.As a result,
price0Average
andprice1Average
will not be updated for a long time, any other contracts or functions that rely on this price will be affected.Recommendation
Change to: