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

If statement incorrectly adds 1 to x

Summary

Line 56 if iszero(sub(div(add(z, x), y), 1)) { x := add(x, 1) } adds 1 to x if x and y are the same WAD number.

Vulnerability Details

When executing mulWadUp with value 3e18 for x and y it adds 3 to the number giving an incorrect result:

function testMulWadUpWrongResult() public {
console2.log("Test start");
uint256 x = 3e18;
uint256 y = 3e18;
uint256 z = MathMasters.mulWadUp(x, y);
console2.logUint(z); // 9000000000000000003 -> should be 9000000000000000000
}

Impact

High - incorrect functionality

Tools Used

forge test --match-test testMulWadUpWrongResult -vv

Recommendations

Remove 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.