The borrow()
and withdrawNFT()
functions in LendingPool.sol incorrectly compare the user's collateral value to their debt threshold using percentage multiplication (percentMul
) instead of percentage division (percentDiv
). This mistake underestimates the required collateral, allowing users to borrow or withdraw NFTs while being undercollateralized, potentially leading to unexpected liquidations.
liquidationThreshold
is initialized to BASE_LIQUIDATION_THRESHOLD = 80 * 1e2; // 80% in basis points
:
If it's updated, it requires newValue <= 100_00
, i.e. less or equal to 100% in basis point:
Now, here's the obvious flaw in borrow()
:
userTotalDebt.percentMul(liquidationThreshold)
reduces the debt instead of properly scaling up prior to comparing it with the required collateral.
The correct formula should divide debt by the liquidation threshold, scaling the userTotalDebt
more than 100% to determine the required collateral.
Similar flawed logic is unfortunately exhibited in withdrawNFT()
too:
Users can withdraw NFTs or borrow beyond safe limits, leaving their positions undercollateralized.
This leads to unexpected liquidations where users may lose their collateral even when they believed they were safe.
The system could become insolvent, as borrowers may be unable to fully repay their debts with a trend of easy money easy go.
Manual
Consider making the following refactoring:
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.