Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Wrong value in checks of the `lt` of a right shift

Summary

The code contains a discrepancy in the sqrt function's comment, where the correct value of 16777215 is mentioned, but the code incorrectly uses 16777002. This inconsistency may lead to incorrect comparisons in the algorithm, affecting the initial estimate provided by the Babylonian method.

Vulnerability Details

The specific issue arises is present in this code:

r := or(r, shl(4, lt(16777002, shr(r, x))))

where 16777002 should be corrected to 16777215 to accurately reflect the maximum value resulting from a right shift.

Impact

The impact of this issue lies in the potential misalignment of the initial estimate provided by the Babylonian method. Incorrect comparisons may lead to unexpected behavior, affecting the convergence speed of the algorithm.

The significance of this issue lies in the fact that the value 16777002 does not accurately represent the maximum value that can result from a right shift. Specifically, when r is right-shifted by x bits, the maximum value it can have is 0xffffff, not 0xffff2a. Therefore, the lt (less than) comparison may produce incorrect results and potentially lead to unexpected behavior.

Tools Used

Manual code review and analysis.

Recommendations

Use correct decimal value in the code:

-lt(16777002, shr(r, x))
+lt(16777215, shr(r, x))
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Sqrt yields incorrect results for certain inputs because 16777002 doesn't represent the maximum value resulting from a right shift

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.