Context:
for (uint256 i = 0; i < facetCutsLength; ++i) {
L94for (uint256 i = 0; i < selectorsLength; ++i) {
L132for (uint256 i = 0; i < selectorsLength; ++i) {
L153for (uint256 i = 0; i < selectorsLength; ++i) {
L173
Description:
This can save 30-40 gas per loop iteration.
Recommendation:
Example how to fix. Change:
for (uint256 i = 0; i < orders.length; ++i) {
// Do the thing
}
To:
for (uint256 i = 0; i < orders.length;) {
// Do the thing
unchecked { ++i; }
}
Context:
- Executor. _getBlockProofPublicInput
- Executor._maxU256
- Executor._blockPassThroughData
- Executor._blockMetaParameters
- Executor._blockAuxilaryOutput
- Mailbox._L2MessageToLog
- L1EthBridge._getDepositL2Calldata
- L2ContractHelper.bytecodeLen
Description:
If they are not inlined, they cost an additional 20 to 40 gas because of 2 extra jump instructions and additional stack operations needed for function calls.
Context:
bool isEnabled = isAccessPublic[_target];
L76bool currentPermission = hasSpecialAccessToCall[_caller][_target][_functionSig];
L129
Recommendation:
Read the state variable from storage.
Context:
function _commitOneBlock(StoredBlockInfo memory _previousBlock, CommitBlockInfo calldata _newBlock)
L23 (_previousBlock)function _calculateBlockHash(StoredBlockInfo memory _previousBlock, CommitBlockInfo calldata _newBlock)
L80 (_previousBlock)function _executeOneBlock(StoredBlockInfo memory _storedBlock, uint256 _executedBlockIdx) internal {
L190 (_storedBlock)VerifierParams memory _verifierParams
L278function _hashStoredBlockInfo(StoredBlockInfo memory _storedBlockInfo) internal pure returns (bytes32) {
L385L2Log memory _log,
L43L2Log memory _log,
L53function diamondCut(DiamondCutData memory _diamondCut) internal {
L89bytes4[] memory _selectors,
L121bytes4[] memory _selectors,
L145function _removeFunctions(address _facet, bytes4[] memory _selectors) private {
L167 (_selectors)function _initializeDiamondCut(address _init, bytes memory _calldata) private {
L277 (_calldata)function pushBack(Queue storage _queue, PriorityOperation memory _operation) internal {
L54 (_operation)function _parseL2WithdrawalMessage(bytes memory _l2ToL1message)
L260function _parseL2WithdrawalMessage(bytes memory _message)
L214function sendMessageToL1(bytes memory _message) internal returns (bytes32) {
L43function hashL2Bytecode(bytes memory _bytecode) internal pure returns (bytes32 hashedBytecode) {
L47function bridgeInitialize(address _l1Address, bytes memory _data) external initializer {
L43 (_data)function decodeString(bytes memory _input) external pure returns (string memory result) {
L10function decodeUint8(bytes memory _input) external pure returns (uint8 result) {
L15
Description:
If a reference type function parameter is read-only, it is recommended to use calldata instead of memory because this provides significant gas savings. Since Solidity v0.6.9, memory and calldata are allowed in all functions regardless of their visibility type (ie external, public, etc).