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

Custom Errors Reverts Fail and Signatures are wrong

Summary

this library is attempting to revert with custom errors signatures, but fails the test.

Signature code is wrong as well.
mstore(0x40, 0xbac65e5b) // MathMasters__MulWadFailed(). code 0xbac65e5b is not the correct signature for MathMasters_MulWadFailed()

using cast we geth the 4byte signature code 0xa56044f7

cast sig "MathMasters__MulWadFailed()"
0xa56044f7
Original Code | ::
function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
// @solidity memory-safe-assembly
assembly {
// Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
if mul(y, gt(x, div(not(0), y))) {
mstore(0x40, 0xbac65e5b) // `MathMasters__MulWadFailed()`. <----
revert(0x1c, 0x04)
}
z := div(mul(x, y), WAD)
}
}
/// forge test
function test_MulWad_customError_() public {
vm.expectRevert(MathMasters.MathMasters__MulWadFailed.selector);
MathMasters.mulWad(type(uint256).max + 1, 0); // <== Force Overflow to trigger revert
}
......
[FAIL. Reason: Error != expected error: NH{q◄ != 0xa56044f7] test_MulWad_customError_() (gas: 3131)
Traces:
[3131] MathMastersTest::test_MulWad_customError_()
├─ [0] VM::expectRevert(0xa56044f7)
│ └─ ← ()
└─ ← "Arithmetic over/underflow"
Test result: FAILED. 1 passed; 1 failed; finished in 731.50µs

Vulnerability Details

unneccesary code can add to gas cost. It also make the code less readable and prone to more errors.

Impact

unnessary gas cost

Tools Used

Forge

Recommendations

Because the contract is using ^0.8.3, underflow/ overflow protection is built into solidity. In both mulWad and mulWadUp remove Remove Custom Errors assembly line code and revert.

if mul(y, gt(x, div(not(0), y))) {
//mstore(0x40, 0xbac65e5b) // `MathMasters__MulWadFailed()`. <== DISABLE line
revert(0, 0) /// <== revert
}
[PASS] test_MulWad_customError_() (gas: 3131)
Traces:
[3131] MathMastersTest::test_MulWad_customError_()
├─ [0] VM::expectRevert()
│ └─ ← ()
└─ ← "Arithmetic over/underflow"
Updates

Lead Judging Commences

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

Wrong error selector

Support

FAQs

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