Skip to content

Commit

Permalink
feat: Update EVM emulator feature in zkstack and zk (#3397)
Browse files Browse the repository at this point in the history
## What ❔

Following the latest changes to the EVM emulator contracts, the process
for enabling the EVM emulator has changed.

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [X] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [X] Documentation comments have been added / updated.
- [X] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
0xVolosnikov authored Dec 19, 2024
1 parent 5a1e6d2 commit e4848c5
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 41 deletions.
7 changes: 5 additions & 2 deletions infrastructure/zk/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ export async function erc20BridgeFinish(args: any[] = []): Promise<void> {

export async function registerHyperchain({
baseTokenName,
deploymentMode
deploymentMode,
allowEvmEmulator
}: {
baseTokenName?: string;
deploymentMode?: DeploymentMode;
allowEvmEmulator?: boolean;
}): Promise<void> {
await utils.confirmAction();

Expand All @@ -241,7 +243,8 @@ export async function registerHyperchain({
privateKey ? `--private-key ${privateKey}` : '',
baseTokenName ? `--base-token-name ${baseTokenName}` : '',
deploymentMode == DeploymentMode.Validium ? '--validium-mode' : '',
tokenMultiplierSetterAddress ? `--token-multiplier-setter-address ${tokenMultiplierSetterAddress}` : ''
tokenMultiplierSetterAddress ? `--token-multiplier-setter-address ${tokenMultiplierSetterAddress}` : '',
allowEvmEmulator ? '--allow-evm-emulation' : ''
];
await utils.spawn(`yarn l1-contracts register-hyperchain ${args.join(' ')} | tee registerHyperchain.log`);
const deployLog = fs.readFileSync('registerHyperchain.log').toString();
Expand Down
25 changes: 19 additions & 6 deletions infrastructure/zk/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,19 @@ type InitHyperchainOptions = {
baseTokenName?: string;
localLegacyBridgeTesting?: boolean;
deploymentMode: DeploymentMode;
allowEvmEmulator?: boolean;
};
const initHyperchain = async ({
includePaymaster,
baseTokenName,
localLegacyBridgeTesting,
deploymentMode
deploymentMode,
allowEvmEmulator
}: InitHyperchainOptions): Promise<void> => {
await announced('Registering Hyperchain', contract.registerHyperchain({ baseTokenName, deploymentMode }));
await announced(
'Registering Hyperchain',
contract.registerHyperchain({ baseTokenName, deploymentMode, allowEvmEmulator })
);
await announced('Reloading env', env.reload());
await announced('Running server genesis setup', server.genesisFromSources());
await announced(
Expand Down Expand Up @@ -146,6 +151,7 @@ type InitDevCmdActionOptions = InitSetupOptions & {
validiumMode?: boolean;
localLegacyBridgeTesting?: boolean;
shouldCheckPostgres: boolean; // Whether to perform `cargo sqlx prepare --check`
allowEvmEmulator?: boolean;
};
export const initDevCmdAction = async ({
skipEnvSetup,
Expand All @@ -157,7 +163,8 @@ export const initDevCmdAction = async ({
runObservability,
validiumMode,
localLegacyBridgeTesting,
shouldCheckPostgres
shouldCheckPostgres,
allowEvmEmulator
}: InitDevCmdActionOptions): Promise<void> => {
if (localLegacyBridgeTesting) {
await makeEraChainIdSameAsCurrent();
Expand All @@ -181,7 +188,8 @@ export const initDevCmdAction = async ({
includePaymaster: true,
baseTokenName,
localLegacyBridgeTesting,
deploymentMode
deploymentMode,
allowEvmEmulator
});
if (localLegacyBridgeTesting) {
await makeEraAddressSameAsCurrent();
Expand Down Expand Up @@ -214,13 +222,15 @@ type InitHyperCmdActionOptions = {
baseTokenName?: string;
runObservability: boolean;
deploymentMode: DeploymentMode;
allowEvmEmulator?: boolean;
};
export const initHyperCmdAction = async ({
skipSetupCompletely,
bumpChainId,
baseTokenName,
runObservability,
deploymentMode
deploymentMode,
allowEvmEmulator
}: InitHyperCmdActionOptions): Promise<void> => {
if (bumpChainId) {
config.bumpChainId();
Expand All @@ -237,7 +247,8 @@ export const initHyperCmdAction = async ({
await initHyperchain({
includePaymaster: true,
baseTokenName,
deploymentMode
deploymentMode,
allowEvmEmulator
});
};

Expand All @@ -254,6 +265,7 @@ export const initCommand = new Command('init')
'used to test LegacyBridge compatibily. The chain will have the same id as the era chain id, while eraChainId in L2SharedBridge will be 0'
)
.option('--should-check-postgres', 'Whether to perform cargo sqlx prepare --check during database setup', true)
.option('--allow-evm-emulator', 'allow deployment of EVM contracts (not supported yet)')
.description('Deploys the shared bridge and registers a hyperchain locally, as quickly as possible.')
.action(initDevCmdAction);

Expand All @@ -278,4 +290,5 @@ initCommand
.option('--base-token-name <base-token-name>', 'base token name')
.option('--validium-mode', 'deploy contracts in Validium mode')
.option('--run-observability', 'run observability suite')
.option('--allow-evm-emulator', 'allow deployment of EVM contracts (not supported yet)')
.action(initHyperCmdAction);
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct ChainL1Config {
pub base_token_gas_price_multiplier_denominator: u64,
pub governance_security_council_address: Address,
pub governance_min_delay: u64,
pub allow_evm_emulator: bool,
}

impl ZkStackConfig for RegisterChainL1Config {}
Expand Down Expand Up @@ -84,6 +85,7 @@ impl RegisterChainL1Config {
== L1BatchCommitmentMode::Validium,
validator_sender_operator_commit_eth: wallets_config.operator.address,
validator_sender_operator_blobs_eth: wallets_config.blob_operator.address,
allow_evm_emulator: chain_config.evm_emulator,
},
owner_address: wallets_config.governor.address,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ pub const SETUP_LEGACY_BRIDGE: ForgeScriptParams = ForgeScriptParams {
output: "script-out/setup-legacy-bridge.toml",
script_path: "deploy-scripts/dev/SetupLegacyBridge.s.sol",
};

pub const ENABLE_EVM_EMULATOR_PARAMS: ForgeScriptParams = ForgeScriptParams {
input: "script-config/enable-evm-emulator.toml",
output: "script-out/output-enable-evm-emulator.toml",
script_path: "deploy-scripts/EnableEvmEmulator.s.sol",
};
9 changes: 0 additions & 9 deletions zkstack_cli/crates/config/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::path::Path;

use anyhow::Context as _;
use xshell::Shell;
use zksync_basic_types::L1ChainId;
pub use zksync_config::GenesisConfig;
Expand All @@ -20,14 +19,6 @@ pub fn update_from_chain_config(
// TODO(EVM-676): for now, the settlement layer is always the same as the L1 network
genesis.l1_chain_id = L1ChainId(config.l1_network.chain_id());
genesis.l1_batch_commit_data_generator_mode = config.l1_batch_commit_data_generator_mode;
genesis.evm_emulator_hash = if config.evm_emulator {
Some(genesis.evm_emulator_hash.context(
"impossible to initialize a chain with EVM emulator: the template genesis config \
does not contain EVM emulator hash",
)?)
} else {
None
};
Ok(())
}

Expand Down
43 changes: 43 additions & 0 deletions zkstack_cli/crates/zkstack/completion/_zkstack.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,23 @@ _arguments "${_arguments_options[@]}" : \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(enable-evm-emulator)
_arguments "${_arguments_options[@]}" : \
'--verify=[Verify deployed contracts]' \
'--verifier=[Verifier to use]:VERIFIER:(etherscan sourcify blockscout oklink)' \
'--verifier-url=[Verifier URL, if using a custom provider]:VERIFIER_URL:_default' \
'--verifier-api-key=[Verifier API key]:VERIFIER_API_KEY:_default' \
'*-a+[List of additional arguments that can be passed through the CLI]:ADDITIONAL_ARGS:_default' \
'*--additional-args=[List of additional arguments that can be passed through the CLI]:ADDITIONAL_ARGS:_default' \
'--chain=[Chain to use]:CHAIN:_default' \
'--resume[]' \
'-v[Verbose mode]' \
'--verbose[Verbose mode]' \
'--ignore-prerequisites[Ignores prerequisites checks]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_zkstack__chain__help_commands" \
Expand Down Expand Up @@ -707,6 +724,10 @@ _arguments "${_arguments_options[@]}" : \
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(enable-evm-emulator)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
Expand Down Expand Up @@ -2705,6 +2726,10 @@ _arguments "${_arguments_options[@]}" : \
(update-token-multiplier-setter)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(enable-evm-emulator)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
esac
;;
Expand Down Expand Up @@ -3234,6 +3259,7 @@ _zkstack__chain_commands() {
'deploy-upgrader:Deploy Default Upgrader' \
'deploy-paymaster:Deploy paymaster smart contract' \
'update-token-multiplier-setter:Update Token Multiplier Setter address on L1' \
'enable-evm-emulator:Enable EVM emulation on chain (Not supported yet)' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'zkstack chain commands' commands "$@"
Expand Down Expand Up @@ -3283,6 +3309,11 @@ _zkstack__chain__deploy-upgrader_commands() {
local commands; commands=()
_describe -t commands 'zkstack chain deploy-upgrader commands' commands "$@"
}
(( $+functions[_zkstack__chain__enable-evm-emulator_commands] )) ||
_zkstack__chain__enable-evm-emulator_commands() {
local commands; commands=()
_describe -t commands 'zkstack chain enable-evm-emulator commands' commands "$@"
}
(( $+functions[_zkstack__chain__genesis_commands] )) ||
_zkstack__chain__genesis_commands() {
local commands; commands=(
Expand Down Expand Up @@ -3343,6 +3374,7 @@ _zkstack__chain__help_commands() {
'deploy-upgrader:Deploy Default Upgrader' \
'deploy-paymaster:Deploy paymaster smart contract' \
'update-token-multiplier-setter:Update Token Multiplier Setter address on L1' \
'enable-evm-emulator:Enable EVM emulation on chain (Not supported yet)' \
'help:Print this message or the help of the given subcommand(s)' \
)
_describe -t commands 'zkstack chain help commands' commands "$@"
Expand Down Expand Up @@ -3392,6 +3424,11 @@ _zkstack__chain__help__deploy-upgrader_commands() {
local commands; commands=()
_describe -t commands 'zkstack chain help deploy-upgrader commands' commands "$@"
}
(( $+functions[_zkstack__chain__help__enable-evm-emulator_commands] )) ||
_zkstack__chain__help__enable-evm-emulator_commands() {
local commands; commands=()
_describe -t commands 'zkstack chain help enable-evm-emulator commands' commands "$@"
}
(( $+functions[_zkstack__chain__help__genesis_commands] )) ||
_zkstack__chain__help__genesis_commands() {
local commands; commands=(
Expand Down Expand Up @@ -4661,6 +4698,7 @@ _zkstack__help__chain_commands() {
'deploy-upgrader:Deploy Default Upgrader' \
'deploy-paymaster:Deploy paymaster smart contract' \
'update-token-multiplier-setter:Update Token Multiplier Setter address on L1' \
'enable-evm-emulator:Enable EVM emulation on chain (Not supported yet)' \
)
_describe -t commands 'zkstack help chain commands' commands "$@"
}
Expand Down Expand Up @@ -4709,6 +4747,11 @@ _zkstack__help__chain__deploy-upgrader_commands() {
local commands; commands=()
_describe -t commands 'zkstack help chain deploy-upgrader commands' commands "$@"
}
(( $+functions[_zkstack__help__chain__enable-evm-emulator_commands] )) ||
_zkstack__help__chain__enable-evm-emulator_commands() {
local commands; commands=()
_describe -t commands 'zkstack help chain enable-evm-emulator commands' commands "$@"
}
(( $+functions[_zkstack__help__chain__genesis_commands] )) ||
_zkstack__help__chain__genesis_commands() {
local commands; commands=(
Expand Down
Loading

0 comments on commit e4848c5

Please sign in to comment.