When sqrtRatioAX96 is zero, it can lead to problematic calculations, such as division by zero or other errors. Uniswap V3 addresses a similar concern by incorporating a requirement require(sqrtRatioAX96 > 0), which ensures that sqrtRatioAX96 is always greater than zero.
Vulnerability Detail
In the LiquidityAmounts.getAmount0ForLiquidity() function, there is an issue with sqrtRatioAX96 not being checked for a value of 0 before performing calculations. If sqrtRatioAX96 is 0, it could lead to problematic calculations, possibly resulting in division by zero or other errors.
In Uniswap V3, a similar calculation is safeguarded with the requirement require(sqrtRatioAX96 > 0) to ensure that sqrtRatioAX96 is not zero, preventing potential issues. The absence of such a check in this code could pose a risk in scenarios where sqrtRatioAX96 might become 0, and it's essential to validate this value to ensure the correctness and safety of the calculations.
Bauer
medium
Missing check for
sqrtRatioAX96 > 0
Summary
When
sqrtRatioAX96
is zero, it can lead to problematic calculations, such as division by zero or other errors. Uniswap V3 addresses a similar concern by incorporating a requirementrequire(sqrtRatioAX96 > 0)
, which ensures thatsqrtRatioAX96
is always greater than zero.Vulnerability Detail
In the
LiquidityAmounts.getAmount0ForLiquidity()
function, there is an issue withsqrtRatioAX96
not being checked for a value of 0 before performing calculations. IfsqrtRatioAX96
is 0, it could lead to problematic calculations, possibly resulting in division by zero or other errors. In Uniswap V3, a similar calculation is safeguarded with the requirementrequire(sqrtRatioAX96 > 0)
to ensure thatsqrtRatioAX96
is not zero, preventing potential issues. The absence of such a check in this code could pose a risk in scenarios wheresqrtRatioAX96
might become 0, and it's essential to validate this value to ensure the correctness and safety of the calculations.Impact
The absence of the check for sqrtRatioAX96 > 0 could lead to potential issues in the calculation process.
Code Snippet
https://github.com/sherlock-audit/2023-10-real-wagmi/blob/main/wagmi-leverage/contracts/abstract/LiquidityManager.sol#L129
Tool used
Manual Review
Recommendation
Implement a validation check to ensure that
sqrtRatioAX96
is a positive value before performing any calculations that rely on it