15,000 USDC
View results
Submission Details
Severity: gas

Continous recall of Array length in loop uses excess gas

Summary

Continous recall of Array length in loop uses excess gas

Vulnerability Details

from L118 & L353 of DSCEngine.sol contract, continuously recalling the Array length uses excess gas due to the more computational calculation needed

118. for (uint256 i = 0; i < tokenAddresses.length; i++) {
...
353. for (uint256 i = 0; i < s_collateralTokens.length; i++) {
...

Tools Used

solidity

Recommendations

Assign a variable to the Array length once then using the variable in the loop

++ uint tokenAddressesLength = tokenAddresses.length;
118. for (uint256 i = 0; i < tokenAddressesLength; i++) {
...
+++ uint s_collateralTokensLength = s_collateralTokens.length;
353. for (uint256 i = 0; i < s_collateralTokensLength; i++) {
...

Support

FAQs

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