OrderBook

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

Redundant id field in Order struct causing unnecessary gas consumption

Description:

The OrderBook contract contains a redundant id field in the Order struct that duplicates information already available as the mapping key. The field is set during order creation but serves no functional purpose, as the order ID is already accessible through the orders mapping key and function parameters.

The redundant field appears in the struct definition:

struct Order {
uint256 id; // ← Redundant field
address seller;
address tokenToSell;
// ... other fields
}

The field is populated during order creation but only used once in the getOrderDetailsString() function, where it could easily be replaced with the _orderId parameter that's already available.

Impact:

Each order creation consumes an additional ~20,000 gas for the unnecessary SSTORE operation

Each order consumes an extra 32 bytes of contract storage

Maintains duplicate data that serves no functional purpose

With frequent order creation, these gas costs accumulate significantly, making the protocol less cost-efficient for users.

Recommended Mitigation:

  1. Remove the id field from the Order struct:

struct Order {
// uint256 id; ← Remove this field
address seller;
address tokenToSell;
uint256 amountToSell;
uint256 priceInUSDC;
uint256 deadlineTimestamp;
bool isActive;
}
  1. Update the getOrderDetailsString() function to use the parameter instead:

details = string(
abi.encodePacked(
"Order ID: ",
_orderId.toString(), // ← Use parameter instead of order.id
"\n",
// ... rest of the string
)
);
  1. Remove the id assignment from order creation in createSellOrder().

Updates

Lead Judging Commences

yeahchibyke Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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