The sqrt
function in this contract, which employs the Babylonian method to calculate the integer square root, does not include a termination condition for cases when x
is zero. This could result in an infinite loop, leading to excessive gas consumption and the possibility of denial-of-service (DoS) attacks.
The sqrt
function computes the square root by iteratively updating values until convergence. However, if the input x
is zero, the function lacks a condition to return immediately, leading to a loop with no termination. This can potentially cause the function to consume all available gas and fail to return, impacting contract reliability and usability.
This issue can cause an infinite loop for an input of x = 0
Manual code review
Add an explicit check for x == 0
to return 0
immediately
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.