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-1 .LENGTH SHOULD NOT BE LOOKED UP IN EVERY LOOP OF A FOR-LOOP
The overheads outlined below are PER LOOP, excluding the first loop
storage arrays incur a sload(100 gas)
memory arrays use MLOAD (3 gas)
calldata arrays use CALLDATALOAD (3 gas)
Caching the length changes each of these to a DUP<N> (3 gas), and gets rid of the extra DUP<N> needed to store the stack offset
2 instances for this issue: ERC1155Fuse.sol L#92 ERC1155Fuse.sol L#205
G-2 REQUIRE()/REVERT() STRINGS LONGER THAN 32 BYTES COST EXTRA GAS
Each extra chunk of byetes past the original 32 iincurs an MSTORE which costs 3 gas
G-3 USING PRIVATE RATHER THAN PUBLIC FOR CONSTANTS, SAVE GAS
If needed, the value can be read from the verified contract source code. Savings are due to the compiler not having to create non-payable getter functions for deployment calldata, and not adding another entry to the method ID table
G-1 .LENGTH SHOULD NOT BE LOOKED UP IN EVERY LOOP OF A FOR-LOOP
The overheads outlined below are PER LOOP, excluding the first loop
storage arrays incur a
sload
(100 gas)memory arrays use
MLOAD
(3 gas)calldata arrays use
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 offset2 instances for this issue:
ERC1155Fuse.sol L#92
ERC1155Fuse.sol L#205
G-2 REQUIRE()/REVERT() STRINGS LONGER THAN 32 BYTES COST EXTRA GAS
Each extra chunk of byetes past the original 32 iincurs an MSTORE which costs 3 gas
https://github.com/code-423n4/2022-07-ens/blob/main/contracts/ethregistrar/ETHRegistrarController.sol#:~:text=%3E%200)%20%7B-,require(,)%3B,-%7D
https://github.com/code-423n4/2022-07-ens/blob/main/contracts/ethregistrar/ETHRegistrarController.sol#:~:text=(name%2C%20duration)%3B-,require(,)%3B,-_consumeCommitment(
https://github.com/code-423n4/2022-07-ens/blob/main/contracts/ethregistrar/ETHRegistrarController.sol#:~:text=%3A36%5D)%3B-,require(,)%3B,-resolver.functionCall
G-3 USING
PRIVATE
RATHER THANPUBLIC
FOR CONSTANTS, SAVE GASIf needed, the value can be read from the verified contract source code. Savings are due to the compiler not having to create non-payable getter functions for deployment calldata, and not adding another entry to the method ID table
There is 1 instance of this issue:
ETHRegistrarController.sol L#21
G-4
ABI.ENCODE()
IS LESS EFFICIENT THANABI.ENCODEPACKED()
There is one issue of this:
ETHRegistrarController.sol L#106
G-5 USE CUSTOM ERRORS RATHER THAN REVERT()/REQUIRE() STRINGS TO SAVE GAS
Custom errors are available from solidity version 0.8.4. Custom errors save ~50 gas each time they’re hitby avoiding having to allocate and store the revert string. Not defining the strings also save deployment gas.
https://github.com/code-423n4/2022-07-ens/blob/main/contracts/ethregistrar/ETHRegistrarController.sol#:~:text=%3E%200)%20%7B-,require(,)%3B,-%7D
https://github.com/code-423n4/2022-07-ens/blob/main/contracts/ethregistrar/ETHRegistrarController.sol#:~:text=(name%2C%20duration)%3B-,require(,)%3B,-_consumeCommitment(
https://github.com/code-423n4/2022-07-ens/blob/main/contracts/ethregistrar/ETHRegistrarController.sol#:~:text=%3A36%5D)%3B-,require(,)%3B,-resolver.functionCall
The text was updated successfully, but these errors were encountered: