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

function mulWadUp overflow, does not protect against over flow.

Summary

On the library function MathMasters::mulWadUp, the if statement to prevent overflow is not working. when x is type(uint256).max and y is over 1, revert does not occur as I think it should.

Vulnerability Details

Depending on what the contract uses the library for and what the contract uses this function for, will determine the severity of the vulnerabilities. The following could include:

  • Financial Loss

  • Unexpected behavior

  • Denial of Service (DoS)

  • Exploitation by Attackers:

Impact

function testMulWadUpOverflow() public {
uint x = type(uint).max;
uint y = 1;
assertEq(MathMasters.mulWadUp(x, y), 115792089237316195423570985008687907853269984665640564039458);
Running 1 test for test/MathMasters.t.sol:MathMastersTest
[PASS] testMulWadUpOverflow() (gas: 446)
Traces:
[446] MathMastersTest::testMulWadUpOverflow()
└─ ← ()
}
This number stays the same if uint x = type(uint).max, y can be anything above 0. If uint y is 0 then the result is 0.

Tools Used

  • Foundary

  • Remix.

Recommendations

- if mul(y, gt(x, or(div(not(0), y), x)))
+ if or(iszero(y), gt(x, div(sub(not(0), y), y)))
Updates

Lead Judging Commences

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

`mulWadUp` has a bad overflow check

Support

FAQs

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