Skip to content

Commit

Permalink
Rename interpreter to emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Oct 9, 2024
1 parent d76a8d1 commit c4eaf04
Show file tree
Hide file tree
Showing 38 changed files with 149 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract CustomUpgradeTest is BaseZkSyncUpgrade {
_setBaseSystemContracts(
_proposedUpgrade.bootloaderHash,
_proposedUpgrade.defaultAccountHash,
_proposedUpgrade.evmSimulatorHash,
_proposedUpgrade.evmEmulatorHash,
isPatchOnly
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ contract ExecutorProvingTest is ExecutorFacet {
return _processL2Logs(_newBatch, _expectedSystemContractUpgradeTxHash);
}

/// Sets the DefaultAccount Hash and Bootloader Hash.
/// Sets the DefaultAccount Hash, Bootloader Hash and EVM emulator Hash.
function setHashes(
bytes32 l2DefaultAccountBytecodeHash,
bytes32 l2BootloaderBytecodeHash,
bytes32 l2EvmSimulatorBytecode
bytes32 l2EvmEmulatorBytecode
) external {
s.l2DefaultAccountBytecodeHash = l2DefaultAccountBytecodeHash;
s.l2BootloaderBytecodeHash = l2BootloaderBytecodeHash;
s.l2EvmSimulatorBytecodeHash = l2EvmSimulatorBytecode;
s.l2EvmEmulatorBytecodeHash = l2EvmEmulatorBytecode;
s.zkPorterIsAvailable = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
factoryDeps: bytesEmptyArray,
bootloaderHash: bytes32(0),
defaultAccountHash: bytes32(0),
evmSimulatorHash: bytes32(0),
evmEmulatorHash: bytes32(0),
verifier: address(0),
verifierParams: VerifierParams({
recursionNodeLevelVkHash: bytes32(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract DiamondInit is ZkSyncHyperchainBase, IDiamondInit {
s.__DEPRECATED_verifierParams = _initializeData.verifierParams;
s.l2BootloaderBytecodeHash = _initializeData.l2BootloaderBytecodeHash;
s.l2DefaultAccountBytecodeHash = _initializeData.l2DefaultAccountBytecodeHash;
s.l2EvmSimulatorBytecodeHash = _initializeData.l2EvmSimulatorBytecodeHash;
s.l2EvmEmulatorBytecodeHash = _initializeData.l2EvmEmulatorBytecodeHash;
s.priorityTxMaxGasLimit = _initializeData.priorityTxMaxGasLimit;
s.feeParams = _initializeData.feeParams;
s.blobVersionedHashRetriever = _initializeData.blobVersionedHashRetriever;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +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.
/// @notice Bytecode hash of evm emulator.
/// @dev Used as an input to zkp-circuit.
bytes32 l2EvmSimulatorBytecodeHash;
bytes32 l2EvmEmulatorBytecodeHash;
/// @dev Indicates that the porter may be touched on L2 transactions.
/// @dev Used as an input to zkp-circuit.
bool zkPorterIsAvailable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,13 @@ contract ExecutorFacet is ZkSyncHyperchainBase, IExecutor {

function _batchMetaParameters() internal view returns (bytes memory) {
bytes32 l2DefaultAccountBytecodeHash = s.l2DefaultAccountBytecodeHash;
bytes32 l2EvmSimulatorBytecodeHash = s.l2EvmSimulatorBytecodeHash;
bytes32 l2EvmEmulatorBytecodeHash = s.l2EvmEmulatorBytecodeHash;
return
abi.encodePacked(
s.zkPorterIsAvailable,
s.l2BootloaderBytecodeHash,
l2DefaultAccountBytecodeHash,
l2EvmSimulatorBytecodeHash
l2EvmEmulatorBytecodeHash
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ contract GettersFacet is ZkSyncHyperchainBase, IGetters, ILegacyGetters {
}

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

/// @inheritdoc IGetters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {FeeParams} from "../chain-deps/ZkSyncHyperchainStorage.sol";
/// @param verifierParams Verifier config parameters that describes the circuit to be verified
/// @param l2BootloaderBytecodeHash The hash of bootloader L2 bytecode
/// @param l2DefaultAccountBytecodeHash The hash of default account L2 bytecode
/// @param l2EvmEmulatorBytecodeHash The hash of EVM emulator L2 bytecode
/// @param priorityTxMaxGasLimit maximum number of the L2 gas that a user can request for L1 -> L2 transactions
/// @param feeParams Fee parameters to be used for L1->L2 transactions
/// @param blobVersionedHashRetriever Address of contract used to pull the blob versioned hash for a transaction.
Expand All @@ -36,7 +37,7 @@ struct InitializeData {
VerifierParams verifierParams;
bytes32 l2BootloaderBytecodeHash;
bytes32 l2DefaultAccountBytecodeHash;
bytes32 l2EvmSimulatorBytecodeHash;
bytes32 l2EvmEmulatorBytecodeHash;
uint256 priorityTxMaxGasLimit;
FeeParams feeParams;
address blobVersionedHashRetriever;
Expand All @@ -46,6 +47,7 @@ struct InitializeData {
/// @param verifierParams Verifier config parameters that describes the circuit to be verified
/// @param l2BootloaderBytecodeHash The hash of bootloader L2 bytecode
/// @param l2DefaultAccountBytecodeHash The hash of default account L2 bytecode
/// @param l2EvmEmulatorBytecodeHash The hash of EVM emulator L2 bytecode
/// @param priorityTxMaxGasLimit maximum number of the L2 gas that a user can request for L1 -> L2 transactions
/// @param feeParams Fee parameters to be used for L1->L2 transactions
/// @param blobVersionedHashRetriever Address of contract used to pull the blob versioned hash for a transaction.
Expand All @@ -54,7 +56,7 @@ struct InitializeDataNewChain {
VerifierParams verifierParams;
bytes32 l2BootloaderBytecodeHash;
bytes32 l2DefaultAccountBytecodeHash;
bytes32 l2EvmSimulatorBytecodeHash;
bytes32 l2EvmEmulatorBytecodeHash;
uint256 priorityTxMaxGasLimit;
FeeParams feeParams;
address blobVersionedHashRetriever;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ 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 Bytecode hash of EVM emulator.
function getL2EvmEmulatorBytecodeHash() external view returns (bytes32);

/// @return Verifier parameters.
/// @dev This function is deprecated and will soon be removed.
Expand Down
30 changes: 16 additions & 14 deletions l1-contracts/contracts/upgrades/BaseZkSyncUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ProposedUpgrade {
bytes[] factoryDeps;
bytes32 bootloaderHash;
bytes32 defaultAccountHash;
bytes32 evmSimulatorHash;
bytes32 evmEmulatorHash;
address verifier;
VerifierParams verifierParams;
bytes l1ContractsUpgradeCalldata;
Expand All @@ -57,7 +57,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 Сhanges to the bytecode that is used in L2 as an EVM emulator
event NewL2EvmEmulatorBytecodeHash(bytes32 indexed previousBytecodeHash, bytes32 indexed newBytecodeHash);

/// @notice Verifier address changed
event NewVerifier(address indexed oldVerifier, address indexed newVerifier);
Expand Down Expand Up @@ -87,7 +88,7 @@ abstract contract BaseZkSyncUpgrade is ZkSyncHyperchainBase {
_setBaseSystemContracts(
_proposedUpgrade.bootloaderHash,
_proposedUpgrade.defaultAccountHash,
_proposedUpgrade.evmSimulatorHash,
_proposedUpgrade.evmEmulatorHash,
isPatchOnly
);

Expand Down Expand Up @@ -125,24 +126,24 @@ 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
/// @notice Change EVM emulator bytecode hash, that is used on L2
/// @param _l2EvmEmulatorBytecodeHash The hash of EVM emulator 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)) {
function _setL2EvmEmulatorBytecodeHash(bytes32 _l2EvmEmulatorBytecodeHash, bool _patchOnly) private {
if (_l2EvmEmulatorBytecodeHash == bytes32(0)) {
return;
}

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

L2ContractHelper.validateBytecodeHash(_l2EvmSimulatorBytecodeHash);
L2ContractHelper.validateBytecodeHash(_l2EvmEmulatorBytecodeHash);

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

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

/// @notice Change bootloader bytecode hash, that is used on L2
Expand Down Expand Up @@ -214,16 +215,17 @@ abstract contract BaseZkSyncUpgrade is ZkSyncHyperchainBase {
/// @notice Updates the bootloader hash and the hash of the default account
/// @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 _evmEmulatorHash The hash of the new EVM emulator 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,
bytes32 _evmSimulatorHash,
bytes32 _evmEmulatorHash,
bool _patchOnly
) internal {
_setL2BootloaderBytecodeHash(_bootloaderHash, _patchOnly);
_setL2DefaultAccountBytecodeHash(_defaultAccountHash, _patchOnly);
_setL2EvmSimulatorBytecodeHash(_evmSimulatorHash, _patchOnly);
_setL2EvmEmulatorBytecodeHash(_evmEmulatorHash, _patchOnly);
}

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

struct TokensConfig {
Expand Down Expand Up @@ -443,7 +443,7 @@ contract DeployL1Script is Script {
verifierParams: verifierParams,
l2BootloaderBytecodeHash: config.contracts.bootloaderHash,
l2DefaultAccountBytecodeHash: config.contracts.defaultAAHash,
l2EvmSimulatorBytecodeHash: config.contracts.evmSimulatorHash,
l2EvmEmulatorBytecodeHash: config.contracts.evmEmulatorHash,
priorityTxMaxGasLimit: config.contracts.priorityTxMaxGasLimit,
feeParams: feeParams,
blobVersionedHashRetriever: addresses.blobVersionedHashRetriever
Expand Down
8 changes: 4 additions & 4 deletions l1-contracts/scripts/upgrade-consistency-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const expectedRecursionLeafLevelVkHash = "0xf9664f4324c1400fa5c3822d667f30e873f5
const expectedRecursionCircuitsSetVksHash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const expectedBootloaderHash = "0x010008e7894d0dd14681c76bdb4d5e4e7f6b51bfe40c957d50eed3fec829fdb0";
const expectedDefaultAccountHash = "0x0100058deb36e1f2eeb48bf3846d0e8eb38e9176754b73116bb41a472459a4dd";
const expectedEvmSimulatorHash = "0x01000f197081a9906cc411d0698c4961aeb5c74877f37f7071681da6e8ef3f31";
const expectedEvmEmulatorHash = "0x01000f197081a9906cc411d0698c4961aeb5c74877f37f7071681da6e8ef3f31";

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

// // We unpack fee params
Expand Down Expand Up @@ -279,8 +279,8 @@ 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");
if (l2EvmEmulatorBytecodeHash.toLowerCase() !== expectedEvmEmulatorHash.toLowerCase()) {
throw new Error("L2 EVM emulator bytecode hash is not correct");
}

console.log("STM init data correct!");
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export function readSystemContractsBytecode(fileName: string) {
return JSON.parse(artifact.toString()).bytecode;
}

export function readEvmSimulatorbytecode() {
export function readEvmEmulatorbytecode() {
const systemContractsPath = path.join(process.env.ZKSYNC_HOME as string, "contracts/system-contracts");
return fs.readFileSync(`${systemContractsPath}/contracts-preprocessed/artifacts/EvmInterpreter.yul.zbin`);
return fs.readFileSync(`${systemContractsPath}/contracts-preprocessed/artifacts/EvmEmulator.yul.zbin`);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src.ts/deploy-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ADDRESS_ONE } from "../src.ts/utils";

export const L2_BOOTLOADER_BYTECODE_HASH = "0x1000100000000000000000000000000000000000000000000000000000000000";
export const L2_DEFAULT_ACCOUNT_BYTECODE_HASH = "0x1001000000000000000000000000000000000000000000000000000000000000";
export const L2_EVM_SIMULATOR_BYTECODE_HASH = "0x1010000000000000000000000000000000000000000000000000000000000000";
export const L2_EVM_EMULATOR_BYTECODE_HASH = "0x1010000000000000000000000000000000000000000000000000000000000000";

export async function initialBridgehubDeployment(
deployer: Deployer,
Expand Down
8 changes: 4 additions & 4 deletions l1-contracts/src.ts/deploy-test-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Deployer } from "./deploy";
import {
L2_BOOTLOADER_BYTECODE_HASH,
L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
L2_EVM_SIMULATOR_BYTECODE_HASH,
L2_EVM_EMULATOR_BYTECODE_HASH,
initialBridgehubDeployment,
registerHyperchain,
} from "./deploy-process";
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function defaultDeployerForTests(deployWallet: Wallet, ownerAddress
addresses: addressConfig,
bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH,
defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
evmSimulatorBytecodeHash: L2_EVM_SIMULATOR_BYTECODE_HASH,
evmEmulatorBytecodeHash: L2_EVM_EMULATOR_BYTECODE_HASH,
});
}

Expand All @@ -78,7 +78,7 @@ export async function defaultEraDeployerForTests(deployWallet: Wallet, ownerAddr
addresses: addressConfig,
bootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH,
defaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
evmSimulatorBytecodeHash: L2_EVM_SIMULATOR_BYTECODE_HASH,
evmEmulatorBytecodeHash: L2_EVM_EMULATOR_BYTECODE_HASH,
});
const l2_rpc_addr = "http://localhost:3050";
const web3Provider = new zkethers.Provider(l2_rpc_addr);
Expand Down Expand Up @@ -318,7 +318,7 @@ export class EraDeployer extends Deployer {
verifierParams,
l2BootloaderBytecodeHash: L2_BOOTLOADER_BYTECODE_HASH,
l2DefaultAccountBytecodeHash: L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
l2EvmSimulatorBytecodeHash: L2_EVM_SIMULATOR_BYTECODE_HASH,
l2EvmEmulatorBytecodeHash: L2_EVM_EMULATOR_BYTECODE_HASH,
priorityTxMaxGasLimit,
feeParams,
blobVersionedHashRetriever: this.addresses.BlobVersionedHashRetriever,
Expand Down
14 changes: 7 additions & 7 deletions l1-contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
packSemver,
readBatchBootloaderBytecode,
readSystemContractsBytecode,
readEvmSimulatorbytecode,
readEvmEmulatorbytecode,
unpackStringSemVer,
} from "../scripts/utils";
import { getTokens } from "./deploy-token";
Expand Down Expand Up @@ -44,7 +44,7 @@ import type { Contract, Overrides } from "@ethersproject/contracts";

let L2_BOOTLOADER_BYTECODE_HASH: string;
let L2_DEFAULT_ACCOUNT_BYTECODE_HASH: string;
let L2_EVM_SIMULATOR_BYTECODE_HASH: string;
let L2_EVM_EMULATOR_BYTECODE_HASH: string;

export interface DeployerConfig {
deployWallet: Wallet;
Expand All @@ -53,7 +53,7 @@ export interface DeployerConfig {
verbose?: boolean;
bootloaderBytecodeHash?: string;
defaultAccountBytecodeHash?: string;
evmSimulatorBytecodeHash?: string;
evmEmulatorBytecodeHash?: string;
}

export interface Operation {
Expand Down Expand Up @@ -81,9 +81,9 @@ export class Deployer {
L2_DEFAULT_ACCOUNT_BYTECODE_HASH = config.defaultAccountBytecodeHash
? config.defaultAccountBytecodeHash
: hexlify(hashL2Bytecode(readSystemContractsBytecode("DefaultAccount")));
L2_EVM_SIMULATOR_BYTECODE_HASH = config.evmSimulatorBytecodeHash
? config.evmSimulatorBytecodeHash
: hexlify(hashL2Bytecode(readEvmSimulatorbytecode()));
L2_EVM_EMULATOR_BYTECODE_HASH = config.evmEmulatorBytecodeHash
? config.evmEmulatorBytecodeHash
: hexlify(hashL2Bytecode(readEvmEmulatorbytecode()));
this.ownerAddress = config.ownerAddress != null ? config.ownerAddress : this.deployWallet.address;
this.chainId = parseInt(process.env.CHAIN_ETH_ZKSYNC_NETWORK_ID!);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ export class Deployer {
verifierParams,
L2_BOOTLOADER_BYTECODE_HASH,
L2_DEFAULT_ACCOUNT_BYTECODE_HASH,
L2_EVM_SIMULATOR_BYTECODE_HASH,
L2_EVM_EMULATOR_BYTECODE_HASH,
this.addresses.StateTransition.Verifier,
this.addresses.BlobVersionedHashRetriever,
+priorityTxMaxGasLimit,
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src.ts/diamondCut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface InitializeData {
allowList: BigNumberish;
l2BootloaderBytecodeHash: string;
l2DefaultAccountBytecodeHash: string;
l2EvmSimulatorBytecodeHash: string;
l2EvmEmulatorBytecodeHash: string;
priorityTxMaxGasLimit: BigNumberish;
}

Expand Down
Loading

0 comments on commit c4eaf04

Please sign in to comment.