The Reth derivative contract implements the poolPrice function to get the spot price of the derivative asset using a Uniswap V3 pool. The function queries the pool to fetch the sqrtPriceX96 and does the following calculation:
The main issue here is that the multiplications in the expression sqrtPriceX96 * (uint(sqrtPriceX96)) * (1e18) may eventually overflow. This case is taken into consideration by the implementation of the OracleLibrary.getQuoteAtTick function which is part of the Uniswap V3 periphery set of contracts.
Note that this implementation guards against different numerical issues. In particular, the if in line 58 checks for a potential overflow of sqrtRatioX96 and switches the implementation to avoid the issue.
Recommendation
The poolPrice function can delegate the calculation directly to the OracleLibrary.getQuoteAtTick function of the v3-periphery package:
Lines of code
https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/derivatives/Reth.sol#L228-L242
Vulnerability details
Impact
The Reth derivative contract implements the
poolPrice
function to get the spot price of the derivative asset using a Uniswap V3 pool. The function queries the pool to fetch thesqrtPriceX96
and does the following calculation:https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/derivatives/Reth.sol#L228-L242
The main issue here is that the multiplications in the expression
sqrtPriceX96 * (uint(sqrtPriceX96)) * (1e18)
may eventually overflow. This case is taken into consideration by the implementation of the OracleLibrary.getQuoteAtTick function which is part of the Uniswap V3 periphery set of contracts.https://github.com/Uniswap/v3-periphery/blob/main/contracts/libraries/OracleLibrary.sol#L49-L69
Note that this implementation guards against different numerical issues. In particular, the if in line 58 checks for a potential overflow of
sqrtRatioX96
and switches the implementation to avoid the issue.Recommendation
The
poolPrice
function can delegate the calculation directly to the OracleLibrary.getQuoteAtTick function of thev3-periphery
package: