The MarginCollateralConfiguration::configure function is responsible for collateralType configuration such as setting the decimals of a collateral. This function is supposed to ensure that self.decimals <= Constants.SYSTEM_DECIMALS for all collaterals to conform with the protocol design.
However, there is no check(s) in the MarginCollateralConfiguration::configure function to ensure that self.decimals <= Constants.SYSTEM_DECIMALS for all collaterals.
Because of the missing check(s) in the MarginCollateralConfiguration::configure function to ensure that self.decimals <= Constants.SYSTEM_DECIMALS for all collaterals as specified in the natspec of MarginCollateralConfiguration::convertTokenAmountToUd60x18, the MarginCollateralConfiguration::convertTokenAmountToUd60x18 and MarginCollateralConfiguration::convertUd60x18ToTokenAmount functions panic with an arithmetic underflow or overflow whenever self.decimals is greater than Constants.SYSTEM_DECIMALS, disrupting the protocol's functionality.
Note that the MarginCollateralConfiguration::configure function has no checks regarding the setting of decimals for collaterals as shown below:
This results in an issue for the MarginCollateralConfiguration::convertTokenAmountToUd60x18 and MarginCollateralConfiguration::convertUd60x18ToTokenAmount functions that operate on the assumption that self.decimals <= Constants.SYSTEM_DECIMALS for all collaterals and therefore carries out their operations without running any checks.
In the natspec of MarginCollateralConfiguration::convertTokenAmountToUd60x18, it is specified that when setting decimals, the protocol ensures that self.decimals is always less than or equal to Constants.SYSTEM_DECIMALS for all collaterals. Since the MarginCollateralConfiguration::configure function sets all the parameters for a collateral but sets the decimals without making any checks to ensure that self.decimals is always less than or equal to Constants.SYSTEM_DECIMALS as specified in the natspec, this causes some issues for the MarginCollateralConfiguration::convertTokenAmountToUd60x18 and MarginCollateralConfiguration::convertUd60x18ToTokenAmount functions. Whenever when self.decimals is greater than Constants.SYSTEM_DECIMALS, the two functions panic with an arithmetic underflow or overflow instead of returning the converted values, thereby affecting the protocol's functionality.
Manual Review
Fuzz testing using foundry
Proof of Concept: Consider
setting a collateral configuration using the MarginCollateralConfiguration::configure function such that decimals > Constants.SYSTEM_DECIMALS,
then call the MarginCollateralConfiguration::convertTokenAmountToUd60x18 function which causes panic throwing an arithmetic overflow or underflow
Also, calling the MarginCollateralConfiguration::convertUd60x18ToTokenAmount function causes panic throwing an arithmetic overflow or underflow
Secondly, place the following code into convertUd60x18ToTokenAmount.t.sol.
Consider adding a check in the MarginCollateralConfiguration::configure function to ensure that decimals <= Constants.SYSTEM_DECIMALS during collateral configuration in order to avoid arithmetic overflow or underflow in the MarginCollateralConfiguration::convertTokenAmountToUd60x18 and MarginCollateralConfiguration::convertUd60x18ToTokenAmount functions. This way, the protocol's funtionality is preserved.
Consider adding a custom error to use similar to TokensWithSuchDecimalsNotAllowed(string maxDecimal)
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.