DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: high
Invalid

`OrderBranch::simulateTrade()` is not taking into account the order and the settlement fee

Summary

When creating an order there is a check if a user is in liquidatable state and if it is true he should not be able to create an order and his position has to be liquidated. The problem is that fees are not accounted when checking for this which means that there will be scenarios where the trader can't cover the fees for the new order but he will still be able to create one and he will then be put in liquidatable state, but when he gets liquidated his margin will not be able to cover everything so the rest will be just taken from the protocol.

Vulnerability Detailss

When creating an order there is a check in the simulateTrade() function if the position of the trader is liquidatable and if it is you should not be able to create this order.

This is the check:

function simulateTrade(
uint128 tradingAccountId,
uint128 marketId,
uint128 settlementConfigurationId,
int128 sizeDelta
)
public
view
returns (
SD59x18 marginBalanceUsdX18,
UD60x18 requiredInitialMarginUsdX18,
UD60x18 requiredMaintenanceMarginUsdX18,
UD60x18 orderFeeUsdX18,
UD60x18 settlementFeeUsdX18,
UD60x18 fillPriceX18
)
{
...
if (TradingAccount.isLiquidatable(ctx.previousRequiredMaintenanceMarginUsdX18, marginBalanceUsdX18)) {
revert Errors.AccountIsLiquidatable(tradingAccountId);
}
...
}

The problem here is that we are not taking into account the order and the settlement fee when checking this. If the user has no collateral to cover this fees this means that his position is in liquidatable state and he should not be able to create this order. In the current implementation if the user manages to open a position where he could not cover the fees and he gets liquidated the fees will be paid by the protocol because it holds the funds of all the users

Impacts

Impact is high because this leads to loss of funds to the protocol. The protocol holds all the collateral from all traders, so the fee will be paid but not by the trader's collateral but from someone else.

Tools Used

Manual review

Recommendations

Add the settlement and the order fee when checking if the user is liquidatable in the simulateTrade()

Updates

Lead Judging Commences

inallhonesty Lead Judge
11 months ago
inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.