15,000 USDC
View results
Submission Details
Severity: gas

Storing the storage array in memory

Summary

s_collateralTokens can be stored in memory in the getAccountCollateralValue function to save gas.

Details

In the DSCEngine contract in the getAccountCollateralValue function s_collateralTokens array can be stored in memory to save gas. The bigger the array is, the more expensive the for loop becomes.

Recommendations

Just add the storage array in memory and use that in the for loop.

address[] memory collateralTokens = s_collateralTokens;

Add this line above the for loop and use this collateralTokens array to perform operations on.

Support

FAQs

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