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

Incorrect error selector in `mulWadUp` function of MathMasters Library

Summary

The mulWadUp function in the MathMasters library incorrectly references the MathMasters__MulWadFailed error with the selector 0xbac65e5b instead of the correct selector 0xa56044f7. This misalignment may lead to confusion and unexpected behavior.

Vulnerability Details

In the assembly code of the mulWadUp function, the error is specified with the incorrect selector, potentially causing issues in error handling and reporting.

Impact

This discrepancy in the error selector may result in misidentifying errors related to the mulWadUp function, affecting the accuracy of error handling. Developers relying on the correct error selector may face challenges in debugging and understanding the root cause of potential failures.

POC

  • Run this cmd forge inspect MathMasters errors and you will see the selector for MathMasters__MulWadFailed is a56044f7 not 0xbac65e5b

{
"MathMasters__MulWadFailed()": "a56044f7"
}

Recommendations

Update the selector for the MathMasters__MulWadFailed error in the mulWadUp function to the correct value (0xa56044f7). Ensure consistency between error definitions and their associated selectors for accurate error identification and reporting.

Update code should be:

function mulWadUp(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, or(div(not(0), y), x))) {
mstore(0x40, a56044f7) // `MathMasters__MulWadFailed()`
revert(0x1c, 0x04)
}
if iszero(sub(div(add(z, x), y), 1)) { x := add(x, 1) }
z := add(iszero(iszero(mod(mul(x, y), WAD))), 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.