From 9e29d7f80f696fe007a6a7b07ee855b03bf61a1d Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Thu, 2 Nov 2023 10:59:49 +0100 Subject: [PATCH 1/3] add initial protocol version --- docs/Overview.md | 13 +++++++------ ethereum/contracts/zksync/DiamondInit.sol | 2 ++ ethereum/src.ts/deploy.ts | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/Overview.md b/docs/Overview.md index 67e2fed83..72b4021d1 100644 --- a/docs/Overview.md +++ b/docs/Overview.md @@ -77,9 +77,9 @@ zkSync Era governed contracts. Each upgrade consists of two steps: - Upgrade Proposal - The governor can schedule upgrades in two different manners: - - Fully transparent data. All implementation contracts and migration contracts are known to the community. The governor must wait + - Fully transparent data. All implementation contracts and migration contracts are known to the community. The governor must wait for the timelock to execute the upgrade. - - Shadow upgrade. The governor only shows the commitment for the upgrade. The upgrade can be executed only with security council + - Shadow upgrade. The governor only shows the commitment for the upgrade. The upgrade can be executed only with security council approval without timelock. - Upgrade execution - perform the upgrade that was proposed. @@ -166,6 +166,7 @@ The state transition is divided into three stages: - `executeBatches` - finalize the state, marking L1 -> L2 communication processing, and saving Merkle tree with L2 logs. Each L2 -> L1 system log will have a key that is part of the following: + ```solidity enum SystemLogKey { L2_TO_L1_LOGS_TREE_ROOT_KEY, @@ -184,16 +185,16 @@ When a batch is committed, we process L2 -> L1 system logs. Here are the invaria - In a given batch there will be either 7 or 8 system logs. The 8th log is only required for a protocol upgrade. - There will be a single log for each key that is containted within `SystemLogKey` - Three logs from the `L2_TO_L1_MESSENGER` with keys: - - `L2_TO_L1_LOGS_TREE_ROOT_KEY` - - `TOTAL_L2_TO_L1_PUBDATA_KEY` - - `STATE_DIFF_HASH_KEY` +- `L2_TO_L1_LOGS_TREE_ROOT_KEY` +- `TOTAL_L2_TO_L1_PUBDATA_KEY` +- `STATE_DIFF_HASH_KEY` - Two logs from `L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR` with keys: - `PACKED_BATCH_AND_L2_BLOCK_TIMESTAMP_KEY` - `PREV_BATCH_HASH_KEY` - Two or three logs from `L2_BOOTLOADER_ADDRESS` with keys: - `CHAINED_PRIORITY_TXN_HASH_KEY` - `NUMBER_OF_LAYER_1_TXS_KEY` - - `EXPECTED_SYSTEM_CONTRACT_UPGRADE_TX_HASH_KEY` + - `EXPECTED_SYSTEM_CONTRACT_UPGRADE_TX_HASH_KEY` - None logs from other addresses (may be changed in the future). #### Bridges diff --git a/ethereum/contracts/zksync/DiamondInit.sol b/ethereum/contracts/zksync/DiamondInit.sol index 40adeae86..5867dd6f2 100644 --- a/ethereum/contracts/zksync/DiamondInit.sol +++ b/ethereum/contracts/zksync/DiamondInit.sol @@ -44,6 +44,7 @@ contract DiamondInit is Base { bytes32 l2BootloaderBytecodeHash; bytes32 l2DefaultAccountBytecodeHash; uint256 priorityTxMaxGasLimit; + uint256 initialProtocolVersion; } /// @dev Initialize the implementation to prevent any possibility of a Parity hack. @@ -81,6 +82,7 @@ contract DiamondInit is Base { s.l2BootloaderBytecodeHash = _initalizeData.l2BootloaderBytecodeHash; s.l2DefaultAccountBytecodeHash = _initalizeData.l2DefaultAccountBytecodeHash; s.priorityTxMaxGasLimit = _initalizeData.priorityTxMaxGasLimit; + s.protocolVersion = _initalizeData.initialProtocolVersion; // While this does not provide a protection in the production, it is needed for local testing // Length of the L2Log encoding should not be equal to the length of other L2Logs' tree nodes preimages diff --git a/ethereum/src.ts/deploy.ts b/ethereum/src.ts/deploy.ts index 42772e3d7..35613aad5 100644 --- a/ethereum/src.ts/deploy.ts +++ b/ethereum/src.ts/deploy.ts @@ -121,6 +121,7 @@ export class Deployer { recursionCircuitsSetVksHash: getHashFromEnv('CONTRACTS_RECURSION_CIRCUITS_SET_VKS_HASH') }; const priorityTxMaxGasLimit = getNumberFromEnv('CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT'); + const initialProtocolVersion = getNumberFromEnv('CONTRACTS_INITIAL_PROTOCOL_VERSION'); const DiamondInit = new Interface(hardhat.artifacts.readArtifactSync('DiamondInit').abi); const diamondInitCalldata = DiamondInit.encodeFunctionData('initialize', [ @@ -137,6 +138,7 @@ export class Deployer { l2BootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH, l2DefaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH, priorityTxMaxGasLimit, + initialProtocolVersion } ]); From 38663a7dc600bf5d019b978a5099c38e2d20a14a Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Thu, 2 Nov 2023 11:18:59 +0100 Subject: [PATCH 2/3] fix hardhat unit tests --- ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts | 1 + ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts | 3 ++- ethereum/test/unit_tests/l2-upgrade.test.spec.ts | 5 +++-- ethereum/test/unit_tests/mailbox_test.spec.ts | 3 ++- ethereum/test/unit_tests/proxy_test.spec.ts | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts b/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts index ce6a63458..b1683760c 100644 --- a/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts +++ b/ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts @@ -67,6 +67,7 @@ describe(`L1ERC20Bridge tests`, function () { l2BootloaderBytecodeHash: dummyHash, l2DefaultAccountBytecodeHash: dummyHash, priorityTxMaxGasLimit: 10000000, + initialProtocolVersion: 0 } ]); diff --git a/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts b/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts index f7047c25e..e4785d167 100644 --- a/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts +++ b/ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts @@ -98,7 +98,8 @@ describe('WETH Bridge tests', () => { zkPorterIsAvailable: false, l2BootloaderBytecodeHash: dummyHash, l2DefaultAccountBytecodeHash: dummyHash, - priorityTxMaxGasLimit: 10000000 + priorityTxMaxGasLimit: 10000000, + initialProtocolVersion: 0 } ]); diff --git a/ethereum/test/unit_tests/l2-upgrade.test.spec.ts b/ethereum/test/unit_tests/l2-upgrade.test.spec.ts index 791ba7ad6..065a7fcf0 100644 --- a/ethereum/test/unit_tests/l2-upgrade.test.spec.ts +++ b/ethereum/test/unit_tests/l2-upgrade.test.spec.ts @@ -27,7 +27,7 @@ import { SYSTEM_LOG_KEYS, constructL2Log, L2_TO_L1_MESSENGER, - packBatchTimestampAndBatchTimestamp + packBatchTimestampAndBatchTimestamp, } from './utils'; import * as ethers from 'ethers'; import { BigNumber, BigNumberish, BytesLike } from 'ethers'; @@ -100,7 +100,8 @@ describe('L2 upgrade test', function () { zkPorterIsAvailable: false, l2BootloaderBytecodeHash: dummyHash, l2DefaultAccountBytecodeHash: dummyHash, - priorityTxMaxGasLimit: 10000000 + priorityTxMaxGasLimit: 10000000, + initialProtocolVersion: 0 } ]); diff --git a/ethereum/test/unit_tests/mailbox_test.spec.ts b/ethereum/test/unit_tests/mailbox_test.spec.ts index ba6458c92..2867491e0 100644 --- a/ethereum/test/unit_tests/mailbox_test.spec.ts +++ b/ethereum/test/unit_tests/mailbox_test.spec.ts @@ -76,7 +76,8 @@ describe('Mailbox tests', function () { zkPorterIsAvailable: false, l2BootloaderBytecodeHash: dummyHash, l2DefaultAccountBytecodeHash: dummyHash, - priorityTxMaxGasLimit: 10000000 + priorityTxMaxGasLimit: 10000000, + initialProtocolVersion: 0 } ]); diff --git a/ethereum/test/unit_tests/proxy_test.spec.ts b/ethereum/test/unit_tests/proxy_test.spec.ts index ef352eaa3..5fa710688 100644 --- a/ethereum/test/unit_tests/proxy_test.spec.ts +++ b/ethereum/test/unit_tests/proxy_test.spec.ts @@ -80,7 +80,8 @@ describe('Diamond proxy tests', function () { zkPorterIsAvailable: false, l2BootloaderBytecodeHash: '0x0100000000000000000000000000000000000000000000000000000000000000', l2DefaultAccountBytecodeHash: '0x0100000000000000000000000000000000000000000000000000000000000000', - priorityTxMaxGasLimit: 500000 + priorityTxMaxGasLimit: 500000, + initialProtocolVersion: 0 } ]); From ba64dbdfa59b4986cdd004165c0192104061ccc7 Mon Sep 17 00:00:00 2001 From: Stanislav Breadless Date: Thu, 2 Nov 2023 11:24:30 +0100 Subject: [PATCH 3/3] fix forge tests --- .../concrete/Bridge/L1WethBridge/_L1WethBridge_Shared.t.sol | 3 ++- .../test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol | 3 ++- .../test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ethereum/test/foundry/unit/concrete/Bridge/L1WethBridge/_L1WethBridge_Shared.t.sol b/ethereum/test/foundry/unit/concrete/Bridge/L1WethBridge/_L1WethBridge_Shared.t.sol index df7a5d1d1..7ee51db2e 100644 --- a/ethereum/test/foundry/unit/concrete/Bridge/L1WethBridge/_L1WethBridge_Shared.t.sol +++ b/ethereum/test/foundry/unit/concrete/Bridge/L1WethBridge/_L1WethBridge_Shared.t.sol @@ -49,7 +49,8 @@ contract L1WethBridgeTest is Test { false, dummyHash, dummyHash, - 10000000 + 10000000, + 0 ); Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](2); diff --git a/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol b/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol index 388b34ae9..59b012684 100644 --- a/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol +++ b/ethereum/test/foundry/unit/concrete/DiamondCut/UpgradeLogic.t.sol @@ -81,7 +81,8 @@ contract UpgradeLogicTest is DiamondCutTest { false, 0x0100000000000000000000000000000000000000000000000000000000000000, 0x0100000000000000000000000000000000000000000000000000000000000000, - 500000 // priority tx max L2 gas limit + 500000, // priority tx max L2 gas limit + 0 ); Diamond.DiamondCutData memory diamondCutData = Diamond.DiamondCutData({ diff --git a/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol b/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol index b0166ca09..da61ad39d 100644 --- a/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol +++ b/ethereum/test/foundry/unit/concrete/Executor/_Executor_Shared.t.sol @@ -132,7 +132,8 @@ contract ExecutorTest is Test { false, dummyHash, dummyHash, - 1000000 + 1000000, + 0 ); Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](4);