OrderBook

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

Redundant code execution in status determination causing unnecessary gas consumption

Description:

The getOrderDetailsString() function contains redundant code logic that performs duplicate status calculations and assignments. The function first calculates the order status using a complex ternary operator, then immediately overwrites this result with a second if-else block that performs the same logic. This redundancy occurs because the second block always executes and completely determines the final status value, making the first calculation meaningless.

The problematic code structure executes two separate status determination operations:

  1. First block assigns status using ternary operators

  2. Second block immediately overwrites the status with if-else logic

In all execution paths, the second block either duplicates the first block's result or completely overwrites it, making the first block's computation wasteful.

Impact:

Every call to getOrderDetailsString() performs unnecessary string assignments and logical operations

The contract performs duplicate calculations that provide no value

While this doesn't pose a direct security risk, it represents inefficient code that increases operational costs for users calling the function and creates maintenance burdens for developers.

Recommended Mitigation:

  1. Remove the redundant first block and keep only the second block:

function getOrderDetailsString(uint256 _orderId) public view returns (string memory details) {
Order storage order = orders[_orderId];
if (order.seller == address(0)) revert OrderNotFound();
// ... token symbol logic ...
// Remove redundant first assignment, keep only this logic:
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";
}
// ... rest of function ...
}

These changes will reduce gas consumption, improve code clarity, and eliminate the potential for future development errors related to the redundant logic.

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.