Lucky Punch Ferret
Medium
DebtNeeded rounds down the calculation when collateral to liquidate exceeds user's balance.
When calculating the debt, if the collateral to liquidate exceeds the user's balance, the liquidator receives the total collateral balance of the borrower. The debt amount the liquidator will repay is recalculated, but the calculation rounds down the debt repayment amount. This is problematic because after the liquidation, the full collateral will be liquidated while leaving some debt due to the rounding. This remaining debt is directly added to the reserve deficit, causing the protocol to take the loss since it's added to the deficit.
When collateral exceeds user balance:
if (vars.maxCollateralToLiquidate > userCollateralBalance) {
vars.collateralAmount = userCollateralBalance;
vars.debtAmountNeeded = ((vars.collateralAssetPrice * vars.collateralAmount * debtAssetUnit) /
(debtAssetPrice * collateralAssetUnit)).percentDiv(liquidationBonus);
The rounding down in this calculation means: Liquidator pays slightly less debt Gets full collateral amount Difference becomes bad debt Added to reserve deficit This directly conflicts with protocol goals: Avoiding dust/bad debt buildup Preventing loss of funds caused by liquidations
collateral exceeds borrowers balance
No response
No response
Each liquidation could create small amounts of bad debt Accumulates over time Protocol bears the loss
User has 1 ETH collateral ETH price: $2000 USDC price: $1 Liquidation bonus: 110%
debtAmountNeeded = ((2000e8 * 1e18 * 1e6) / (1e8 * 1e18)).percentDiv(11000)
- 2000e8 * 1e18 = 2000e26
-
- 1e6 = 2000e32
- / 1e8 = 2000e24
- / 1e18 = 2000e6
- percentDiv(2000e6, 11000): (2000e6 * 10000) / 11000 = 1818.181818...e6 Rounds down to 1818e6 USDC
Result:
Liquidator pays: 1,818 USDC Gets: 1 ETH worth 2,000 USD Protocol loss: 0.181818... USDC per liquidation
Impact at scale: 100 such liquidations = 18.18 USDC loss 1000 liquidations = 181.81 USDC loss
loss per liquidation for the protocol
Expected repayment = 1818.181818... USDC Actual repayment = 1818.000000 USDC Loss = 0.181818... USDC
Loss percentage calculation: (0.181818... / 1818.181818...) * 100 = 0.0001 * 100 = 0.01% this makes this issue valid according to sherlock rules
round up when calculating the debtamount