20,000 USDC
View results
Submission Details
Severity: gas
Valid

<array>.length should not be looked up in every loop of a for-loop

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<N> needed to store the stack offset

Support

FAQs

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