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
USE CUSTOM ERRORS RATHER THAN REVERT()/REQUIRE() STRINGS TO SAVE GAS
Rigor is using solidity version 0.8.6, while custom errors are available from solidity version 0.8.4, so it's suitable to use custom error. 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
.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 (3 gas), and gets rid of the extra DUP needed to store the stack offset
example loop _changeOrderedTask.length inside Project.sol
++I COSTS LESS GAS THAN I++, ESPECIALLY WHEN IT’S USED IN FOR-LOOPS (--I/I-- TOO)
Saves 6 gas per loop
example loop inside Community.sol, Project.sol, HomeFiProxy.sol, Tasks.sol
for (uint256 i = 0; i < _length; i++)
SPLITTING REQUIRE() STATEMENTS THAT USE && SAVES GAS
See (this issue)[https://github.com/code-423n4/2022-01-xdefi-findings/issues/128] which describes the fact that there is a larger deployment gas cost, but with enough runtime calls, the change ends up being cheaper.
this issue exist inside Community.sol, Disputes.sol
USING PRIVATE RATHER THAN PUBLIC FOR CONSTANTS, SAVES 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
example issue in Project.sol
uint256 public constant override VERSION = 25000;
The text was updated successfully, but these errors were encountered:
USE CUSTOM ERRORS RATHER THAN REVERT()/REQUIRE() STRINGS TO SAVE GAS
Rigor is using solidity version 0.8.6, while custom errors are available from solidity version 0.8.4, so it's suitable to use custom error. 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
.LENGTH SHOULD NOT BE LOOKED UP IN EVERY LOOP OF A FOR-LOOP
The overheads outlined below are PER LOOP, excluding the first loop
Caching the length changes each of these to a DUP (3 gas), and gets rid of the extra DUP needed to store the stack offset
example loop
_changeOrderedTask.length
inside Project.sol++I COSTS LESS GAS THAN I++, ESPECIALLY WHEN IT’S USED IN FOR-LOOPS (--I/I-- TOO)
Saves 6 gas per loop
example loop inside Community.sol, Project.sol, HomeFiProxy.sol, Tasks.sol
SPLITTING REQUIRE() STATEMENTS THAT USE && SAVES GAS
See (this issue)[https://github.com/code-423n4/2022-01-xdefi-findings/issues/128] which describes the fact that there is a larger deployment gas cost, but with enough runtime calls, the change ends up being cheaper.
this issue exist inside Community.sol, Disputes.sol
USING PRIVATE RATHER THAN PUBLIC FOR CONSTANTS, SAVES 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
example issue in Project.sol
The text was updated successfully, but these errors were encountered: