Unnecessary checked arithmetic in for-loops #198
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Handle
Dravee
Vulnerability details
Impact
In Solidity 0.8+, there's a default overflow check on unsigned integers. It's possible to uncheck this in for-loops and save 77 gas per iteration, but at the cost of some code readability, as this uncheck cannot be made inline.
ethereum/solidity#10695
Proof of Concept
Instances include:
Tools Used
VS Code
Recommended Mitigation Steps
The code would go from:
to:
While the risk are overflow is inexistant for a
uint256 i
, you might want to manually check for bounds once before the for-loop ifi
is smaller than auint256
(such asuint8
, never recommended and not the case in this project).The text was updated successfully, but these errors were encountered: