Submitted by said, also found by radev_sw, Satyam_Sharma, 0xmuxyz, LokiThe5th, Team_FliBit, and T1MOH
poolMatchesOracle is used to compare price calculated from uniswap v3 pool and chainlink oracle and decide whether rebalance should happened or not. priceX8 will be holding price information calculated using sqrtPriceX96 and when operations is performed, it will try to scale down using 2 ** 12. However, the scale down is not enough and overflow can still happened.
Consider this scenario, The GeVault is using WBTC for token0 and WETH for token1.
These are information for the WBTC/WETH from uniswap v3 pool (0x4585FE77225b41b697C938B018E2Ac67Ac5a20c0):
slot0 data (at current time) :
token0 (WBTC) decimals is 8 and token1 (WETH) decimals is 18.
Using these information, try to reproduce the priceX8 calculation :
the test result in overflow :
This will cause calculation still overflow, even using the widely used WBTC/WETH pair
Consider to change the scale down using the recommended value from uniswap v3 library:
https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/OracleLibrary.sol#L49-L69
or change the scale down similar to the one used inside library
Keref (Good Entry) confirmed and commented:
Good Entry Mitigated:
Status: Mitigation confirmed. Full details in reports from kutugu, xuwinnie and 3docSec.
