15,000 USDC
View results
Submission Details
Severity: gas

Inefficient loop in the constructor

Summary

Inefficient Loop Condition in the constructor: Loop condition i < tokenAddresses.length in the

constructor(address[] memory tokenAddresses, address[] memory priceFeedAddresses, address dscAddress) {

should use cached array length instead of referencing length member of the storage array (src/DSCEngine.sol#112).

Vulnerability Details

Array length, the code directly references the length member of the storage array tokenAddresses within the loop. This 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.

Impact

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.

Tools Used

Manually inspection

Recommendations

Cache the array length before entering the loop.

Support

FAQs

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