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

The function selector for MathMasters__MulWadFailed() in mulWad is not correct

Summary

In muldWad(), the function selector used for the custom error MathMasters__MulWadFailed() is not correct. The function selector for a custom error is the same as the function selector for a function. That means the function selector should be bytes4(keccak256("MathMasters__MulWadFailed()") - that gives you 0xa56044f7. But the function selector for the MathMasters__MulWadFailed() error used in mulWad() is 0xbac65e5b.

Vulnerability Details

Here is the mulWad() function which stores a function selector for a custom error MathMasters__MulWadFailed() of 0xbac65e5b:

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)
}
}

Impact

Users will not get the proper custom errors which may confuse them with regard to what is going wrong. In this case, no custom errors in the contract have this function selector, so it provides no information about what caused the reversion.

Tools Used

Manual review

Recommendations

The correct function selector is 0xa56044f7, so the code should be (also with the storage slot corrected):

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(0x00, 0xa56044f7) // `MathMasters__MulWadFailed()`.
revert(0x1c, 0x04)
}
z := div(mul(x, y), WAD)
}
}
Updates

Lead Judging Commences

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.