You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[G-01] Functions guaranteed to revert when called 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.
In Solidity 0.8+, there’s a default overflow check on unsigned integers. It’s possible to uncheck this in for-loops and save some gas at each iteration, but at the cost of some code readability, as this uncheck cannot be made inline.
[G-05] No need to explicitly initialize variables with default values
If a variable is not set/initialized, it is assumed to have the default value (0 for uint, false for bool, address(0) for address…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
As an example: for (uint256 i = 0; i < numIterations; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {
[G-07] Usage of uints/ints smaller than 32 bytes (256 bits) incurs overhead
When using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.
[G-01] Functions guaranteed to revert when called 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 aspayable
will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.There are 5 instances of this issue:
AxelarGasService.sol#L120
AxelarGasService.sol#L140
AxelarAuthWeighted.sol#L47
XC20Wrapper.sol#L44
XC20Wrapper.sol#L66
[G-02]
<array>.length
should not be looked up in every loop of afor
-loopThe overheads outlined below are PER LOOP, excluding the first loop
MLOAD
(3 gas)CALLDATALOAD
(3 gas)Caching the length changes each of these to a
DUP<N>
(3 gas), and gets rid of the extraDUP<N>
needed to store the stack offsetThere are 7 instances of this issue:
AxelarGasService.sol#L123
AxelarDepositService.sol#L114
AxelarDepositService.sol#L168
AxelarDepositService.sol#L204
AxelarAuthWeighted.sol#L17
AxelarAuthWeighted.sol#L98
AxelarAuthWeighted.sol#L116
[G-03]
++i
costs less gas thani++
, especially when it's used in for-loops (--i
/i--
too)Saves 6 gas per loop.
There are 4 instances of this issue:
AxelarGasService.sol#L123
AxelarDepositService.sol#L114
AxelarDepositService.sol#L168
AxelarDepositService.sol#L204
[G-04] Increments can be unchecked
In Solidity 0.8+, there’s a default overflow check on unsigned integers. It’s possible to uncheck this in for-loops and save some gas at each iteration, but at the cost of some code readability, as this uncheck cannot be made inline.
ethereum/solidity#10695
There are 10 instances of this issue:
AxelarGasService.sol#L123
AxelarDepositService.sol#L114
AxelarDepositService.sol#L168
AxelarDepositService.sol#L204
AxelarAuthWeighted.sol#L17
AxelarAuthWeighted.sol#L69
AxelarAuthWeighted.sol#L98
AxelarAuthWeighted.sol#L101
AxelarAuthWeighted.sol#L109
AxelarAuthWeighted.sol#L116
[G-05] No need to explicitly initialize variables with default values
If a variable is not set/initialized, it is assumed to have the default value (
0
foruint
,false
forbool
,address(0)
foraddress
…). Explicitly initializing it with its default value is an anti-pattern and wastes gas.As an example:
for (uint256 i = 0; i < numIterations; ++i) {
should be replaced withfor (uint256 i; i < numIterations; ++i) {
There are 5 instances of this issue:
AxelarAuthWeighted.sol#L68-L69
AxelarAuthWeighted.sol#L94-L98
[G-06]
x = x + y
is cheaper thanx += y
There are 2 instances of this issue:
AxelarAuthWeighted.sol#L70
AxelarAuthWeighted.sol#L105
[G-07] Usage of
uints
/ints
smaller than 32 bytes (256 bits) incurs overheadWhen using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.
https://docs.soliditylang.org/en/v0.8.11/internals/layout_in_storage.html Use a larger size then downcast where needed
There is 1 instance of this issue:
AxelarAuthWeighted.sol#L14
[G-08] Use custom error 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.
There are 15 instances of this issue
XC20Wrapper.sol
Search for
revert
The text was updated successfully, but these errors were encountered: