Inefficient Loop Condition: Loop condition i < s_collateralTokens.length
in the getAccountCollateralValue function (src/DSCEngine.sol#355) should use cached array length instead of referencing length
member of the storage array.
The vulnerability lies in the loop condition i < s_collateralTokens.length in the for loop. Instead of using the cached array length, the code directly references the length member of the storage array s_collateralTokens within the loop. This can result in additional gas costs as the loop's length is checked for every iteration, which can be especially expensive if the array is large.
The impact of this vulnerability is mainly increased gas costs during contract execution. By not caching the array length before the loop, the contract will perform an SLOAD operation to fetch the array's length from storage at each iteration of the loop. This can result in unnecessary and avoidable gas expenses, making the contract less efficient and potentially costly for users.
Slither - static analysis framework.
Cache the array length before entering the loop.
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.