mulWadUp function should revert if there is a overflow but due to incorrect overflow checks it will not revert and returns a wrong answer because of overflow.
The vulnerability occurs due to the wrong overflow condition check inside mulWadUp function inside MathMasters.sol
It is assumed that the overflow check at line 52 is equivalent to require(y == 0 || x <= type(uint256).max / y)
but it is actually not.
The incorrect overflow check at line 52 is mul(y, gt(x, or(div(not(0), y), x)))
Here first it gets the maximum safe value of x by div(not(0), y)
and then performs or
operation with x.
We know that or
operation performed on x
and div(not(0), y)
will yield at least x
as the answer and the condition gt(x, or(div(not(0), y), x))
will always be false, because or(div(not(0), y), x)
will always be >=x
.
Thus, even if there is a overflow it will not revert and still returns incorrect answer.
In case of overflow, the function mulWadUp
will not revert and still returns incorrect answer.
Add the test in the file: test/MathMasters.t.sol
Run the test:
Manual Review
Eliminate the unnecessary or
operation.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.