gas

`++i`/`i++` should be `unchecked{++i}`/`unchecked{i++}` when it is not possib...

Reward

Total

0.22 USDC

0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
0.00 USDC
Selected
0.01 USDC
Selected Submission

++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

Severity

Gas Optimization / Informational

Relevant GitHub Links

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

Summary

++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

Vulnerability Details

The unchecked keyword is new in solidity version 0.8.0, so this only applies to that version or higher, which these instances are. This saves 30-40 gas per loop

Instances (2):

File: src/DSCEngine.sol

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

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


Link to code - https://github.com/Cyfrin/2023-07-foundry-defi-stablecoin/tree/main/src/DSCEngine.sol

Tools Used

Code Review using VSCode

Recommendations

Use unchecked{++i}/unchecked{i++} in loops