diff --git a/bootloader/bootloader.yul b/bootloader/bootloader.yul index 80cad37c..dde0fdaa 100644 --- a/bootloader/bootloader.yul +++ b/bootloader/bootloader.yul @@ -632,36 +632,6 @@ object "Bootloader" { } } - /// @dev Checks whether the code hash of the system context contract is correct and updates it if needed. - /// @dev The bootloader implementation strictly relies of the ability of the system context contract to work with the - /// L2 blocks. However, the old system context did not support the correspodning interface at all. Usually we upgrade system context - /// via an upgrade transaction, but in this case the transaction won't be even processed, because of failure to create an L2 block. - function upgradeSystemContextIfNeeded() { - let expectedCodeHash := {{SYSTEM_CONTEXT_EXPECTED_CODE_HASH}} - - let actualCodeHash := extcodehash(SYSTEM_CONTEXT_ADDR()) - if iszero(eq(expectedCodeHash, actualCodeHash)) { - // Preparing the calldata to upgrade the SystemContext contract - {{UPGRADE_SYSTEM_CONTEXT_CALLDATA}} - - // We'll use a mimicCall to simulate the correct sender. - let success := mimicCallOnlyResult( - CONTRACT_DEPLOYER_ADDR(), - FORCE_DEPLOYER(), - 0, - 0, - 0, - 0, - 0, - 0 - ) - - if iszero(success) { - assertionError("system context upgrade fail") - } - } - } - /// @dev Calculates the canonical hash of the L1->L2 transaction that will be /// sent to L1 as a message to the L1 contract that a certain operation has been processed. function getCanonicalL1TxHash(txDataOffset) -> ret { @@ -3655,11 +3625,6 @@ object "Bootloader" { validateOperatorProvidedPrices(L1_GAS_PRICE, FAIR_L2_GAS_PRICE) - // This implementation of the bootloader relies on the correct version of the SystemContext - // and it can not be upgraded via a standard upgrade transaction, but needs to ensure - // correctness itself before any transaction is executed. - upgradeSystemContextIfNeeded() - let baseFee := 0 diff --git a/contracts/Constants.sol b/contracts/Constants.sol index 047c1dee..bb9166f5 100644 --- a/contracts/Constants.sol +++ b/contracts/Constants.sol @@ -93,3 +93,7 @@ enum SystemLogKey { NUMBER_OF_LAYER_1_TXS_KEY, EXPECTED_SYSTEM_CONTRACT_UPGRADE_TX_HASH } + +/// @dev The number of leaves in the L2->L1 log Merkle tree. +/// While formally a tree of any length is acceptable, the node supports only a constant length of 2048 leaves. +uint256 constant L2_TO_L1_LOGS_MERKLE_TREE_LEAVES = 2048; diff --git a/contracts/L1Messenger.sol b/contracts/L1Messenger.sol index 9e2527c2..dc28938c 100644 --- a/contracts/L1Messenger.sol +++ b/contracts/L1Messenger.sol @@ -6,7 +6,7 @@ import "./interfaces/IL1Messenger.sol"; import "./interfaces/ISystemContract.sol"; import "./libraries/SystemContractHelper.sol"; import "./libraries/EfficientCall.sol"; -import {SYSTEM_CONTEXT_CONTRACT, KNOWN_CODE_STORAGE_CONTRACT, COMPRESSOR_CONTRACT, STATE_DIFF_ENTRY_SIZE, SystemLogKey, MAX_ALLOWED_PUBDATA_PER_BATCH} from "./Constants.sol"; +import {SYSTEM_CONTEXT_CONTRACT, KNOWN_CODE_STORAGE_CONTRACT, COMPRESSOR_CONTRACT, STATE_DIFF_ENTRY_SIZE, SystemLogKey, MAX_ALLOWED_PUBDATA_PER_BATCH, L2_TO_L1_LOGS_MERKLE_TREE_LEAVES} from "./Constants.sol"; /** * @author Matter Labs @@ -200,12 +200,10 @@ contract L1Messenger is IL1Messenger, ISystemContract { /// Check logs uint32 numberOfL2ToL1Logs = uint32(bytes4(_totalL2ToL1PubdataAndStateDiffs[calldataPtr:calldataPtr + 4])); + require(numberOfL2ToL1Logs <= numberOfL2ToL1Logs, "Too many L2->L1 logs"); calldataPtr += 4; - // 512 is used here to reflect the value passed in to construct the tree here https://github.com/matter-labs/zksync-2-dev/blob/20848f149b4b0e245fd87df4649b95d623132b98/core/lib/types/src/commitment.rs#L244 - // This limit is based on the constraint on number of logs per batch. - uint256 l2ToL1LogsTreeLeaves = 512; - bytes32[] memory l2ToL1LogsTreeArray = new bytes32[](l2ToL1LogsTreeLeaves); + bytes32[] memory l2ToL1LogsTreeArray = new bytes32[](L2_TO_L1_LOGS_MERKLE_TREE_LEAVES); bytes32 reconstructedChainedLogsHash; for (uint256 i = 0; i < numberOfL2ToL1Logs; ++i) { bytes32 hashedLog = EfficientCall.keccak( @@ -219,10 +217,10 @@ contract L1Messenger is IL1Messenger, ISystemContract { reconstructedChainedLogsHash == chainedLogsHash, "reconstructedChainedLogsHash is not equal to chainedLogsHash" ); - for (uint256 i = numberOfL2ToL1Logs; i < l2ToL1LogsTreeLeaves; ++i) { + for (uint256 i = numberOfL2ToL1Logs; i < L2_TO_L1_LOGS_MERKLE_TREE_LEAVES; ++i) { l2ToL1LogsTreeArray[i] = L2_L1_LOGS_TREE_DEFAULT_LEAF_HASH; } - uint256 nodesOnCurrentLevel = l2ToL1LogsTreeLeaves; + uint256 nodesOnCurrentLevel = L2_TO_L1_LOGS_MERKLE_TREE_LEAVES; while (nodesOnCurrentLevel > 1) { nodesOnCurrentLevel /= 2; for (uint i = 0; i < nodesOnCurrentLevel; ++i) { diff --git a/contracts/interfaces/IMailbox.sol b/contracts/interfaces/IMailbox.sol index f362f639..b82305fc 100644 --- a/contracts/interfaces/IMailbox.sol +++ b/contracts/interfaces/IMailbox.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; interface IMailbox { function finalizeEthWithdrawal( - uint256 _l2BlockNumber, + uint256 _l2BatchNumber, uint256 _l2MessageIndex, uint16 _l2TxNumberInBlock, bytes calldata _message,