Trying to learn how Uniswap V3 works, and was reading through the whitepaper. Supposedly, the formula for getting the tick from the current square root price should be: enter image description here

The whitepaper says that the variables you can request from the contract include the following: enter image description here

Yet getting the current values for a pool on Etherscan shows these values to be the actual square root price and tick values:

enter image description here

1360350530493305778931717664053685 for sqrtPriceX96, 195028 for tick in text format for copy paste.

When I plug the sqrtPriceX96 into the formula for sqrt(P), I would expect the tick to be 1,525,937 rather than 195,028. These numbers are obviously very different, is there something about my understanding of when the contract updates these values that is wrong, or something entirely about my understanding of the formula?

I have tried different variations on squaring different numbers then rerunning the formula, and nothing seems even close.

1 Answer 1


sqrtPriceX96 is stored as a uint160, but from a mathematical perspective it behaves as a Q64.96 value, not an integer. Q64.96 is a way of representing a fixed-point number, and it has its own rules regarding how it can and cannot be manipulated.

Under the hood, all the conversions pertaining to the log formula are handled by the TickMath library. If you go and take a look at it you'll see why I'm not going into the minutia of how it works here. (Mainly because I barely understand it myself.)

We are just sort of left to assume that all of these assembly lines and bitwise operations have been coded correctly and do what the developers claim they do.

  • Ahh that makes a lot of sense, time to deep dive into TickMath then, thank you! It's funny because I was well aware of this in regards to signed values being stored as unsigned twos complement, but didn't even consider that they did the same for floating point.
    – colevs
    Jan 9, 2022 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.