15,000 USDC
View results
Submission Details
Severity: gas

`<array>.length` Should Not Be Looked Up In Every Loop Of A `For`-loop

Summary

Vulnerability Details

The overheads outlined below are PER LOOP, excluding the first loop

  • storage arrays incur a Gwarmaccess (100 gas)

  • memory arrays use MLOAD (3 gas)

  • calldata arrays use CALLDATALOAD (3 gas)
    Caching the length changes each of these to a DUP<N> (3 gas), and gets rid of the extra DUP needed to store the stack offset

Impact

Gas Consumption

Tools Used

Recommendations

Support

FAQs

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