15,000 USDC
View results
Submission Details
Severity: gas

Variables does not need to be initialized to its default value

Summary

Initializing variables to their default value cost more gas than not initializing them.

Vulnerability Details

Explicitly initializing a variable to its default value costs more gas than uninitializing it. For example, uint256 i can be used instead of uint256 i = 0 in the following code:

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/d1c5501aa79320ca0aeaa73f47f0dbc88c7b77e2/src/DSCEngine.sol#L118

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

https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/blob/d1c5501aa79320ca0aeaa73f47f0dbc88c7b77e2/src/DSCEngine.sol#L353

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

Impact

Not initializing variables to their default value saves gas.

Tools Used

Manual review and VS Code

Recommendations

Do not initialize variables to their default value.

Support

FAQs

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