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

Overriding free memory pointer and incorrect use of the function selector, for the second time.

Summary

There is a second incorrect use of a function selector which overwrites the free memory pointer.

Vulnerability Details

Wrong use of function selector at line 53 which overwrites the free memory pointer

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, 0xbac65e5b) // `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))
}
}

Impact

Functions start write the slot returned by mload(0x40) and overwrite your data. Therefore, overriding the free memory pointer could cause to overwrite some data and an increase in gas spent due to increase of memory allocation.

Tools Used

Manual review

Recommendations

Remove the line 53 from the code.
In this case, there is no need to store anything in memory. Then the revert has to be changed from revert (0x1c, 0x04) to a call revert(0,0).

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, 0xbac65e5b) // `MathMasters__MulWadFailed()`.
- revert(0x1c, 0x04)
+ revert(0, 0)
}
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
inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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