abdk-libraries-solidity icon indicating copy to clipboard operation
abdk-libraries-solidity copied to clipboard

Incorrect hardcoded value of 0x8 in sqrtu function (should be 0x4)

Open nonergodic opened this issue 2 years ago • 1 comments

The hardcoded value here is wrong.

0x8 = 1<<3 but it should be 1<<2 i.e. 0x4

I'm not sure how smart solc is (whether it will unroll loops if one cranks the optimization runs sufficiently high - I haven't tried it yet), but all of this could be avoided by

using the 1 << shift syntax
writing the entire thing as a loop (same with the 7x code repetition below)

nonergodic avatar Jun 24 '22 02:06 nonergodic

@nonergodic Can you provide an input and an expected output for which the hardcoded value would create problems?

cleanunicorn avatar Sep 20 '22 13:09 cleanunicorn