DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: low
Invalid

Gas Optimisation

Summary

  1. AN ARRAY’S LENGTH SHOULD BE CACHED TO SAVE GAS IN FOR-LOOPS
    Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
    Caching the array length in the stack saves around 3 gas per iteration.

  2. ++i costs less than i++
    ++i costs less gas compared to i++ for unsigned integer, as pre-increment is cheaper (about 5 gas per iteration) i++ increments i and returns the initial value of i .

Impact

More Gas will be used otherwise. for chains like ETH, it can be upto 1$ worth of GAS

Tools Used

Manual Review

Recommendations

  1. Caching the array length in the stack.

  2. use ++i instead of i++

Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational/Gas

Invalid as per docs https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity

Support

FAQs

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