Submitted by pkqs90, also found by Evo
First, we need to know how liquidation of a non bad-debt position works. The liquidator passes the amount repayAmount, pays a penalty, and buys the position collateral at a discount price.
The issue here is after deducting the penalty, the repayAmount must be exactly equal to the amount of debt at the current second in order to completely pay off the debt. Aligning with the code, this means the repayAmount * liquidationPenalty must be equal to calcTotalDebt(debtData). If it is larger, the liquidation would fail due to integer underflow in calcDecrease().
However, since the result of calcTotalDebt(debtData) is increasing as time passes, and the transaction cannot pinpoint which second it is executed, the liquidator cannot know the amount of calcTotalDebt(debtData).
This means it is nearly impossible for liquidators to fully pay off the non bad-debt position, which is unexpected.
Add a check where if deltaDebt > maxRepayment, set the deltaDebt to maxRepayment, and reverse calculate the repayAmount by maxRepayment / liquidationPenalty.
0xtj24 (LoopFi) disputed and commented:
Koolex (judge) increased severity to High and commented:
0xAlix2 (warden) commented:
pkqs90 (warden) commented:
Koolex (judge) commented:
