Dria

Swan
NFTHardhat
21,000 USDC
View results
Submission Details
Severity: low
Invalid

Function `sqrt` in `Statistics` lib will revert due to overflow if input is max value of uint256

Summary

TX will revert if function sqrt is called with a max value of uint256 as input. Although it is very unlikely this bug will be triggered in the current implementation of Dria protocol, it should be fixed in order for sqrt to work properly for all inputs.

Vulnerability Details

This is the sqrt function containing the bug:

function sqrt(uint256 x) internal pure returns (uint256 y) {
uint256 z = (x + 1) / 2;
...

Increasing the x by 1 will result in overflow when input is max uint256 value.

Impact

TX reverts when if consuming the sqrt function with max uint256 value as input.

Tools Used

Manual review

Recommendations

Change the implementation of sqrt to avoid overflow:

function sqrt(uint256 x) internal pure returns (uint256 y) {
- uint256 z = (x + 1) / 2;
+ uint256 z = x / 2 + 1;
Updates

Lead Judging Commences

inallhonesty Lead Judge 12 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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