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

Unrealized PnL is not considered for margin validation during settlements.

Summary

Unlike order and settlement fees, unrealized PnL is not considered for margin validation during settlements (SettlementBranch._fillOrder()). As a result, some orders that should not be settled will succeed, while some orders that should be settled will be reverted.

Vulnerability Details

During settlements, the resulting margin is checked, but only settlement and order fees are considered. Unrealized PnL is added or subtracted from the account's collateral later. Consequently, the margin validated after settlement is incorrect, as it does not include unrealized PnL. This leads to scenarios where:

  1. Increasing orders that should not be settled (because they would bring the account below the initial margin) will succeed.

  2. Orders that should be settled (because they would not bring the account below the initial margin) will revert.

Consider the following scenarios:

  1. Alice's current collateral is above the initial margin, but she has unrealized negative PnL that would bring her collateral below the initial margin. Since this unrealized PnL is not considered during the settlement margin validation, she can increase her position even though it would bring her below the initial margin after settlement.

  2. Alice's current collateral is below the initial margin, but she has unrealized positive PnL that would bring her collateral above the initial margin, even with an increasing order. However, since this positive unrealized PnL is not considered, her order will revert, even though her account would be above the initial margin after order settlement.

Impact

Some orders that should not be settled will be settled, leaving accounts below the initial margin. Conversely, other orders that should be settled will revert.

Tools Used

Manual Review.

Recommendations

Include unrealized PnL (both negative and positive) in margin validation, as is done for settlement and order fees.

Updates

Lead Judging Commences

inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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