Skip to content
Request an audit

‹ All findings

Custom error for overflowing the total principal is not raised

Low/InfoM^0 Minter Gateway·Three Sigma · Stablecoin framework · 8th January, 2024Codebase3S-M^0-L07

Description

In the MToken._mint function, there's a check to make sure the total principal doesn't become larger than a uint112: if ( principalOfTotalEarningSupply + _getPrincipalAmountRoundedDown(totalNonEarningSupply) >= type(uint112).max

solidity
) {
revert OverflowsPrincipalOfTotalSupply();
}

Inside the condition, we're adding two uint112 numbers, which will panic overflow if the result is greater than type(uint112).max (solidity 0.8 is being used). For this reason, the error inside the if statement will never actually be reached.

Recommendation

Cast one of the numbers to uint256 to prevent the addition from panic overflowing:

solidity
if ( uint256(principalOfTotalEarningSupply) +
_getPrincipalAmountRoundedDown(totalNonEarningSupply) >= type(uint112).max
) {
revert OverflowsPrincipalOfTotalSupply();
}

Status

Addressed in #bdd94b9.