-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Math.sqrt #3149
Comments
Thanks for the request @Dentrax! The reason we don't have this function currently is that it's not constant time. But I think we should take a closer look to see if there is real risk of running out of gas in the worst case, and what is the "average" cost. It would be interesting to see smart contracts in production that are using sqrt to see if they took any special precautions and what particular implementations they used. |
@frangio UniswapV2 pairs use sqrt. |
O(1) implementation of |
🧐 Motivation
It would be nice to have. Currently, we have to write our "custom" function that we can find the logic on the internet. But I'm not so sure whether those are "safe" to use.
📝 Details
Something like:
https://github.com/Uniswap/v2-core/blob/4dd59067c76dea4a0e8e4bfdda41877a6b16dedc/contracts/libraries/Math.sol#L11
In OpenZeppelin way:
The text was updated successfully, but these errors were encountered: