OrderBook

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

Inefficient storage access in getOrderDetailsString

Root + Impact

Description

  • The getOrderDetailsString function is designed as a view function that only reads order data to format and return order details without modifying any state.

  • The function uses a storage reference to access order data instead of copying it to memory, resulting in higher gas costs for each field access and potential risks if the function is later modified to be non-view.

@> Order storage order = orders[_orderId];

Risk

Likelihood:

  • This inefficiency occurs every time getOrderDetailsString is called, affecting all users querying order details

  • The gas overhead accumulates with each field access throughout the function execution

Impact:

  • Unnecessary gas consumption due to repeated storage reads instead of single memory copy

  • Potential security risk if the view modifier is accidentally removed in future modifications

  • Performance degradation from inefficient memory access patterns

  • Higher transaction costs for users calling the function

Proof of Concept

This analysis shows how using storage reference creates unnecessary gas overhead for read-only operations:

// Current inefficient approach
Order storage order = orders[_orderId];
// Each field access (order.isActive, order.deadlineTimestamp, etc.)
// requires a separate storage read operation (SLOAD)
// More efficient approach would be:
Order memory order = orders[_orderId];
// Single storage read to copy entire struct to memory,
// then all field accesses use cheaper memory operations (MLOAD)

Recommended Mitigation

Change the storage reference to memory to optimize gas usage for read-only operations:

- Order storage order = orders[_orderId];
+ Order memory order = orders[_orderId];
Updates

Lead Judging Commences

yeahchibyke Lead Judge about 2 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.