-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new EVM enable flow to zkstack_cli
- Loading branch information
1 parent
b9d60f5
commit 93e8e2a
Showing
8 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
zkstack_cli/crates/config/src/forge_interface/enable_evm_emulator/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use ethers::types::Address; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::traits::ZkStackConfig; | ||
|
||
impl ZkStackConfig for EnableEvmEmulatorInput {} | ||
|
||
#[derive(Debug, Deserialize, Serialize, Clone)] | ||
pub struct EnableEvmEmulatorInput { | ||
pub target_addr: Address, | ||
pub governor: Address, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
zkstack_cli/crates/zkstack/src/commands/chain/enable_evm_emulator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::Context; | ||
use common::{forge::ForgeScriptArgs, logger, spinner::Spinner}; | ||
use config::EcosystemConfig; | ||
use xshell::Shell; | ||
|
||
use crate::{ | ||
enable_evm_emulator::enable_evm_emulator, | ||
messages::{ | ||
MSG_ENABLING_EVM_EMULATOR, MSG_CHAIN_NOT_INITIALIZED, MSG_EVM_EMULATOR_ENABLED, | ||
MSG_L1_SECRETS_MUST_BE_PRESENTED, | ||
}, | ||
}; | ||
|
||
pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { | ||
let ecosystem_config = EcosystemConfig::from_file(shell)?; | ||
let chain_config = ecosystem_config | ||
.load_current_chain() | ||
.context(MSG_CHAIN_NOT_INITIALIZED)?; | ||
let contracts = chain_config.get_contracts_config()?; | ||
let secrets = chain_config.get_secrets_config()?; | ||
let l1_rpc_url = secrets | ||
.l1 | ||
.context(MSG_L1_SECRETS_MUST_BE_PRESENTED)? | ||
.l1_rpc_url | ||
.expose_str() | ||
.to_string(); | ||
|
||
enable_evm_emulator( | ||
shell, | ||
&ecosystem_config, | ||
contracts.l1.chain_admin_addr, | ||
&chain_config.get_wallets_config()?.governor, | ||
contracts.l1.diamond_proxy_addr, | ||
&args, | ||
l1_rpc_url.clone(), | ||
) | ||
.await?; | ||
logger::success(MSG_EVM_EMULATOR_ENABLED); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use common::{ | ||
forge::{Forge, ForgeScript, ForgeScriptArgs}, | ||
spinner::Spinner, | ||
wallets::Wallet, | ||
}; | ||
use config::{forge_interface::script_params::ENABLE_EVM_EMULATOR_PARAMS, EcosystemConfig}; | ||
use ethers::{abi::parse_abi, contract::BaseContract, types::Address}; | ||
use lazy_static::lazy_static; | ||
use xshell::Shell; | ||
|
||
use crate::{ | ||
messages::MSG_ENABLING_EVM_EMULATOR, | ||
utils::forge::{check_the_balance, fill_forge_private_key, WalletOwner}, | ||
}; | ||
|
||
lazy_static! { | ||
static ref ENABLE_EVM_EMULATOR: BaseContract = BaseContract::from( | ||
parse_abi(&[ | ||
"function chainAllowEvmEmulation(address chainAdmin, address target) public", | ||
]) | ||
.unwrap(), | ||
); | ||
} | ||
|
||
pub async fn enable_evm_emulator( | ||
shell: &Shell, | ||
ecosystem_config: &EcosystemConfig, | ||
admin: Address, | ||
governor: &Wallet, | ||
target_address: Address, | ||
forge_args: &ForgeScriptArgs, | ||
l1_rpc_url: String, | ||
) -> anyhow::Result<()> { | ||
// Resume for accept admin doesn't work properly. Foundry assumes that if signature of the function is the same, | ||
// than it's the same call, but because we are calling this function multiple times during the init process, | ||
// code assumes that doing only once is enough, but actually we need to accept admin multiple times | ||
let mut forge_args = forge_args.clone(); | ||
forge_args.resume = false; | ||
|
||
let calldata = ENABLE_EVM_EMULATOR | ||
.encode("chainAllowEvmEmulation", (admin, target_address)) | ||
.unwrap(); | ||
let foundry_contracts_path = ecosystem_config.path_to_foundry(); | ||
let forge = Forge::new(&foundry_contracts_path) | ||
.script( | ||
&ENABLE_EVM_EMULATOR_PARAMS.script(), | ||
forge_args.clone(), | ||
) | ||
.with_ffi() | ||
.with_rpc_url(l1_rpc_url) | ||
.with_broadcast() | ||
.with_calldata(&calldata); | ||
enable_evm_inner(shell, governor, forge).await | ||
} | ||
|
||
async fn enable_evm_inner( | ||
shell: &Shell, | ||
governor: &Wallet, | ||
mut forge: ForgeScript, | ||
) -> anyhow::Result<()> { | ||
forge = fill_forge_private_key(forge, Some(governor), WalletOwner::Governor)?; | ||
check_the_balance(&forge).await?; | ||
let spinner = Spinner::new(MSG_ENABLING_EVM_EMULATOR); | ||
forge.run(shell)?; | ||
spinner.finish(); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters