solidity-lib icon indicating copy to clipboard operation
solidity-lib copied to clipboard

The proof for Babylonian square root algorithm in audit report is wrong

Open yonggewang opened this issue 3 years ago • 8 comments

The proof for Babylonian square root algorithm in audit report is wrong https://uniswap.org/audit.html

yonggewang avatar Nov 14 '20 15:11 yonggewang

@yonggewang can you elaborate? does the code not match the proof?

moodysalem avatar Nov 14 '20 19:11 moodysalem

mathematical claim in the audit report is wrong. the code may produce results not as claimed in the audit report

yonggewang avatar Nov 14 '20 20:11 yonggewang

I'm not sure what is meant by 'wrong', can you be specific about what part of the proof is incorrect?

moodysalem avatar Nov 14 '20 20:11 moodysalem

too complicated to describe details here. The last two lines of the proof has a wrong argument. after one shows that a >b.. the value of b is not necessarily the largest value below b. It can be anything below b

The last formula has typo in it. but that is not main issue there. In the last formula, you have an extra Z_{N-1} which is a ghost. I do not see where it comes from. But you can just drop that without any issue. So that is a typo only I assume

yonggewang avatar Nov 14 '20 21:11 yonggewang

Max N for y<=2^x for odd x appears to be N = (x+1)/2+ floor(log((x+1)/2)/log(2)) giving N=135 and 136 for x=255 and 257.

zawy12 avatar Nov 15 '20 15:11 zawy12

@livnev do these comments make sense to you?

moodysalem avatar Nov 19 '20 17:11 moodysalem

For my part, I'm only saying that I have an equation that may help derive the guess of N=135 that's in the proof as opposed to settling for N<255.

zawy12 avatar Nov 19 '20 18:11 zawy12

the best practice for Babylonian's algorithm is to have a few extra digits (or a few bits in binary case)... e.g., if we want the accuracy for all digits on the left hand side of the fractional point, it is better to have one extra digit on the right hand side of the fractional point during the iteration. This could be proved easily. But the "proof" in the audit report seems to be faulty and cannot prove this fact (even if we keep several extra bits during iteration).

So assume zawy12's comments are talking about the same thing (extra bits beyond required accuracy). thanks!

yonggewang avatar Nov 19 '20 21:11 yonggewang