Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'evm-equivalence-yul-new' into update_solidity_version
Browse files Browse the repository at this point in the history
IAvecilla authored Aug 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents f710555 + 7487de0 commit 5f4caf3
Showing 49 changed files with 6,809 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ contract CustomUpgradeTest is BaseZkSyncUpgrade {
(uint32 newMinorVersion, bool isPatchOnly) = _setNewProtocolVersion(_proposedUpgrade.newProtocolVersion);
_upgradeL1Contract(_proposedUpgrade.l1ContractsUpgradeCalldata);
_upgradeVerifier(_proposedUpgrade.verifier, _proposedUpgrade.verifierParams);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash, isPatchOnly);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash, _proposedUpgrade.evmSimulatorHash, isPatchOnly);

bytes32 txHash;
txHash = _setL2SystemContractUpgrade(
Original file line number Diff line number Diff line change
@@ -33,9 +33,10 @@ contract ExecutorProvingTest is ExecutorFacet {
}

/// Sets the DefaultAccount Hash and Bootloader Hash.
function setHashes(bytes32 l2DefaultAccountBytecodeHash, bytes32 l2BootloaderBytecodeHash) external {
function setHashes(bytes32 l2DefaultAccountBytecodeHash, bytes32 l2BootloaderBytecodeHash, bytes32 l2EvmSimulatorBytecode) external {
s.l2DefaultAccountBytecodeHash = l2DefaultAccountBytecodeHash;
s.l2BootloaderBytecodeHash = l2BootloaderBytecodeHash;
s.l2EvmSimulatorBytecodeHash = l2EvmSimulatorBytecode;
s.zkPorterIsAvailable = false;
}
}
Original file line number Diff line number Diff line change
@@ -343,6 +343,7 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
factoryDeps: bytesEmptyArray,
bootloaderHash: bytes32(0),
defaultAccountHash: bytes32(0),
evmSimulatorHash: bytes32(0),
verifier: address(0),
verifierParams: VerifierParams({
recursionNodeLevelVkHash: bytes32(0),
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ contract DiamondInit is ZkSyncHyperchainBase, IDiamondInit {
s.__DEPRECATED_verifierParams = _initializeData.verifierParams;
s.l2BootloaderBytecodeHash = _initializeData.l2BootloaderBytecodeHash;
s.l2DefaultAccountBytecodeHash = _initializeData.l2DefaultAccountBytecodeHash;
s.l2EvmSimulatorBytecodeHash = _initializeData.l2EvmSimulatorBytecodeHash;
s.priorityTxMaxGasLimit = _initializeData.priorityTxMaxGasLimit;
s.feeParams = _initializeData.feeParams;
s.blobVersionedHashRetriever = _initializeData.blobVersionedHashRetriever;
Original file line number Diff line number Diff line change
@@ -98,6 +98,9 @@ struct ZkSyncHyperchainStorage {
/// @notice Bytecode hash of default account (bytecode for EOA).
/// @dev Used as an input to zkp-circuit.
bytes32 l2DefaultAccountBytecodeHash;
/// @notice Bytecode hash of evm simulator.
/// @dev Used as an input to zkp-circuit.
bytes32 l2EvmSimulatorBytecodeHash;
/// @dev Indicates that the porter may be touched on L2 transactions.
/// @dev Used as an input to zkp-circuit.
bool zkPorterIsAvailable;
Original file line number Diff line number Diff line change
@@ -519,13 +519,14 @@ contract ExecutorFacet is ZkSyncHyperchainBase, IExecutor {

function _batchMetaParameters() internal view returns (bytes memory) {
bytes32 l2DefaultAccountBytecodeHash = s.l2DefaultAccountBytecodeHash;
bytes32 l2EvmSimulatorBytecodeHash = s.l2EvmSimulatorBytecodeHash;
return
abi.encodePacked(
s.zkPorterIsAvailable,
s.l2BootloaderBytecodeHash,
l2DefaultAccountBytecodeHash,
// VM 1.5.0 requires us to pass the EVM simulator code hash. For now it is the same as the default account.
l2DefaultAccountBytecodeHash
l2EvmSimulatorBytecodeHash
);
}

Original file line number Diff line number Diff line change
@@ -137,6 +137,11 @@ contract GettersFacet is ZkSyncHyperchainBase, IGetters, ILegacyGetters {
return s.l2DefaultAccountBytecodeHash;
}

/// @inheritdoc IGetters
function getL2EvmSimulatorBytecodeHash() external view returns (bytes32) {
return s.l2EvmSimulatorBytecodeHash;
}

/// @inheritdoc IGetters
function getVerifierParams() external view returns (VerifierParams memory) {
return s.__DEPRECATED_verifierParams;
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ struct InitializeData {
VerifierParams verifierParams;
bytes32 l2BootloaderBytecodeHash;
bytes32 l2DefaultAccountBytecodeHash;
bytes32 l2EvmSimulatorBytecodeHash;
uint256 priorityTxMaxGasLimit;
FeeParams feeParams;
address blobVersionedHashRetriever;
@@ -53,6 +54,7 @@ struct InitializeDataNewChain {
VerifierParams verifierParams;
bytes32 l2BootloaderBytecodeHash;
bytes32 l2DefaultAccountBytecodeHash;
bytes32 l2EvmSimulatorBytecodeHash;
uint256 priorityTxMaxGasLimit;
FeeParams feeParams;
address blobVersionedHashRetriever;
Original file line number Diff line number Diff line change
@@ -78,6 +78,9 @@ interface IGetters is IZkSyncHyperchainBase {
/// @return Bytecode hash of default account (bytecode for EOA).
function getL2DefaultAccountBytecodeHash() external view returns (bytes32);

/// @return Bytecode hash of EVM simulator.
function getL2EvmSimulatorBytecodeHash() external view returns (bytes32);

/// @return Verifier parameters.
/// @dev This function is deprecated and will soon be removed.
function getVerifierParams() external view returns (VerifierParams memory);
28 changes: 26 additions & 2 deletions l1-contracts/contracts/upgrades/BaseZkSyncUpgrade.sol
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ struct ProposedUpgrade {
bytes[] factoryDeps;
bytes32 bootloaderHash;
bytes32 defaultAccountHash;
bytes32 evmSimulatorHash;
address verifier;
VerifierParams verifierParams;
bytes l1ContractsUpgradeCalldata;
@@ -54,6 +55,8 @@ abstract contract BaseZkSyncUpgrade is ZkSyncHyperchainBase {
/// @notice Сhanges to the bytecode that is used in L2 as a default account
event NewL2DefaultAccountBytecodeHash(bytes32 indexed previousBytecodeHash, bytes32 indexed newBytecodeHash);

event NewL2EvmSimulatorBytecodeHash(bytes32 indexed previousBytecodeHash, bytes32 indexed newBytecodeHash);

/// @notice Verifier address changed
event NewVerifier(address indexed oldVerifier, address indexed newVerifier);

@@ -77,7 +80,7 @@ abstract contract BaseZkSyncUpgrade is ZkSyncHyperchainBase {
(uint32 newMinorVersion, bool isPatchOnly) = _setNewProtocolVersion(_proposedUpgrade.newProtocolVersion);
_upgradeL1Contract(_proposedUpgrade.l1ContractsUpgradeCalldata);
_upgradeVerifier(_proposedUpgrade.verifier, _proposedUpgrade.verifierParams);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash, isPatchOnly);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash, _proposedUpgrade.evmSimulatorHash, isPatchOnly);

txHash = _setL2SystemContractUpgrade(
_proposedUpgrade.l2ProtocolUpgradeTx,
@@ -111,6 +114,26 @@ abstract contract BaseZkSyncUpgrade is ZkSyncHyperchainBase {
emit NewL2DefaultAccountBytecodeHash(previousDefaultAccountBytecodeHash, _l2DefaultAccountBytecodeHash);
}

/// @notice Change default account bytecode hash, that is used on L2
/// @param _l2EvmSimulatorBytecodeHash The hash of default account L2 bytecode
/// @param _patchOnly Whether only the patch part of the protocol version semver has changed
function _setL2EvmSimulatorBytecodeHash(bytes32 _l2EvmSimulatorBytecodeHash, bool _patchOnly) private {
if (_l2EvmSimulatorBytecodeHash == bytes32(0)) {
return;
}

require(!_patchOnly, "Patch only upgrade can not set new default account");

L2ContractHelper.validateBytecodeHash(_l2EvmSimulatorBytecodeHash);

// Save previous value into the stack to put it into the event later
bytes32 previousL2EvmSimulatorBytecodeHash = s.l2EvmSimulatorBytecodeHash;

// Change the default account bytecode hash
s.l2EvmSimulatorBytecodeHash = _l2EvmSimulatorBytecodeHash;
emit NewL2EvmSimulatorBytecodeHash(previousL2EvmSimulatorBytecodeHash, _l2EvmSimulatorBytecodeHash);
}

/// @notice Change bootloader bytecode hash, that is used on L2
/// @param _l2BootloaderBytecodeHash The hash of bootloader L2 bytecode
/// @param _patchOnly Whether only the patch part of the protocol version semver has changed
@@ -179,9 +202,10 @@ abstract contract BaseZkSyncUpgrade is ZkSyncHyperchainBase {
/// @param _bootloaderHash The hash of the new bootloader bytecode. If zero, it will not be updated.
/// @param _defaultAccountHash The hash of the new default account bytecode. If zero, it will not be updated.
/// @param _patchOnly Whether only the patch part of the protocol version semver has changed.
function _setBaseSystemContracts(bytes32 _bootloaderHash, bytes32 _defaultAccountHash, bool _patchOnly) internal {
function _setBaseSystemContracts(bytes32 _bootloaderHash, bytes32 _defaultAccountHash, bytes32 _evmSimulatorHash, bool _patchOnly) internal {
_setL2BootloaderBytecodeHash(_bootloaderHash, _patchOnly);
_setL2DefaultAccountBytecodeHash(_defaultAccountHash, _patchOnly);
_setL2EvmSimulatorBytecodeHash(_evmSimulatorHash, _patchOnly);
}

/// @notice Sets the hash of the L2 system contract upgrade transaction for the next batch to be committed
2 changes: 2 additions & 0 deletions l1-contracts/deploy-scripts/DeployL1.s.sol
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ contract DeployL1Script is Script {
bytes diamondCutData;
bytes32 bootloaderHash;
bytes32 defaultAAHash;
bytes32 evmSimulatorHash;
}

struct TokensConfig {
@@ -435,6 +436,7 @@ contract DeployL1Script is Script {
verifierParams: verifierParams,
l2BootloaderBytecodeHash: config.contracts.bootloaderHash,
l2DefaultAccountBytecodeHash: config.contracts.defaultAAHash,
l2EvmSimulatorBytecodeHash: config.contracts.evmSimulatorHash,
priorityTxMaxGasLimit: config.contracts.priorityTxMaxGasLimit,
feeParams: feeParams,
blobVersionedHashRetriever: addresses.blobVersionedHashRetriever
2 changes: 1 addition & 1 deletion l1-contracts/deploy-scripts/InitializeL2WethToken.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity 0.8.20;

// solhint-disable no-console

11 changes: 9 additions & 2 deletions l1-contracts/scripts/upgrade-consistency-checker.ts
Original file line number Diff line number Diff line change
@@ -66,8 +66,9 @@ const expectedGenesisRoot = "0xabdb766b18a479a5c783a4b80e12686bc8ea3cc2d8a305049
const expectedRecursionNodeLevelVkHash = "0xf520cd5b37e74e19fdb369c8d676a04dce8a19457497ac6686d2bb95d94109c8";
const expectedRecursionLeafLevelVkHash = "0xf9664f4324c1400fa5c3822d667f30e873f53f1b8033180cd15fe41c1e2355c6";
const expectedRecursionCircuitsSetVksHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const expectedBootloaderHash = "0x010008e742608b21bf7eb23c1a9d0602047e3618b464c9b59c0fba3b3d7ab66e";
const expectedDefaultAccountHash = "0x01000563374c277a2c1e34659a2a1e87371bb6d852ce142022d497bfb50b9e32";
const expectedBootloaderHash = "0x010008e7894d0dd14681c76bdb4d5e4e7f6b51bfe40c957d50eed3fec829fdb0";
const expectedDefaultAccountHash = "0x0100058deb36e1f2eeb48bf3846d0e8eb38e9176754b73116bb41a472459a4dd";
const expectedEvmSimulatorHash = "0x01000f197081a9906cc411d0698c4961aeb5c74877f37f7071681da6e8ef3f31";

const validatorOne = process.env.ETH_SENDER_SENDER_OPERATOR_COMMIT_ETH_ADDR!;
const validatorTwo = process.env.ETH_SENDER_SENDER_OPERATOR_BLOBS_ETH_ADDR!;
@@ -219,6 +220,7 @@ async function extractProxyInitializationData(contract: ethers.Contract, data: s
recursionCircuitsSetVksHash,
l2BootloaderBytecodeHash,
l2DefaultAccountBytecodeHash,
l2EvmSimulatorBytecodeHash,
// priorityTxMaxGasLimit,

// // We unpack fee params
@@ -238,6 +240,7 @@ async function extractProxyInitializationData(contract: ethers.Contract, data: s
"bytes32",
"bytes32",
"bytes32",
"bytes32",
"uint256",
"uint256",
"uint256",
@@ -274,6 +277,10 @@ async function extractProxyInitializationData(contract: ethers.Contract, data: s
throw new Error("L2 default account bytecode hash is not correct");
}

if (l2EvmSimulatorBytecodeHash.toLowerCase() !== expectedEvmSimulatorHash.toLowerCase()) {
throw new Error("L2 default account bytecode hash is not correct");
}

console.log("STM init data correct!");
}

2 changes: 2 additions & 0 deletions l1-contracts/src.ts/deploy-process.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ import { ADDRESS_ONE } from "../src.ts/utils";

export const L2_BOOTLOADER_BYTECODE_HASH = "0x1000100000000000000000000000000000000000000000000000000000000000";
export const L2_DEFAULT_ACCOUNT_BYTECODE_HASH = "0x1001000000000000000000000000000000000000000000000000000000000000";
// This is the actual hash, not a placeholder like the other two.
export const L2_EVM_SIMULATOR_BYTECODE_HASH = "0x01000f197081a9906cc411d0698c4961aeb5c74877f37f7071681da6e8ef3f31";

export async function initialBridgehubDeployment(
deployer: Deployer,
2 changes: 2 additions & 0 deletions l1-contracts/src.ts/deploy-test-process.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import { Deployer } from "./deploy";
import {
L2_BOOTLOADER_BYTECODE_HASH,
L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
L2_EVM_SIMULATOR_BYTECODE_HASH,
initialBridgehubDeployment,
registerHyperchain,
} from "./deploy-process";
@@ -315,6 +316,7 @@ export class EraDeployer extends Deployer {
verifierParams,
l2BootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH,
l2DefaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
l2EvmSimulatorBytecodeHash: L2_EVM_SIMULATOR_BYTECODE_HASH,
priorityTxMaxGasLimit,
feeParams,
blobVersionedHashRetriever: this.addresses.BlobVersionedHashRetriever,
2 changes: 2 additions & 0 deletions l1-contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ import { getCurrentFacetCutsForAdd } from "./diamondCut";

import { ChainAdminFactory, ERC20Factory, StateTransitionManagerFactory } from "../typechain";
import type { Contract, Overrides } from "@ethersproject/contracts";
import { L2_EVM_SIMULATOR_BYTECODE_HASH } from "./deploy-process";

let L2_BOOTLOADER_BYTECODE_HASH: string;
let L2_DEFAULT_ACCOUNT_BYTECODE_HASH: string;
@@ -105,6 +106,7 @@ export class Deployer {
verifierParams,
L2_BOOTLOADER_BYTECODE_HASH,
L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
L2_EVM_SIMULATOR_BYTECODE_HASH,
this.addresses.StateTransition.Verifier,
this.addresses.BlobVersionedHashRetriever,
+priorityTxMaxGasLimit,
1 change: 1 addition & 0 deletions l1-contracts/src.ts/diamondCut.ts
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ export interface InitializeData {
allowList: BigNumberish;
l2BootloaderBytecodeHash: string;
l2DefaultAccountBytecodeHash: string;
l2EvmSimulatorBytecodeHash: string,
priorityTxMaxGasLimit: BigNumberish;
}

7 changes: 7 additions & 0 deletions l1-contracts/src.ts/utils.ts
Original file line number Diff line number Diff line change
@@ -187,6 +187,7 @@ function checkValidInitialCutHashParams(
verifierParams: VerifierParams,
l2BootloaderBytecodeHash: string,
l2DefaultAccountBytecodeHash: string,
l2EvmSimulatorBytecodeHash: string,
verifier: string,
blobVersionedHashRetriever: string,
priorityTxMaxGasLimit: number
@@ -215,6 +216,9 @@ function checkValidInitialCutHashParams(
if (l2DefaultAccountBytecodeHash === ethers.constants.HashZero) {
throw new Error("L2 default account bytecode hash is zero");
}
if (l2EvmSimulatorBytecodeHash === ethers.constants.HashZero) {
throw new Error("L2 evm simulator bytecode hash is zero");
}
if (verifier === ethers.constants.AddressZero) {
throw new Error("Verifier address is zero");
}
@@ -234,6 +238,7 @@ export function compileInitialCutHash(
verifierParams: VerifierParams,
l2BootloaderBytecodeHash: string,
l2DefaultAccountBytecodeHash: string,
l2EvmSimulatorBytecodeHash: string,
verifier: string,
blobVersionedHashRetriever: string,
priorityTxMaxGasLimit: number,
@@ -246,6 +251,7 @@ export function compileInitialCutHash(
verifierParams,
l2BootloaderBytecodeHash,
l2DefaultAccountBytecodeHash,
l2EvmSimulatorBytecodeHash,
verifier,
blobVersionedHashRetriever,
priorityTxMaxGasLimit
@@ -279,6 +285,7 @@ export function compileInitialCutHash(
verifierParams,
l2BootloaderBytecodeHash,
l2DefaultAccountBytecodeHash,
l2EvmSimulatorBytecodeHash,
priorityTxMaxGasLimit,
feeParams,
blobVersionedHashRetriever,
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@ contract UpgradeLogicTest is DiamondCutTest {
// zkPorterIsAvailable: false,
l2BootloaderBytecodeHash: 0x0100000000000000000000000000000000000000000000000000000000000000,
l2DefaultAccountBytecodeHash: 0x0100000000000000000000000000000000000000000000000000000000000000,
l2EvmBytecodeHash: 0x0100000000000000000000000000000000000000000000000000000000000000,
priorityTxMaxGasLimit: 500000, // priority tx max L2 gas limit
// initialProtocolVersion: 0,
feeParams: FeeParams({
Original file line number Diff line number Diff line change
@@ -75,9 +75,12 @@ contract ExecutorProofTest is Test {
/// This test is based on a block generated in a local system.
function test_Hashes() public {
utilsFacet.util_setL2DefaultAccountBytecodeHash(
0x0100065d134a862a777e50059f5e0fbe68b583f3617a67820f7edda0d7f253a0
0x0100058deb36e1f2eeb48bf3846d0e8eb38e9176754b73116bb41a472459a4dd
);
utilsFacet.util_setL2BootloaderBytecodeHash(0x010009416e909e0819593a9806bbc841d25c5cdfed3f4a1523497c6814e5194a);
utilsFacet.util_setL2EvmSimulatorBytecodeHash(
0x01000f197081a9906cc411d0698c4961aeb5c74877f37f7071681da6e8ef3f31
);
utilsFacet.util_setL2BootloaderBytecodeHash(0x010008e7894d0dd14681c76bdb4d5e4e7f6b51bfe40c957d50eed3fec829fdb0);
utilsFacet.util_setZkPorterAvailability(false);

IExecutor.CommitBatchInfo memory nextBatch = IExecutor.CommitBatchInfo({
Original file line number Diff line number Diff line change
@@ -83,19 +83,20 @@ contract ExecutorTest is Test {
selectors[12] = getters.storedBatchHash.selector;
selectors[13] = getters.getL2BootloaderBytecodeHash.selector;
selectors[14] = getters.getL2DefaultAccountBytecodeHash.selector;
selectors[15] = getters.getVerifierParams.selector;
selectors[16] = getters.isDiamondStorageFrozen.selector;
selectors[17] = getters.getPriorityTxMaxGasLimit.selector;
selectors[18] = getters.isEthWithdrawalFinalized.selector;
selectors[19] = getters.facets.selector;
selectors[20] = getters.facetFunctionSelectors.selector;
selectors[21] = getters.facetAddresses.selector;
selectors[22] = getters.facetAddress.selector;
selectors[23] = getters.isFunctionFreezable.selector;
selectors[24] = getters.isFacetFreezable.selector;
selectors[25] = getters.getTotalBatchesCommitted.selector;
selectors[26] = getters.getTotalBatchesVerified.selector;
selectors[27] = getters.getTotalBatchesExecuted.selector;
selectors[15] = getters.getL2EvmSimulatorBytecodeHash.selector;
selectors[16] = getters.getVerifierParams.selector;
selectors[17] = getters.isDiamondStorageFrozen.selector;
selectors[18] = getters.getPriorityTxMaxGasLimit.selector;
selectors[19] = getters.isEthWithdrawalFinalized.selector;
selectors[20] = getters.facets.selector;
selectors[21] = getters.facetFunctionSelectors.selector;
selectors[22] = getters.facetAddresses.selector;
selectors[23] = getters.facetAddress.selector;
selectors[24] = getters.isFunctionFreezable.selector;
selectors[25] = getters.isFacetFreezable.selector;
selectors[26] = getters.getTotalBatchesCommitted.selector;
selectors[27] = getters.getTotalBatchesVerified.selector;
selectors[28] = getters.getTotalBatchesExecuted.selector;
return selectors;
}

@@ -176,6 +177,7 @@ contract ExecutorTest is Test {
}),
l2BootloaderBytecodeHash: dummyHash,
l2DefaultAccountBytecodeHash: dummyHash,
l2EvmSimulatorBytecodeHash: dummyHash,
priorityTxMaxGasLimit: 1000000,
feeParams: defaultFeeParams(),
blobVersionedHashRetriever: blobVersionedHashRetriever
Loading

0 comments on commit 5f4caf3

Please sign in to comment.