Skip to content

Latest commit

 

History

History
78 lines (52 loc) · 3.04 KB

File metadata and controls

78 lines (52 loc) · 3.04 KB

Fast Khaki Raccoon

Medium

Liquidators won't always liquidate positions

Summary

Liquidators will sometimes get unprofitable liquidations due to the way protocol fee is taken, this will lower liquidations and push the system into reaching bad debt more easily.

Fees are taken from liquidator's collateral, which would decrease it's earning and may even make liquidations unprofitable in some cases.

The code snippet bellow shows how we: https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/fraxlend/src/contracts/FraxlendPairCore.sol#L1132-L1157

            // get liquidator's liquidating assets
            uint256 _liquidationAmountInCollateralUnits =
                ((_totalBorrow.toAmount(_sharesToLiquidate, false) * _exchangeRate) / EXCHANGE_PRECISION);

            // calculate the fee he would get for executing the task
            uint256 _optimisticCollateralForLiquidator =
                (_liquidationAmountInCollateralUnits * (LIQ_PRECISION + cleanLiquidationFee)) / LIQ_PRECISION;

             // get leftover and make sure we aren't getting more collateral than the user has
            _leftoverCollateral = (_userCollateralBalance.toInt256() - _optimisticCollateralForLiquidator.toInt256());

            _collateralForLiquidator = _leftoverCollateral <= 0
                ? _userCollateralBalance
                : (_liquidationAmountInCollateralUnits * (LIQ_PRECISION + dirtyLiquidationFee)) / LIQ_PRECISION;

            // calculate the protocol fee from liquidator's final amount
            if (protocolLiquidationFee > 0) {
                _feesAmount = (protocolLiquidationFee * _collateralForLiquidator) / LIQ_PRECISION;
                _collateralForLiquidator = _collateralForLiquidator - _feesAmount;
            }

However since we are taking the fee from the liquidator's final amount that protocol fee is applied on a bigger value (coll + liquidator fee), thus having more impact and being proportionally bigger.

Root Cause

Taking the fee from the liquidator's final amount

https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/fraxlend/src/contracts/FraxlendPairCore.sol#L1149-L1151

            if (protocolLiquidationFee > 0) {
                _feesAmount = (protocolLiquidationFee * _collateralForLiquidator) / LIQ_PRECISION;
                _collateralForLiquidator = _collateralForLiquidator - _feesAmount;
            }

Internal Pre-conditions

No response

External Pre-conditions

No response

Attack Path

  1. Protocol and liquidator fees are 10% each
  2. Liquidator liquidates 10k worth of assets
  3. We math out his _collateralForLiquidator to be worth 11k
  4. Fees would be 11k * 10% -> 1.1k
  5. Final _collateralForLiquidator would be 9.9k making the liquidation bad for the liquidator

Impact

Liquidators will sometimes get unprofitable liquidations due to the way protocol fee is taken, this will lower liquidations and push the system into reaching bad debt more easily.

PoC

No response

Mitigation

Take the fee from the amount before the increase.