Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 5.57 KB

halden-G.md

File metadata and controls

53 lines (36 loc) · 5.57 KB

[G-01] Optimizations with assembly

[G-01.1] Use assembly for math (add, sub, mul, div)

[G-01.2] Use assembly to check for address(0)

File Diamond.Proxy.sol 29

File Diamond.sol: 126, 135, 150, 170, 278

File AllowList.sol: 33

[G-01.3] Use assembly to store storage values

File DiamondCut.sol: 27-29, 68, 83-85, 98, 109, 114

File Executor.sol 164, 173, 202, 215, 270, 341, 343

[G-02] X += Y or X -= Y costs more gas than X = X + Y or X = X - Y for state variables

File DiamondCut.sol: 29

[G-03] Cache storage values in memory to minimize SLOADs

s.totalBlocksVerified should be cached File Executor.sol 340, 345

        if (newTotalBlocksCommitted < s.totalBlocksVerified) { // 1 SLOAD
            s.totalBlocksVerified = newTotalBlocksCommitted;
        }
        s.totalBlocksCommitted = newTotalBlocksCommitted; // 2 SLOAD

        emit BlocksRevert(s.totalBlocksCommitted, s.totalBlocksVerified, s.totalBlocksExecuted); // 3 SLOAD

cache s.totalBlocksCommitted to minimize usage in event File Executor.sol 345 from emit BlocksRevert(s.totalBlocksCommitted, s.totalBlocksVerified, s.totalBlocksExecuted); to emit BlocksRevert(newTotalBlocksCommitted, s.totalBlocksVerified, s.totalBlocksExecuted);

cache s.totalBlocksExecuted to minimize usage in event File Executor.sol 338, 345

[G-04] Using calldata instead of memory for read-only arguments in external functions saves gas

File Mailbox.sol: 43, 53

File L2ContractHelper.sol: 43, 47

File ExternalDecoder.so: 10, 15

[G-05] Optimize names to save gas

public/external function names and public member variable names can be optimized to save gas. Below are the interfaces/abstract contracts that can be optimized so that the most frequently-called functions use the least amount of gas possible during method lookup. Method IDs that have two leading zero bytes can save 128 gas each during deployment, and renaming functions to have lower method IDs will save 22 gas per call, per sorted position shifted

Files: IDiamondCut, IExecutor.sol, IGetters.sol, IGovernance.sol, IMailbox.sol, IZkSync.sol