OrderBook

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

Expired Orders Can Be Resurrected and Manipulated via amendSellOrder

Root + Impact

Normal behavior And Vulnerability:

  • The system is expected to enforce strict expiry logic — once an order's deadlineTimestamp passes, it should be irreversibly expired and unusable.

  • The amendSellOrder() function contains a check
    if (block.timestamp >= order.deadlineTimestamp) revert OrderExpired();
    However, the isActive flag is never updated when a deadline is passed. This means expired orders remain "active" in storage and can be reactivated through amendment.

function amendSellOrder(...) public {
...
@> if (block.timestamp >= order.deadlineTimestamp) revert OrderExpired();
...
}

DESCRIPTION

Normally, once an order's deadlineTimestamp has passed, it is considered expired and should no longer be modifiable or fillable. However, the current logic does not update the isActive flag or cleanly enforce expiration.

This creates a dangerous loophole: expired orders remain "active" and can be amended with new deadlines and prices — effectively resurrecting stale orders, undermining the trust and predictability of time-based expiry.


Risk

Likelihood:

  • Common: Sellers may unknowingly (or maliciously) revive old orders that users assumed expired.

  • Easy to exploit: Sellers simply call amendSellOrder with a new deadline.

Impact:

  • Buyers may fill stale orders with outdated terms.

  • Undermines integrity of the on-chain deadline mechanism.

  • Possible regulatory or compliance concern in high-value DeFi use.

Proof of Concept


Explanation: No persistent state tracks that the deadline passed; the order remains amendable forever unless explicitly cancelled or filled.

// Assume seller creates an order with 60s deadline
orderBook.createSellOrder(token, 1000e18, 100e6, 60);
// Wait 61 seconds...
vm.warp(block.timestamp + 61);
// Now amend the expired order — this should fail, but it succeeds
orderBook.amendSellOrder(orderId, 1000e18, 105e6, 180); // ⛔️ No expiration enforcement

Recommended Mitigation

Enforce strict expiry rules by marking expired orders as inactive across the board. Suggested fix in buyOrder and other flows:


And similarly update getOrderDetailsString, amendSellOrder, and other views to ensure consistent isActive logic.

function buyOrder(...) {
- if (block.timestamp >= order.deadlineTimestamp) revert OrderExpired();
+ if (block.timestamp >= order.deadlineTimestamp) {
+ order.isActive = false;
+ revert OrderExpired();
+ }
}
Updates

Lead Judging Commences

yeahchibyke Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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