In GlobalConfigurationBranch
, function removeCollateralFromLiquidationPriority
is due to removing collateral from collateralLiquidationPriority
array. Even if protocol doesn't have any bad intention by removing collateral from collateralLiquidationPriority
array, there can following cases where protocol team needs to remove collateral from collateralLiquidationPriority
array:
1) Protocol team needs to add new collateral
and it's position in collateralLiquidationPriority
array is not at last element
2) Protocol team needs to change the order of elements of collateralLiquidationPriority
array
In above two cases, protocol team will need to momentarily remove collateral
from collateralLiquidationPriority
array and vulnerabilities that can occur due to this is explained below:
When collateral
is excluded from thecollateralLiquidationPriority
array, it won't be sold off to cover the trader's debts during a liquidation event. However, the collateral value is still considered in calculating account margin. Due to this, when an account is going to be liquidated, the loss to be recovered by calling deductMargin
will not consider the collateral
which is removed. But the calculation of margin of protocol was also including the collateral removed. This means that even if a trader's position is liquidated, the full amount owed might not be recovered because some collateral is off-limits. This can lead to significant losses for the protocol and its participants, as the protocol might need to cover the shortfall. Also, the positions which are near to be liquidated can't add the collateral to the margin if it's removed temporarily for changing order of collateralLiquidationPriority
array.
Related code snippets:
Only considers thecollateralLiquidationPriority
array while margin deduction https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/leaves/TradingAccount.sol#L505-L508
Considering all the deposited collateral in calculation of marginhttps://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/leaves/TradingAccount.sol#L178C55-L181
function. to remove collateral from collateralLiquidationPriority
array https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/leaves/GlobalConfiguration.sol#L119
If a trader's position is liquidated, the full amount owed might not be recovered because some collateral is off-limits. This can lead to significant losses for the protocol and its participants, as the protocol might need to cover the shortfall.
Manual review
If the protocol team has plan to remove the collateral once it has been enabled previously, then margin
calculation should only take into consideration the collateral which can be liquidated
If the protocol team doesn't have plan to remove the collateral but only need to do that in case of updating collateralLiquidationPriority
array, then the method should be added to ensure that every addition and removal is done in one go without affecting other positions.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.