This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
roguereddwarf - BaseVault: liquidationSurcharge amount is too high if collateralToLiquidate gets capped #89
Labels
Duplicate
A valid issue that is a duplicate of an issue with `Has Duplicates` label
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
roguereddwarf
medium
BaseVault: liquidationSurcharge amount is too high if collateralToLiquidate gets capped
Summary
According to the comment explaining the
LIQUIDATION_SURCHARGE
percentage, it should be a percentage of the liquidated amount:Link
So if say $100 of collateral is liquidated, the surcharge should be $2. I will show how this is not true in some cases. I.e. the surcharge may be higher (even a lot higher).
I had a discussion about this with the sponsor and it was assessed that this is unintended behavior. The liquidation surcharge percentage breaks in the case that I will show.
Vulnerability Detail
Let's have a look at how the liquidation surcharge is calculated:
Link
The
collateralToLiquidate
is calculated by multiplyingcollateralToLiquidateWithoutDiscount
bytotalLiquidationDiscount
.And then it is capped at
_accountCollateral
. The cap is necessary because it is not possible to remove more collateral from the loan than there is left.As part of the return statement, the
liquidationSurcharge
return value is calculated as(collateralToLiquidateWithoutDiscount * LIQUIDATION_SURCHARGE) / Constants.PRECISION
.It becomes clear that this can result in a higher liquidation surcharge than expected:
Let
collateralToLiquidateWithoutDiscount=$100
,totalLiquidationDiscount=120%
(20% percent discount on the collateral).Then
collateralToLiquidate=$100*120%=$120
andliquidationSurcharge=$100*2%=$2
.If however the
collateralToLiquidate
gets capped at say $50, thenliquidationSurcharge
is still calculated in the same way.But the surcharge percentage would actually be
$2/$50=4%
instead of the expected 2%.Impact
The
liquidationSurcharge
that is charged to the liquidator by subtracting it from the collateral he receives may not be the 2% that it is supposed to. This means that the liquidator needs to pay a higher liquidation fee in some cases and ends up with less profit.Code Snippet
https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/Vault/BaseVault.sol#L396-L422
https://github.com/sherlock-audit/2023-03-taurus/blob/main/taurus-contracts/contracts/Vault/BaseVault.sol#L432-L445
Tool used
Manual Review
Recommendation
It is not obvious how this issue can be fixed because the surcharge percentage is not well defined for when
collateralToLiquidate > _accountCollateral
and thecollateralToLiquidate
is capped.After all if this is the case then what should
collateralToLiquidateWithoutDiscount
be?Should the amount by which
collateralToLiquidate
is reduced due to the cap be taken from the discount or fromcollateralToLiquidate
AND the discount.In other words it is not clear what value to use to calculate the liquidation surcharge.
This has been discussed with the sponsor and they should look into different ways to modify the calculation by first firmly establishing how the liquidation surcharge is intended to behave.
Duplicate of #61
The text was updated successfully, but these errors were encountered: