Unnecessary checked arithmetic in for loops #157
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Handle
WatchPug
Vulnerability details
There is no risk of overflow caused by increamenting the iteration index in for loops (the
i++
in forfor (uint256 i = 0; i < idsIn.length; i++)
).Increments perform overflow checks that are not necessary in this case.
Recommendation
Surround the increment expressions with an
unchecked { ... }
block to avoid the default overflow checks. For example, change the for loop:https://github.com/code-423n4/2021-12-nftx/blob/194073f750b7e2c9a886ece34b6382b4f1355f36/nftx-protocol-v2/contracts/solidity/NFTXMarketplaceZap.sol#L437-L440
to:
The text was updated successfully, but these errors were encountered: