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] REVERT CHECK ON INPUT CAN BE PLACED AT START OF FUNCTION BODY
When a revert check on the input is placed at the start of the function body, the subsequent operations that cost more gas are prevented from running if it does revert.
For the following code, if (gatewayImplementation.code.length == 0) revert InvalidImplementation(); can be placed above _setAddress(KEY_IMPLEMENTATION, gatewayImplementation);.
[G-02] VARIABLE DOES NOT NEED TO BE INITIALIZED TO ITS DEFAULT VALUE
Explicitly initializing a variable with its default value costs more gas than uninitializing it. For example, uint256 i can be used instead of uint256 i = 0 in the following code.
contracts\AxelarGateway.sol
207: for (uint256 i = 0; i < symbols.length; i++) {
contracts\auth\AxelarAuthWeighted.sol
69: for (uint256 i = 0; i < weightsLength; ++i) {
98: for (uint256 i = 0; i < signatures.length; ++i) {
[G-03] ARRAY LENGTH CAN BE CACHED OUTSIDE OF LOOP
Caching the array length outside of the loop and using the cached length in the loop costs less gas than reading the array length for each iteration. For example, symbols.length in the following code can be cached outside of the loop like uint256 symbolsLength = symbols.length, and i < symbolsLength can be used for each iteration.
contracts\AxelarGateway.sol
207: for (uint256 i = 0; i < symbols.length; i++) {
contracts\auth\AxelarAuthWeighted.sol
17: for (uint256 i; i < recentOperators.length; ++i) {
98: for (uint256 i = 0; i < signatures.length; ++i) {
116: for (uint256 i; i < accounts.length - 1; ++i) {
contracts\deposit-service\AxelarDepositService.sol
114: for (uint256 i; i < refundTokens.length; i++) {
168: for (uint256 i; i < refundTokens.length; i++) {
204: for (uint256 i; i < refundTokens.length; i++) {
contracts\gas-service\AxelarGasService.sol
123: for (uint256 i; i < tokens.length; i++) {
[G-04] ++VARIABLE CAN BE USED INSTEAD OF VARIABLE++
++variable costs less gas than variable++. For example, i++ can be changed to ++i in the following code.
contracts\AxelarGateway.sol
207: for (uint256 i = 0; i < symbols.length; i++) {
contracts\deposit-service\AxelarDepositService.sol
114: for (uint256 i; i < refundTokens.length; i++) {
168: for (uint256 i; i < refundTokens.length; i++) {
204: for (uint256 i; i < refundTokens.length; i++) {
contracts\gas-service\AxelarGasService.sol
123: for (uint256 i; i < tokens.length; i++) {
[G-05] X = X + Y CAN BE USED INSTEAD OF X += Y
x = x + y costs less gas than x += y. For example, totalWeight += newWeights[i] can be changed to totalWeight = totalWeight + newWeights[i] in the following code.
[G-06] ARITHMETIC OPERATIONS THAT DO NOT OVERFLOW CAN BE UNCHECKED
Explicitly unchecking arithmetic operations that do not overflow by wrapping these in unchecked {} costs less gas than implicitly checking these.
For the following loops, if increasing the counter variable is very unlikely to overflow, then unchecked {++i} at the end of the loop block can be used, where i is the counter variable.
contracts\AxelarGateway.sol
195: for (uint256 i; i < adminCount; ++i) {
207: for (uint256 i = 0; i < symbols.length; i++) {
292: for (uint256 i; i < commandsLength; ++i) {
contracts\auth\AxelarAuthWeighted.sol
17: for (uint256 i; i < recentOperators.length; ++i) {
69: for (uint256 i = 0; i < weightsLength; ++i) {
98: for (uint256 i = 0; i < signatures.length; ++i) {
101: for (; operatorIndex < operatorsLength && signer != operators[operatorIndex]; ++operatorIndex) {}
116: for (uint256 i; i < accounts.length - 1; ++i) {
contracts\deposit-service\AxelarDepositService.sol
114: for (uint256 i; i < refundTokens.length; i++) {
168: for (uint256 i; i < refundTokens.length; i++) {
204: for (uint256 i; i < refundTokens.length; i++) {
contracts\gas-service\AxelarGasService.sol
123: for (uint256 i; i < tokens.length; i++) {
[G-07] REVERT WITH CUSTOM ERROR CAN BE USED INSTEAD OF REVERT() WITH REASON STRING
revert with custom error can cost less gas than revert() with reason string. Please consider using revert with custom error to replace the following revert().
xc20\contracts\XC20Wrapper.sol
55: if (axelarToken == address(0)) revert('NotAxelarToken()');
56: if (xc20Token.codehash != xc20Codehash) revert('NotXc20Token()');
57: if (wrapped[axelarToken] != address(0)) revert('AlreadyWrappingAxelarToken()');
58: if (unwrapped[xc20Token] != address(0)) revert('AlreadyWrappingXC20Token()');
61: if (!LocalAsset(xc20Token).set_team(address(this), address(this), address(this))) revert('NotOwner()');
62: if (!LocalAsset(xc20Token).set_metadata(newName, newSymbol, IERC20(axelarToken).decimals())) revert('CannotSetMetadata()');
68: if (axelarToken == address(0)) revert('NotAxelarToken()');
70: if (xc20Token == address(0)) revert('NotWrappingToken()');
78: if (wrappedToken == address(0)) revert('NotAxelarToken()');
79: if (!LocalAsset(wrappedToken).mint(msg.sender, amount)) revert('CannotMint()');
84: if (axelarToken == address(0)) revert('NotXc20Token()');
85: if (IERC20(wrappedToken).balanceOf(msg.sender) < amount) revert('InsufficientBalance()');
86: if (!LocalAsset(wrappedToken).burn(msg.sender, amount)) revert('CannotBurn()');
98: if (!transferred || tokenAddress.code.length == 0) revert('TransferFailed()');
111: if (!transferred || tokenAddress.code.length == 0) revert('TransferFailed()');
The text was updated successfully, but these errors were encountered:
[G-01] REVERT CHECK ON INPUT CAN BE PLACED AT START OF FUNCTION BODY
When a
revert
check on the input is placed at the start of the function body, the subsequent operations that cost more gas are prevented from running if it does revert.For the following code,
if (gatewayImplementation.code.length == 0) revert InvalidImplementation();
can be placed above_setAddress(KEY_IMPLEMENTATION, gatewayImplementation);
.[G-02] VARIABLE DOES NOT NEED TO BE INITIALIZED TO ITS DEFAULT VALUE
Explicitly initializing a variable with its default value costs more gas than uninitializing it. For example,
uint256 i
can be used instead ofuint256 i = 0
in the following code.[G-03] ARRAY LENGTH CAN BE CACHED OUTSIDE OF LOOP
Caching the array length outside of the loop and using the cached length in the loop costs less gas than reading the array length for each iteration. For example,
symbols.length
in the following code can be cached outside of the loop likeuint256 symbolsLength = symbols.length
, andi < symbolsLength
can be used for each iteration.[G-04] ++VARIABLE CAN BE USED INSTEAD OF VARIABLE++
++variable costs less gas than variable++. For example,
i++
can be changed to++i
in the following code.[G-05] X = X + Y CAN BE USED INSTEAD OF X += Y
x = x + y costs less gas than x += y. For example,
totalWeight += newWeights[i]
can be changed tototalWeight = totalWeight + newWeights[i]
in the following code.[G-06] ARITHMETIC OPERATIONS THAT DO NOT OVERFLOW CAN BE UNCHECKED
Explicitly unchecking arithmetic operations that do not overflow by wrapping these in
unchecked {}
costs less gas than implicitly checking these.For the following loops, if increasing the counter variable is very unlikely to overflow, then
unchecked {++i}
at the end of the loop block can be used, wherei
is the counter variable.[G-07] REVERT WITH CUSTOM ERROR CAN BE USED INSTEAD OF REVERT() WITH REASON STRING
revert
with custom error can cost less gas thanrevert()
with reason string. Please consider usingrevert
with custom error to replace the followingrevert()
.The text was updated successfully, but these errors were encountered: