Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Support 2048 leaves tree and remove unneeded forced upgrade #22

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions bootloader/bootloader.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

<!-- @if BOOTLOADER_TYPE=='proved_batch' -->
Expand Down
4 changes: 4 additions & 0 deletions contracts/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 5 additions & 7 deletions contracts/L1Messenger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IMailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.0;

interface IMailbox {
function finalizeEthWithdrawal(
uint256 _l2BlockNumber,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBlock,
bytes calldata _message,
Expand Down