Skip to content

Commit

Permalink
Add initial protocol version (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless authored Nov 2, 2023
1 parent 86f2436 commit 9a74c72
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 14 deletions.
13 changes: 7 additions & 6 deletions docs/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ethereum/contracts/zksync/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ethereum/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -137,6 +138,7 @@ export class Deployer {
l2BootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH,
l2DefaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
priorityTxMaxGasLimit,
initialProtocolVersion
}
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ contract L1WethBridgeTest is Test {
false,
dummyHash,
dummyHash,
10000000
10000000,
0
);

Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ contract ExecutorTest is Test {
false,
dummyHash,
dummyHash,
1000000
1000000,
0
);

Diamond.FacetCut[] memory facetCuts = new Diamond.FacetCut[](4);
Expand Down
1 change: 1 addition & 0 deletions ethereum/test/unit_tests/l1_erc20_bridge_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe(`L1ERC20Bridge tests`, function () {
l2BootloaderBytecodeHash: dummyHash,
l2DefaultAccountBytecodeHash: dummyHash,
priorityTxMaxGasLimit: 10000000,
initialProtocolVersion: 0
}
]);

Expand Down
3 changes: 2 additions & 1 deletion ethereum/test/unit_tests/l1_weth_bridge_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ describe('WETH Bridge tests', () => {
zkPorterIsAvailable: false,
l2BootloaderBytecodeHash: dummyHash,
l2DefaultAccountBytecodeHash: dummyHash,
priorityTxMaxGasLimit: 10000000
priorityTxMaxGasLimit: 10000000,
initialProtocolVersion: 0
}
]);

Expand Down
5 changes: 3 additions & 2 deletions ethereum/test/unit_tests/l2-upgrade.test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -100,7 +100,8 @@ describe('L2 upgrade test', function () {
zkPorterIsAvailable: false,
l2BootloaderBytecodeHash: dummyHash,
l2DefaultAccountBytecodeHash: dummyHash,
priorityTxMaxGasLimit: 10000000
priorityTxMaxGasLimit: 10000000,
initialProtocolVersion: 0
}
]);

Expand Down
3 changes: 2 additions & 1 deletion ethereum/test/unit_tests/mailbox_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ describe('Mailbox tests', function () {
zkPorterIsAvailable: false,
l2BootloaderBytecodeHash: dummyHash,
l2DefaultAccountBytecodeHash: dummyHash,
priorityTxMaxGasLimit: 10000000
priorityTxMaxGasLimit: 10000000,
initialProtocolVersion: 0
}
]);

Expand Down
3 changes: 2 additions & 1 deletion ethereum/test/unit_tests/proxy_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('Diamond proxy tests', function () {
zkPorterIsAvailable: false,
l2BootloaderBytecodeHash: '0x0100000000000000000000000000000000000000000000000000000000000000',
l2DefaultAccountBytecodeHash: '0x0100000000000000000000000000000000000000000000000000000000000000',
priorityTxMaxGasLimit: 500000
priorityTxMaxGasLimit: 500000,
initialProtocolVersion: 0
}
]);

Expand Down

0 comments on commit 9a74c72

Please sign in to comment.