15,000 USDC
View results
Submission Details
Severity: gas
Valid

`++i/i++` should be `unchecked{++i}/unchecked{i++}` when it is not possible for them to overflow, as is the case when used in for and while loops

Summary

Use unchecked where possible

Vulnerability Details

++i/i++ should be unchecked{++i}/unchecked{i++} when it is not possible for them to overflow, as is the case when used in for and while loops.

The unchecked is a solidity 0.8 feature. This can save 30-40 gas per loop

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

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

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

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

Impact

Refactor the code to achieve gas savings, 30-40 gas per loop

Tools Used

Manual review

Recommendations

Use unchecked where possible

Support

FAQs

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