Skip to content

Commit e4848c5

Browse files
authored
feat: Update EVM emulator feature in zkstack and zk (#3397)
## 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`.
1 parent 5a1e6d2 commit e4848c5

File tree

14 files changed

+316
-41
lines changed

14 files changed

+316
-41
lines changed

infrastructure/zk/src/contract.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ export async function erc20BridgeFinish(args: any[] = []): Promise<void> {
216216

217217
export async function registerHyperchain({
218218
baseTokenName,
219-
deploymentMode
219+
deploymentMode,
220+
allowEvmEmulator
220221
}: {
221222
baseTokenName?: string;
222223
deploymentMode?: DeploymentMode;
224+
allowEvmEmulator?: boolean;
223225
}): Promise<void> {
224226
await utils.confirmAction();
225227

@@ -241,7 +243,8 @@ export async function registerHyperchain({
241243
privateKey ? `--private-key ${privateKey}` : '',
242244
baseTokenName ? `--base-token-name ${baseTokenName}` : '',
243245
deploymentMode == DeploymentMode.Validium ? '--validium-mode' : '',
244-
tokenMultiplierSetterAddress ? `--token-multiplier-setter-address ${tokenMultiplierSetterAddress}` : ''
246+
tokenMultiplierSetterAddress ? `--token-multiplier-setter-address ${tokenMultiplierSetterAddress}` : '',
247+
allowEvmEmulator ? '--allow-evm-emulation' : ''
245248
];
246249
await utils.spawn(`yarn l1-contracts register-hyperchain ${args.join(' ')} | tee registerHyperchain.log`);
247250
const deployLog = fs.readFileSync('registerHyperchain.log').toString();

infrastructure/zk/src/init.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,19 @@ type InitHyperchainOptions = {
106106
baseTokenName?: string;
107107
localLegacyBridgeTesting?: boolean;
108108
deploymentMode: DeploymentMode;
109+
allowEvmEmulator?: boolean;
109110
};
110111
const initHyperchain = async ({
111112
includePaymaster,
112113
baseTokenName,
113114
localLegacyBridgeTesting,
114-
deploymentMode
115+
deploymentMode,
116+
allowEvmEmulator
115117
}: InitHyperchainOptions): Promise<void> => {
116-
await announced('Registering Hyperchain', contract.registerHyperchain({ baseTokenName, deploymentMode }));
118+
await announced(
119+
'Registering Hyperchain',
120+
contract.registerHyperchain({ baseTokenName, deploymentMode, allowEvmEmulator })
121+
);
117122
await announced('Reloading env', env.reload());
118123
await announced('Running server genesis setup', server.genesisFromSources());
119124
await announced(
@@ -146,6 +151,7 @@ type InitDevCmdActionOptions = InitSetupOptions & {
146151
validiumMode?: boolean;
147152
localLegacyBridgeTesting?: boolean;
148153
shouldCheckPostgres: boolean; // Whether to perform `cargo sqlx prepare --check`
154+
allowEvmEmulator?: boolean;
149155
};
150156
export const initDevCmdAction = async ({
151157
skipEnvSetup,
@@ -157,7 +163,8 @@ export const initDevCmdAction = async ({
157163
runObservability,
158164
validiumMode,
159165
localLegacyBridgeTesting,
160-
shouldCheckPostgres
166+
shouldCheckPostgres,
167+
allowEvmEmulator
161168
}: InitDevCmdActionOptions): Promise<void> => {
162169
if (localLegacyBridgeTesting) {
163170
await makeEraChainIdSameAsCurrent();
@@ -181,7 +188,8 @@ export const initDevCmdAction = async ({
181188
includePaymaster: true,
182189
baseTokenName,
183190
localLegacyBridgeTesting,
184-
deploymentMode
191+
deploymentMode,
192+
allowEvmEmulator
185193
});
186194
if (localLegacyBridgeTesting) {
187195
await makeEraAddressSameAsCurrent();
@@ -214,13 +222,15 @@ type InitHyperCmdActionOptions = {
214222
baseTokenName?: string;
215223
runObservability: boolean;
216224
deploymentMode: DeploymentMode;
225+
allowEvmEmulator?: boolean;
217226
};
218227
export const initHyperCmdAction = async ({
219228
skipSetupCompletely,
220229
bumpChainId,
221230
baseTokenName,
222231
runObservability,
223-
deploymentMode
232+
deploymentMode,
233+
allowEvmEmulator
224234
}: InitHyperCmdActionOptions): Promise<void> => {
225235
if (bumpChainId) {
226236
config.bumpChainId();
@@ -237,7 +247,8 @@ export const initHyperCmdAction = async ({
237247
await initHyperchain({
238248
includePaymaster: true,
239249
baseTokenName,
240-
deploymentMode
250+
deploymentMode,
251+
allowEvmEmulator
241252
});
242253
};
243254

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

@@ -278,4 +290,5 @@ initCommand
278290
.option('--base-token-name <base-token-name>', 'base token name')
279291
.option('--validium-mode', 'deploy contracts in Validium mode')
280292
.option('--run-observability', 'run observability suite')
293+
.option('--allow-evm-emulator', 'allow deployment of EVM contracts (not supported yet)')
281294
.action(initHyperCmdAction);

zkstack_cli/crates/config/src/forge_interface/register_chain/input.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct ChainL1Config {
4848
pub base_token_gas_price_multiplier_denominator: u64,
4949
pub governance_security_council_address: Address,
5050
pub governance_min_delay: u64,
51+
pub allow_evm_emulator: bool,
5152
}
5253

5354
impl ZkStackConfig for RegisterChainL1Config {}
@@ -84,6 +85,7 @@ impl RegisterChainL1Config {
8485
== L1BatchCommitmentMode::Validium,
8586
validator_sender_operator_commit_eth: wallets_config.operator.address,
8687
validator_sender_operator_blobs_eth: wallets_config.blob_operator.address,
88+
allow_evm_emulator: chain_config.evm_emulator,
8789
},
8890
owner_address: wallets_config.governor.address,
8991
})

zkstack_cli/crates/config/src/forge_interface/script_params.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ pub const SETUP_LEGACY_BRIDGE: ForgeScriptParams = ForgeScriptParams {
6767
output: "script-out/setup-legacy-bridge.toml",
6868
script_path: "deploy-scripts/dev/SetupLegacyBridge.s.sol",
6969
};
70+
71+
pub const ENABLE_EVM_EMULATOR_PARAMS: ForgeScriptParams = ForgeScriptParams {
72+
input: "script-config/enable-evm-emulator.toml",
73+
output: "script-out/output-enable-evm-emulator.toml",
74+
script_path: "deploy-scripts/EnableEvmEmulator.s.sol",
75+
};

zkstack_cli/crates/config/src/genesis.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::path::Path;
22

3-
use anyhow::Context as _;
43
use xshell::Shell;
54
use zksync_basic_types::L1ChainId;
65
pub use zksync_config::GenesisConfig;
@@ -20,14 +19,6 @@ pub fn update_from_chain_config(
2019
// TODO(EVM-676): for now, the settlement layer is always the same as the L1 network
2120
genesis.l1_chain_id = L1ChainId(config.l1_network.chain_id());
2221
genesis.l1_batch_commit_data_generator_mode = config.l1_batch_commit_data_generator_mode;
23-
genesis.evm_emulator_hash = if config.evm_emulator {
24-
Some(genesis.evm_emulator_hash.context(
25-
"impossible to initialize a chain with EVM emulator: the template genesis config \
26-
does not contain EVM emulator hash",
27-
)?)
28-
} else {
29-
None
30-
};
3122
Ok(())
3223
}
3324

zkstack_cli/crates/zkstack/completion/_zkstack.zsh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,23 @@ _arguments "${_arguments_options[@]}" : \
603603
'--help[Print help (see more with '\''--help'\'')]' \
604604
&& ret=0
605605
;;
606+
(enable-evm-emulator)
607+
_arguments "${_arguments_options[@]}" : \
608+
'--verify=[Verify deployed contracts]' \
609+
'--verifier=[Verifier to use]:VERIFIER:(etherscan sourcify blockscout oklink)' \
610+
'--verifier-url=[Verifier URL, if using a custom provider]:VERIFIER_URL:_default' \
611+
'--verifier-api-key=[Verifier API key]:VERIFIER_API_KEY:_default' \
612+
'*-a+[List of additional arguments that can be passed through the CLI]:ADDITIONAL_ARGS:_default' \
613+
'*--additional-args=[List of additional arguments that can be passed through the CLI]:ADDITIONAL_ARGS:_default' \
614+
'--chain=[Chain to use]:CHAIN:_default' \
615+
'--resume[]' \
616+
'-v[Verbose mode]' \
617+
'--verbose[Verbose mode]' \
618+
'--ignore-prerequisites[Ignores prerequisites checks]' \
619+
'-h[Print help (see more with '\''--help'\'')]' \
620+
'--help[Print help (see more with '\''--help'\'')]' \
621+
&& ret=0
622+
;;
606623
(help)
607624
_arguments "${_arguments_options[@]}" : \
608625
":: :_zkstack__chain__help_commands" \
@@ -707,6 +724,10 @@ _arguments "${_arguments_options[@]}" : \
707724
_arguments "${_arguments_options[@]}" : \
708725
&& ret=0
709726
;;
727+
(enable-evm-emulator)
728+
_arguments "${_arguments_options[@]}" : \
729+
&& ret=0
730+
;;
710731
(help)
711732
_arguments "${_arguments_options[@]}" : \
712733
&& ret=0
@@ -2705,6 +2726,10 @@ _arguments "${_arguments_options[@]}" : \
27052726
(update-token-multiplier-setter)
27062727
_arguments "${_arguments_options[@]}" : \
27072728
&& ret=0
2729+
;;
2730+
(enable-evm-emulator)
2731+
_arguments "${_arguments_options[@]}" : \
2732+
&& ret=0
27082733
;;
27092734
esac
27102735
;;
@@ -3234,6 +3259,7 @@ _zkstack__chain_commands() {
32343259
'deploy-upgrader:Deploy Default Upgrader' \
32353260
'deploy-paymaster:Deploy paymaster smart contract' \
32363261
'update-token-multiplier-setter:Update Token Multiplier Setter address on L1' \
3262+
'enable-evm-emulator:Enable EVM emulation on chain (Not supported yet)' \
32373263
'help:Print this message or the help of the given subcommand(s)' \
32383264
)
32393265
_describe -t commands 'zkstack chain commands' commands "$@"
@@ -3283,6 +3309,11 @@ _zkstack__chain__deploy-upgrader_commands() {
32833309
local commands; commands=()
32843310
_describe -t commands 'zkstack chain deploy-upgrader commands' commands "$@"
32853311
}
3312+
(( $+functions[_zkstack__chain__enable-evm-emulator_commands] )) ||
3313+
_zkstack__chain__enable-evm-emulator_commands() {
3314+
local commands; commands=()
3315+
_describe -t commands 'zkstack chain enable-evm-emulator commands' commands "$@"
3316+
}
32863317
(( $+functions[_zkstack__chain__genesis_commands] )) ||
32873318
_zkstack__chain__genesis_commands() {
32883319
local commands; commands=(
@@ -3343,6 +3374,7 @@ _zkstack__chain__help_commands() {
33433374
'deploy-upgrader:Deploy Default Upgrader' \
33443375
'deploy-paymaster:Deploy paymaster smart contract' \
33453376
'update-token-multiplier-setter:Update Token Multiplier Setter address on L1' \
3377+
'enable-evm-emulator:Enable EVM emulation on chain (Not supported yet)' \
33463378
'help:Print this message or the help of the given subcommand(s)' \
33473379
)
33483380
_describe -t commands 'zkstack chain help commands' commands "$@"
@@ -3392,6 +3424,11 @@ _zkstack__chain__help__deploy-upgrader_commands() {
33923424
local commands; commands=()
33933425
_describe -t commands 'zkstack chain help deploy-upgrader commands' commands "$@"
33943426
}
3427+
(( $+functions[_zkstack__chain__help__enable-evm-emulator_commands] )) ||
3428+
_zkstack__chain__help__enable-evm-emulator_commands() {
3429+
local commands; commands=()
3430+
_describe -t commands 'zkstack chain help enable-evm-emulator commands' commands "$@"
3431+
}
33953432
(( $+functions[_zkstack__chain__help__genesis_commands] )) ||
33963433
_zkstack__chain__help__genesis_commands() {
33973434
local commands; commands=(
@@ -4661,6 +4698,7 @@ _zkstack__help__chain_commands() {
46614698
'deploy-upgrader:Deploy Default Upgrader' \
46624699
'deploy-paymaster:Deploy paymaster smart contract' \
46634700
'update-token-multiplier-setter:Update Token Multiplier Setter address on L1' \
4701+
'enable-evm-emulator:Enable EVM emulation on chain (Not supported yet)' \
46644702
)
46654703
_describe -t commands 'zkstack help chain commands' commands "$@"
46664704
}
@@ -4709,6 +4747,11 @@ _zkstack__help__chain__deploy-upgrader_commands() {
47094747
local commands; commands=()
47104748
_describe -t commands 'zkstack help chain deploy-upgrader commands' commands "$@"
47114749
}
4750+
(( $+functions[_zkstack__help__chain__enable-evm-emulator_commands] )) ||
4751+
_zkstack__help__chain__enable-evm-emulator_commands() {
4752+
local commands; commands=()
4753+
_describe -t commands 'zkstack help chain enable-evm-emulator commands' commands "$@"
4754+
}
47124755
(( $+functions[_zkstack__help__chain__genesis_commands] )) ||
47134756
_zkstack__help__chain__genesis_commands() {
47144757
local commands; commands=(

0 commit comments

Comments
 (0)