[G-05] Functions guaranteed to revert when called by normal users can be marked payable (If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.):-
[G-06] Use a more recent version of solidity (Use a solidity version of at least 0.8.15 to have external calls skip contract existence checks if the external call has a return value):-
[G-07] Multiple address mappings can be combined into a single mapping of an address to a struct, where appropriate (Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot):-
[G-01] State variables only set in the constructor should be declared immutable (Avoids a Gsset (20000 gas)):-
address public marketPlace;`
[G-02] x = x + y is cheaper than x += y:-
[G-03]
require()
orrevert()
statements that check input arguments should be at the top of the function:-[G-04] Use custom errors rather than
revert()/require()
strings to save deployment gas:-[G-05] Functions guaranteed to revert when called by normal users can be marked
payable
(If a function modifier such asonlyOwner
is used, the function will revert if a normal user tries to pay the function. Marking the function aspayable
will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.):-[G-06] Use a more recent version of solidity (Use a solidity version of at least 0.8.15 to have external calls skip contract existence checks if the external call has a return value):-
[G-07] Multiple address mappings can be combined into a single mapping of an address to a struct, where appropriate (Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot):-
mapping(address => mapping(address => uint256)) public allowance;`
mapping(address => mapping(address => uint256)) public allowance;`
mapping(address => mapping(address => uint256)) public allowance;`