OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: medium
Likelihood: high
Invalid

## OrderBook.sol ## [ Missing deadline check, cancelSellOrder() ]

Root + Impact

Description

The cancelSellOrder function does not enforce the documented behavior:

If the order isn't filled before the deadline, sellers can cancel and retrieve their tokens.

Currently, the function allows sellers to cancel their orders after the deadline has passed. However, based on the intended logic, cancellation should only be allowed before the deadline.

function cancelSellOrder(uint256 _orderId) public {
Order storage order = orders[_orderId];
// Validation checks
if (order.seller == address(0)) revert OrderNotFound();
if (order.seller != msg.sender) revert NotOrderSeller();
if (!order.isActive) revert OrderAlreadyInactive(); // Already inactive (filled or cancelled)
// Mark as inactive
order.isActive = false;
// Return locked tokens to the seller
IERC20(order.tokenToSell).safeTransfer(order.seller, order.amountToSell);
emit OrderCancelled(_orderId, order.seller);
}

Expected Behavior

  • Sellers should be allowed to cancel their orders before the deadline (if the order is still active).

  • After the deadline has passed, the seller should no longer be able to cancel the order.

    Risk

Likelihood:

  • This issue will occur every time a seller tries to cancel an expired order.

  • There's no restriction stopping them from doing so.

Impact:

  • Breaks time-based control over the order book.

  • Invalidates expiration logic, allowing orders to be removed outside their window.

  • Could lead to unfair behavior, where sellers pull out of committed offers even after the deadline has passed.

Proof of Concept

1: Seller creates an order with a 1-hour deadline.
2: Wait for the deadline to pass.
3: Seller calls cancelSellOrder(orderId) — it succeeds, even though the order has expired.

Recommended Mitigation

Add a condition to prevent cancellation after the deadline:

+ if (block.timestamp > order.deadlineTimestamp) revert OrderNotExpired();
Updates

Lead Judging Commences

yeahchibyke Lead Judge
about 1 month ago
yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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