OrderBook

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

Inefficient Gas Usage that break the readme statement of maintaining a secure and gas-efficient architecture

Root + Impact

Description

  • The `getOrderDetailsString()` function in the OrderBook contract contains logically redundant code for computing the status of the order, resulting in unnecessary gas usage during view calls. This broke the readme statement of maintaining a "gas-efficient architecture".

The function assigns a value to the status variable using a ternary operator :

string memory status = order.isActive
? (block.timestamp < order.deadlineTimestamp ? "Active" : "Expired (Active but past deadline)")
: "Inactive (Filled/Cancelled)";

However, this value is immediately overwritten by the following if-else block :

if (order.isActive && block.timestamp >= order.deadlineTimestamp) {
status = "Expired (Awaiting Cancellation)";
} else if (!order.isActive) {
status = "Inactive (Filled/Cancelled)";
} else {
status = "Active";
}

As a result, the initial ternary assignment serves no purpose and introduces unnecessary operations.


Risk

Impact:

  • Increased bytecode size: Redundant logic increases contract complexity and deployment size.

  • Unnecessary gas consumption: Although this is a view function, excessive logic may still incur higher execution cost during off-chain calls.

  • Reduced maintainability: The code is harder to read and reason about, increasing the risk of errors in future updates.

  • Misleading claim: The README states that the architecture is "gas-efficient", which is not fully accurate given this inefficiency.

Proof of Concept

Recommended Mitigation

Delete the redundant logic to use only a single conditional block

- string memory status = order.isActive
- ? (block.timestamp < order.deadlineTimestamp ? "Active" : "Expired (Active but past deadline)")
- : "Inactive (Filled/Cancelled)";
+ string memory status;
if (order.isActive && block.timestamp >= order.deadlineTimestamp) {
status = "Expired (Awaiting Cancellation)";
} else if (!order.isActive) {
status = "Inactive (Filled/Cancelled)";
} else {
status = "Active";
}
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.