The majority of Solidity for loops increment a uint256 variable that starts at 0. These increment operations never need to be checked for over/underflow because the variable will never reach the max number of uint256 (will run out of gas long before that happens). The default over/underflow check wastes gas in every iteration of virtually every for loop.
e.g Let’s work with a sample loop below.
can be written as shown below.
We can also write it as an inlined function like below (recommended as there are multiple for loop so code can be reuse)
Gas saved: 30-40 gas per iteration
Number Of Instances: 2
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.