Unnecessary checked arithmetic in for loops #28
Labels
bug
Warden finding
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Handle
pants
Vulnerability details
There is no risk of overflow caused by increaments to the iteration index in for loops (the
i++
infor (uint256 i = 0; i < numIterations; i++)
).Impact
Increaments perform overflow checks that are not necessary in this case.
Tool Used
Manual code review.
Recommended Mitigation Steps
Surround the increament expressions with an
unchecked { ... }
block to avoid the default overflow checks. For example, change the loopto
It is a little less readable but it saves a significant amount of gas.
The text was updated successfully, but these errors were encountered: