there are some more require() function inside GobblersERC721.sol, GobblersERC1155B.sol, and PagesERC721.sol
++I COSTS LESS GAS COMPARED TO I++ OR I += 1 (SAME FOR --I VS I-- OR I -= 1)
A common gas optimization which sometimes it miss to look up
There are some i++ being used in some contracts
Pages.sol:L251
for (uint256 i = 0; i < numPages; i++) _mint(community, ++lastMintedPageId);
GobblerReserve.sol:L37
for (uint256 i = 0; i < ids.length; i++) {
artGobblers.transferFrom(address(this), to, ids[i]);
}
Pre-increments and pre-decrements are cheaper.
Increment:
i += 1 is the most expensive form
i++ costs 6 gas less than i += 1++i costs 5 gas less than i++ (11 gas less than i += 1)
Decrement:
i -= 1 is the most expensive form
i-- costs 11 gas less than i -= 1--i costs 5 gas less than i-- (16 gas less than i -= 1)
Note that post-increments (or post-decrements) return the old value before incrementing or decrementing, hence the name post-increment:
Use custom errors rather than
revert()
/require()
strings to save deployment gasCustom errors are available from solidity version 0.8.4. The instances below match or exceed that version
https://github.com/code-423n4/2022-09-artgobblers/blob/main/src/ArtGobblers.sol#L437
https://github.com/code-423n4/2022-09-artgobblers/blob/main/src/ArtGobblers.sol#L885-L892
there are some more
require()
function insideGobblersERC721.sol
,GobblersERC1155B.sol
, andPagesERC721.sol
++I COSTS LESS GAS COMPARED TO I++ OR I += 1 (SAME FOR --I VS I-- OR I -= 1)
A common gas optimization which sometimes it miss to look up
There are some
i++
being used in some contractsPages.sol:L251
GobblerReserve.sol:L37
Pre-increments and pre-decrements are cheaper.
Increment:
i += 1
is the most expensive formi++
costs 6 gas less thani += 1
++i
costs 5 gas less thani++
(11 gas less thani += 1
)Decrement:
i -= 1
is the most expensive formi--
costs 11 gas less thani -= 1
--i
costs 5 gas less thani--
(16 gas less thani -= 1
) Note that post-increments (or post-decrements) return the old value before incrementing or decrementing, hence the name post-increment: