Market::_computeClosingFactor wrong collateralization calculation can cause liquidatee solvency to become worse
Summary
During a market liquidation, a closing factor is computed to ensure that enough of a liquidatee position is closed to make the liquidatee solvent again. However due to a wrong variable used in the calculation, the closing factor is wrongly computed and can lead to the solvency of a liquidatee to become worse after liquidation.
Vulnerability Detail
Let's follow along the calculations made in the function _computeClosingFactor, and see how they impact repaid borrow amount and seized collateral.
For the account to be solvent after liquidation, we want DNew < 0.8 Cnew:
Dnew < 0.8 Cnew
Cold*0.8 - 5.25X < (Cold - 6.87X) * 0.8
Cold - 6.56 X < Cold - 6.87 X
Which is impossible if X > 0
Impact
A position can not be fully liquidated, because closing factor is not big enough. This will leave unhealthy positions unliquidated and cause bad debt to the protocol
Code Snippet
Tool used
Manual Review
Recommendation
Replace collateralizationFactor by _liquidationCollateralizationFactor when computing diff:
cergyk
high
Market::_computeClosingFactor wrong collateralization calculation can cause liquidatee solvency to become worse
Summary
During a market liquidation, a closing factor is computed to ensure that enough of a liquidatee position is closed to make the liquidatee solvent again. However due to a wrong variable used in the calculation, the closing factor is wrongly computed and can lead to the solvency of a liquidatee to become worse after liquidation.
Vulnerability Detail
Let's follow along the calculations made in the function _computeClosingFactor, and see how they impact repaid borrow amount and seized collateral.
First let's eval diff:
This gives x (repayable borrow):
Before liquidation:
let's define X such as:
After liquidation:
For the account to be solvent after liquidation, we want
DNew < 0.8 Cnew
:Impact
A position can not be fully liquidated, because closing factor is not big enough. This will leave unhealthy positions unliquidated and cause bad debt to the protocol
Code Snippet
Tool used
Manual Review
Recommendation
Replace
collateralizationFactor
by_liquidationCollateralizationFactor
when computingdiff
:Duplicate of #53