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

Cache array length outside of loop

Summary

Cache array length outside of loop

Vulnerability Details

If not cached, the solidity compiler will always read the length of the array during each iteration. 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.

File: src/Lender.sol
280: loans.length - 1,

Link to code - https://github.com/Cyfrin/2023-07-beedle/tree/main/src/Lender.sol

Tools Used

Manual Code Review by SolSaver

Recommendations

Cache array length outside of loop

Support

FAQs

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