You can cache array lengths used in for loops
The for loops in the contracts do not cache the array lengths but reread them from storage everytime.
This implies every iteration the length of array is read from storage which increases gas costs rather than a cached value that is read from memory
Gas Savings: Rereading a value form storage incurs 100 gas wheres from memory 3 gas. These costs add up as in each iteration 100 gas for storage is used up to reread array length that could have just been read once and cached in memory.
Manual Analysis
DSCEngine.sol line 118 loop for length part can be rewritten as (Not that key as read from memory)
uint256 _len = tokenAddresses.length
for (uint256 i = 0; i < _len;) {....etc
DSCEngine.sol line 118 loop for length part can be rewritten as (This save as lot of gas as read from storage)
uint256 _len = s_collateralTokens.length
for (uint256 i = 0; i < _len;) {....etc
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.