Partial Liquidators can Cause the Last Liquidator to Suffer a Loss
The liquidation fee calculation in FraxlendPairCore gives partial liquidators a disproportionate share of collateral, leaving the final liquidator with less than the promised bonus or even a loss. This can discourage final liquidations, leaving insolvent loans unliquidated.
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/349
Found by
pkqs90, prosper, uuzall
Summary
When a position is liquidated, the liquidators are paid a certain percent of fees. In some positions, partial liquidators will get an unfair shares of the fees when they liquidate first and the final liquidators will be left with small crumbs of fees or even full losses which will cause a lot of insolvent loan positions to never be liquidated.
Root Cause
The liquidate function allows a third party to repay a borrower's debt if they have become insolvent. The liquidators get paid a percentage of collateral as fees when they liquidate the position as a bonus:
function liquidate(uint128 _sharesToLiquidate, uint256 _deadline, address _borrower)
...
uint256 _optimisticCollateralForLiquidator =
@> (_liquidationAmountInCollateralUnits * (LIQ_PRECISION + cleanLiquidationFee)) / LIQ_PRECISION;
_leftoverCollateral = (_userCollateralBalance.toInt256() - _optimisticCollateralForLiquidator.toInt256());
_collateralForLiquidator = _leftoverCollateral <= 0
? _userCollateralBalance
@> : (_liquidationAmountInCollateralUnits * (LIQ_PRECISION + dirtyLiquidationFee)) / LIQ_PRECISION;
if (protocolLiquidationFee > 0) {
_feesAmount = (protocolLiquidationFee * _collateralForLiquidator) / LIQ_PRECISION;
_collateralForLiquidator = _collateralForLiquidator - _feesAmount;
This bonus is calculated as either the cleanLiquidationFee or the dirtyLiquidationFee (as shown above) depending on whether the liquidator liquidates the entire position or only a partial position.
The problem is that in certain situations, liquidators who liquidate the position last will not get their fair share of the collateral tokens. This happens because the final liquidator gets the entirety of the collateral the position holds.
Internal Pre-conditions
- The maxLTV of a Pair is set to
100 - maxLTV ≲ liquidationFees. - Borrower takes out a loan.
- Borrower's loan becomes insolvent.
- A series of liquidators partially liquidate the function.
- The final liquidator does not get their fair share.
External Pre-conditions
- The borrower's loan becomes insolvent due to various external factors.
Attack Path
Take the following situation as an example:
- A loan's
maxLTVis95%, and thecleanLiquidationFeeis6%. - The loan while being liquidated has
100assets, and105.26collateral. For simplicity, let's say that the exchange rate is1:1. - This gives
LTV = 95%. This will trigger liquidation.
Now, lets say that Liquidator_1 comes to partially liquidate half of the position.
While the position is being liquidated, the following code will trigger:
_leftoverCollateral = (_userCollateralBalance.toInt256() - _optimisticCollateralForLiquidator.toInt256());
_collateralForLiquidator = _leftoverCollateral <= 0 ? _userCollateralBalance : (_liquidationAmountInCollateralUnits * (LIQ_PRECISION + dirtyLiquidationFee)) / LIQ_PRECISION;
The _collateralForLiquidator will be set to $50 \times 1.054 = 52.7$.
So, the liquidator gets transferred the _userCollateralBalance of 52.7.
Which means the position has the following balances, $Asset = 100 - 50 = 50$, and $Collateral = 105.26 - 52.7 = 52.56$.
So, the person who liquidates the remaining position will see the following:
- They transfer in
50assets, and get52.56collateral back. - They were promised a
6%bonus when they agreed to liquidate, which should come out to53collateral. - Hence, they suffered a $6 - 5.12 = 0.88$% loss. (Note: $(52.56 - 50)/50 = 5.12$%)
Let's consider a similar situation with an even larger partial liquidation,
If the first person liquidated 90% of the position:
Liquidator_1: Asset: 90; Collateral: 94.86
What remains in the position is:
Asset: 10; Collateral: 5.14
This means either the final liquidator needs to suffer an incredible amount of loss or that the protocol will have to deal with the inevitable increase in insolvent loans that will never be liquidated because their collaterals are not enough.
Impact
The final liquidators of a position will have to suffer losses if they want to liquidate the position. Their loss will be higher than 0.1%, and may even reach 50% in certain situations.
PoC
No response
Mitigation
No response
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the fee calculation uses the dirty liquidation fee for partial liquidations but does not reserve enough collateral for the final liquidator, so the last liquidator receives only the remaining collateral, which may be less than the promised bonus.
Impact
The final liquidator could suffer a loss greater than 0.1% and up to 50%, which may cause insolvent loans to never be liquidated.
What the attacker needed
MaxLTV set so 100 - maxLTV ≤ liquidation fees; borrower's loan becomes insolvent; multiple partial liquidations occur
How it was found
- Set the pair's maxLTV such that 100 - maxLTV is less than or equal to the liquidation fees.
- A borrower takes out a loan and the loan becomes insolvent.
- A series of liquidators partially liquidate the position.
- The final liquidator receives less than the fair share of collateral.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a loan becomes unsafe, anyone can repay part of it and receive some of the borrower's collateral as a reward. This report shows that if several people repay parts of the loan, the last person gets a smaller reward than promised, sometimes even losing money. That makes people avoid finishing the job, so bad loans stay on the books.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.