Partial liquidations and price changes can block liquidations
Closed this issue · 0 comments
Lines of code
Vulnerability details
The liquidatePosition() function in the CDPVault contract allows for partial liquidations of positions. However, the current implementation can lead to a situation where partial liquidations block subsequent liquidation attempts, potentially resulting in positions remaining undercollateralized for longer periods than necessary.
The liquidatePosition() function calculates the amount of collateral to take based on the repayment amount provided by the liquidator:
uint256 takeCollateral = wdiv(repayAmount, discountedPrice);
if (takeCollateral > position.collateral) revert CDPVault__tooHighRepayAmount();This check ensures that the liquidator cannot take more collateral than available in the position. However, it also means that if a partial liquidation occurs, leaving some collateral in the position, subsequent liquidation attempts might fail if they try to liquidate the entire remaining position.
Impact
- Inefficient liquidation process: Positions may remain undercollateralized for longer periods, increasing the risk of bad debt accumulation.
- Potential for manipulation: Malicious actors could perform small partial liquidations to block larger liquidations. This could be attempted by the owner.
Proof of Concept
- Alice's position has 100 units of collateral and 150 units of debt.
- The position becomes undercollateralized due to price fluctuations.
- Bob attempts to liquidate the position, but only repays 50 units of debt, taking 33.33 units of collateral (assuming a liquidation discount).
- Charlie attempts to liquidate the remaining position by repaying 100 units of debt.
- Charlie's transaction reverts due to the
CDPVault__tooHighRepayAmount()error, as the calculatedtakeCollateralwould be greater than the remaining position collateral.
It is also possible that a decrease in price blocks a liquidations for the same reason. This does not makes sense since the liquidator is getting a better deal than expected. The below mitigation can solve these issues.
Tools Used
Manual review
Recommended Mitigation Steps
To address this issue, consider implementing a more flexible liquidation mechanism that allows liquidators to specify both a minimum and maximum repayment amount and a maxPrice. This approach would enable more efficient liquidations and prevent partial liquidations and changes in price from blocking liquidations.
Assessed type
Other