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

Fill order(Settlement) doesn't check whether order is still pending

Summary

When creating an order, there is a check done using the checkPendingOrderfunction. This check is to ensure that the order has existed for the minimum order lifetime.

https://github.com/Cyfrin/2024-07-zaros/blob/d687fe96bb7ace8652778797052a38763fbcbb1b/src/perpetuals/branches/OrderBranch.sol#L349

// OrderBranch.sol
function createMarketOrder(CreateMarketOrderParams calldata params) external {
...
// reverts if a trader has a pending order and that pending order hasn't
// existed for the minimum order lifetime
@> marketOrder.checkPendingOrder();
}
// MarketOrder.sol
function checkPendingOrder(Data storage self) internal view {
GlobalConfiguration.Data storage globalConfiguration = GlobalConfiguration.load();
uint128 marketOrderMinLifetime = globalConfiguration.marketOrderMinLifetime;
if (
self.timestamp != 0 && marketOrderMinLifetime != 0
&& block.timestamp - self.timestamp <= marketOrderMinLifetime
) {
revert Errors.MarketOrderStillPending(self.timestamp);
}
}

This prevents recently updated orders from entering the market. But there is no check for this when filling an order that was recently created.

The lack of this check results in the following vulnerability:

  • Recently created orders will enter the market without reaching the criteria for the marketOrderMinLifetimeonce their pass on the fillOrder.

Impact

  • Loss of Funds: recently created orders will change skew/OI and be filled before updated orders.

  • Unfairness: recently created orders can be filled before the checkPendingOrdervalidation.

Tools Used

Manual Review

Recommendations

Add the marketOrder.checkPendingOrder()for the _fillOrderfunction. This will ensure that all filled orders have met the minimum market order lifetime.

Updates

Lead Judging Commences

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

Appeal created

holydevoti0n Submitter
9 months ago
inallhonesty Lead Judge
9 months ago
inallhonesty Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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