The liquidation process in the protocol has a potential vulnerability due to the use of stale debt information when approving token transfers. This can lead to failures in the liquidation process if the approved amount is insufficient to cover the user's actual debt at the time of liquidation.
In the liquidateBorrower() function in StabilityPool works as follows:
1.Stale Debt Calculation
:
The getUserDebt() function returns the user's debt based on the current usageIndex, which may be stale.
The reserve.usageIndex reflects the state of the reserve at the last update, and if there have been significant changes in the reserve's state (like deposits or withdrawals) since that last update, the returned debt may not accurately represent the user's current obligation.
2.Approval Based on Stale Debt:
The retrieved userDebt is then used to set the approval for the lendingPool to transfer the necessary amount of tokens from the StabilityPool. This approval is based on potentially outdated information.
3.State Update in Finalization:
After the approval is set, the finalizeLiquidation() function is called on the lendingPool.
This function first updates the reserve state by calling ReserveLibrary.updateReserveState(), which recalculates the usageIndex and subsequently the user's debt based on the updated state.
Now, if the actual required tokens to be pulled from the StabilityPool (amountScaled) exceed the amount that was approved based on the stale userDebt, the transaction will fail when the lendingPool attempts to transfer the tokens.
This can lead to a failure in the liquidation process, leaving users in a precarious position where their debts are not settled, and they remain under liquidation. This undermines the reliability of the lending protocol and could result in financial losses for users.
Manual Review
Ensure that the debt is recalculated and the approval is set based on the most current state of the reserve when initiating the liquidation in the stabilityPool:
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.