User will not be able to create any pool where baseDecimals is greater than quoteDecimals.
Proof of Concept
To Create new Pool, User can use Router contract's following functions:
createPool
createPoolEth
These functions first validate the decimals, ensuring that the difference between them does not exceed MAX_BASE_QUOTE_DECIMALS_DIFFERENCE, which is set to 12.
The _validateDecimals function performs the validation:
function _validateDecimals(uint8 baseDecimals, uint8 quoteDecimals) internal pure {
if (baseDecimals == 0 || quoteDecimals == 0) {
revert ErrZeroDecimals();
}
if (quoteDecimals - baseDecimals > MAX_BASE_QUOTE_DECIMALS_DIFFERENCE) {
revert ErrDecimalsDifferenceTooLarge();
}
}
However, the validation only accounts for scenarios where quoteDecimals > baseDecimals by 12 or more.
If baseDecimals > quoteDecimals, an underflow occurs, resulting in an immediate revert even if the difference between them is less than 12 decimals.
This leads to a DoS situation for creating pools where baseDecimals > quoteDecimals.
Tools Used
VS Code
Recommended Mitigation Steps
Refactor the validation as shown below which correctly handles scenarios where either baseDecimals or quoteDecimals is larger and both are within Max Decimal Difference allowed.
Lines of code
https://github.com/code-423n4/2024-03-abracadabra-money/blob/main/src/mimswap/periphery/Router.sol#L598-L605
Vulnerability details
Impact
User will not be able to create any pool where
baseDecimals
is greater thanquoteDecimals
.Proof of Concept
To Create new Pool, User can use
Router
contract's following functions:createPool
createPoolEth
These functions first validate the decimals, ensuring that the difference between them does not exceed
MAX_BASE_QUOTE_DECIMALS_DIFFERENCE
, which is set to 12.The
_validateDecimals
function performs the validation:However, the validation only accounts for scenarios where
quoteDecimals > baseDecimals
by 12 or more.If
baseDecimals > quoteDecimals
, an underflow occurs, resulting in an immediate revert even if the difference between them is less than 12 decimals.This leads to a DoS situation for creating pools where
baseDecimals > quoteDecimals
.Tools Used
VS Code
Recommended Mitigation Steps
Refactor the validation as shown below which correctly handles scenarios where either
baseDecimals
orquoteDecimals
is larger and both are within Max Decimal Difference allowed.Assessed type
Invalid Validation