In the borrow function, the contract attempts to ensure that a user’s collateral sufficiently covers the total debt after borrowing. However, the collateral check uses the expression userTotalDebt.percentMul(liquidationThreshold) to compute the required collateral. Since liquidationThreshold is set to 80% (expressed in basis points), applying percentMul in this manner effectively scales down the debt value, reducing the required collateral threshold. This miscalculation can allow users to borrow assets even when their collateral does not adequately cover their debt, resulting in undercollateralized positions.
Incorrect Collateral Validation in borrow
The function includes the following check:
Intended Logic:
The goal is to ensure that after borrowing, the user’s collateral value is at least a specified percentage (80% in this case) of their total debt. This is meant to safeguard against over-borrowing relative to the collateral provided.
Issue with Calculation:
The use of percentMul on userTotalDebt with the liquidationThreshold scales down the debt value. For example, if a user’s total debt is 100 units, applying an 80% factor would yield 80 units. This lowered requirement means that as long as the collateral exceeds this reduced threshold, the borrow operation is allowed—even if the actual debt-to-collateral ratio is unsound. In effect, the check does not enforce the intended strict collateralization standard, permitting undercollateralized borrowing.
Example Scenario:
User’s Collateral: 800 units
User’s Current Debt: 100 units
Borrowing Action: The user borrows an amount that increases userTotalDebt to 150 units
Expected Behavior: The required collateral should be 150 * 80% = 120 units
Actual Behavior: Due to the flawed calculation, the contract might only require a lower effective threshold, allowing the borrow even if the collateral is insufficient relative to the true risk.
Undercollateralized Borrowing:
Users can borrow more than what their collateral securely supports, resulting in positions that are vulnerable to market fluctuations and rapid devaluation.
Increased Protocol Risk:
Allowing undercollateralized positions heightens the risk of defaults, which could compromise the stability of the lending pool and the overall protocol.
Economic Exploitation:
Malicious actors may exploit this vulnerability to maximize borrowing capacity, potentially extracting more value from the protocol than intended.
In this POC:
Insufficient Collateral Test: Verifies that borrowing 300 units (requiring 240 collateral) reverts when only 200 collateral is available.
Sufficient Collateral Test: Confirms that borrowing 200 units (requiring 160 collateral) is allowed with the available 200 collateral.
This targeted change ensures that the collateral requirement is calculated correctly, preventing undercollateralized borrow operations.
Manul review
Revise the Collateral Check:
Update the logic in the borrow function to calculate the required collateral without inadvertently reducing the debt value. For example, compute the required collateral using direct multiplication and division to maintain precision:
Ensure that the calculation accurately reflects the intended 80% collateral requirement.
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.