Closed tomwade closed 12 months ago
This was taken from the Euler Risk Manager contract: https://github.com/euler-xyz/euler-contracts/blob/master/contracts/modules/RiskManager.sol
I'll look at reviewing this issue to see if I can create a test suite that breaks the current flow and would be resolved by the change in formula but will make this a lower priority.
UVP-03M: Decoding Loss of Precision
Description:
The
UniswapV3PricingExecutor::_decodeSqrtPriceX96
function will attempt to decode the Uniswap V3 encoded price to the pair's price, however, it does so without properly accommodating for mathematical inaccuracies.Impact:
Price calculations that end out-of-bounds could result in improper zero-price assessments.
Example:
Recommendation:
We advise the code to instead multiply
sqrtPriceX96
by itself, divide by thetoken1
decimals, multiply by thetoken0
decimals, and finally divide by the2 ** 192
value. This order of operations will guarantee maximum accuracy of theprice
calculated whilst ensuring that it remains within safe bounds by balancing the multiplication and division operations.