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-2 .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 Gwarmaccess (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 Project.sol L#603
G-3 ++I COSTS LESS GAS THAN I++, ESPECIALLY WHEN IT’S USED IN FOR-LOOPS (--I/I-- TOO)
Saves 6 gas per loop
G-4 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. Finally, if both fields are accessed in the same function, can save ~42 gas per access due to not having to recalculate the key’s keccak256 hash (Gkeccak256 - 30 gas) and that calculation’s associated stack operations.
G-1 UNCHECKED{++I} INSTEAD OF I++
[HomeFiProxy.sol L#87]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=for%20all%20implementation-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20_length%3B%20i%2B%2B)%20%7B,-_generateProxy(allContractNames%5Bi
[HomeFiProxy.sol L#136]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=//%20Replace%20implementations-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20_length%3B%20i%2B%2B)%20%7B,-_replaceImplementation(_contractNames%5Bi
Project.sol L#248
[Project.sol L#311]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=for%20each%20task.-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20_length%3B%20i%2B%2B)%20%7B,-_inviteSC(_taskList%5Bi
Project.sol L#322
Project.sol L#603
G-2 .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 Gwarmaccess (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 offsetProject.sol L#603
G-3
++I
COSTS LESS GAS THANI++
, ESPECIALLY WHEN IT’S USED IN FOR-LOOPS (--I
/I--
TOO)Saves 6 gas per loop
[HomeFiProxy.sol L#87]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=for%20all%20implementation-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20_length%3B%20i%2B%2B)%20%7B,-_generateProxy(allContractNames%5Bi
[HomeFiProxy.sol L#136]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFiProxy.sol#:~:text=//%20Replace%20implementations-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20_length%3B%20i%2B%2B)%20%7B,-_replaceImplementation(_contractNames%5Bi
Project.sol L#248
[Project.sol L#311]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/Project.sol#:~:text=for%20each%20task.-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20_length%3B%20i%2B%2B)%20%7B,-_inviteSC(_taskList%5Bi
Project.sol L#322
Project.sol L#603
G-4 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. Finally, if both fields are accessed in the same function, can save ~42 gas per access due to not having to recalculate the key’s keccak256 hash (Gkeccak256 - 30 gas) and that calculation’s associated stack operations.
[HomeFi.sol L#62-66]https://github.com/code-423n4/2022-08-rigor/blob/b17b2a11d04289f9e927c71703b42771dd7b86a4/contracts/HomeFi.sol#:~:text=mapping(uint256,public%20override%20wrappedToken%3B
G-5 USING
> 0
COSTS MORE GAS THAN!= 0
WHEN USED ON A UINT IN AREQUIRE()
STATEMENTCommunity.sol L#764
The text was updated successfully, but these errors were encountered: