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

mulWadUp performs unnecessary round up.

Summary

The mulWadUp performs unnecessary round up.

Vulnerability Details

The assembly operation in line 56 of MathMasters.sol results in true even when x is equal to y. Valid round up operations is included on line 57, iszero(iszero(mod(mul(x, y), WAD))).

The test below represents the case when mulWadUp rounds up the result even when x is equal to y.

function testMulWadUpWithUnnecessaryRoundUp() public {
uint256 x = 1e18;
uint256 y = 1e18;
uint256 z = MathMasters.mulWadUp(x, y);
assertNotEq(z, 1e18);
assertEq(z, 1e18 + 1);
}

Add the test in MathMasters.t.sol and run forge test -vvvv --mt testMulWadUpWithUnnecessaryRoundUp to see the result.

$ forge test -vvvv --mt testMulWadUpWithUnnecessaryRoundUp
[⠑] Compiling...
No files changed, compilation skipped
Running 1 test for test/MathMasters.t.sol:MathMastersTest
[PASS] testMulWadUpWithUnnecessaryRoundUp() (gas: 759)
Traces:
[759] MathMastersTest::testMulWadUpWithUnnecessaryRoundUp()
└─ ← ()
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.67ms
Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)

Impact

Unnecessary round up leads to losses in the context of calculating token amount.

Tools Used

  • Foundry

Recommendations

Delete line 56.

Updates

Lead Judging Commences

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

`mulWadUp` has an unnecessary line that makes the result wrong for some inputs

Support

FAQs

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