You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Liquidation is not possible in certain conditions with eMode
Summary
Liquidation is not possible in certain conditions with eMode. If the HF value is lower than specific point in eMode usage. eMode allows user to borrow more amount of funds with high LTV and high liquidation threshold.
Mathematically, there is a strong relation between $LT * Bonus$ and HF.
We can say that if following condition meets the bad debt is already created:
All the numbers are in base currency
$$Debt * Bonus > Collateral$$
We can also define HF as:
$$(LT * Collateral) / Debt = HF$$
Then:
$$Bonus > Collateral / Debt$$
$$HF / LT = Collateral / Debt$$
$$Bonus > HF / LT$$
$$Bonus * LT > HF$$
In conclusion if $Bonus * LT > HF$ the bad debt is already created
Currently, live Aave configuration is using 0.95 LT and 1.01 Bonus. $0.95 * 1.01 = 0.9595$. We also know that positions can be liquidated up to 50% if the HF is between 0.95 and 1 level. Therefore, we can say that bad debt will occur if HF is between 0.95 and 0.9595 and it can only liquidate up to 50% of the debt.
This is not a big problem because after liquidation the debt will decrease significantly and after reaching below to 2000e8 ( MIN_BASE ) point, we can fully liquidate the position.
But this is not possible in certain cases because bad debt may lower the collateral amount below MIN_LEFTOVER point and it may revert.
// to prevent accumulation of dust on the protocol, it is enforced that you either// 1. liquidate all debt// 2. liquidate all collateral// 3. leave more than MIN_LEFTOVER_BASE of collateral & debtif (
vars.actualDebtToLiquidate < vars.userReserveDebt &&
vars.actualCollateralToLiquidate + vars.liquidationProtocolFeeAmount <
vars.userCollateralBalance
) {
bool isDebtMoreThanLeftoverThreshold = ((vars.userReserveDebt - vars.actualDebtToLiquidate) *
vars.debtAssetPrice) /
vars.debtAssetUnit >=
MIN_LEFTOVER_BASE;
bool isCollateralMoreThanLeftoverThreshold = ((vars.userCollateralBalance -
vars.actualCollateralToLiquidate -
vars.liquidationProtocolFeeAmount) * vars.collateralAssetPrice) /
vars.collateralAssetUnit >=
MIN_LEFTOVER_BASE;
}
Internal Pre-conditions
$$HF < LT * Bonus$$
External Pre-conditions
No response
Attack Path
At mentioned point liquidation won't be possible
Liquidators should wait until HF goes down below 0.95 level or HF should be increased by the borrower
Of course second one is not an option here, waiting for HF will cause loss of funds because it will create more deficit
Impact
Liquidation is not possible in mentioned situation, liquidation call will revert due to bad debt. It creates DoS attack vector in time-sensitive function. It may cause loss of funds in the end.
PoC
Following PoC fuzz test will find an edgecase scenario which cause revert due to error 103 ( MUST_NOT_LEAVE_DUST ):
Add this test to Pool.Liquidations.CloseFactor.t.sol file
Add following lines to LiquidationLogic.sol for logging ( also import forge-std/console2 ):
Macho Tartan Finch
Medium
Liquidation is not possible in certain conditions with eMode
Summary
Liquidation is not possible in certain conditions with eMode. If the HF value is lower than specific point in eMode usage. eMode allows user to borrow more amount of funds with high LTV and high liquidation threshold.
For instance currently, 0.95 LT and 1.01 Liquidation Bonus is used in Aave live eMode configuration.
Root Cause
Mathematically, there is a strong relation between$LT * Bonus$ and HF.
We can say that if following condition meets the bad debt is already created:
We can also define HF as:
Then:
In conclusion if$Bonus * LT > HF$ the bad debt is already created
Currently, live Aave configuration is using 0.95 LT and 1.01 Bonus.$0.95 * 1.01 = 0.9595$ . We also know that positions can be liquidated up to 50% if the HF is between 0.95 and 1 level. Therefore, we can say that bad debt will occur if HF is between 0.95 and 0.9595 and it can only liquidate up to 50% of the debt.
This is not a big problem because after liquidation the debt will decrease significantly and after reaching below to 2000e8 ( MIN_BASE ) point, we can fully liquidate the position.
But this is not possible in certain cases because bad debt may lower the collateral amount below MIN_LEFTOVER point and it may revert.
Reference1
Reference2
Internal Pre-conditions
External Pre-conditions
No response
Attack Path
Impact
Liquidation is not possible in mentioned situation, liquidation call will revert due to bad debt. It creates DoS attack vector in time-sensitive function. It may cause loss of funds in the end.
PoC
Following PoC fuzz test will find an edgecase scenario which cause revert due to error 103 ( MUST_NOT_LEAVE_DUST ):
Add this test to Pool.Liquidations.CloseFactor.t.sol file
Add following lines to LiquidationLogic.sol for logging ( also import forge-std/console2 ):
Also change the configuration of USDX in reserve for eMode configuration ( in AaveV3TestListing.sol file) :
Command :
forge test --match-test test_fuzz_wrong_state -vv
Output:
Mitigation
Reduce LT * Bonus below to 0.95 level or implement another logic which increase the close factor to 100% in guaranteed bad debt scenarios.
The text was updated successfully, but these errors were encountered: