Skip to content

Latest commit

 

History

History
109 lines (89 loc) · 4.35 KB

0xRoxas-G.md

File metadata and controls

109 lines (89 loc) · 4.35 KB

Gas Report

Optimizations found [5]

[G-01] Use Bit Shift Operators for MUL/DIV/MOD of Powers of 2

Findings [6]:

/ethereum/contracts/common/L2ContractHelper.sol Line(s): 50, 52

50:	require(_bytecode.length % 32 == 0, "po");
52:	uint256 bytecodeLenInWords = _bytecode.length / 32;

suggested change

50:	require(_bytecode.length & 31 == 0, "po");
52:	uint256 bytecodeLenInWords = _bytecode.length >> 5;

/ethereum/contracts/zksync/Config.sol Line(s): 12

12:	uint256 constant L2_TO_L1_LOGS_COMMITMENT_BYTES = 4 + L2_TO_L1_LOG_SERIALIZE_SIZE * 512;

suggested change

12:	uint256 constant L2_TO_L1_LOGS_COMMITMENT_BYTES = 4 + L2_TO_L1_LOG_SERIALIZE_SIZE << 9;

/ethereum/contracts/zksync/libraries/Merkle.sol Line(s): 29, 34

29:	if (_index % 2 == 0) {
34:	_index /= 2;

suggested changes

29:	if (_index & 1 == 0) {
34:	_index = _index >> 1;

/ethereum/contracts/common/L2ContractHelper.sol Line(s): 54, 67, 72

54:	require(bytecodeLenInWords % 2 == 1, "pr");
67:	require(bytecodeLen(_bytecodeHash) % 2 == 1, "uy");
72:	codeLengthInWords = uint256(uint8(_bytecodeHash[2])) * 256 + uint256(uint8(_bytecodeHash[3]));

suggested changes

54:	require(bytecodeLenInWords & 1 == 1, "pr");
67:	require(bytecodeLen(_bytecodeHash) & 1 == 1, "uy");
72:	codeLengthInWords = uint256(uint8(_bytecodeHash[2])) << 8 + uint256(uint8(_bytecodeHash[3]));

[G-02] Unless Used for Variable Packing uint8 May Be More Expensive Than Using uint256

Findings [2]:

/ethereum/contracts/common/L2ContractHelper.sol Line(s): 64

64:	uint8 version = uint8(_bytecodeHash[0]);

/zksync/contracts/bridge/L2StandardERC20.sol Line(s): 29

29:	uint8 private decimals_;

[G-03] ++i is cheaper than i += 1

Findings [1]:

/ethereum/contracts/zksync/facets/DiamondCut.sol Line(s): 29

29:	s.diamondCutStorage.currentProposalId += 1;

Suggested Change

29:	++s.diamondCutStorage.currentProposalId;

[G-04] Public constant Can Be made private to Save Gas

/ethereum/contracts/zksync/libraries/Diamond.sol

14:	bytes32 constant DIAMOND_STORAGE_POSITION = 0xc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131b;

[G-05] Break Apart Require Statments Instead of &&

Breaking apart require and if statements saves gas.

Findings [1]:

/ethereum/contracts/common/AllowList.sol Line(s): 97

96:	require(
97:		callersLength == _targets.length &&
98:			callersLength == _functionSigs.length &&
99:			callersLength == _enables.length,
100:		"yw"
101:	); // The size of arrays should be equal