DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: low
Valid

New positions may be able to be liquidated immediately

Summary

tradingAccount.validateMarginRequirement()is not check at the end of _fillOrder, some positions may get liquidated immediately after settlement.

Vulnerability Details

SettlementBranch.sol

(
UD60x18 requiredInitialMarginUsdX18,
UD60x18 requiredMaintenanceMarginUsdX18,
SD59x18 accountTotalUnrealizedPnlUsdX18
) = tradingAccount.getAccountMarginRequirementUsdAndUnrealizedPnlUsd(marketId, sizeDeltaX18);

Inside `tradingAccount.getAccountMarginRequirementUsdAndUnrealizedPnlUsd()`, Chainlink feed is used to calculate PnL, but actually PnL is claculated with Chainlink stream price:

ctx.pnlUsdX18 =
oldPosition.getUnrealizedPnl(fillPriceX18).add(oldPosition.getAccruedFunding(ctx.fundingFeePerUnitX18));

The difference between the two is enough to make a difference in the user's actual margin after settlement, and the new value may subject to liquidation.

Impact

Some positions may get liquidated immediately after settlement.

Tools Used

VS code

Recommendations

check maintaince margin at the end of execution.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

`isLiquidatable` check missing in `_fillOrder()`

Support

FAQs

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