StabilityPool::liquidateBorrower function is designed to liquidate a borrower's position. But in the user debt calculation this is incorrectly scaled twice during liquidation. This occurs because the function scales the already-scaled debt returned by LendingPool::getUserDebt with the normalization factor again usage.index`. This leads to an overestimation of user debt during liquidation.
StabilityPool.sol
LendingPool.sol
Consider the following scenario:
User's scaled debt balance: 100
Usage index: 1.1 RAY (1.1 * 1e27)
In StabilityPool::liquidateBorrower:
First scaling (in LendingPool::getUserDebt):
userDebt = scaledDebtBalance.rayMul(usageIndex)
userDebt = 100 * (1.1 * 1e27) / 1e27
userDebt = 110 // Correct scaled debt
Second incorrect scaling:
scaledUserDebt = userDebt.rayMul(usageIndex)
scaledUserDebt = 110 * (1.1 * 1e27) / 1e27
scaledUserDebt = 121 // Incorrectly scaled
Result:
Actual user debt: 110
Incorrectly calculated debt: 121
Excess liquidation amount: 11 (10% more than actual debt)
The user would be overcharged by 121 USDC during liquidation
In the liquidateBorrower there is a double application of the normalization factor to the user's debt. This causes a severe overestimation of user debt during liquidation. Users are liquidated for more debt than they actually owe.
Manual review
Remove the second scaling operation in liquidateBorrower.
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.