G-02 In for loop use outside variable for array length
For loop written like thisfor (uint256 i; i < array.length; ++i) { will cost more gas than for (uint256 i; i < _lengthOfArray; ++i) { because for every iteration we use mload and memory_offset
that will cost about 6 gas
Use of bit shifting operations are more cheap than normal multiplication/division operations. MUL and DIV costs 5 gas rather than SHL and SHR that costs 3 gas. You can use them where is possible
G-06 Recomend to use uint256(1)/uint256(2) for true and false
If you don't use boolean for storage you will avoid Gwarmaccess (100 gas). Also boolean from true to false cost 20000 gas rather than uint256(2) to uint256(1) that cost less.
There have 4 istance of this issues:
mapping(address => mapping(address => bool)) public isApprovedForAll;
G-01 Use defualt value rather than overwriite variable with their default value.
Overriting varibles with defualt values with their default value will waste only gas and not necessary.
There are 7 instances of this issue:
File: ArtGobblers.sol lines 432, 592
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L432
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L592
File: Pages.sol line 251
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/Pages.sol#L251
File: GobblerReserve.sol line 37
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/GobblerReserve.sol#L37
File: GobblersERC1155B lines 114,173
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC1155B.sol#L114
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC1155B.sol#L173
File: GobblersERC721 line 186
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC721.sol#L186
G-02 In for loop use outside variable for array length
For loop written like this
for (uint256 i; i < array.length; ++i) {
will cost more gas thanfor (uint256 i; i < _lengthOfArray; ++i) {
because for every iteration we use mload and memory_offset that will cost about 6 gasThere are 2 instances of this issue:
File: GobblerReserve.sol: line 37
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/GobblerReserve.sol#L37
File GobblersERC1155B.sol line 114
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC1155B.sol#L114
G-03 If you use bit shifting will save some gas
Use of bit shifting operations are more cheap than normal multiplication/division operations.
MUL
andDIV
costs 5 gas rather thanSHL
andSHR
that costs 3 gas. You can use them where is possibleThere are 2 instances of this issue:
File: ArtGobblers.sol lines 449,462
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L449
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L462
G-05 i++, i += 1 and i = i + 1 IN FOR LOOPS COSTS MORE GAS COMPARED TO ++i
++i will save about 5 gas for each iteration
There are 2 instances of this issue:
File: Pages.sol line 251
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/Pages.sol#L251
File: GobblerReserve.sol line 37
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/GobblerReserve.sol#L37
G-06 Recomend to use
uint256(1)
/uint256(2)
for true and falseIf you don't use boolean for storage you will avoid Gwarmaccess (100 gas). Also boolean from true to false cost 20000 gas rather than uint256(2) to uint256(1) that cost less.
There have 4 istance of this issues:
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC721.sol#L77
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L149
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L212
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/PagesERC721.sol#L70
G-07 Recomend to use one operator for comparison where is possible
If you use
>=
or<=
this will cost more gas because in the EVM there is no implementation of Opcodes for>=
and `<= and two operations are done.There have 4 istance of this issues:
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L435
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L497
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L695
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L702
G-04 = + cost less than += for state variables
There have 2 istance of this issues:
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L439
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L464
G-03 Use
uncheck()
in for loops whenere overflow and undeflow is not possibleUsing of
uncheck(i++)
/uncheck(++i)
will save about 30 gas per iteration because compiler not save check everytime. This feature come from 0.8There are 7 instances of this issue:
File: ArtGobblers.sol lines 432, 592
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L432
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/ArtGobblers.sol#L592
File: Pages.sol line 251
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/Pages.sol#L251
File: GobblerReserve.sol line 37
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/GobblerReserve.sol#L37
File: GobblersERC1155B lines 114,173
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC1155B.sol#L114
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC1155B.sol#L173
File: GobblersERC721 line 186
https://github.com/code-423n4/2022-09-artgobblers/blob/d2087c5a8a6a4f1b9784520e7fe75afa3a9cbdbe/src/utils/token/GobblersERC721.sol#L186