Gas inefficiency due to uncached storage array length
The DSCEngine.sol:353
contains the getAccountCollateralValue
function, which calculates the total collateral value in USD for a specific user. However, the function uses a for loop to iterate over the s_collateralTokens
storage array and references s_collateralTokens.length
in each iteration. This inefficient practice leads to unnecessary storage reads, resulting in increased gas costs.
Vulnerable Code Snippet:
The inefficient use of the s_collateralTokens.length
member in the for loop can lead to higher gas costs for contract users.
Manual Review
Cache the length of the s_collateralTokens
storage array in a local variable before entering the for loop. Since the array length remains unchanged within the loop, this optimization will decrease the number of storage reads and significantly improve the contract's gas efficiency.
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.