The amount of debt removed during liquidation
may be worth more than the account's collateral
#1620
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-03
primary issue
Highest quality submission among a set of duplicates
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/2286f80f928f41c8bc189d0657d74ba83286c668/contracts/markets/bigBang/BigBang.sol#L822
Vulnerability details
Impact
The contract decreases user's debts but may not take the full worth in collateral from the user, leading to the contract losing potential funds from the missing collateral.
Proof of concept
During the
liquidate()
function call, the function_updateBorrowAndCollateralShare()
is eventually invoked. This function liquidates a user's debt and collateral based on the value of the collateral they own.In particular, the equivalent amount of debt,
availableBorrowPart
is calculated from the user's collateral on line 225 through thecomputeClosingFactor()
function call.Then, an additional fee through the
liquidationBonusAmount
is applied to the debt, which is then compared to the user's debt on line 240. The minimum of the two is assignedborrowPart
, which intuitively means the maximum amount of debt that can be removed from the user's debt.borrowPart
is then increased by a bonus throughliquidationMultiplier
, and then converted to generatecollateralShare
, which represents the amount of collateral equivalent in value toborrowPart
(plus some fees and bonus).This new
collateralShare
may be more than the collateral that the user owns. In that case, thecollateralShare
is simply decreased to the user's collateral.collateralShare
is then removed from the user's collateral.The problem lies in that although the
collateralShare
is equivalent to theborrowPart
, or the debt removed from the user's account, it could be worth more than the collateral that the user owns in the first place. Hence, the contract loses out on funds, as debt is removed for less than it is actually worth.To demonstrate, we provide a runnable POC.
Preconditions
Add the
require
statement to line 261. This require statement essentially reverts the contract when theif
condition satisfies. Theif
condition holds true when thecollateralShare
is greater that the user's collateral, which is the target bug.Once the changes have been made, add the following test into the
singularity.test.ts
test intapioca-bar-audit/test
Code
Expected Result
As demonstrated, the function call reverts due to the
require
statement added in the preconditions.Recommended Mitigation
One potential mitigation for this issue would be to calculate the
borrowPart
depending on the existing users' collateral factoring in the fees and bonuses. ThecollateralShare
with the fees and bonuses should not exceed the user's collateral.Assessed type
Math
The text was updated successfully, but these errors were encountered: