15,000 USDC
View results
Submission Details
Severity: gas

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

Summary

[G-18] .length should not be looked up in every loop of a for-loop

Caching the length changes each of these to a DUP (3 gas), and gets rid of the extra DUP needed to store the stack offset.

file: /src/DSCEngine.sol

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L353

file: /src/DSCEngine.sol
118 for (uint256 i = 0; i < tokenAddresses.length; i++) {

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/main/src/DSCEngine.sol#L118

Support

FAQs

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