Submitted by KIntern_NA, also found by carrotsmuggler and 0xRobocop
Incorrect amount of assets that will be liquidated
Function BigBang._liquidateUser() is used to liquidate an under-collateralization position in the market. This function calls BigBang._updateBorrowAndCollateralShare() to calculate the amount of borrowPart and collateralShare that will be removed from the users position and update the storage.
The amount of borrowPart to be removed can be calculated using the function Market.computeClosingFactor(). This amount will then be converted to borrowAmount, which is the corresponding elastic amount, and be used to determine the amount of collateralShare that needs to be removed.
However, the returned value from Market.computeClosingFactor() is incorrect, which leads to the wrong update for the users position.
To prove the statement above, lets denote:
Following the update of these variables depicted in the function BigBang._updateBorrowAndCollateralShare(), we have:
After the liquidation, the function Market._isSolvent(user) must return true. In other words, at least the following equation should hold:
Solving the equation, we get:
So, the returned value of the function Market.computeClosingFactor() should be the corresponding base amount of x (totalBorrow.toBase(x, false)).
Comparing it to the current implementation of computeClosingFactor(), we can see the issues are:
Correct the formula of function computeClosingFactor() following the section Proof of Concept.
cryptotechmaker (Tapioca) confirmed
