sherlock-audit / 2023-02-blueberry-judging

12 stars 5 forks source link

eierina - BBMath can overflow #349

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

eierina

false

BBMath can overflow

Summary

BBMath's divCeil can overflow.

Vulnerability Detail

divCeil sums the quotient and the dividend, which may overflow.

function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
    return (a + b - 1) / b;
}

Impact

Overflow if the sum of the quotient and the dividend is greater than type(uint256).max.

Code Snippet

https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/libraries/BBMath.sol#L7-L9

Tool used

Manual Review

Recommendation

Change divCeil with a form that does not overflow.

function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
    return a == 0 ? 0 : (a - 1) / b + 1;
}