From 402a69f5def5d8de164a01fea5d78bd067f3aa60 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 11:30:12 +0200 Subject: [PATCH 01/89] feat: add `zki ecosystem build` (based on `zki ecosystem init`) --- .../src/commands/ecosystem/args/build.rs | 142 +++++++ .../src/commands/ecosystem/args/mod.rs | 1 + .../src/commands/ecosystem/build.rs | 352 ++++++++++++++++++ .../src/commands/ecosystem/init.rs | 19 +- .../src/commands/ecosystem/mod.rs | 6 + .../src/commands/ecosystem/utils.rs | 14 + 6 files changed, 518 insertions(+), 16 deletions(-) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs create mode 100644 zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs create mode 100644 zk_toolbox/crates/zk_inception/src/commands/ecosystem/utils.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs new file mode 100644 index 000000000000..eb1722a0cf04 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -0,0 +1,142 @@ +use std::path::PathBuf; + +use clap::Parser; +use common::{forge::ForgeScriptArgs, Prompt, PromptConfirm}; +use serde::{Deserialize, Serialize}; +use types::L1Network; +use url::Url; + +use crate::{ + commands::chain::args::genesis::GenesisArgs, + defaults::LOCAL_RPC_URL, + messages::{ + MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, + MSG_DEV_ARG_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, + MSG_L1_RPC_URL_PROMPT, MSG_OBSERVABILITY_HELP, MSG_OBSERVABILITY_PROMPT, + }, +}; + +#[derive(Debug, Clone, Serialize, Deserialize, Parser)] +pub struct EcosystemArgs { + /// Deploy ecosystem contracts + #[clap(long, default_missing_value = "true", num_args = 0..=1)] + pub deploy_ecosystem: Option, + /// Path to ecosystem contracts + #[clap(long)] + pub ecosystem_contracts_path: Option, + #[clap(long, help = MSG_L1_RPC_URL_HELP)] + pub l1_rpc_url: Option, +} + +impl EcosystemArgs { + pub fn fill_values_with_prompt(self, l1_network: L1Network, dev: bool) -> EcosystemArgsFinal { + let deploy_ecosystem = self.deploy_ecosystem.unwrap_or_else(|| { + if dev { + true + } else { + PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT) + .default(true) + .ask() + } + }); + + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { + let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); + if dev { + return LOCAL_RPC_URL.to_string(); + } + if l1_network == L1Network::Localhost { + prompt = prompt.default(LOCAL_RPC_URL); + } + prompt + .validate_with(|val: &String| -> Result<(), String> { + Url::parse(val) + .map(|_| ()) + .map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) + }) + .ask() + }); + EcosystemArgsFinal { + deploy_ecosystem, + ecosystem_contracts_path: self.ecosystem_contracts_path, + l1_rpc_url, + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct EcosystemArgsFinal { + pub deploy_ecosystem: bool, + pub ecosystem_contracts_path: Option, + pub l1_rpc_url: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Parser)] +pub struct EcosystemBuildArgs { + /// Deploy Paymaster contract + #[clap(long, default_missing_value = "true", num_args = 0..=1)] + pub deploy_paymaster: Option, + /// Deploy ERC20 contracts + #[clap(long, default_missing_value = "true", num_args = 0..=1)] + pub deploy_erc20: Option, + #[clap(flatten)] + #[serde(flatten)] + pub ecosystem: EcosystemArgs, + #[clap(flatten)] + #[serde(flatten)] + pub forge_args: ForgeScriptArgs, + #[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)] + #[serde(flatten)] + pub genesis_args: GenesisArgs, + #[clap(long, help = MSG_DEV_ARG_HELP)] + pub dev: bool, + #[clap(long, short = 'o', help = MSG_OBSERVABILITY_HELP, default_missing_value = "true", num_args = 0..=1)] + pub observability: Option, +} + +impl EcosystemBuildArgs { + pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemBuildArgsFinal { + let (deploy_paymaster, deploy_erc20) = if self.dev { + (true, true) + } else { + let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { + PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) + .default(true) + .ask() + }); + let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| { + PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT) + .default(true) + .ask() + }); + (deploy_paymaster, deploy_erc20) + }; + let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, self.dev); + let observability = if self.dev { + true + } else { + self.observability.unwrap_or_else(|| { + PromptConfirm::new(MSG_OBSERVABILITY_PROMPT) + .default(true) + .ask() + }) + }; + + EcosystemBuildArgsFinal { + deploy_paymaster, + deploy_erc20, + ecosystem, + forge_args: self.forge_args.clone(), + dev: self.dev, + } + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct EcosystemBuildArgsFinal { + pub deploy_paymaster: bool, + pub deploy_erc20: bool, + pub ecosystem: EcosystemArgsFinal, + pub forge_args: ForgeScriptArgs, + pub dev: bool, +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs index 8a6048a8643b..46de2bed5aa7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs @@ -1,3 +1,4 @@ +pub mod build; pub mod change_default; pub mod create; pub mod init; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs new file mode 100644 index 000000000000..03d11a777670 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -0,0 +1,352 @@ +use std::{path::PathBuf, str::FromStr}; + +use anyhow::Context; +use common::{ + config::global_config, + forge::{Forge, ForgeScriptArgs}, + git, logger, + spinner::Spinner, + Prompt, +}; +use config::{ + forge_interface::{ + deploy_ecosystem::{ + input::{ + DeployErc20Config, DeployL1Config, Erc20DeploymentConfig, InitialDeploymentConfig, + }, + output::{DeployL1Output, ERC20Tokens}, + }, + script_params::{DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, DEPLOY_ERC20_SCRIPT_PARAMS}, + }, + traits::{ + FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, + SaveConfigWithBasePath, + }, + ContractsConfig, EcosystemConfig, GenesisConfig, +}; +use types::{L1Network, ProverMode}; +use xshell::Shell; + +use super::{ + args::build::{EcosystemArgsFinal, EcosystemBuildArgs, EcosystemBuildArgsFinal}, + utils::{build_system_contracts, install_yarn_dependencies}, +}; +use crate::{ + accept_ownership::accept_owner, + commands::{ + chain::{self, args::init::PortOffset}, + ecosystem::create_configs::{ + create_erc20_deployment_config, create_initial_deployments_config, + }, + }, + messages::{ + msg_ecosystem_initialized, msg_ecosystem_no_found_preexisting_contract, + msg_initializing_chain, MSG_CHAIN_NOT_INITIALIZED, + MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_DEPLOYING_ERC20, + MSG_DEPLOYING_ERC20_SPINNER, MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, + MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_INITIALIZING_ECOSYSTEM, + MSG_INTALLING_DEPS_SPINNER, + }, + utils::forge::{check_the_balance, fill_forge_private_key}, +}; + +pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { + let ecosystem_config = EcosystemConfig::from_file(shell)?; + + git::submodule_update(shell, ecosystem_config.link_to_code.clone())?; + + let initial_deployment_config = match ecosystem_config.get_initial_deployment_config() { + Ok(config) => config, + Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, + }; + + let mut genesis_args = args.genesis_args.clone(); + if args.dev { + genesis_args.use_default = true; + } + let mut final_ecosystem_args = args.fill_values_with_prompt(ecosystem_config.l1_network); + + logger::info(MSG_INITIALIZING_ECOSYSTEM); + + let contracts_config = init( + &mut final_ecosystem_args, + shell, + &ecosystem_config, + &initial_deployment_config, + ) + .await?; + + if final_ecosystem_args.deploy_erc20 { + logger::info(MSG_DEPLOYING_ERC20); + let erc20_deployment_config = match ecosystem_config.get_erc20_deployment_config() { + Ok(config) => config, + Err(_) => create_erc20_deployment_config(shell, &ecosystem_config.config)?, + }; + deploy_erc20( + shell, + &erc20_deployment_config, + &ecosystem_config, + &contracts_config, + final_ecosystem_args.forge_args.clone(), + final_ecosystem_args.ecosystem.l1_rpc_url.clone(), + ) + .await?; + } + + // If the name of chain passed then we deploy exactly this chain otherwise deploy all chains + let list_of_chains = if let Some(name) = global_config().chain_name.clone() { + vec![name] + } else { + ecosystem_config.list_of_chains() + }; + + for chain_name in &list_of_chains { + logger::info(msg_initializing_chain(chain_name)); + let chain_config = ecosystem_config + .load_chain(Some(chain_name.clone())) + .context(MSG_CHAIN_NOT_INITIALIZED)?; + + let mut chain_init_args = chain::args::init::InitArgsFinal { + forge_args: final_ecosystem_args.forge_args.clone(), + genesis_args: genesis_args.clone().fill_values_with_prompt(&chain_config), + deploy_paymaster: final_ecosystem_args.deploy_paymaster, + l1_rpc_url: final_ecosystem_args.ecosystem.l1_rpc_url.clone(), + port_offset: PortOffset::from_chain_id(chain_config.id as u16).into(), + }; + + chain::init::init( + &mut chain_init_args, + shell, + &ecosystem_config, + &chain_config, + ) + .await?; + } + + logger::outro(msg_ecosystem_initialized(&list_of_chains.join(","))); + + Ok(()) +} + +async fn init( + init_args: &mut EcosystemBuildArgsFinal, + shell: &Shell, + ecosystem_config: &EcosystemConfig, + initial_deployment_config: &InitialDeploymentConfig, +) -> anyhow::Result { + let spinner = Spinner::new(MSG_INTALLING_DEPS_SPINNER); + install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?; + build_system_contracts(shell, &ecosystem_config.link_to_code)?; + spinner.finish(); + + let contracts = deploy_ecosystem( + shell, + &mut init_args.ecosystem, + init_args.forge_args.clone(), + ecosystem_config, + initial_deployment_config, + ) + .await?; + contracts.save_with_base_path(shell, &ecosystem_config.config)?; + Ok(contracts) +} + +async fn deploy_erc20( + shell: &Shell, + erc20_deployment_config: &Erc20DeploymentConfig, + ecosystem_config: &EcosystemConfig, + contracts_config: &ContractsConfig, + forge_args: ForgeScriptArgs, + l1_rpc_url: String, +) -> anyhow::Result { + let deploy_config_path = DEPLOY_ERC20_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); + let wallets = ecosystem_config.get_wallets()?; + DeployErc20Config::new( + erc20_deployment_config, + contracts_config, + vec![ + wallets.governor.address, + wallets.operator.address, + wallets.blob_operator.address, + ], + ) + .save(shell, deploy_config_path)?; + + let mut forge = Forge::new(&ecosystem_config.path_to_foundry()) + .script(&DEPLOY_ERC20_SCRIPT_PARAMS.script(), forge_args.clone()) + .with_ffi() + .with_rpc_url(l1_rpc_url) + .with_broadcast(); + + forge = fill_forge_private_key( + forge, + ecosystem_config.get_wallets()?.deployer_private_key(), + )?; + + let spinner = Spinner::new(MSG_DEPLOYING_ERC20_SPINNER); + check_the_balance(&forge).await?; + forge.run(shell)?; + spinner.finish(); + + let result = ERC20Tokens::read( + shell, + DEPLOY_ERC20_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code), + )?; + result.save_with_base_path(shell, &ecosystem_config.config)?; + Ok(result) +} + +async fn deploy_ecosystem( + shell: &Shell, + ecosystem: &mut EcosystemArgsFinal, + forge_args: ForgeScriptArgs, + ecosystem_config: &EcosystemConfig, + initial_deployment_config: &InitialDeploymentConfig, +) -> anyhow::Result { + if ecosystem.deploy_ecosystem { + return deploy_ecosystem_inner( + shell, + forge_args, + ecosystem_config, + initial_deployment_config, + ecosystem.l1_rpc_url.clone(), + ) + .await; + } + + let ecosystem_contracts_path = match &ecosystem.ecosystem_contracts_path { + Some(path) => Some(path.clone()), + None => { + let input_path: String = Prompt::new(MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT) + .allow_empty() + .validate_with(|val: &String| { + if val.is_empty() { + return Ok(()); + } + PathBuf::from_str(val) + .map(|_| ()) + .map_err(|_| MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR.to_string()) + }) + .ask(); + if input_path.is_empty() { + None + } else { + Some(input_path.into()) + } + } + }; + + let ecosystem_preexisting_configs_path = + ecosystem_config + .get_preexisting_configs_path() + .join(format!( + "{}.yaml", + ecosystem_config.l1_network.to_string().to_lowercase() + )); + + // currently there are not some preexisting ecosystem contracts in + // chains, so we need check if this file exists. + if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() { + anyhow::bail!(msg_ecosystem_no_found_preexisting_contract( + &ecosystem_config.l1_network.to_string() + )) + } + + let ecosystem_contracts_path = + ecosystem_contracts_path.unwrap_or_else(|| match ecosystem_config.l1_network { + L1Network::Localhost => { + ContractsConfig::get_path_with_base_path(&ecosystem_config.config) + } + L1Network::Sepolia | L1Network::Holesky | L1Network::Mainnet => { + ecosystem_preexisting_configs_path + } + }); + + ContractsConfig::read(shell, ecosystem_contracts_path) +} + +async fn deploy_ecosystem_inner( + shell: &Shell, + forge_args: ForgeScriptArgs, + config: &EcosystemConfig, + initial_deployment_config: &InitialDeploymentConfig, + l1_rpc_url: String, +) -> anyhow::Result { + let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&config.link_to_code); + + let default_genesis_config = + GenesisConfig::read_with_base_path(shell, config.get_default_configs_path()) + .context("Context")?; + + let wallets_config = config.get_wallets()?; + // For deploying ecosystem we only need genesis batch params + let deploy_config = DeployL1Config::new( + &default_genesis_config, + &wallets_config, + initial_deployment_config, + config.era_chain_id, + config.prover_version == ProverMode::NoProofs, + ); + deploy_config.save(shell, deploy_config_path)?; + + let mut forge = Forge::new(&config.path_to_foundry()) + .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) + .with_ffi() + .with_rpc_url(l1_rpc_url.clone()) + .with_broadcast(); + + if config.l1_network == L1Network::Localhost { + // It's a kludge for reth, just because it doesn't behave properly with large amount of txs + forge = forge.with_slow(); + } + + forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; + + let spinner = Spinner::new(MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER); + check_the_balance(&forge).await?; + forge.run(shell)?; + spinner.finish(); + + let script_output = DeployL1Output::read( + shell, + DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&config.link_to_code), + )?; + let mut contracts_config = ContractsConfig::default(); + contracts_config.update_from_l1_output(&script_output); + accept_owner( + shell, + config, + contracts_config.l1.governance_addr, + config.get_wallets()?.governor_private_key(), + contracts_config.ecosystem_contracts.bridgehub_proxy_addr, + &forge_args, + l1_rpc_url.clone(), + ) + .await?; + + accept_owner( + shell, + config, + contracts_config.l1.governance_addr, + config.get_wallets()?.governor_private_key(), + contracts_config.bridges.shared.l1_address, + &forge_args, + l1_rpc_url.clone(), + ) + .await?; + + accept_owner( + shell, + config, + contracts_config.l1.governance_addr, + config.get_wallets()?.governor_private_key(), + contracts_config + .ecosystem_contracts + .state_transition_proxy_addr, + &forge_args, + l1_rpc_url.clone(), + ) + .await?; + + Ok(contracts_config) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs index 0862d1018d89..2af70f52c2b4 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -1,11 +1,7 @@ -use std::{ - path::{Path, PathBuf}, - str::FromStr, -}; +use std::{path::PathBuf, str::FromStr}; use anyhow::Context; use common::{ - cmd::Cmd, config::global_config, forge::{Forge, ForgeScriptArgs}, git, logger, @@ -29,11 +25,12 @@ use config::{ ContractsConfig, EcosystemConfig, GenesisConfig, }; use types::{L1Network, ProverMode}; -use xshell::{cmd, Shell}; +use xshell::Shell; use super::{ args::init::{EcosystemArgsFinal, EcosystemInitArgs, EcosystemInitArgsFinal}, setup_observability, + utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::{ accept_ownership::accept_owner, @@ -358,13 +355,3 @@ async fn deploy_ecosystem_inner( Ok(contracts_config) } - -fn install_yarn_dependencies(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { - let _dir_guard = shell.push_dir(link_to_code); - Ok(Cmd::new(cmd!(shell, "yarn install")).run()?) -} - -fn build_system_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { - let _dir_guard = shell.push_dir(link_to_code.join("contracts")); - Ok(Cmd::new(cmd!(shell, "yarn sc build")).run()?) -} diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs index cb5195ccf937..e0082a8c83eb 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs @@ -1,3 +1,4 @@ +use args::build::EcosystemBuildArgs; use clap::Subcommand; use xshell::Shell; @@ -6,11 +7,13 @@ use crate::commands::ecosystem::args::{ }; mod args; +pub(crate) mod build; mod change_default; mod create; pub mod create_configs; pub(crate) mod init; mod setup_observability; +mod utils; #[derive(Subcommand, Debug)] #[allow(clippy::large_enum_variant)] @@ -18,6 +21,8 @@ pub enum EcosystemCommands { /// Create a new ecosystem and chain, /// setting necessary configurations for later initialization Create(EcosystemCreateArgs), + /// + Build(EcosystemBuildArgs), /// Initialize ecosystem and chain, /// deploying necessary contracts and performing on-chain operations Init(EcosystemInitArgs), @@ -33,6 +38,7 @@ pub enum EcosystemCommands { pub(crate) async fn run(shell: &Shell, args: EcosystemCommands) -> anyhow::Result<()> { match args { EcosystemCommands::Create(args) => create::run(args, shell), + EcosystemCommands::Build(args) => build::run(args, shell).await, EcosystemCommands::Init(args) => init::run(args, shell).await, EcosystemCommands::ChangeDefaultChain(args) => change_default::run(args, shell), EcosystemCommands::SetupObservability => setup_observability::run(shell), diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/utils.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/utils.rs new file mode 100644 index 000000000000..a51adc75fb42 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/utils.rs @@ -0,0 +1,14 @@ +use std::path::Path; + +use common::cmd::Cmd; +use xshell::{cmd, Shell}; + +pub(super) fn install_yarn_dependencies(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { + let _dir_guard = shell.push_dir(link_to_code); + Ok(Cmd::new(cmd!(shell, "yarn install")).run()?) +} + +pub(super) fn build_system_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { + let _dir_guard = shell.push_dir(link_to_code.join("contracts")); + Ok(Cmd::new(cmd!(shell, "yarn sc build")).run()?) +} From d5b42cb0f6c700f3700e4e6c021602a62026ab9d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 11:39:06 +0200 Subject: [PATCH 02/89] refactor: remove chains initialization step --- .../src/commands/ecosystem/args/build.rs | 11 +---- .../src/commands/ecosystem/build.rs | 46 ++----------------- 2 files changed, 6 insertions(+), 51 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index eb1722a0cf04..806e5cd0293c 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -12,7 +12,7 @@ use crate::{ messages::{ MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, MSG_DEV_ARG_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, - MSG_L1_RPC_URL_PROMPT, MSG_OBSERVABILITY_HELP, MSG_OBSERVABILITY_PROMPT, + MSG_L1_RPC_URL_PROMPT, MSG_OBSERVABILITY_HELP, }, }; @@ -112,15 +112,6 @@ impl EcosystemBuildArgs { (deploy_paymaster, deploy_erc20) }; let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, self.dev); - let observability = if self.dev { - true - } else { - self.observability.unwrap_or_else(|| { - PromptConfirm::new(MSG_OBSERVABILITY_PROMPT) - .default(true) - .ask() - }) - }; EcosystemBuildArgsFinal { deploy_paymaster, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 03d11a777670..c91236b76dad 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -2,7 +2,6 @@ use std::{path::PathBuf, str::FromStr}; use anyhow::Context; use common::{ - config::global_config, forge::{Forge, ForgeScriptArgs}, git, logger, spinner::Spinner, @@ -33,17 +32,12 @@ use super::{ }; use crate::{ accept_ownership::accept_owner, - commands::{ - chain::{self, args::init::PortOffset}, - ecosystem::create_configs::{ - create_erc20_deployment_config, create_initial_deployments_config, - }, + commands::ecosystem::create_configs::{ + create_erc20_deployment_config, create_initial_deployments_config, }, messages::{ - msg_ecosystem_initialized, msg_ecosystem_no_found_preexisting_contract, - msg_initializing_chain, MSG_CHAIN_NOT_INITIALIZED, - MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_DEPLOYING_ERC20, - MSG_DEPLOYING_ERC20_SPINNER, MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, + msg_ecosystem_no_found_preexisting_contract, MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, + MSG_DEPLOYING_ERC20, MSG_DEPLOYING_ERC20_SPINNER, MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, }, @@ -93,37 +87,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> .await?; } - // If the name of chain passed then we deploy exactly this chain otherwise deploy all chains - let list_of_chains = if let Some(name) = global_config().chain_name.clone() { - vec![name] - } else { - ecosystem_config.list_of_chains() - }; - - for chain_name in &list_of_chains { - logger::info(msg_initializing_chain(chain_name)); - let chain_config = ecosystem_config - .load_chain(Some(chain_name.clone())) - .context(MSG_CHAIN_NOT_INITIALIZED)?; - - let mut chain_init_args = chain::args::init::InitArgsFinal { - forge_args: final_ecosystem_args.forge_args.clone(), - genesis_args: genesis_args.clone().fill_values_with_prompt(&chain_config), - deploy_paymaster: final_ecosystem_args.deploy_paymaster, - l1_rpc_url: final_ecosystem_args.ecosystem.l1_rpc_url.clone(), - port_offset: PortOffset::from_chain_id(chain_config.id as u16).into(), - }; - - chain::init::init( - &mut chain_init_args, - shell, - &ecosystem_config, - &chain_config, - ) - .await?; - } - - logger::outro(msg_ecosystem_initialized(&list_of_chains.join(","))); + logger::outro("TODO"); Ok(()) } From 243973c69161f58f210f0234cd4482130bf5470e Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 12:06:41 +0200 Subject: [PATCH 03/89] refactor: remove dev and observability args, add sender --- .../src/commands/ecosystem/args/build.rs | 43 ++++++++----------- .../src/commands/ecosystem/build.rs | 7 +-- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index 806e5cd0293c..cb4753858152 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -11,8 +11,8 @@ use crate::{ defaults::LOCAL_RPC_URL, messages::{ MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, - MSG_DEV_ARG_HELP, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, - MSG_L1_RPC_URL_PROMPT, MSG_OBSERVABILITY_HELP, + MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, + MSG_L1_RPC_URL_PROMPT, }, }; @@ -79,6 +79,9 @@ pub struct EcosystemBuildArgs { /// Deploy ERC20 contracts #[clap(long, default_missing_value = "true", num_args = 0..=1)] pub deploy_erc20: Option, + /// Address of the transaction sender. + #[arg(long)] + pub sender: String, #[clap(flatten)] #[serde(flatten)] pub ecosystem: EcosystemArgs, @@ -88,46 +91,38 @@ pub struct EcosystemBuildArgs { #[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)] #[serde(flatten)] pub genesis_args: GenesisArgs, - #[clap(long, help = MSG_DEV_ARG_HELP)] - pub dev: bool, - #[clap(long, short = 'o', help = MSG_OBSERVABILITY_HELP, default_missing_value = "true", num_args = 0..=1)] - pub observability: Option, } impl EcosystemBuildArgs { pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemBuildArgsFinal { - let (deploy_paymaster, deploy_erc20) = if self.dev { - (true, true) - } else { - let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { - PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) - .default(true) - .ask() - }); - let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| { - PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT) - .default(true) - .ask() - }); - (deploy_paymaster, deploy_erc20) - }; - let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, self.dev); + let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { + PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) + .default(true) + .ask() + }); + let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| { + PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT) + .default(true) + .ask() + }); + + let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, false); EcosystemBuildArgsFinal { + sender: self.sender, deploy_paymaster, deploy_erc20, ecosystem, forge_args: self.forge_args.clone(), - dev: self.dev, } } } #[derive(Debug, Serialize, Deserialize)] pub struct EcosystemBuildArgsFinal { + pub sender: String, pub deploy_paymaster: bool, pub deploy_erc20: bool, pub ecosystem: EcosystemArgsFinal, pub forge_args: ForgeScriptArgs, - pub dev: bool, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index c91236b76dad..3596e650eb92 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -54,10 +54,6 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, }; - let mut genesis_args = args.genesis_args.clone(); - if args.dev { - genesis_args.use_default = true; - } let mut final_ecosystem_args = args.fill_values_with_prompt(ecosystem_config.l1_network); logger::info(MSG_INITIALIZING_ECOSYSTEM); @@ -264,7 +260,8 @@ async fn deploy_ecosystem_inner( forge = forge.with_slow(); } - forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; + // TODO add sender instead of private key + // forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; let spinner = Spinner::new(MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER); check_the_balance(&forge).await?; From bc39ffa1e7ef02589225d90c78b024fa01e70cc5 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 12:11:58 +0200 Subject: [PATCH 04/89] refactor: format code --- infrastructure/zk/src/prover_setup.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/infrastructure/zk/src/prover_setup.ts b/infrastructure/zk/src/prover_setup.ts index b5bd4c828aec..0ef3515cc750 100644 --- a/infrastructure/zk/src/prover_setup.ts +++ b/infrastructure/zk/src/prover_setup.ts @@ -30,7 +30,8 @@ export async function setupProver(proverType: ProverType) { } else { env.modify( 'FRI_PROVER_SETUP_DATA_PATH', - `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${proverType === ProverType.GPU ? 'gpu' : 'cpu' + `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${ + proverType === ProverType.GPU ? 'gpu' : 'cpu' }/`, process.env.ENV_FILE! ); @@ -97,7 +98,8 @@ async function setupProverKeys(proverType: ProverType) { env.modify( 'FRI_PROVER_SETUP_DATA_PATH', - `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${proverType === ProverType.GPU ? 'gpu' : 'cpu' + `${process.env.ZKSYNC_HOME}/etc/hyperchains/prover-keys/${process.env.ZKSYNC_ENV}/${ + proverType === ProverType.GPU ? 'gpu' : 'cpu' }/`, process.env.ENV_FILE! ); From 6cb124925798467af5efe20d04eb48cd210148b8 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 12:27:02 +0200 Subject: [PATCH 05/89] refactor: remove l1_rpc_url option from ecosystem build --- .../src/commands/ecosystem/args/build.rs | 44 ++++--------------- .../src/commands/ecosystem/build.rs | 42 +----------------- 2 files changed, 9 insertions(+), 77 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index cb4753858152..968e29914ffb 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -1,18 +1,14 @@ use std::path::PathBuf; use clap::Parser; -use common::{forge::ForgeScriptArgs, Prompt, PromptConfirm}; +use common::{forge::ForgeScriptArgs, PromptConfirm}; use serde::{Deserialize, Serialize}; -use types::L1Network; -use url::Url; use crate::{ commands::chain::args::genesis::GenesisArgs, - defaults::LOCAL_RPC_URL, messages::{ MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, - MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, - MSG_L1_RPC_URL_PROMPT, + MSG_GENESIS_ARGS_HELP, }, }; @@ -24,42 +20,19 @@ pub struct EcosystemArgs { /// Path to ecosystem contracts #[clap(long)] pub ecosystem_contracts_path: Option, - #[clap(long, help = MSG_L1_RPC_URL_HELP)] - pub l1_rpc_url: Option, } impl EcosystemArgs { - pub fn fill_values_with_prompt(self, l1_network: L1Network, dev: bool) -> EcosystemArgsFinal { + pub fn fill_values_with_prompt(self) -> EcosystemArgsFinal { let deploy_ecosystem = self.deploy_ecosystem.unwrap_or_else(|| { - if dev { - true - } else { - PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT) - .default(true) - .ask() - } - }); - - let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { - let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); - if dev { - return LOCAL_RPC_URL.to_string(); - } - if l1_network == L1Network::Localhost { - prompt = prompt.default(LOCAL_RPC_URL); - } - prompt - .validate_with(|val: &String| -> Result<(), String> { - Url::parse(val) - .map(|_| ()) - .map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) - }) + PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT) + .default(true) .ask() }); + EcosystemArgsFinal { deploy_ecosystem, ecosystem_contracts_path: self.ecosystem_contracts_path, - l1_rpc_url, } } } @@ -68,7 +41,6 @@ impl EcosystemArgs { pub struct EcosystemArgsFinal { pub deploy_ecosystem: bool, pub ecosystem_contracts_path: Option, - pub l1_rpc_url: String, } #[derive(Debug, Clone, Serialize, Deserialize, Parser)] @@ -94,7 +66,7 @@ pub struct EcosystemBuildArgs { } impl EcosystemBuildArgs { - pub fn fill_values_with_prompt(self, l1_network: L1Network) -> EcosystemBuildArgsFinal { + pub fn fill_values_with_prompt(self) -> EcosystemBuildArgsFinal { let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) .default(true) @@ -106,7 +78,7 @@ impl EcosystemBuildArgs { .ask() }); - let ecosystem = self.ecosystem.fill_values_with_prompt(l1_network, false); + let ecosystem = self.ecosystem.fill_values_with_prompt(); EcosystemBuildArgsFinal { sender: self.sender, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 3596e650eb92..6eea65650961 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -54,7 +54,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, }; - let mut final_ecosystem_args = args.fill_values_with_prompt(ecosystem_config.l1_network); + let mut final_ecosystem_args = args.fill_values_with_prompt(); logger::info(MSG_INITIALIZING_ECOSYSTEM); @@ -78,7 +78,6 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> &ecosystem_config, &contracts_config, final_ecosystem_args.forge_args.clone(), - final_ecosystem_args.ecosystem.l1_rpc_url.clone(), ) .await?; } @@ -117,7 +116,6 @@ async fn deploy_erc20( ecosystem_config: &EcosystemConfig, contracts_config: &ContractsConfig, forge_args: ForgeScriptArgs, - l1_rpc_url: String, ) -> anyhow::Result { let deploy_config_path = DEPLOY_ERC20_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); let wallets = ecosystem_config.get_wallets()?; @@ -135,7 +133,6 @@ async fn deploy_erc20( let mut forge = Forge::new(&ecosystem_config.path_to_foundry()) .script(&DEPLOY_ERC20_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(l1_rpc_url) .with_broadcast(); forge = fill_forge_private_key( @@ -169,7 +166,6 @@ async fn deploy_ecosystem( forge_args, ecosystem_config, initial_deployment_config, - ecosystem.l1_rpc_url.clone(), ) .await; } @@ -230,7 +226,6 @@ async fn deploy_ecosystem_inner( forge_args: ForgeScriptArgs, config: &EcosystemConfig, initial_deployment_config: &InitialDeploymentConfig, - l1_rpc_url: String, ) -> anyhow::Result { let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&config.link_to_code); @@ -252,7 +247,6 @@ async fn deploy_ecosystem_inner( let mut forge = Forge::new(&config.path_to_foundry()) .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() - .with_rpc_url(l1_rpc_url.clone()) .with_broadcast(); if config.l1_network == L1Network::Localhost { @@ -274,40 +268,6 @@ async fn deploy_ecosystem_inner( )?; let mut contracts_config = ContractsConfig::default(); contracts_config.update_from_l1_output(&script_output); - accept_owner( - shell, - config, - contracts_config.l1.governance_addr, - config.get_wallets()?.governor_private_key(), - contracts_config.ecosystem_contracts.bridgehub_proxy_addr, - &forge_args, - l1_rpc_url.clone(), - ) - .await?; - - accept_owner( - shell, - config, - contracts_config.l1.governance_addr, - config.get_wallets()?.governor_private_key(), - contracts_config.bridges.shared.l1_address, - &forge_args, - l1_rpc_url.clone(), - ) - .await?; - - accept_owner( - shell, - config, - contracts_config.l1.governance_addr, - config.get_wallets()?.governor_private_key(), - contracts_config - .ecosystem_contracts - .state_transition_proxy_addr, - &forge_args, - l1_rpc_url.clone(), - ) - .await?; Ok(contracts_config) } From 110b87b88d503f357e75cea08067e7339af26419 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 15:20:51 +0200 Subject: [PATCH 06/89] fix: use dummy RPC endpoint --- zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 6eea65650961..f5930c800e66 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -31,7 +31,6 @@ use super::{ utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::{ - accept_ownership::accept_owner, commands::ecosystem::create_configs::{ create_erc20_deployment_config, create_initial_deployments_config, }, @@ -133,6 +132,7 @@ async fn deploy_erc20( let mut forge = Forge::new(&ecosystem_config.path_to_foundry()) .script(&DEPLOY_ERC20_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() + .with_rpc_url("127.0.0.1:8545".to_string()) .with_broadcast(); forge = fill_forge_private_key( @@ -247,6 +247,7 @@ async fn deploy_ecosystem_inner( let mut forge = Forge::new(&config.path_to_foundry()) .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() + .with_rpc_url("127.0.0.1:8545".to_string()) .with_broadcast(); if config.l1_network == L1Network::Localhost { From f5187051e117ca78ef338d286d79eea139b80926 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 15:49:45 +0200 Subject: [PATCH 07/89] feat: wire forge sender option --- zk_toolbox/crates/common/src/forge.rs | 10 ++++++++++ .../zk_inception/src/commands/ecosystem/build.rs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/zk_toolbox/crates/common/src/forge.rs b/zk_toolbox/crates/common/src/forge.rs index f00921a0bf20..c90cd1421712 100644 --- a/zk_toolbox/crates/common/src/forge.rs +++ b/zk_toolbox/crates/common/src/forge.rs @@ -96,6 +96,12 @@ impl ForgeScript { self } + /// Add the sender address to the forge script command. + pub fn with_sender(mut self, address: String) -> Self { + self.args.add_arg(ForgeScriptArg::Sender { address }); + self + } + /// Add the rpc-url flag to the forge script command. pub fn with_rpc_url(mut self, rpc_url: String) -> Self { self.args.add_arg(ForgeScriptArg::RpcUrl { url: rpc_url }); @@ -244,6 +250,10 @@ pub enum ForgeScriptArg { }, Verify, Resume, + #[strum(to_string = "sender={address}")] + Sender { + address: String, + }, } /// ForgeScriptArgs is a set of arguments that can be passed to the forge script command. diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index f5930c800e66..d52afb805ddd 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -53,6 +53,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, }; + let sender = args.sender.clone(); let mut final_ecosystem_args = args.fill_values_with_prompt(); logger::info(MSG_INITIALIZING_ECOSYSTEM); @@ -62,6 +63,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> shell, &ecosystem_config, &initial_deployment_config, + sender.clone(), ) .await?; @@ -77,6 +79,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> &ecosystem_config, &contracts_config, final_ecosystem_args.forge_args.clone(), + sender, ) .await?; } @@ -91,6 +94,7 @@ async fn init( shell: &Shell, ecosystem_config: &EcosystemConfig, initial_deployment_config: &InitialDeploymentConfig, + sender: String, ) -> anyhow::Result { let spinner = Spinner::new(MSG_INTALLING_DEPS_SPINNER); install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?; @@ -103,6 +107,7 @@ async fn init( init_args.forge_args.clone(), ecosystem_config, initial_deployment_config, + sender, ) .await?; contracts.save_with_base_path(shell, &ecosystem_config.config)?; @@ -115,6 +120,7 @@ async fn deploy_erc20( ecosystem_config: &EcosystemConfig, contracts_config: &ContractsConfig, forge_args: ForgeScriptArgs, + sender: String, ) -> anyhow::Result { let deploy_config_path = DEPLOY_ERC20_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); let wallets = ecosystem_config.get_wallets()?; @@ -133,6 +139,7 @@ async fn deploy_erc20( .script(&DEPLOY_ERC20_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() .with_rpc_url("127.0.0.1:8545".to_string()) + .with_sender(sender) .with_broadcast(); forge = fill_forge_private_key( @@ -159,6 +166,7 @@ async fn deploy_ecosystem( forge_args: ForgeScriptArgs, ecosystem_config: &EcosystemConfig, initial_deployment_config: &InitialDeploymentConfig, + sender: String, ) -> anyhow::Result { if ecosystem.deploy_ecosystem { return deploy_ecosystem_inner( @@ -166,6 +174,7 @@ async fn deploy_ecosystem( forge_args, ecosystem_config, initial_deployment_config, + sender, ) .await; } @@ -226,6 +235,7 @@ async fn deploy_ecosystem_inner( forge_args: ForgeScriptArgs, config: &EcosystemConfig, initial_deployment_config: &InitialDeploymentConfig, + sender: String, ) -> anyhow::Result { let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&config.link_to_code); @@ -248,6 +258,7 @@ async fn deploy_ecosystem_inner( .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() .with_rpc_url("127.0.0.1:8545".to_string()) + .with_sender(sender) .with_broadcast(); if config.l1_network == L1Network::Localhost { From af8f9cb99c1f28e6ead9c4e0014a5e9c85e173fa Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 16:46:14 +0200 Subject: [PATCH 08/89] refactor: remove Paymaster and ERC20 contracts from build subcommand --- .../src/commands/ecosystem/args/build.rs | 26 +----- .../src/commands/ecosystem/build.rs | 84 ++----------------- 2 files changed, 9 insertions(+), 101 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index 968e29914ffb..cec73e69f4d0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -6,10 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::{ commands::chain::args::genesis::GenesisArgs, - messages::{ - MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_DEPLOY_ERC20_PROMPT, MSG_DEPLOY_PAYMASTER_PROMPT, - MSG_GENESIS_ARGS_HELP, - }, + messages::{MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_GENESIS_ARGS_HELP}, }; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] @@ -45,12 +42,6 @@ pub struct EcosystemArgsFinal { #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct EcosystemBuildArgs { - /// Deploy Paymaster contract - #[clap(long, default_missing_value = "true", num_args = 0..=1)] - pub deploy_paymaster: Option, - /// Deploy ERC20 contracts - #[clap(long, default_missing_value = "true", num_args = 0..=1)] - pub deploy_erc20: Option, /// Address of the transaction sender. #[arg(long)] pub sender: String, @@ -67,23 +58,10 @@ pub struct EcosystemBuildArgs { impl EcosystemBuildArgs { pub fn fill_values_with_prompt(self) -> EcosystemBuildArgsFinal { - let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { - PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) - .default(true) - .ask() - }); - let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| { - PromptConfirm::new(MSG_DEPLOY_ERC20_PROMPT) - .default(true) - .ask() - }); - let ecosystem = self.ecosystem.fill_values_with_prompt(); EcosystemBuildArgsFinal { sender: self.sender, - deploy_paymaster, - deploy_erc20, ecosystem, forge_args: self.forge_args.clone(), } @@ -93,8 +71,6 @@ impl EcosystemBuildArgs { #[derive(Debug, Serialize, Deserialize)] pub struct EcosystemBuildArgsFinal { pub sender: String, - pub deploy_paymaster: bool, - pub deploy_erc20: bool, pub ecosystem: EcosystemArgsFinal, pub forge_args: ForgeScriptArgs, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index d52afb805ddd..97508421b089 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -10,12 +10,10 @@ use common::{ use config::{ forge_interface::{ deploy_ecosystem::{ - input::{ - DeployErc20Config, DeployL1Config, Erc20DeploymentConfig, InitialDeploymentConfig, - }, - output::{DeployL1Output, ERC20Tokens}, + input::{DeployL1Config, InitialDeploymentConfig}, + output::DeployL1Output, }, - script_params::{DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, DEPLOY_ERC20_SCRIPT_PARAMS}, + script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, }, traits::{ FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, @@ -31,16 +29,13 @@ use super::{ utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::{ - commands::ecosystem::create_configs::{ - create_erc20_deployment_config, create_initial_deployments_config, - }, + commands::ecosystem::create_configs::create_initial_deployments_config, messages::{ msg_ecosystem_no_found_preexisting_contract, MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, - MSG_DEPLOYING_ERC20, MSG_DEPLOYING_ERC20_SPINNER, MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, - MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_INITIALIZING_ECOSYSTEM, - MSG_INTALLING_DEPS_SPINNER, + MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, + MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, }, - utils::forge::{check_the_balance, fill_forge_private_key}, + utils::forge::check_the_balance, }; pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { @@ -58,7 +53,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> logger::info(MSG_INITIALIZING_ECOSYSTEM); - let contracts_config = init( + let _contracts_config = init( &mut final_ecosystem_args, shell, &ecosystem_config, @@ -67,23 +62,6 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> ) .await?; - if final_ecosystem_args.deploy_erc20 { - logger::info(MSG_DEPLOYING_ERC20); - let erc20_deployment_config = match ecosystem_config.get_erc20_deployment_config() { - Ok(config) => config, - Err(_) => create_erc20_deployment_config(shell, &ecosystem_config.config)?, - }; - deploy_erc20( - shell, - &erc20_deployment_config, - &ecosystem_config, - &contracts_config, - final_ecosystem_args.forge_args.clone(), - sender, - ) - .await?; - } - logger::outro("TODO"); Ok(()) @@ -114,52 +92,6 @@ async fn init( Ok(contracts) } -async fn deploy_erc20( - shell: &Shell, - erc20_deployment_config: &Erc20DeploymentConfig, - ecosystem_config: &EcosystemConfig, - contracts_config: &ContractsConfig, - forge_args: ForgeScriptArgs, - sender: String, -) -> anyhow::Result { - let deploy_config_path = DEPLOY_ERC20_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); - let wallets = ecosystem_config.get_wallets()?; - DeployErc20Config::new( - erc20_deployment_config, - contracts_config, - vec![ - wallets.governor.address, - wallets.operator.address, - wallets.blob_operator.address, - ], - ) - .save(shell, deploy_config_path)?; - - let mut forge = Forge::new(&ecosystem_config.path_to_foundry()) - .script(&DEPLOY_ERC20_SCRIPT_PARAMS.script(), forge_args.clone()) - .with_ffi() - .with_rpc_url("127.0.0.1:8545".to_string()) - .with_sender(sender) - .with_broadcast(); - - forge = fill_forge_private_key( - forge, - ecosystem_config.get_wallets()?.deployer_private_key(), - )?; - - let spinner = Spinner::new(MSG_DEPLOYING_ERC20_SPINNER); - check_the_balance(&forge).await?; - forge.run(shell)?; - spinner.finish(); - - let result = ERC20Tokens::read( - shell, - DEPLOY_ERC20_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code), - )?; - result.save_with_base_path(shell, &ecosystem_config.config)?; - Ok(result) -} - async fn deploy_ecosystem( shell: &Shell, ecosystem: &mut EcosystemArgsFinal, From c38ba3b151555c3993f65c8177866ccf6330108b Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 3 Sep 2024 17:47:07 +0200 Subject: [PATCH 09/89] refactor: do not broadcast transactions on build --- zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 97508421b089..f2185f711d06 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -190,8 +190,7 @@ async fn deploy_ecosystem_inner( .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() .with_rpc_url("127.0.0.1:8545".to_string()) - .with_sender(sender) - .with_broadcast(); + .with_sender(sender); if config.l1_network == L1Network::Localhost { // It's a kludge for reth, just because it doesn't behave properly with large amount of txs From c05dffe6a6c53e03118f9ad8d9fa80f66ddbb44c Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 10:54:39 +0200 Subject: [PATCH 10/89] feat: create command output directory --- .gitignore | 1 + .../src/commands/ecosystem/args/build.rs | 6 ++++ .../src/commands/ecosystem/build.rs | 34 +++++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 725b5940afeb..d12f325a62c8 100644 --- a/.gitignore +++ b/.gitignore @@ -117,3 +117,4 @@ chains/era/configs/* configs/* era-observability/ core/tests/ts-integration/deployments-zk +transactions/ \ No newline at end of file diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index cec73e69f4d0..9e5fe19fe6cf 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -9,6 +9,8 @@ use crate::{ messages::{MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_GENESIS_ARGS_HELP}, }; +const DEFAULT_OUT_DIR: &str = "transactions"; + #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct EcosystemArgs { /// Deploy ecosystem contracts @@ -45,6 +47,8 @@ pub struct EcosystemBuildArgs { /// Address of the transaction sender. #[arg(long)] pub sender: String, + #[arg(long, short)] + pub out: Option, #[clap(flatten)] #[serde(flatten)] pub ecosystem: EcosystemArgs, @@ -62,6 +66,7 @@ impl EcosystemBuildArgs { EcosystemBuildArgsFinal { sender: self.sender, + out: self.out.unwrap_or_else(|| DEFAULT_OUT_DIR.into()), ecosystem, forge_args: self.forge_args.clone(), } @@ -71,6 +76,7 @@ impl EcosystemBuildArgs { #[derive(Debug, Serialize, Deserialize)] pub struct EcosystemBuildArgsFinal { pub sender: String, + pub out: String, pub ecosystem: EcosystemArgsFinal, pub forge_args: ForgeScriptArgs, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index f2185f711d06..6f7f8d71e686 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -2,6 +2,7 @@ use std::{path::PathBuf, str::FromStr}; use anyhow::Context; use common::{ + files::save_toml_file, forge::{Forge, ForgeScriptArgs}, git, logger, spinner::Spinner, @@ -38,6 +39,9 @@ use crate::{ utils::forge::check_the_balance, }; +const DEPLOY_TRANSACTIONS_FILE: &str = + "contracts/l1-contracts/broadcast/DeployL1.s.sol/9/dry-run/run-latest.json"; + pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; @@ -53,7 +57,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> logger::info(MSG_INITIALIZING_ECOSYSTEM); - let _contracts_config = init( + let contracts_config = init( &mut final_ecosystem_args, shell, &ecosystem_config, @@ -62,7 +66,24 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> ) .await?; - logger::outro("TODO"); + shell + .create_dir(&final_ecosystem_args.out) + .context("Impossible to create out dir")?; + + save_toml_file( + shell, + format!("{}/contracts.toml", final_ecosystem_args.out), + contracts_config, + "", + ) + .context("Impossible to save contracts file")?; + + shell.copy_file( + DEPLOY_TRANSACTIONS_FILE, + format!("{}/deploy.json", final_ecosystem_args.out), + )?; + + logger::outro("Transactions successfully built"); Ok(()) } @@ -79,7 +100,7 @@ async fn init( build_system_contracts(shell, &ecosystem_config.link_to_code)?; spinner.finish(); - let contracts = deploy_ecosystem( + let contracts = build_ecosystem( shell, &mut init_args.ecosystem, init_args.forge_args.clone(), @@ -92,7 +113,7 @@ async fn init( Ok(contracts) } -async fn deploy_ecosystem( +async fn build_ecosystem( shell: &Shell, ecosystem: &mut EcosystemArgsFinal, forge_args: ForgeScriptArgs, @@ -101,7 +122,7 @@ async fn deploy_ecosystem( sender: String, ) -> anyhow::Result { if ecosystem.deploy_ecosystem { - return deploy_ecosystem_inner( + return build_ecosystem_inner( shell, forge_args, ecosystem_config, @@ -162,7 +183,7 @@ async fn deploy_ecosystem( ContractsConfig::read(shell, ecosystem_contracts_path) } -async fn deploy_ecosystem_inner( +async fn build_ecosystem_inner( shell: &Shell, forge_args: ForgeScriptArgs, config: &EcosystemConfig, @@ -176,6 +197,7 @@ async fn deploy_ecosystem_inner( .context("Context")?; let wallets_config = config.get_wallets()?; + // For deploying ecosystem we only need genesis batch params let deploy_config = DeployL1Config::new( &default_genesis_config, From 0c64d2bbe141d5e746d55e2ee14e10c2b0a40db3 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 11:02:11 +0200 Subject: [PATCH 11/89] refactor: rename deploy_ecosystem to build_ecosystem --- .../zk_inception/src/commands/ecosystem/args/build.rs | 9 +++++---- .../crates/zk_inception/src/commands/ecosystem/build.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index 9e5fe19fe6cf..90cb056f6e1a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -15,7 +15,7 @@ const DEFAULT_OUT_DIR: &str = "transactions"; pub struct EcosystemArgs { /// Deploy ecosystem contracts #[clap(long, default_missing_value = "true", num_args = 0..=1)] - pub deploy_ecosystem: Option, + pub build_ecosystem: Option, /// Path to ecosystem contracts #[clap(long)] pub ecosystem_contracts_path: Option, @@ -23,14 +23,14 @@ pub struct EcosystemArgs { impl EcosystemArgs { pub fn fill_values_with_prompt(self) -> EcosystemArgsFinal { - let deploy_ecosystem = self.deploy_ecosystem.unwrap_or_else(|| { + let build_ecosystem = self.build_ecosystem.unwrap_or_else(|| { PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT) .default(true) .ask() }); EcosystemArgsFinal { - deploy_ecosystem, + build_ecosystem, ecosystem_contracts_path: self.ecosystem_contracts_path, } } @@ -38,7 +38,7 @@ impl EcosystemArgs { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct EcosystemArgsFinal { - pub deploy_ecosystem: bool, + pub build_ecosystem: bool, pub ecosystem_contracts_path: Option, } @@ -47,6 +47,7 @@ pub struct EcosystemBuildArgs { /// Address of the transaction sender. #[arg(long)] pub sender: String, + /// Output directory for the generated files. #[arg(long, short)] pub out: Option, #[clap(flatten)] diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 6f7f8d71e686..09182ff6dec0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -121,7 +121,7 @@ async fn build_ecosystem( initial_deployment_config: &InitialDeploymentConfig, sender: String, ) -> anyhow::Result { - if ecosystem.deploy_ecosystem { + if ecosystem.build_ecosystem { return build_ecosystem_inner( shell, forge_args, From 76cd0a5fac5c8cde11e8bc8e30e1b1ed459515b5 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 11:11:07 +0200 Subject: [PATCH 12/89] refactor: use more idiomatic flag implementation --- .../src/commands/ecosystem/args/build.rs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index 90cb056f6e1a..eaffd0d1c31a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -1,21 +1,18 @@ use std::path::PathBuf; use clap::Parser; -use common::{forge::ForgeScriptArgs, PromptConfirm}; +use common::forge::ForgeScriptArgs; use serde::{Deserialize, Serialize}; -use crate::{ - commands::chain::args::genesis::GenesisArgs, - messages::{MSG_DEPLOY_ECOSYSTEM_PROMPT, MSG_GENESIS_ARGS_HELP}, -}; +use crate::{commands::chain::args::genesis::GenesisArgs, messages::MSG_GENESIS_ARGS_HELP}; const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct EcosystemArgs { /// Deploy ecosystem contracts - #[clap(long, default_missing_value = "true", num_args = 0..=1)] - pub build_ecosystem: Option, + #[arg(long)] + pub build_ecosystem: bool, /// Path to ecosystem contracts #[clap(long)] pub ecosystem_contracts_path: Option, @@ -23,14 +20,8 @@ pub struct EcosystemArgs { impl EcosystemArgs { pub fn fill_values_with_prompt(self) -> EcosystemArgsFinal { - let build_ecosystem = self.build_ecosystem.unwrap_or_else(|| { - PromptConfirm::new(MSG_DEPLOY_ECOSYSTEM_PROMPT) - .default(true) - .ask() - }); - EcosystemArgsFinal { - build_ecosystem, + build_ecosystem: self.build_ecosystem, ecosystem_contracts_path: self.ecosystem_contracts_path, } } From 919705eca3eb72f8dae9782a2206023f2d6959ce Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 11:19:42 +0200 Subject: [PATCH 13/89] refactor: move ecosystem contract prompt to args/build --- .../src/commands/ecosystem/args/build.rs | 36 ++++++++++++-- .../src/commands/ecosystem/build.rs | 48 +++++-------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index eaffd0d1c31a..e0d9a2be5703 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -1,10 +1,16 @@ -use std::path::PathBuf; +use std::{path::PathBuf, str::FromStr}; use clap::Parser; -use common::forge::ForgeScriptArgs; +use common::{forge::ForgeScriptArgs, Prompt}; use serde::{Deserialize, Serialize}; -use crate::{commands::chain::args::genesis::GenesisArgs, messages::MSG_GENESIS_ARGS_HELP}; +use crate::{ + commands::chain::args::genesis::GenesisArgs, + messages::{ + MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, + MSG_GENESIS_ARGS_HELP, + }, +}; const DEFAULT_OUT_DIR: &str = "transactions"; @@ -20,9 +26,31 @@ pub struct EcosystemArgs { impl EcosystemArgs { pub fn fill_values_with_prompt(self) -> EcosystemArgsFinal { + let ecosystem_contracts_path = match &self.ecosystem_contracts_path { + Some(path) => Some(path.clone()), + None => { + let input_path: String = Prompt::new(MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT) + .allow_empty() + .validate_with(|val: &String| { + if val.is_empty() { + return Ok(()); + } + PathBuf::from_str(val) + .map(|_| ()) + .map_err(|_| MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR.to_string()) + }) + .ask(); + if input_path.is_empty() { + None + } else { + Some(input_path.into()) + } + } + }; + EcosystemArgsFinal { build_ecosystem: self.build_ecosystem, - ecosystem_contracts_path: self.ecosystem_contracts_path, + ecosystem_contracts_path, } } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 09182ff6dec0..ab52afb92d15 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -1,12 +1,9 @@ -use std::{path::PathBuf, str::FromStr}; - use anyhow::Context; use common::{ files::save_toml_file, forge::{Forge, ForgeScriptArgs}, git, logger, spinner::Spinner, - Prompt, }; use config::{ forge_interface::{ @@ -33,7 +30,6 @@ use crate::{ commands::ecosystem::create_configs::create_initial_deployments_config, messages::{ msg_ecosystem_no_found_preexisting_contract, MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, - MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, }, utils::forge::check_the_balance, @@ -132,28 +128,6 @@ async fn build_ecosystem( .await; } - let ecosystem_contracts_path = match &ecosystem.ecosystem_contracts_path { - Some(path) => Some(path.clone()), - None => { - let input_path: String = Prompt::new(MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT) - .allow_empty() - .validate_with(|val: &String| { - if val.is_empty() { - return Ok(()); - } - PathBuf::from_str(val) - .map(|_| ()) - .map_err(|_| MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR.to_string()) - }) - .ask(); - if input_path.is_empty() { - None - } else { - Some(input_path.into()) - } - } - }; - let ecosystem_preexisting_configs_path = ecosystem_config .get_preexisting_configs_path() @@ -164,21 +138,25 @@ async fn build_ecosystem( // currently there are not some preexisting ecosystem contracts in // chains, so we need check if this file exists. - if ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() { + if ecosystem.ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() + { anyhow::bail!(msg_ecosystem_no_found_preexisting_contract( &ecosystem_config.l1_network.to_string() )) } let ecosystem_contracts_path = - ecosystem_contracts_path.unwrap_or_else(|| match ecosystem_config.l1_network { - L1Network::Localhost => { - ContractsConfig::get_path_with_base_path(&ecosystem_config.config) - } - L1Network::Sepolia | L1Network::Holesky | L1Network::Mainnet => { - ecosystem_preexisting_configs_path - } - }); + ecosystem + .ecosystem_contracts_path + .clone() + .unwrap_or_else(|| match ecosystem_config.l1_network { + L1Network::Localhost => { + ContractsConfig::get_path_with_base_path(&ecosystem_config.config) + } + L1Network::Sepolia | L1Network::Holesky | L1Network::Mainnet => { + ecosystem_preexisting_configs_path + } + }); ContractsConfig::read(shell, ecosystem_contracts_path) } From e438a8e67fdc7dec6be224bdb9776699166abd43 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 11:38:00 +0200 Subject: [PATCH 14/89] fix: use string constants for logging --- .../src/commands/ecosystem/build.rs | 17 ++++++++--------- zk_toolbox/crates/zk_inception/src/messages.rs | 7 +++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index ab52afb92d15..a53832f9e407 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -29,8 +29,10 @@ use super::{ use crate::{ commands::ecosystem::create_configs::create_initial_deployments_config, messages::{ - msg_ecosystem_no_found_preexisting_contract, MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER, - MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, + msg_ecosystem_no_found_preexisting_contract, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, + MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_BUILD_OUTRO, + MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, + MSG_INTALLING_DEPS_SPINNER, }, utils::forge::check_the_balance, }; @@ -64,7 +66,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> shell .create_dir(&final_ecosystem_args.out) - .context("Impossible to create out dir")?; + .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; save_toml_file( shell, @@ -72,14 +74,14 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> contracts_config, "", ) - .context("Impossible to save contracts file")?; + .context(MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR)?; shell.copy_file( DEPLOY_TRANSACTIONS_FILE, format!("{}/deploy.json", final_ecosystem_args.out), )?; - logger::outro("Transactions successfully built"); + logger::outro(MSG_ECOSYSTEM_BUILD_OUTRO); Ok(()) } @@ -197,10 +199,7 @@ async fn build_ecosystem_inner( forge = forge.with_slow(); } - // TODO add sender instead of private key - // forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; - - let spinner = Spinner::new(MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER); + let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); check_the_balance(&forge).await?; forge.run(shell)?; spinner.finish(); diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 30cb422dfca6..9a25940dbe44 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -114,6 +114,13 @@ pub(super) fn msg_chain_doesnt_exist_err(chain_name: &str, chains: &Vec) ) } +/// Ecosystem build related messages +pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecosystem contracts..."; +pub(super) const MSG_ECOSYSTEM_BUILD_OUTRO: &str = "Transactions successfully built"; +pub(super) const MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR: &str = + "Impossible to save contracts file"; +pub(super) const MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; + /// Chain create related messages pub(super) const MSG_PROVER_MODE_HELP: &str = "Prover options"; pub(super) const MSG_CHAIN_ID_HELP: &str = "Chain ID"; From 168a92b8006253fd8ab77c5f210523c07596ff7d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 12:16:28 +0200 Subject: [PATCH 15/89] feat: add l1_rpc_url command option --- .../src/commands/ecosystem/args/build.rs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index e0d9a2be5703..7c5171fe84e9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -3,12 +3,15 @@ use std::{path::PathBuf, str::FromStr}; use clap::Parser; use common::{forge::ForgeScriptArgs, Prompt}; use serde::{Deserialize, Serialize}; +use url::Url; use crate::{ commands::chain::args::genesis::GenesisArgs, + defaults::LOCAL_RPC_URL, messages::{ MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, - MSG_GENESIS_ARGS_HELP, + MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, + MSG_L1_RPC_URL_PROMPT, }, }; @@ -22,6 +25,8 @@ pub struct EcosystemArgs { /// Path to ecosystem contracts #[clap(long)] pub ecosystem_contracts_path: Option, + #[clap(long, help = MSG_L1_RPC_URL_HELP)] + pub l1_rpc_url: Option, } impl EcosystemArgs { @@ -48,9 +53,21 @@ impl EcosystemArgs { } }; + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { + Prompt::new(MSG_L1_RPC_URL_PROMPT) + .default(LOCAL_RPC_URL) + .validate_with(|val: &String| -> Result<(), String> { + Url::parse(val) + .map(|_| ()) + .map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) + }) + .ask() + }); + EcosystemArgsFinal { build_ecosystem: self.build_ecosystem, ecosystem_contracts_path, + l1_rpc_url, } } } @@ -59,6 +76,7 @@ impl EcosystemArgs { pub struct EcosystemArgsFinal { pub build_ecosystem: bool, pub ecosystem_contracts_path: Option, + pub l1_rpc_url: String, } #[derive(Debug, Clone, Serialize, Deserialize, Parser)] From 4394d72e8873c0b884147bbb9af8c298454210b0 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 12:21:20 +0200 Subject: [PATCH 16/89] refactor: remove useless code --- .../crates/zk_inception/src/commands/ecosystem/build.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index a53832f9e407..7e57ad566f8f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -194,11 +194,6 @@ async fn build_ecosystem_inner( .with_rpc_url("127.0.0.1:8545".to_string()) .with_sender(sender); - if config.l1_network == L1Network::Localhost { - // It's a kludge for reth, just because it doesn't behave properly with large amount of txs - forge = forge.with_slow(); - } - let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); check_the_balance(&forge).await?; forge.run(shell)?; From a01ee9031976e5deffff4e661339c6217f11e55c Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 12:23:19 +0200 Subject: [PATCH 17/89] refactor: remove unneeded mut modifier --- zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 7e57ad566f8f..45659f31fa5d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -188,7 +188,7 @@ async fn build_ecosystem_inner( ); deploy_config.save(shell, deploy_config_path)?; - let mut forge = Forge::new(&config.path_to_foundry()) + let forge = Forge::new(&config.path_to_foundry()) .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) .with_ffi() .with_rpc_url("127.0.0.1:8545".to_string()) From 89a3fa9bb7cec8426b1d61168ec4c9c15a452aeb Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 12:38:47 +0200 Subject: [PATCH 18/89] refactor: absorb init function into run --- .../src/commands/ecosystem/build.rs | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 45659f31fa5d..8d708b2e767c 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -55,12 +55,18 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> logger::info(MSG_INITIALIZING_ECOSYSTEM); - let contracts_config = init( - &mut final_ecosystem_args, + let spinner = Spinner::new(MSG_INTALLING_DEPS_SPINNER); + install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?; + build_system_contracts(shell, &ecosystem_config.link_to_code)?; + spinner.finish(); + + let contracts = build_ecosystem( shell, + &mut final_ecosystem_args.ecosystem, + final_ecosystem_args.forge_args.clone(), &ecosystem_config, &initial_deployment_config, - sender.clone(), + sender, ) .await?; @@ -71,7 +77,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> save_toml_file( shell, format!("{}/contracts.toml", final_ecosystem_args.out), - contracts_config, + contracts, "", ) .context(MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR)?; @@ -86,31 +92,6 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> Ok(()) } -async fn init( - init_args: &mut EcosystemBuildArgsFinal, - shell: &Shell, - ecosystem_config: &EcosystemConfig, - initial_deployment_config: &InitialDeploymentConfig, - sender: String, -) -> anyhow::Result { - let spinner = Spinner::new(MSG_INTALLING_DEPS_SPINNER); - install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?; - build_system_contracts(shell, &ecosystem_config.link_to_code)?; - spinner.finish(); - - let contracts = build_ecosystem( - shell, - &mut init_args.ecosystem, - init_args.forge_args.clone(), - ecosystem_config, - initial_deployment_config, - sender, - ) - .await?; - contracts.save_with_base_path(shell, &ecosystem_config.config)?; - Ok(contracts) -} - async fn build_ecosystem( shell: &Shell, ecosystem: &mut EcosystemArgsFinal, From 3654de780bf845b678d0876143a306f64777f111 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 12:49:18 +0200 Subject: [PATCH 19/89] refactor: merge build_ecosystem and build_ecosystem_inner --- .../src/commands/ecosystem/build.rs | 103 ++++++++---------- 1 file changed, 43 insertions(+), 60 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 8d708b2e767c..b5553009cd5a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -13,17 +13,14 @@ use config::{ }, script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, }, - traits::{ - FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, - SaveConfigWithBasePath, - }, + traits::{FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig}, ContractsConfig, EcosystemConfig, GenesisConfig, }; use types::{L1Network, ProverMode}; use xshell::Shell; use super::{ - args::build::{EcosystemArgsFinal, EcosystemBuildArgs, EcosystemBuildArgsFinal}, + args::build::{EcosystemArgsFinal, EcosystemBuildArgs}, utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::{ @@ -51,7 +48,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> }; let sender = args.sender.clone(); - let mut final_ecosystem_args = args.fill_values_with_prompt(); + let final_ecosystem_args = args.fill_values_with_prompt(); logger::info(MSG_INITIALIZING_ECOSYSTEM); @@ -62,11 +59,12 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> let contracts = build_ecosystem( shell, - &mut final_ecosystem_args.ecosystem, + &mut final_ecosystem_args.ecosystem.clone(), final_ecosystem_args.forge_args.clone(), &ecosystem_config, &initial_deployment_config, sender, + final_ecosystem_args.ecosystem.l1_rpc_url.clone(), ) .await?; @@ -99,16 +97,47 @@ async fn build_ecosystem( ecosystem_config: &EcosystemConfig, initial_deployment_config: &InitialDeploymentConfig, sender: String, + l1_rpc_url: String, ) -> anyhow::Result { if ecosystem.build_ecosystem { - return build_ecosystem_inner( - shell, - forge_args, - ecosystem_config, + let deploy_config_path = + DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); + + let default_genesis_config = + GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) + .context("Context")?; + + let wallets_config = ecosystem_config.get_wallets()?; + + // For deploying ecosystem we only need genesis batch params + let deploy_config = DeployL1Config::new( + &default_genesis_config, + &wallets_config, initial_deployment_config, - sender, - ) - .await; + ecosystem_config.era_chain_id, + ecosystem_config.prover_version == ProverMode::NoProofs, + ); + deploy_config.save(shell, deploy_config_path)?; + + let forge = Forge::new(&ecosystem_config.path_to_foundry()) + .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) + .with_ffi() + .with_rpc_url(l1_rpc_url) + .with_sender(sender); + + let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); + check_the_balance(&forge).await?; + forge.run(shell)?; + spinner.finish(); + + let script_output = DeployL1Output::read( + shell, + DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code), + )?; + let mut contracts_config = ContractsConfig::default(); + contracts_config.update_from_l1_output(&script_output); + + return Ok(contracts_config); } let ecosystem_preexisting_configs_path = @@ -143,49 +172,3 @@ async fn build_ecosystem( ContractsConfig::read(shell, ecosystem_contracts_path) } - -async fn build_ecosystem_inner( - shell: &Shell, - forge_args: ForgeScriptArgs, - config: &EcosystemConfig, - initial_deployment_config: &InitialDeploymentConfig, - sender: String, -) -> anyhow::Result { - let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&config.link_to_code); - - let default_genesis_config = - GenesisConfig::read_with_base_path(shell, config.get_default_configs_path()) - .context("Context")?; - - let wallets_config = config.get_wallets()?; - - // For deploying ecosystem we only need genesis batch params - let deploy_config = DeployL1Config::new( - &default_genesis_config, - &wallets_config, - initial_deployment_config, - config.era_chain_id, - config.prover_version == ProverMode::NoProofs, - ); - deploy_config.save(shell, deploy_config_path)?; - - let forge = Forge::new(&config.path_to_foundry()) - .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) - .with_ffi() - .with_rpc_url("127.0.0.1:8545".to_string()) - .with_sender(sender); - - let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); - check_the_balance(&forge).await?; - forge.run(shell)?; - spinner.finish(); - - let script_output = DeployL1Output::read( - shell, - DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&config.link_to_code), - )?; - let mut contracts_config = ContractsConfig::default(); - contracts_config.update_from_l1_output(&script_output); - - Ok(contracts_config) -} From 62472313f3bd35f15a8e2ab53b26874655e17901 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 13:06:42 +0200 Subject: [PATCH 20/89] refactor: remove genesis args --- .../src/commands/ecosystem/args/build.rs | 7 +- .../src/commands/ecosystem/build.rs | 145 ++---------------- .../crates/zk_inception/src/messages.rs | 2 - 3 files changed, 18 insertions(+), 136 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index 7c5171fe84e9..a06bf8826aa2 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -6,12 +6,10 @@ use serde::{Deserialize, Serialize}; use url::Url; use crate::{ - commands::chain::args::genesis::GenesisArgs, defaults::LOCAL_RPC_URL, messages::{ MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, - MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, - MSG_L1_RPC_URL_PROMPT, + MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, }, }; @@ -93,9 +91,6 @@ pub struct EcosystemBuildArgs { #[clap(flatten)] #[serde(flatten)] pub forge_args: ForgeScriptArgs, - #[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)] - #[serde(flatten)] - pub genesis_args: GenesisArgs, } impl EcosystemBuildArgs { diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index b5553009cd5a..36b8782675c9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -1,33 +1,15 @@ use anyhow::Context; -use common::{ - files::save_toml_file, - forge::{Forge, ForgeScriptArgs}, - git, logger, - spinner::Spinner, -}; -use config::{ - forge_interface::{ - deploy_ecosystem::{ - input::{DeployL1Config, InitialDeploymentConfig}, - output::DeployL1Output, - }, - script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, - }, - traits::{FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig}, - ContractsConfig, EcosystemConfig, GenesisConfig, -}; -use types::{L1Network, ProverMode}; +use common::{forge::Forge, git, logger, spinner::Spinner}; +use config::{forge_interface::script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, EcosystemConfig}; use xshell::Shell; use super::{ - args::build::{EcosystemArgsFinal, EcosystemBuildArgs}, + args::build::EcosystemBuildArgs, utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::{ - commands::ecosystem::create_configs::create_initial_deployments_config, messages::{ - msg_ecosystem_no_found_preexisting_contract, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, - MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_BUILD_OUTRO, + MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_OUTRO, MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, }, @@ -42,11 +24,6 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> git::submodule_update(shell, ecosystem_config.link_to_code.clone())?; - let initial_deployment_config = match ecosystem_config.get_initial_deployment_config() { - Ok(config) => config, - Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, - }; - let sender = args.sender.clone(); let final_ecosystem_args = args.fill_values_with_prompt(); @@ -57,29 +34,24 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> build_system_contracts(shell, &ecosystem_config.link_to_code)?; spinner.finish(); - let contracts = build_ecosystem( - shell, - &mut final_ecosystem_args.ecosystem.clone(), - final_ecosystem_args.forge_args.clone(), - &ecosystem_config, - &initial_deployment_config, - sender, - final_ecosystem_args.ecosystem.l1_rpc_url.clone(), - ) - .await?; + let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); + let forge = Forge::new(&ecosystem_config.path_to_foundry()) + .script( + &DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), + final_ecosystem_args.forge_args.clone(), + ) + .with_ffi() + .with_rpc_url(final_ecosystem_args.ecosystem.l1_rpc_url) + .with_sender(sender); + + check_the_balance(&forge).await?; + forge.run(shell)?; + spinner.finish(); shell .create_dir(&final_ecosystem_args.out) .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; - save_toml_file( - shell, - format!("{}/contracts.toml", final_ecosystem_args.out), - contracts, - "", - ) - .context(MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR)?; - shell.copy_file( DEPLOY_TRANSACTIONS_FILE, format!("{}/deploy.json", final_ecosystem_args.out), @@ -89,86 +61,3 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> Ok(()) } - -async fn build_ecosystem( - shell: &Shell, - ecosystem: &mut EcosystemArgsFinal, - forge_args: ForgeScriptArgs, - ecosystem_config: &EcosystemConfig, - initial_deployment_config: &InitialDeploymentConfig, - sender: String, - l1_rpc_url: String, -) -> anyhow::Result { - if ecosystem.build_ecosystem { - let deploy_config_path = - DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); - - let default_genesis_config = - GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) - .context("Context")?; - - let wallets_config = ecosystem_config.get_wallets()?; - - // For deploying ecosystem we only need genesis batch params - let deploy_config = DeployL1Config::new( - &default_genesis_config, - &wallets_config, - initial_deployment_config, - ecosystem_config.era_chain_id, - ecosystem_config.prover_version == ProverMode::NoProofs, - ); - deploy_config.save(shell, deploy_config_path)?; - - let forge = Forge::new(&ecosystem_config.path_to_foundry()) - .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) - .with_ffi() - .with_rpc_url(l1_rpc_url) - .with_sender(sender); - - let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); - check_the_balance(&forge).await?; - forge.run(shell)?; - spinner.finish(); - - let script_output = DeployL1Output::read( - shell, - DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code), - )?; - let mut contracts_config = ContractsConfig::default(); - contracts_config.update_from_l1_output(&script_output); - - return Ok(contracts_config); - } - - let ecosystem_preexisting_configs_path = - ecosystem_config - .get_preexisting_configs_path() - .join(format!( - "{}.yaml", - ecosystem_config.l1_network.to_string().to_lowercase() - )); - - // currently there are not some preexisting ecosystem contracts in - // chains, so we need check if this file exists. - if ecosystem.ecosystem_contracts_path.is_none() && !ecosystem_preexisting_configs_path.exists() - { - anyhow::bail!(msg_ecosystem_no_found_preexisting_contract( - &ecosystem_config.l1_network.to_string() - )) - } - - let ecosystem_contracts_path = - ecosystem - .ecosystem_contracts_path - .clone() - .unwrap_or_else(|| match ecosystem_config.l1_network { - L1Network::Localhost => { - ContractsConfig::get_path_with_base_path(&ecosystem_config.config) - } - L1Network::Sepolia | L1Network::Holesky | L1Network::Mainnet => { - ecosystem_preexisting_configs_path - } - }); - - ContractsConfig::read(shell, ecosystem_contracts_path) -} diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 9a25940dbe44..65e924a44e9e 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -117,8 +117,6 @@ pub(super) fn msg_chain_doesnt_exist_err(chain_name: &str, chains: &Vec) /// Ecosystem build related messages pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecosystem contracts..."; pub(super) const MSG_ECOSYSTEM_BUILD_OUTRO: &str = "Transactions successfully built"; -pub(super) const MSG_ECOSYSTEM_BUILD_CONTRACTS_PATH_INVALID_ERR: &str = - "Impossible to save contracts file"; pub(super) const MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; /// Chain create related messages From 9f8cfd82d14c0620b9c674d63534a072848464e5 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 14:56:43 +0200 Subject: [PATCH 21/89] refactor: use single arguments struct --- .../src/commands/ecosystem/args/build.rs | 59 ++++++------------- .../src/commands/ecosystem/build.rs | 2 +- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index a06bf8826aa2..e981a7247e72 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -16,7 +16,7 @@ use crate::{ const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct EcosystemArgs { +pub struct EcosystemBuildArgs { /// Deploy ecosystem contracts #[arg(long)] pub build_ecosystem: bool, @@ -25,10 +25,19 @@ pub struct EcosystemArgs { pub ecosystem_contracts_path: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, + /// Address of the transaction sender. + #[arg(long)] + pub sender: String, + /// Output directory for the generated files. + #[arg(long, short)] + pub out: Option, + #[clap(flatten)] + #[serde(flatten)] + pub forge_args: ForgeScriptArgs, } -impl EcosystemArgs { - pub fn fill_values_with_prompt(self) -> EcosystemArgsFinal { +impl EcosystemBuildArgs { + pub fn fill_values_with_prompt(self) -> EcosystemBuildArgsFinal { let ecosystem_contracts_path = match &self.ecosystem_contracts_path { Some(path) => Some(path.clone()), None => { @@ -61,47 +70,13 @@ impl EcosystemArgs { }) .ask() }); - - EcosystemArgsFinal { - build_ecosystem: self.build_ecosystem, - ecosystem_contracts_path, - l1_rpc_url, - } - } -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct EcosystemArgsFinal { - pub build_ecosystem: bool, - pub ecosystem_contracts_path: Option, - pub l1_rpc_url: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct EcosystemBuildArgs { - /// Address of the transaction sender. - #[arg(long)] - pub sender: String, - /// Output directory for the generated files. - #[arg(long, short)] - pub out: Option, - #[clap(flatten)] - #[serde(flatten)] - pub ecosystem: EcosystemArgs, - #[clap(flatten)] - #[serde(flatten)] - pub forge_args: ForgeScriptArgs, -} - -impl EcosystemBuildArgs { - pub fn fill_values_with_prompt(self) -> EcosystemBuildArgsFinal { - let ecosystem = self.ecosystem.fill_values_with_prompt(); - EcosystemBuildArgsFinal { sender: self.sender, out: self.out.unwrap_or_else(|| DEFAULT_OUT_DIR.into()), - ecosystem, forge_args: self.forge_args.clone(), + build_ecosystem: self.build_ecosystem, + ecosystem_contracts_path, + l1_rpc_url, } } } @@ -110,6 +85,8 @@ impl EcosystemBuildArgs { pub struct EcosystemBuildArgsFinal { pub sender: String, pub out: String, - pub ecosystem: EcosystemArgsFinal, pub forge_args: ForgeScriptArgs, + pub build_ecosystem: bool, + pub ecosystem_contracts_path: Option, + pub l1_rpc_url: String, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 36b8782675c9..55d943877940 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -41,7 +41,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> final_ecosystem_args.forge_args.clone(), ) .with_ffi() - .with_rpc_url(final_ecosystem_args.ecosystem.l1_rpc_url) + .with_rpc_url(final_ecosystem_args.l1_rpc_url) .with_sender(sender); check_the_balance(&forge).await?; From 07d4813079ff457eadcb5cabf86611ebaa9382e2 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 16:28:58 +0200 Subject: [PATCH 22/89] fix: build required config files --- .../src/commands/ecosystem/build.rs | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 55d943877940..0f0df51415cb 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -1,10 +1,18 @@ use anyhow::Context; use common::{forge::Forge, git, logger, spinner::Spinner}; -use config::{forge_interface::script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, EcosystemConfig}; +use config::{ + forge_interface::{ + deploy_ecosystem::input::DeployL1Config, script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, + }, + traits::{ReadConfigWithBasePath, SaveConfig}, + EcosystemConfig, GenesisConfig, +}; +use types::ProverMode; use xshell::Shell; use super::{ args::build::EcosystemBuildArgs, + create_configs::create_initial_deployments_config, utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::{ @@ -21,11 +29,14 @@ const DEPLOY_TRANSACTIONS_FILE: &str = pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; + let final_ecosystem_args = args.fill_values_with_prompt(); git::submodule_update(shell, ecosystem_config.link_to_code.clone())?; - let sender = args.sender.clone(); - let final_ecosystem_args = args.fill_values_with_prompt(); + let initial_deployment_config = match ecosystem_config.get_initial_deployment_config() { + Ok(config) => config, + Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, + }; logger::info(MSG_INITIALIZING_ECOSYSTEM); @@ -34,6 +45,22 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> build_system_contracts(shell, &ecosystem_config.link_to_code)?; spinner.finish(); + let default_genesis_config = + GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) + .context("Context")?; + + let wallets_config = ecosystem_config.get_wallets()?; + // For deploying ecosystem we only need genesis batch params + let deploy_config = DeployL1Config::new( + &default_genesis_config, + &wallets_config, + &initial_deployment_config, + ecosystem_config.era_chain_id, + ecosystem_config.prover_version == ProverMode::NoProofs, + ); + let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); + deploy_config.save(shell, deploy_config_path)?; + let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); let forge = Forge::new(&ecosystem_config.path_to_foundry()) .script( @@ -42,7 +69,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> ) .with_ffi() .with_rpc_url(final_ecosystem_args.l1_rpc_url) - .with_sender(sender); + .with_sender(final_ecosystem_args.sender); check_the_balance(&forge).await?; forge.run(shell)?; From 9fea58dd70c605fa493fe9e3272f574ee8b4a013 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 16:39:29 +0200 Subject: [PATCH 23/89] fix: unsigned transactions path --- .../crates/zk_inception/src/commands/ecosystem/build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 0f0df51415cb..1eeca2632cfe 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -80,7 +80,11 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; shell.copy_file( - DEPLOY_TRANSACTIONS_FILE, + format!( + "{}/{}", + ecosystem_config.link_to_code.to_string_lossy(), + DEPLOY_TRANSACTIONS_FILE + ), format!("{}/deploy.json", final_ecosystem_args.out), )?; From 80c7ffc321f937547d475e1f0ce13be74ab6312c Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 17:27:04 +0200 Subject: [PATCH 24/89] refactor: lint --- zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs index e0082a8c83eb..de9bc8789ba9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs @@ -21,7 +21,7 @@ pub enum EcosystemCommands { /// Create a new ecosystem and chain, /// setting necessary configurations for later initialization Create(EcosystemCreateArgs), - /// + /// Create transactions to build ecosystem contracts Build(EcosystemBuildArgs), /// Initialize ecosystem and chain, /// deploying necessary contracts and performing on-chain operations From 7aee591afc656edd2c62eb00d09ede433c88ac6f Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 4 Sep 2024 18:07:46 +0200 Subject: [PATCH 25/89] refactor: use PathBuf::join --- .../crates/zk_inception/src/commands/ecosystem/build.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 1eeca2632cfe..0b816a9a5bac 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -7,6 +7,7 @@ use config::{ traits::{ReadConfigWithBasePath, SaveConfig}, EcosystemConfig, GenesisConfig, }; +use tokio::io::join; use types::ProverMode; use xshell::Shell; @@ -80,11 +81,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; shell.copy_file( - format!( - "{}/{}", - ecosystem_config.link_to_code.to_string_lossy(), - DEPLOY_TRANSACTIONS_FILE - ), + ecosystem_config.link_to_code.join(DEPLOY_TRANSACTIONS_FILE), format!("{}/deploy.json", final_ecosystem_args.out), )?; From 30feef04f0f9b087960e78187abce5675c929164 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 5 Sep 2024 10:40:13 +0200 Subject: [PATCH 26/89] refactor: remove balance check --- zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 0b816a9a5bac..8fcdff4d4ae5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -72,7 +72,6 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> .with_rpc_url(final_ecosystem_args.l1_rpc_url) .with_sender(final_ecosystem_args.sender); - check_the_balance(&forge).await?; forge.run(shell)?; spinner.finish(); From d669fa2b4bbfafa23e2a404619faea66c860ab0a Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 5 Sep 2024 10:43:05 +0200 Subject: [PATCH 27/89] refactor: remove unused imports --- .../zk_inception/src/commands/ecosystem/build.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 8fcdff4d4ae5..f0543d016717 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -7,7 +7,6 @@ use config::{ traits::{ReadConfigWithBasePath, SaveConfig}, EcosystemConfig, GenesisConfig, }; -use tokio::io::join; use types::ProverMode; use xshell::Shell; @@ -16,13 +15,10 @@ use super::{ create_configs::create_initial_deployments_config, utils::{build_system_contracts, install_yarn_dependencies}, }; -use crate::{ - messages::{ - MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_OUTRO, - MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, - MSG_INTALLING_DEPS_SPINNER, - }, - utils::forge::check_the_balance, +use crate::messages::{ + MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_OUTRO, + MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, + MSG_INTALLING_DEPS_SPINNER, }; const DEPLOY_TRANSACTIONS_FILE: &str = From cae36e0fc2d794be1e5dbf9eb71932f715d08806 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 5 Sep 2024 10:52:14 +0200 Subject: [PATCH 28/89] refactor: use positional arg for sender --- .../crates/zk_inception/src/commands/ecosystem/args/build.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index e981a7247e72..f55b91e20de4 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -17,6 +17,8 @@ const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct EcosystemBuildArgs { + /// Address of the transaction sender. + pub sender: String, /// Deploy ecosystem contracts #[arg(long)] pub build_ecosystem: bool, @@ -25,9 +27,6 @@ pub struct EcosystemBuildArgs { pub ecosystem_contracts_path: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, - /// Address of the transaction sender. - #[arg(long)] - pub sender: String, /// Output directory for the generated files. #[arg(long, short)] pub out: Option, From db48f49413c890b7d78615857dcf415f86b2e1ea Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 5 Sep 2024 14:51:17 +0200 Subject: [PATCH 29/89] feat: save deployment config file --- .../zk_inception/src/commands/ecosystem/build.rs | 12 ++++++++++-- zk_toolbox/crates/zk_inception/src/messages.rs | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index f0543d016717..4de5c49c16d5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -18,11 +18,12 @@ use super::{ use crate::messages::{ MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_OUTRO, MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, - MSG_INTALLING_DEPS_SPINNER, + MSG_INTALLING_DEPS_SPINNER, MSG_WRITING_OUTPUT_FILES_SPINNER, }; const DEPLOY_TRANSACTIONS_FILE: &str = "contracts/l1-contracts/broadcast/DeployL1.s.sol/9/dry-run/run-latest.json"; +const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { let ecosystem_config = EcosystemConfig::from_file(shell)?; @@ -71,15 +72,22 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> forge.run(shell)?; spinner.finish(); + let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); shell .create_dir(&final_ecosystem_args.out) .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; shell.copy_file( ecosystem_config.link_to_code.join(DEPLOY_TRANSACTIONS_FILE), - format!("{}/deploy.json", final_ecosystem_args.out), + format!("{}/deploy-l1-txns.json", final_ecosystem_args.out), )?; + shell.copy_file( + ecosystem_config.link_to_code.join(SCRIPT_CONFIG_FILE), + format!("{}/deploy-l1-config.toml", final_ecosystem_args.out), + )?; + spinner.finish(); + logger::outro(MSG_ECOSYSTEM_BUILD_OUTRO); Ok(()) diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 65e924a44e9e..0dbfaa19c405 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -116,6 +116,7 @@ pub(super) fn msg_chain_doesnt_exist_err(chain_name: &str, chains: &Vec) /// Ecosystem build related messages pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecosystem contracts..."; +pub(super) const MSG_WRITING_OUTPUT_FILES_SPINNER: &str = "Writing output files..."; pub(super) const MSG_ECOSYSTEM_BUILD_OUTRO: &str = "Transactions successfully built"; pub(super) const MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; From 45a9202e16c76832cc478068eb7e36d5f823819d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 5 Sep 2024 16:55:40 +0200 Subject: [PATCH 30/89] feat: use dedicated script params for ecosystem build --- .../crates/config/src/forge_interface/script_params.rs | 6 ++++++ .../crates/zk_inception/src/commands/ecosystem/build.rs | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/config/src/forge_interface/script_params.rs b/zk_toolbox/crates/config/src/forge_interface/script_params.rs index fb16aa97e6a8..8767044b5a1f 100644 --- a/zk_toolbox/crates/config/src/forge_interface/script_params.rs +++ b/zk_toolbox/crates/config/src/forge_interface/script_params.rs @@ -32,6 +32,12 @@ pub const DEPLOY_ECOSYSTEM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams script_path: "deploy-scripts/DeployL1.s.sol", }; +pub const BUILD_ECOSYSTEM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { + input: "script-config/config-deploy-l1.build.toml", + output: "script-out/output-deploy-l1.build.toml", + script_path: "deploy-scripts/DeployL1.s.sol", +}; + pub const DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { input: "script-config/config-deploy-l2-contracts.toml", output: "script-out/output-deploy-l2-contracts.toml", diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 4de5c49c16d5..dd74c55dc476 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -2,7 +2,7 @@ use anyhow::Context; use common::{forge::Forge, git, logger, spinner::Spinner}; use config::{ forge_interface::{ - deploy_ecosystem::input::DeployL1Config, script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, + deploy_ecosystem::input::DeployL1Config, script_params::BUILD_ECOSYSTEM_SCRIPT_PARAMS, }, traits::{ReadConfigWithBasePath, SaveConfig}, EcosystemConfig, GenesisConfig, @@ -56,13 +56,13 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> ecosystem_config.era_chain_id, ecosystem_config.prover_version == ProverMode::NoProofs, ); - let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); + let deploy_config_path = BUILD_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); deploy_config.save(shell, deploy_config_path)?; let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); let forge = Forge::new(&ecosystem_config.path_to_foundry()) .script( - &DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), + &BUILD_ECOSYSTEM_SCRIPT_PARAMS.script(), final_ecosystem_args.forge_args.clone(), ) .with_ffi() From bd87144e7c6aa222fb50c47c22c7cef235e57b72 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 5 Sep 2024 17:43:06 +0200 Subject: [PATCH 31/89] feat: draft `zki chain build` subcommand --- .../src/commands/chain/args/build.rs | 77 +++++++++++++++++ .../src/commands/chain/args/mod.rs | 1 + .../zk_inception/src/commands/chain/build.rs | 83 +++++++++++++++++++ .../zk_inception/src/commands/chain/mod.rs | 5 ++ 4 files changed, 166 insertions(+) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs create mode 100644 zk_toolbox/crates/zk_inception/src/commands/chain/build.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs new file mode 100644 index 000000000000..5cc7c48226c9 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs @@ -0,0 +1,77 @@ +use clap::Parser; +use common::{forge::ForgeScriptArgs, Prompt}; +use config::ChainConfig; +use serde::{Deserialize, Serialize}; +use types::L1Network; +use url::Url; + +use super::{genesis::GenesisArgsFinal, init::PortOffset}; +use crate::{ + commands::chain::args::genesis::GenesisArgs, + defaults::LOCAL_RPC_URL, + messages::{ + MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, + MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_PORT_OFFSET_HELP, + }, +}; + +#[derive(Debug, Clone, Serialize, Deserialize, Parser)] +pub struct BuildArgs { + /// All ethereum environment related arguments + #[clap(flatten)] + #[serde(flatten)] + pub forge_args: ForgeScriptArgs, + #[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)] + #[serde(flatten)] + pub genesis_args: GenesisArgs, + #[clap(long, default_missing_value = "true", num_args = 0..=1)] + pub deploy_paymaster: Option, + #[clap(long, help = MSG_L1_RPC_URL_HELP)] + pub l1_rpc_url: Option, + #[clap(long, help = MSG_PORT_OFFSET_HELP)] + pub port_offset: Option, +} + +impl BuildArgs { + pub fn fill_values_with_prompt(self, config: &ChainConfig) -> BuildArgsFinal { + let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { + common::PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) + .default(true) + .ask() + }); + + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { + let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); + if config.l1_network == L1Network::Localhost { + prompt = prompt.default(LOCAL_RPC_URL); + } + prompt + .validate_with(|val: &String| -> Result<(), String> { + Url::parse(val) + .map(|_| ()) + .map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) + }) + .ask() + }); + + BuildArgsFinal { + forge_args: self.forge_args, + genesis_args: self.genesis_args.fill_values_with_prompt(config), + deploy_paymaster, + l1_rpc_url, + port_offset: self + .port_offset + .unwrap_or(PortOffset::from_chain_id(config.chain_id.as_u64() as u16)) + .into(), + } + } +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct BuildArgsFinal { + pub forge_args: ForgeScriptArgs, + pub genesis_args: GenesisArgsFinal, + pub deploy_paymaster: bool, + pub l1_rpc_url: String, + pub port_offset: u16, +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs index 08f39a90a843..a61a9a6ebe4d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs @@ -1,3 +1,4 @@ +pub mod build; pub mod create; pub mod genesis; pub mod init; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs new file mode 100644 index 000000000000..8fb5e78662ef --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -0,0 +1,83 @@ +use anyhow::Context; +use common::{config::global_config, forge::Forge, git, logger, spinner::Spinner}; +use config::{ + copy_configs, + forge_interface::{ + register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, + script_params::REGISTER_CHAIN_SCRIPT_PARAMS, + }, + set_l1_rpc_url, + traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, + update_from_chain_config, EcosystemConfig, +}; +use xshell::Shell; + +use crate::{ + commands::chain::args::build::BuildArgs, + messages::{ + msg_initializing_chain, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, + MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, + }, + utils::forge::{check_the_balance, fill_forge_private_key}, +}; + +pub(crate) async fn run(args: BuildArgs, shell: &Shell) -> anyhow::Result<()> { + let chain_name = global_config().chain_name.clone(); + let config = EcosystemConfig::from_file(shell)?; + let chain_config = config + .load_chain(chain_name) + .context(MSG_CHAIN_NOT_FOUND_ERR)?; + let args = args.fill_values_with_prompt(&chain_config); + + logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); + logger::info(msg_initializing_chain("")); + git::submodule_update(shell, config.link_to_code.clone())?; + + copy_configs(shell, &config.link_to_code, &chain_config.configs)?; + + let general_config = chain_config.get_general_config()?; + general_config.save_with_base_path(shell, &chain_config.configs)?; + + let mut genesis_config = chain_config.get_genesis_config()?; + update_from_chain_config(&mut genesis_config, &chain_config); + genesis_config.save_with_base_path(shell, &chain_config.configs)?; + + // Copy ecosystem contracts + let mut contracts_config = config.get_contracts_config()?; + contracts_config.l1.base_token_addr = chain_config.base_token.address; + contracts_config.save_with_base_path(shell, &chain_config.configs)?; + + let mut secrets = chain_config.get_secrets_config()?; + set_l1_rpc_url(&mut secrets, args.l1_rpc_url.clone())?; + secrets.save_with_base_path(shell, &chain_config.configs)?; + + let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); + let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); + + let deploy_config = RegisterChainL1Config::new(&chain_config, &contracts_config)?; + deploy_config.save(shell, deploy_config_path)?; + + let mut forge = Forge::new(&config.path_to_foundry()) + .script( + ®ISTER_CHAIN_SCRIPT_PARAMS.script(), + args.forge_args.clone(), + ) + .with_ffi() + .with_rpc_url(args.l1_rpc_url.clone()); + + forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?; + check_the_balance(&forge).await?; + forge.run(shell)?; + + let register_chain_output = RegisterChainOutput::read( + shell, + REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), + )?; + contracts_config.set_chain_contracts(®ister_chain_output); + + contracts_config.save_with_base_path(shell, &chain_config.configs)?; + spinner.finish(); + + logger::success(MSG_CHAIN_INITIALIZED); + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index dbddc923336a..7cf335606f99 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -1,3 +1,4 @@ +use args::build::BuildArgs; pub(crate) use args::create::ChainCreateArgsFinal; use clap::Subcommand; use common::forge::ForgeScriptArgs; @@ -10,6 +11,7 @@ use crate::commands::chain::{ }; pub(crate) mod args; +mod build; mod create; pub mod deploy_l2_contracts; pub mod deploy_paymaster; @@ -21,6 +23,8 @@ mod set_token_multiplier_setter; pub enum ChainCommands { /// Create a new chain, setting the necessary configurations for later initialization Create(ChainCreateArgs), + /// Create unsigned transactions for chain deployment + Build(BuildArgs), /// Initialize chain, deploying necessary contracts and performing on-chain operations Init(InitArgs), /// Run server genesis @@ -44,6 +48,7 @@ pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<() match args { ChainCommands::Create(args) => create::run(args, shell), ChainCommands::Init(args) => init::run(args, shell).await, + ChainCommands::Build(args) => build::run(args, shell).await, ChainCommands::Genesis(args) => genesis::run(args, shell).await, ChainCommands::DeployL2Contracts(args) => { deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All).await From 78e8d08e26154842f3abb2fe413da4bbdf78658f Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 10:39:57 +0200 Subject: [PATCH 32/89] refactor: format --- zk_toolbox/crates/common/src/forge.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/zk_toolbox/crates/common/src/forge.rs b/zk_toolbox/crates/common/src/forge.rs index c90cd1421712..7fd5399cc66b 100644 --- a/zk_toolbox/crates/common/src/forge.rs +++ b/zk_toolbox/crates/common/src/forge.rs @@ -141,6 +141,7 @@ impl ForgeScript { }); self } + // Do not start the script if balance is not enough pub fn private_key(&self) -> Option { self.args.args.iter().find_map(|a| { From db047fec17cfe845f1248a81ad1e3a167baa88b9 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 11:06:01 +0200 Subject: [PATCH 33/89] feat: first version of zki chain build --- .../src/forge_interface/script_params.rs | 6 ++ .../src/commands/chain/args/build.rs | 48 ++++--------- .../zk_inception/src/commands/chain/build.rs | 70 ++++++++++--------- .../zk_inception/src/commands/chain/mod.rs | 4 +- .../crates/zk_inception/src/messages.rs | 4 ++ 5 files changed, 64 insertions(+), 68 deletions(-) diff --git a/zk_toolbox/crates/config/src/forge_interface/script_params.rs b/zk_toolbox/crates/config/src/forge_interface/script_params.rs index 8767044b5a1f..9a7ec7e35489 100644 --- a/zk_toolbox/crates/config/src/forge_interface/script_params.rs +++ b/zk_toolbox/crates/config/src/forge_interface/script_params.rs @@ -50,6 +50,12 @@ pub const REGISTER_CHAIN_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { script_path: "deploy-scripts/RegisterHyperchain.s.sol", }; +pub const BUILD_CHAIN_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { + input: "script-config/register-hyperchain.toml", + output: "script-out/output-register-hyperchain.toml", + script_path: "deploy-scripts/RegisterHyperchain.s.sol", +}; + pub const DEPLOY_ERC20_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { input: "script-config/config-deploy-erc20.toml", output: "script-out/output-deploy-erc20.toml", diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs index 5cc7c48226c9..d9fc565bd1aa 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use clap::Parser; use common::{forge::ForgeScriptArgs, Prompt}; use config::ChainConfig; @@ -5,41 +7,28 @@ use serde::{Deserialize, Serialize}; use types::L1Network; use url::Url; -use super::{genesis::GenesisArgsFinal, init::PortOffset}; use crate::{ - commands::chain::args::genesis::GenesisArgs, defaults::LOCAL_RPC_URL, - messages::{ - MSG_DEPLOY_PAYMASTER_PROMPT, MSG_GENESIS_ARGS_HELP, MSG_L1_RPC_URL_HELP, - MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, MSG_PORT_OFFSET_HELP, - }, + messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, }; +const DEFAULT_OUT_DIR: &str = "transactions/chain"; + #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct BuildArgs { +pub struct ChainBuildArgs { + /// Output directory for the generated files. + #[arg(long, short)] + pub out: Option, /// All ethereum environment related arguments #[clap(flatten)] #[serde(flatten)] pub forge_args: ForgeScriptArgs, - #[clap(flatten, next_help_heading = MSG_GENESIS_ARGS_HELP)] - #[serde(flatten)] - pub genesis_args: GenesisArgs, - #[clap(long, default_missing_value = "true", num_args = 0..=1)] - pub deploy_paymaster: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, - #[clap(long, help = MSG_PORT_OFFSET_HELP)] - pub port_offset: Option, } -impl BuildArgs { - pub fn fill_values_with_prompt(self, config: &ChainConfig) -> BuildArgsFinal { - let deploy_paymaster = self.deploy_paymaster.unwrap_or_else(|| { - common::PromptConfirm::new(MSG_DEPLOY_PAYMASTER_PROMPT) - .default(true) - .ask() - }); - +impl ChainBuildArgs { + pub fn fill_values_with_prompt(self, config: &ChainConfig) -> ChainBuildArgsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); if config.l1_network == L1Network::Localhost { @@ -54,24 +43,17 @@ impl BuildArgs { .ask() }); - BuildArgsFinal { + ChainBuildArgsFinal { + out: self.out.unwrap_or_else(|| DEFAULT_OUT_DIR.into()), forge_args: self.forge_args, - genesis_args: self.genesis_args.fill_values_with_prompt(config), - deploy_paymaster, l1_rpc_url, - port_offset: self - .port_offset - .unwrap_or(PortOffset::from_chain_id(config.chain_id.as_u64() as u16)) - .into(), } } } #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct BuildArgsFinal { +pub struct ChainBuildArgsFinal { + pub out: PathBuf, pub forge_args: ForgeScriptArgs, - pub genesis_args: GenesisArgsFinal, - pub deploy_paymaster: bool, pub l1_rpc_url: String, - pub port_offset: u16, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index 8fb5e78662ef..d362e6ad8647 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -4,78 +4,82 @@ use config::{ copy_configs, forge_interface::{ register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, - script_params::REGISTER_CHAIN_SCRIPT_PARAMS, + script_params::{BUILD_CHAIN_SCRIPT_PARAMS, REGISTER_CHAIN_SCRIPT_PARAMS}, }, - set_l1_rpc_url, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, - update_from_chain_config, EcosystemConfig, + EcosystemConfig, }; +use ethers::{abi::AbiEncode, utils::hex::ToHex}; use xshell::Shell; use crate::{ - commands::chain::args::build::BuildArgs, + commands::chain::args::build::ChainBuildArgs, messages::{ - msg_initializing_chain, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, + MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, }, - utils::forge::{check_the_balance, fill_forge_private_key}, }; -pub(crate) async fn run(args: BuildArgs, shell: &Shell) -> anyhow::Result<()> { - let chain_name = global_config().chain_name.clone(); +const CHAIN_TRANSACTIONS_FILE: &str = + "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; +const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; + +pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<()> { let config = EcosystemConfig::from_file(shell)?; + let chain_name = global_config().chain_name.clone(); let chain_config = config .load_chain(chain_name) .context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(&chain_config); - logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); - logger::info(msg_initializing_chain("")); - git::submodule_update(shell, config.link_to_code.clone())?; + let args = args.fill_values_with_prompt(&chain_config); copy_configs(shell, &config.link_to_code, &chain_config.configs)?; - let general_config = chain_config.get_general_config()?; - general_config.save_with_base_path(shell, &chain_config.configs)?; + logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); - let mut genesis_config = chain_config.get_genesis_config()?; - update_from_chain_config(&mut genesis_config, &chain_config); - genesis_config.save_with_base_path(shell, &chain_config.configs)?; + git::submodule_update(shell, config.link_to_code.clone())?; // Copy ecosystem contracts - let mut contracts_config = config.get_contracts_config()?; + let mut contracts_config = config.get_contracts_config().context( + "Missing contract.yaml, please be sure to run this command within initialized ecosystem", + )?; contracts_config.l1.base_token_addr = chain_config.base_token.address; contracts_config.save_with_base_path(shell, &chain_config.configs)?; - let mut secrets = chain_config.get_secrets_config()?; - set_l1_rpc_url(&mut secrets, args.l1_rpc_url.clone())?; - secrets.save_with_base_path(shell, &chain_config.configs)?; - let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); let deploy_config = RegisterChainL1Config::new(&chain_config, &contracts_config)?; deploy_config.save(shell, deploy_config_path)?; - let mut forge = Forge::new(&config.path_to_foundry()) - .script( - ®ISTER_CHAIN_SCRIPT_PARAMS.script(), - args.forge_args.clone(), - ) + Forge::new(&config.path_to_foundry()) + .script(&BUILD_CHAIN_SCRIPT_PARAMS.script(), args.forge_args.clone()) .with_ffi() - .with_rpc_url(args.l1_rpc_url.clone()); - - forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?; - check_the_balance(&forge).await?; - forge.run(shell)?; + .with_sender(config.get_wallets()?.governor.address.encode_hex_upper()) + .with_rpc_url(args.l1_rpc_url.clone()) + .run(shell)?; let register_chain_output = RegisterChainOutput::read( shell, - REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), + BUILD_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), )?; contracts_config.set_chain_contracts(®ister_chain_output); contracts_config.save_with_base_path(shell, &chain_config.configs)?; + + shell + .create_dir(&args.out) + .context(MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR)?; + + shell.copy_file( + config.link_to_code.join(CHAIN_TRANSACTIONS_FILE), + args.out.join("chain-txns.json"), + )?; + + shell.copy_file( + config.link_to_code.join(SCRIPT_CONFIG_FILE), + args.out.join("chain-config.toml"), + )?; spinner.finish(); logger::success(MSG_CHAIN_INITIALIZED); diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index 7cf335606f99..4514277ef5fb 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -1,4 +1,4 @@ -use args::build::BuildArgs; +use args::build::ChainBuildArgs; pub(crate) use args::create::ChainCreateArgsFinal; use clap::Subcommand; use common::forge::ForgeScriptArgs; @@ -24,7 +24,7 @@ pub enum ChainCommands { /// Create a new chain, setting the necessary configurations for later initialization Create(ChainCreateArgs), /// Create unsigned transactions for chain deployment - Build(BuildArgs), + Build(ChainBuildArgs), /// Initialize chain, deploying necessary contracts and performing on-chain operations Init(InitArgs), /// Run server genesis diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 0dbfaa19c405..7ef9561ebb4c 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -174,6 +174,7 @@ pub(super) const MSG_INITIALIZING_SERVER_DATABASE: &str = "Initializing server d pub(super) const MSG_FAILED_TO_DROP_SERVER_DATABASE_ERR: &str = "Failed to drop server database"; pub(super) const MSG_INITIALIZING_PROVER_DATABASE: &str = "Initializing prover database"; pub(super) const MSG_FAILED_TO_DROP_PROVER_DATABASE_ERR: &str = "Failed to drop prover database"; + /// Chain update related messages pub(super) const MSG_WALLETS_CONFIG_MUST_BE_PRESENT: &str = "Wallets configuration must be present"; @@ -207,6 +208,9 @@ pub(super) const MSG_DEPLOYING_L2_CONTRACT_SPINNER: &str = "Deploying l2 contrac /// Chain deploy paymaster related messages pub(super) const MSG_DEPLOYING_PAYMASTER: &str = "Deploying paymaster"; +/// Chain build related messages +pub(super) const MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; + /// Run server related messages pub(super) const MSG_SERVER_COMPONENTS_HELP: &str = "Components of server to run"; pub(super) const MSG_SERVER_GENESIS_HELP: &str = "Run server in genesis mode"; From be328a2b4479bde8c5cbc75ec13404c1bd1874af Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 11:25:42 +0200 Subject: [PATCH 34/89] fix: use original script params --- .../config/src/forge_interface/script_params.rs | 12 ------------ .../crates/zk_inception/src/commands/chain/build.rs | 11 +++++++---- .../zk_inception/src/commands/ecosystem/build.rs | 6 +++--- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/zk_toolbox/crates/config/src/forge_interface/script_params.rs b/zk_toolbox/crates/config/src/forge_interface/script_params.rs index 9a7ec7e35489..fb16aa97e6a8 100644 --- a/zk_toolbox/crates/config/src/forge_interface/script_params.rs +++ b/zk_toolbox/crates/config/src/forge_interface/script_params.rs @@ -32,12 +32,6 @@ pub const DEPLOY_ECOSYSTEM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams script_path: "deploy-scripts/DeployL1.s.sol", }; -pub const BUILD_ECOSYSTEM_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { - input: "script-config/config-deploy-l1.build.toml", - output: "script-out/output-deploy-l1.build.toml", - script_path: "deploy-scripts/DeployL1.s.sol", -}; - pub const DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { input: "script-config/config-deploy-l2-contracts.toml", output: "script-out/output-deploy-l2-contracts.toml", @@ -50,12 +44,6 @@ pub const REGISTER_CHAIN_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { script_path: "deploy-scripts/RegisterHyperchain.s.sol", }; -pub const BUILD_CHAIN_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { - input: "script-config/register-hyperchain.toml", - output: "script-out/output-register-hyperchain.toml", - script_path: "deploy-scripts/RegisterHyperchain.s.sol", -}; - pub const DEPLOY_ERC20_SCRIPT_PARAMS: ForgeScriptParams = ForgeScriptParams { input: "script-config/config-deploy-erc20.toml", output: "script-out/output-deploy-erc20.toml", diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index d362e6ad8647..8cd06da5ad2d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -4,12 +4,12 @@ use config::{ copy_configs, forge_interface::{ register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, - script_params::{BUILD_CHAIN_SCRIPT_PARAMS, REGISTER_CHAIN_SCRIPT_PARAMS}, + script_params::REGISTER_CHAIN_SCRIPT_PARAMS, }, traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, EcosystemConfig, }; -use ethers::{abi::AbiEncode, utils::hex::ToHex}; +use ethers::utils::hex::ToHex; use xshell::Shell; use crate::{ @@ -53,7 +53,10 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( deploy_config.save(shell, deploy_config_path)?; Forge::new(&config.path_to_foundry()) - .script(&BUILD_CHAIN_SCRIPT_PARAMS.script(), args.forge_args.clone()) + .script( + ®ISTER_CHAIN_SCRIPT_PARAMS.script(), + args.forge_args.clone(), + ) .with_ffi() .with_sender(config.get_wallets()?.governor.address.encode_hex_upper()) .with_rpc_url(args.l1_rpc_url.clone()) @@ -61,7 +64,7 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( let register_chain_output = RegisterChainOutput::read( shell, - BUILD_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), + REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), )?; contracts_config.set_chain_contracts(®ister_chain_output); diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index dd74c55dc476..4de5c49c16d5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -2,7 +2,7 @@ use anyhow::Context; use common::{forge::Forge, git, logger, spinner::Spinner}; use config::{ forge_interface::{ - deploy_ecosystem::input::DeployL1Config, script_params::BUILD_ECOSYSTEM_SCRIPT_PARAMS, + deploy_ecosystem::input::DeployL1Config, script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, }, traits::{ReadConfigWithBasePath, SaveConfig}, EcosystemConfig, GenesisConfig, @@ -56,13 +56,13 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> ecosystem_config.era_chain_id, ecosystem_config.prover_version == ProverMode::NoProofs, ); - let deploy_config_path = BUILD_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); + let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); deploy_config.save(shell, deploy_config_path)?; let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); let forge = Forge::new(&ecosystem_config.path_to_foundry()) .script( - &BUILD_ECOSYSTEM_SCRIPT_PARAMS.script(), + &DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), final_ecosystem_args.forge_args.clone(), ) .with_ffi() From 258eb0cff87f62c8fa205453e22ee98871843cf2 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 11:46:12 +0200 Subject: [PATCH 35/89] refactor: use message const --- .../crates/zk_inception/src/commands/chain/build.rs | 11 ++++++----- zk_toolbox/crates/zk_inception/src/messages.rs | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index 8cd06da5ad2d..0896a5484361 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -15,8 +15,9 @@ use xshell::Shell; use crate::{ commands::chain::args::build::ChainBuildArgs, messages::{ - MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, - MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, + MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG, MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR, + MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_REGISTERING_CHAIN_SPINNER, + MSG_SELECTED_CONFIG, }, }; @@ -40,9 +41,9 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( git::submodule_update(shell, config.link_to_code.clone())?; // Copy ecosystem contracts - let mut contracts_config = config.get_contracts_config().context( - "Missing contract.yaml, please be sure to run this command within initialized ecosystem", - )?; + let mut contracts_config = config + .get_contracts_config() + .context(MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG)?; contracts_config.l1.base_token_addr = chain_config.base_token.address; contracts_config.save_with_base_path(shell, &chain_config.configs)?; diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 55087e54758e..ce7cb940ca05 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -225,6 +225,8 @@ pub(super) const MSG_DEPLOYING_PAYMASTER: &str = "Deploying paymaster"; /// Chain build related messages pub(super) const MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; +pub(super) const MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG: &str = + "Missing contract.yaml, please be sure to run this command within initialized ecosystem"; /// Run server related messages pub(super) const MSG_SERVER_COMPONENTS_HELP: &str = "Components of server to run"; From e9cdc329aab18dea3b82c6d6c532e003eaea3646 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 11:50:20 +0200 Subject: [PATCH 36/89] refactor: use PathBuf for --out option --- .../zk_inception/src/commands/ecosystem/args/build.rs | 6 +++--- .../crates/zk_inception/src/commands/ecosystem/build.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index f55b91e20de4..f371a58e6f27 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -29,7 +29,7 @@ pub struct EcosystemBuildArgs { pub l1_rpc_url: Option, /// Output directory for the generated files. #[arg(long, short)] - pub out: Option, + pub out: Option, #[clap(flatten)] #[serde(flatten)] pub forge_args: ForgeScriptArgs, @@ -71,7 +71,7 @@ impl EcosystemBuildArgs { }); EcosystemBuildArgsFinal { sender: self.sender, - out: self.out.unwrap_or_else(|| DEFAULT_OUT_DIR.into()), + out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), forge_args: self.forge_args.clone(), build_ecosystem: self.build_ecosystem, ecosystem_contracts_path, @@ -83,7 +83,7 @@ impl EcosystemBuildArgs { #[derive(Debug, Serialize, Deserialize)] pub struct EcosystemBuildArgsFinal { pub sender: String, - pub out: String, + pub out: PathBuf, pub forge_args: ForgeScriptArgs, pub build_ecosystem: bool, pub ecosystem_contracts_path: Option, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 4de5c49c16d5..e09d36e92ff9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -79,12 +79,12 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> shell.copy_file( ecosystem_config.link_to_code.join(DEPLOY_TRANSACTIONS_FILE), - format!("{}/deploy-l1-txns.json", final_ecosystem_args.out), + final_ecosystem_args.out.join("deploy-l1-txns.json"), )?; shell.copy_file( ecosystem_config.link_to_code.join(SCRIPT_CONFIG_FILE), - format!("{}/deploy-l1-config.toml", final_ecosystem_args.out), + final_ecosystem_args.out.join("deploy-l1-config.toml"), )?; spinner.finish(); From 5b0758c7ee2fb9f5db77a211a05fc518589464e6 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 11:56:15 +0200 Subject: [PATCH 37/89] refactor: remove unused option --- .../crates/zk_inception/src/commands/ecosystem/args/build.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index f371a58e6f27..5d071e06790d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -19,9 +19,6 @@ const DEFAULT_OUT_DIR: &str = "transactions"; pub struct EcosystemBuildArgs { /// Address of the transaction sender. pub sender: String, - /// Deploy ecosystem contracts - #[arg(long)] - pub build_ecosystem: bool, /// Path to ecosystem contracts #[clap(long)] pub ecosystem_contracts_path: Option, @@ -73,7 +70,6 @@ impl EcosystemBuildArgs { sender: self.sender, out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), forge_args: self.forge_args.clone(), - build_ecosystem: self.build_ecosystem, ecosystem_contracts_path, l1_rpc_url, } @@ -85,7 +81,6 @@ pub struct EcosystemBuildArgsFinal { pub sender: String, pub out: PathBuf, pub forge_args: ForgeScriptArgs, - pub build_ecosystem: bool, pub ecosystem_contracts_path: Option, pub l1_rpc_url: String, } From b7cce7b01464833c7bfd5aff5a637f56f7494f85 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 12:02:27 +0200 Subject: [PATCH 38/89] fix: remove unsupported option --- .../src/commands/ecosystem/args/build.rs | 34 ++----------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs index 5d071e06790d..fe7229adbcf7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs @@ -1,4 +1,4 @@ -use std::{path::PathBuf, str::FromStr}; +use std::path::PathBuf; use clap::Parser; use common::{forge::ForgeScriptArgs, Prompt}; @@ -7,10 +7,7 @@ use url::Url; use crate::{ defaults::LOCAL_RPC_URL, - messages::{ - MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR, MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT, - MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, - }, + messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, }; const DEFAULT_OUT_DIR: &str = "transactions"; @@ -19,9 +16,6 @@ const DEFAULT_OUT_DIR: &str = "transactions"; pub struct EcosystemBuildArgs { /// Address of the transaction sender. pub sender: String, - /// Path to ecosystem contracts - #[clap(long)] - pub ecosystem_contracts_path: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, /// Output directory for the generated files. @@ -34,28 +28,6 @@ pub struct EcosystemBuildArgs { impl EcosystemBuildArgs { pub fn fill_values_with_prompt(self) -> EcosystemBuildArgsFinal { - let ecosystem_contracts_path = match &self.ecosystem_contracts_path { - Some(path) => Some(path.clone()), - None => { - let input_path: String = Prompt::new(MSG_ECOSYSTEM_CONTRACTS_PATH_PROMPT) - .allow_empty() - .validate_with(|val: &String| { - if val.is_empty() { - return Ok(()); - } - PathBuf::from_str(val) - .map(|_| ()) - .map_err(|_| MSG_ECOSYSTEM_CONTRACTS_PATH_INVALID_ERR.to_string()) - }) - .ask(); - if input_path.is_empty() { - None - } else { - Some(input_path.into()) - } - } - }; - let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_L1_RPC_URL_PROMPT) .default(LOCAL_RPC_URL) @@ -70,7 +42,6 @@ impl EcosystemBuildArgs { sender: self.sender, out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), forge_args: self.forge_args.clone(), - ecosystem_contracts_path, l1_rpc_url, } } @@ -81,6 +52,5 @@ pub struct EcosystemBuildArgsFinal { pub sender: String, pub out: PathBuf, pub forge_args: ForgeScriptArgs, - pub ecosystem_contracts_path: Option, pub l1_rpc_url: String, } From 97d7368ceb18f8d2681617c1241babfce9bd5185 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 12:15:49 +0200 Subject: [PATCH 39/89] refactor: use shadowing for final args --- .../zk_inception/src/commands/ecosystem/build.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index e09d36e92ff9..ea6d18b7d35d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -26,8 +26,8 @@ const DEPLOY_TRANSACTIONS_FILE: &str = const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt(); let ecosystem_config = EcosystemConfig::from_file(shell)?; - let final_ecosystem_args = args.fill_values_with_prompt(); git::submodule_update(shell, ecosystem_config.link_to_code.clone())?; @@ -63,28 +63,28 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> let forge = Forge::new(&ecosystem_config.path_to_foundry()) .script( &DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), - final_ecosystem_args.forge_args.clone(), + args.forge_args.clone(), ) .with_ffi() - .with_rpc_url(final_ecosystem_args.l1_rpc_url) - .with_sender(final_ecosystem_args.sender); + .with_rpc_url(args.l1_rpc_url) + .with_sender(args.sender); forge.run(shell)?; spinner.finish(); let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); shell - .create_dir(&final_ecosystem_args.out) + .create_dir(&args.out) .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; shell.copy_file( ecosystem_config.link_to_code.join(DEPLOY_TRANSACTIONS_FILE), - final_ecosystem_args.out.join("deploy-l1-txns.json"), + args.out.join("deploy-l1-txns.json"), )?; shell.copy_file( ecosystem_config.link_to_code.join(SCRIPT_CONFIG_FILE), - final_ecosystem_args.out.join("deploy-l1-config.toml"), + args.out.join("deploy-l1-config.toml"), )?; spinner.finish(); From 25b4617c80114b3000dbb2b745ea4bf378ef0b6f Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 12:34:16 +0200 Subject: [PATCH 40/89] refactor: use message const for error context --- .../crates/zk_inception/src/commands/ecosystem/build.rs | 5 +++-- zk_toolbox/crates/zk_inception/src/messages.rs | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index ea6d18b7d35d..f4b49b246bb0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -16,7 +16,8 @@ use super::{ utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::messages::{ - MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_OUTRO, + MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, + MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG, MSG_ECOSYSTEM_BUILD_OUTRO, MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, MSG_INTALLING_DEPS_SPINNER, MSG_WRITING_OUTPUT_FILES_SPINNER, }; @@ -45,7 +46,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> let default_genesis_config = GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) - .context("Context")?; + .context(MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG)?; let wallets_config = ecosystem_config.get_wallets()?; // For deploying ecosystem we only need genesis batch params diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index ce7cb940ca05..9007be904c12 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -126,6 +126,8 @@ pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecos pub(super) const MSG_WRITING_OUTPUT_FILES_SPINNER: &str = "Writing output files..."; pub(super) const MSG_ECOSYSTEM_BUILD_OUTRO: &str = "Transactions successfully built"; pub(super) const MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; +pub(super) const MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG: &str = + "Impossible to read genesis config from file"; /// Chain create related messages pub(super) const MSG_PROVER_MODE_HELP: &str = "Prover options"; From f93c0c7213fe66b3ec5eaac02ca2417e6ec0dfed Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 15:21:30 +0200 Subject: [PATCH 41/89] refactor: add default for L1 RPC address --- .../zk_inception/src/commands/chain/args/build.rs | 11 +++-------- .../crates/zk_inception/src/commands/chain/build.rs | 5 ++--- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs index d9fc565bd1aa..cf1ac1388359 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs @@ -2,9 +2,7 @@ use std::path::PathBuf; use clap::Parser; use common::{forge::ForgeScriptArgs, Prompt}; -use config::ChainConfig; use serde::{Deserialize, Serialize}; -use types::L1Network; use url::Url; use crate::{ @@ -28,13 +26,10 @@ pub struct ChainBuildArgs { } impl ChainBuildArgs { - pub fn fill_values_with_prompt(self, config: &ChainConfig) -> ChainBuildArgsFinal { + pub fn fill_values_with_prompt(self) -> ChainBuildArgsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { - let mut prompt = Prompt::new(MSG_L1_RPC_URL_PROMPT); - if config.l1_network == L1Network::Localhost { - prompt = prompt.default(LOCAL_RPC_URL); - } - prompt + Prompt::new(MSG_L1_RPC_URL_PROMPT) + .default(LOCAL_RPC_URL) .validate_with(|val: &String| -> Result<(), String> { Url::parse(val) .map(|_| ()) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index 0896a5484361..e0ce726977a0 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -26,14 +26,14 @@ const CHAIN_TRANSACTIONS_FILE: &str = const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt(); + let config = EcosystemConfig::from_file(shell)?; let chain_name = global_config().chain_name.clone(); let chain_config = config .load_chain(chain_name) .context(MSG_CHAIN_NOT_FOUND_ERR)?; - let args = args.fill_values_with_prompt(&chain_config); - copy_configs(shell, &config.link_to_code, &chain_config.configs)?; logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); @@ -68,7 +68,6 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), )?; contracts_config.set_chain_contracts(®ister_chain_output); - contracts_config.save_with_base_path(shell, &chain_config.configs)?; shell From 97141093fe155894ed0bd736c36918450bb915cd Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 15:22:32 +0200 Subject: [PATCH 42/89] refactor: improve log message --- .../crates/zk_inception/src/commands/ecosystem/build.rs | 8 ++++---- zk_toolbox/crates/zk_inception/src/messages.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index f4b49b246bb0..1d1027a9ca6a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -16,10 +16,10 @@ use super::{ utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::messages::{ - MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, + MSG_BUILDING_ECOSYSTEM, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG, MSG_ECOSYSTEM_BUILD_OUTRO, - MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INITIALIZING_ECOSYSTEM, - MSG_INTALLING_DEPS_SPINNER, MSG_WRITING_OUTPUT_FILES_SPINNER, + MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INTALLING_DEPS_SPINNER, + MSG_WRITING_OUTPUT_FILES_SPINNER, }; const DEPLOY_TRANSACTIONS_FILE: &str = @@ -37,7 +37,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> Err(_) => create_initial_deployments_config(shell, &ecosystem_config.config)?, }; - logger::info(MSG_INITIALIZING_ECOSYSTEM); + logger::info(MSG_BUILDING_ECOSYSTEM); let spinner = Spinner::new(MSG_INTALLING_DEPS_SPINNER); install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?; diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 9007be904c12..4c70d17aca04 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -122,6 +122,7 @@ pub(super) fn msg_chain_load_err(chain_name: &str) -> String { } /// Ecosystem build related messages +pub(super) const MSG_BUILDING_ECOSYSTEM: &str = "Building ecosystem"; pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecosystem contracts..."; pub(super) const MSG_WRITING_OUTPUT_FILES_SPINNER: &str = "Writing output files..."; pub(super) const MSG_ECOSYSTEM_BUILD_OUTRO: &str = "Transactions successfully built"; From f31adcea54f66021d4515a84dcbf3288c9e8716d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 15:35:50 +0200 Subject: [PATCH 43/89] feat: save contracts config to output folder --- zk_toolbox/crates/zk_inception/src/commands/chain/build.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index e0ce726977a0..394a3fe156d4 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -45,7 +45,6 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( .get_contracts_config() .context(MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG)?; contracts_config.l1.base_token_addr = chain_config.base_token.address; - contracts_config.save_with_base_path(shell, &chain_config.configs)?; let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); @@ -68,7 +67,7 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), )?; contracts_config.set_chain_contracts(®ister_chain_output); - contracts_config.save_with_base_path(shell, &chain_config.configs)?; + contracts_config.save_with_base_path(shell, &args.out)?; shell .create_dir(&args.out) From 7bb2ce8ca425713e07bdcfdb354d79fe86ed6e86 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 15:51:17 +0200 Subject: [PATCH 44/89] feat: improve out dir structure --- .../zk_inception/src/commands/chain/args/build.rs | 11 ++++++++--- .../crates/zk_inception/src/commands/chain/build.rs | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs index cf1ac1388359..679aec7f56a8 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use clap::Parser; -use common::{forge::ForgeScriptArgs, Prompt}; +use common::{config::global_config, forge::ForgeScriptArgs, Prompt}; use serde::{Deserialize, Serialize}; use url::Url; @@ -26,7 +26,9 @@ pub struct ChainBuildArgs { } impl ChainBuildArgs { - pub fn fill_values_with_prompt(self) -> ChainBuildArgsFinal { + pub fn fill_values_with_prompt(self, default_chain: String) -> ChainBuildArgsFinal { + let chain_name = global_config().chain_name.clone(); + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_L1_RPC_URL_PROMPT) .default(LOCAL_RPC_URL) @@ -39,7 +41,10 @@ impl ChainBuildArgs { }); ChainBuildArgsFinal { - out: self.out.unwrap_or_else(|| DEFAULT_OUT_DIR.into()), + out: self + .out + .unwrap_or(DEFAULT_OUT_DIR.into()) + .join(&chain_name.unwrap_or(default_chain)), forge_args: self.forge_args, l1_rpc_url, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index 394a3fe156d4..797354e08206 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -26,14 +26,14 @@ const CHAIN_TRANSACTIONS_FILE: &str = const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<()> { - let args = args.fill_values_with_prompt(); - let config = EcosystemConfig::from_file(shell)?; let chain_name = global_config().chain_name.clone(); let chain_config = config .load_chain(chain_name) .context(MSG_CHAIN_NOT_FOUND_ERR)?; + let args = args.fill_values_with_prompt(config.default_chain.clone()); + copy_configs(shell, &config.link_to_code, &chain_config.configs)?; logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); From f7456c8c2b12b749f2ef1cef88007e733304fde4 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 15:55:53 +0200 Subject: [PATCH 45/89] feat: improve out file naming --- zk_toolbox/crates/zk_inception/src/commands/chain/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index 797354e08206..bb19f3447a4a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -75,12 +75,12 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( shell.copy_file( config.link_to_code.join(CHAIN_TRANSACTIONS_FILE), - args.out.join("chain-txns.json"), + args.out.join("register-hyperchain-txns.json"), )?; shell.copy_file( config.link_to_code.join(SCRIPT_CONFIG_FILE), - args.out.join("chain-config.toml"), + args.out.join("register-hyperchain.toml"), )?; spinner.finish(); From 5e8ead377aa1c277d559c22274d090409fb1347c Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 15:57:18 +0200 Subject: [PATCH 46/89] style: improve out file naming --- zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index 1d1027a9ca6a..a3d705b7700b 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -85,7 +85,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> shell.copy_file( ecosystem_config.link_to_code.join(SCRIPT_CONFIG_FILE), - args.out.join("deploy-l1-config.toml"), + args.out.join("config-deploy-l1.toml"), )?; spinner.finish(); From 9b8aaed87bd76c477b9e663cdef546077c728db6 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 16:08:46 +0200 Subject: [PATCH 47/89] refactor: use const for file names --- .../zk_inception/src/commands/chain/build.rs | 16 ++++++++++------ .../src/commands/ecosystem/build.rs | 17 +++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index bb19f3447a4a..694467cef897 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -21,9 +21,13 @@ use crate::{ }, }; -const CHAIN_TRANSACTIONS_FILE: &str = +const CHAIN_TRANSACTIONS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; -const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; +const CHAIN_TRANSACTIONS_FILE_DST: &str = "register-hyperchain-txns.json"; + +const SCRIPT_CONFIG_FILE_SRC: &str = + "contracts/l1-contracts/script-config/register-hyperchain.toml"; +const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml"; pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<()> { let config = EcosystemConfig::from_file(shell)?; @@ -74,13 +78,13 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( .context(MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR)?; shell.copy_file( - config.link_to_code.join(CHAIN_TRANSACTIONS_FILE), - args.out.join("register-hyperchain-txns.json"), + config.link_to_code.join(CHAIN_TRANSACTIONS_FILE_SRC), + args.out.join(CHAIN_TRANSACTIONS_FILE_DST), )?; shell.copy_file( - config.link_to_code.join(SCRIPT_CONFIG_FILE), - args.out.join("register-hyperchain.toml"), + config.link_to_code.join(SCRIPT_CONFIG_FILE_SRC), + args.out.join(SCRIPT_CONFIG_FILE_DST), )?; spinner.finish(); diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index a3d705b7700b..f9d09446e0f7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -22,9 +22,12 @@ use crate::messages::{ MSG_WRITING_OUTPUT_FILES_SPINNER, }; -const DEPLOY_TRANSACTIONS_FILE: &str = +const DEPLOY_TRANSACTIONS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/DeployL1.s.sol/9/dry-run/run-latest.json"; -const SCRIPT_CONFIG_FILE: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; +const DEPLOY_TRANSACTIONS_FILE_DST: &str = "deploy-l1-txns.json"; + +const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; +const SCRIPT_CONFIG_FILE_DST: &str = "config-deploy-l1.toml"; pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(); @@ -79,13 +82,15 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; shell.copy_file( - ecosystem_config.link_to_code.join(DEPLOY_TRANSACTIONS_FILE), - args.out.join("deploy-l1-txns.json"), + ecosystem_config + .link_to_code + .join(DEPLOY_TRANSACTIONS_FILE_SRC), + args.out.join(DEPLOY_TRANSACTIONS_FILE_DST), )?; shell.copy_file( - ecosystem_config.link_to_code.join(SCRIPT_CONFIG_FILE), - args.out.join("config-deploy-l1.toml"), + ecosystem_config.link_to_code.join(SCRIPT_CONFIG_FILE_SRC), + args.out.join(SCRIPT_CONFIG_FILE_DST), )?; spinner.finish(); From e446d7d98e26f734006604653f282ca2d0b03281 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 17:03:50 +0200 Subject: [PATCH 48/89] refactor: lint --- zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs index 679aec7f56a8..0b84239873fa 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs @@ -44,7 +44,7 @@ impl ChainBuildArgs { out: self .out .unwrap_or(DEFAULT_OUT_DIR.into()) - .join(&chain_name.unwrap_or(default_chain)), + .join(chain_name.unwrap_or(default_chain)), forge_args: self.forge_args, l1_rpc_url, } From 6a4d039ed09a464bba6c529c8c9f6bc08b14c99c Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 17:49:39 +0200 Subject: [PATCH 49/89] feat: improve logging --- .../crates/zk_inception/src/commands/chain/build.rs | 12 ++++++++---- .../zk_inception/src/commands/ecosystem/build.rs | 4 +++- zk_toolbox/crates/zk_inception/src/messages.rs | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs index 694467cef897..bcb2b73f18fe 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs @@ -15,9 +15,9 @@ use xshell::Shell; use crate::{ commands::chain::args::build::ChainBuildArgs, messages::{ - MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG, MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR, - MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_REGISTERING_CHAIN_SPINNER, - MSG_SELECTED_CONFIG, + MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG, + MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, + MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, MSG_WRITING_OUTPUT_FILES_SPINNER, }, }; @@ -38,6 +38,7 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( let args = args.fill_values_with_prompt(config.default_chain.clone()); + let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); copy_configs(shell, &config.link_to_code, &chain_config.configs)?; logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); @@ -50,12 +51,13 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( .context(MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG)?; contracts_config.l1.base_token_addr = chain_config.base_token.address; - let spinner = Spinner::new(MSG_REGISTERING_CHAIN_SPINNER); let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); let deploy_config = RegisterChainL1Config::new(&chain_config, &contracts_config)?; deploy_config.save(shell, deploy_config_path)?; + spinner.finish(); + let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER); Forge::new(&config.path_to_foundry()) .script( ®ISTER_CHAIN_SCRIPT_PARAMS.script(), @@ -72,7 +74,9 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( )?; contracts_config.set_chain_contracts(®ister_chain_output); contracts_config.save_with_base_path(shell, &args.out)?; + spinner.finish(); + let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); shell .create_dir(&args.out) .context(MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs index f9d09446e0f7..c15c269237cb 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs @@ -19,7 +19,7 @@ use crate::messages::{ MSG_BUILDING_ECOSYSTEM, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG, MSG_ECOSYSTEM_BUILD_OUTRO, MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INTALLING_DEPS_SPINNER, - MSG_WRITING_OUTPUT_FILES_SPINNER, + MSG_PREPARING_CONFIG_SPINNER, MSG_WRITING_OUTPUT_FILES_SPINNER, }; const DEPLOY_TRANSACTIONS_FILE_SRC: &str = @@ -47,6 +47,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> build_system_contracts(shell, &ecosystem_config.link_to_code)?; spinner.finish(); + let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); let default_genesis_config = GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) .context(MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG)?; @@ -62,6 +63,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> ); let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); deploy_config.save(shell, deploy_config_path)?; + spinner.finish(); let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); let forge = Forge::new(&ecosystem_config.path_to_foundry()) diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 4c70d17aca04..43501aacbacc 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -75,6 +75,7 @@ pub(super) const MSG_DISTRIBUTING_ETH_SPINNER: &str = "Distributing eth..."; pub(super) const MSG_MINT_BASE_TOKEN_SPINNER: &str = "Minting base token to the governance addresses..."; pub(super) const MSG_INTALLING_DEPS_SPINNER: &str = "Installing and building dependencies..."; +pub(super) const MSG_PREPARING_CONFIG_SPINNER: &str = "Preparing config files..."; pub(super) const MSG_DEPLOYING_ERC20_SPINNER: &str = "Deploying ERC20 contracts..."; pub(super) const MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Deploying ecosystem contracts..."; @@ -227,6 +228,8 @@ pub(super) const MSG_DEPLOYING_L2_CONTRACT_SPINNER: &str = "Deploying l2 contrac pub(super) const MSG_DEPLOYING_PAYMASTER: &str = "Deploying paymaster"; /// Chain build related messages +pub(super) const MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER: &str = + "Building chain registration transactions..."; pub(super) const MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; pub(super) const MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG: &str = "Missing contract.yaml, please be sure to run this command within initialized ecosystem"; From 9e197065189b28c2b0c1d52550362a0c9b450d37 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 18:20:27 +0200 Subject: [PATCH 50/89] refactor: rename `zki ecosystem build` to `zki ecosystem transaction` --- .../src/commands/ecosystem/args/mod.rs | 2 +- .../ecosystem/args/{build.rs => transaction.rs} | 10 +++++----- .../zk_inception/src/commands/ecosystem/mod.rs | 8 ++++---- .../ecosystem/{build.rs => transaction.rs} | 14 +++++++------- zk_toolbox/crates/zk_inception/src/messages.rs | 10 +++++----- 5 files changed, 22 insertions(+), 22 deletions(-) rename zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/{build.rs => transaction.rs} (86%) rename zk_toolbox/crates/zk_inception/src/commands/ecosystem/{build.rs => transaction.rs} (87%) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs index 46de2bed5aa7..147ffff99198 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs @@ -1,4 +1,4 @@ -pub mod build; pub mod change_default; pub mod create; pub mod init; +pub mod transaction; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/transaction.rs similarity index 86% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs rename to zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/transaction.rs index fe7229adbcf7..a5c65fe390a8 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/transaction.rs @@ -13,7 +13,7 @@ use crate::{ const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct EcosystemBuildArgs { +pub struct EcosystemTransactionArgs { /// Address of the transaction sender. pub sender: String, #[clap(long, help = MSG_L1_RPC_URL_HELP)] @@ -26,8 +26,8 @@ pub struct EcosystemBuildArgs { pub forge_args: ForgeScriptArgs, } -impl EcosystemBuildArgs { - pub fn fill_values_with_prompt(self) -> EcosystemBuildArgsFinal { +impl EcosystemTransactionArgs { + pub fn fill_values_with_prompt(self) -> EcosystemTransactionArgsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_L1_RPC_URL_PROMPT) .default(LOCAL_RPC_URL) @@ -38,7 +38,7 @@ impl EcosystemBuildArgs { }) .ask() }); - EcosystemBuildArgsFinal { + EcosystemTransactionArgsFinal { sender: self.sender, out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), forge_args: self.forge_args.clone(), @@ -48,7 +48,7 @@ impl EcosystemBuildArgs { } #[derive(Debug, Serialize, Deserialize)] -pub struct EcosystemBuildArgsFinal { +pub struct EcosystemTransactionArgsFinal { pub sender: String, pub out: PathBuf, pub forge_args: ForgeScriptArgs, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs index de9bc8789ba9..d026a63bac5e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs @@ -1,4 +1,4 @@ -use args::build::EcosystemBuildArgs; +use args::transaction::EcosystemTransactionArgs; use clap::Subcommand; use xshell::Shell; @@ -7,12 +7,12 @@ use crate::commands::ecosystem::args::{ }; mod args; -pub(crate) mod build; mod change_default; mod create; pub mod create_configs; pub(crate) mod init; mod setup_observability; +pub(crate) mod transaction; mod utils; #[derive(Subcommand, Debug)] @@ -22,7 +22,7 @@ pub enum EcosystemCommands { /// setting necessary configurations for later initialization Create(EcosystemCreateArgs), /// Create transactions to build ecosystem contracts - Build(EcosystemBuildArgs), + Transaction(EcosystemTransactionArgs), /// Initialize ecosystem and chain, /// deploying necessary contracts and performing on-chain operations Init(EcosystemInitArgs), @@ -38,7 +38,7 @@ pub enum EcosystemCommands { pub(crate) async fn run(shell: &Shell, args: EcosystemCommands) -> anyhow::Result<()> { match args { EcosystemCommands::Create(args) => create::run(args, shell), - EcosystemCommands::Build(args) => build::run(args, shell).await, + EcosystemCommands::Transaction(args) => transaction::run(args, shell).await, EcosystemCommands::Init(args) => init::run(args, shell).await, EcosystemCommands::ChangeDefaultChain(args) => change_default::run(args, shell), EcosystemCommands::SetupObservability => setup_observability::run(shell), diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/transaction.rs similarity index 87% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs rename to zk_toolbox/crates/zk_inception/src/commands/ecosystem/transaction.rs index c15c269237cb..69d249810db3 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/transaction.rs @@ -11,14 +11,14 @@ use types::ProverMode; use xshell::Shell; use super::{ - args::build::EcosystemBuildArgs, + args::transaction::EcosystemTransactionArgs, create_configs::create_initial_deployments_config, utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::messages::{ MSG_BUILDING_ECOSYSTEM, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, - MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG, MSG_ECOSYSTEM_BUILD_OUTRO, - MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR, MSG_INTALLING_DEPS_SPINNER, + MSG_ECOSYSTEM_TXN_IMPOSSIBLE_TO_READ_GENESIS_CONFIG, MSG_ECOSYSTEM_TXN_OUTRO, + MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR, MSG_INTALLING_DEPS_SPINNER, MSG_PREPARING_CONFIG_SPINNER, MSG_WRITING_OUTPUT_FILES_SPINNER, }; @@ -29,7 +29,7 @@ const DEPLOY_TRANSACTIONS_FILE_DST: &str = "deploy-l1-txns.json"; const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; const SCRIPT_CONFIG_FILE_DST: &str = "config-deploy-l1.toml"; -pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> { +pub async fn run(args: EcosystemTransactionArgs, shell: &Shell) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(); let ecosystem_config = EcosystemConfig::from_file(shell)?; @@ -50,7 +50,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); let default_genesis_config = GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) - .context(MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG)?; + .context(MSG_ECOSYSTEM_TXN_IMPOSSIBLE_TO_READ_GENESIS_CONFIG)?; let wallets_config = ecosystem_config.get_wallets()?; // For deploying ecosystem we only need genesis batch params @@ -81,7 +81,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); shell .create_dir(&args.out) - .context(MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR)?; + .context(MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR)?; shell.copy_file( ecosystem_config @@ -96,7 +96,7 @@ pub async fn run(args: EcosystemBuildArgs, shell: &Shell) -> anyhow::Result<()> )?; spinner.finish(); - logger::outro(MSG_ECOSYSTEM_BUILD_OUTRO); + logger::outro(MSG_ECOSYSTEM_TXN_OUTRO); Ok(()) } diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 43501aacbacc..83546e34f695 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -122,13 +122,13 @@ pub(super) fn msg_chain_load_err(chain_name: &str) -> String { format!("Failed to load chain config for {chain_name}") } -/// Ecosystem build related messages -pub(super) const MSG_BUILDING_ECOSYSTEM: &str = "Building ecosystem"; +/// Build ecosystem transactions related messages +pub(super) const MSG_BUILDING_ECOSYSTEM: &str = "Building ecosystem transactions"; pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecosystem contracts..."; pub(super) const MSG_WRITING_OUTPUT_FILES_SPINNER: &str = "Writing output files..."; -pub(super) const MSG_ECOSYSTEM_BUILD_OUTRO: &str = "Transactions successfully built"; -pub(super) const MSG_ECOSYSTEM_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; -pub(super) const MSG_ECOSYSTEM_BUILD_IMPOSSIBLE_TO_READ_GENESIS_CONFIG: &str = +pub(super) const MSG_ECOSYSTEM_TXN_OUTRO: &str = "Transactions successfully built"; +pub(super) const MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR: &str = "Invalid path"; +pub(super) const MSG_ECOSYSTEM_TXN_IMPOSSIBLE_TO_READ_GENESIS_CONFIG: &str = "Impossible to read genesis config from file"; /// Chain create related messages From 66f07e15c1b95e06304d86328402fdd61a9f3503 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 6 Sep 2024 18:43:59 +0200 Subject: [PATCH 51/89] refactor: rename `zki chain build` to `zki chain transaction` --- .../src/commands/chain/args/mod.rs | 2 +- .../chain/args/{build.rs => transaction.rs} | 10 ++++---- .../zk_inception/src/commands/chain/mod.rs | 8 +++---- .../chain/{build.rs => transaction.rs} | 23 ++++++++++--------- .../crates/zk_inception/src/messages.rs | 4 ++-- 5 files changed, 24 insertions(+), 23 deletions(-) rename zk_toolbox/crates/zk_inception/src/commands/chain/args/{build.rs => transaction.rs} (90%) rename zk_toolbox/crates/zk_inception/src/commands/chain/{build.rs => transaction.rs} (80%) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs index a61a9a6ebe4d..7419ecbd1bce 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs @@ -1,4 +1,4 @@ -pub mod build; pub mod create; pub mod genesis; pub mod init; +pub mod transaction; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/transaction.rs similarity index 90% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs rename to zk_toolbox/crates/zk_inception/src/commands/chain/args/transaction.rs index 0b84239873fa..ed170404b871 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/transaction.rs @@ -13,7 +13,7 @@ use crate::{ const DEFAULT_OUT_DIR: &str = "transactions/chain"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct ChainBuildArgs { +pub struct ChainTransactionArgs { /// Output directory for the generated files. #[arg(long, short)] pub out: Option, @@ -25,8 +25,8 @@ pub struct ChainBuildArgs { pub l1_rpc_url: Option, } -impl ChainBuildArgs { - pub fn fill_values_with_prompt(self, default_chain: String) -> ChainBuildArgsFinal { +impl ChainTransactionArgs { + pub fn fill_values_with_prompt(self, default_chain: String) -> ChainTransactionArgsFinal { let chain_name = global_config().chain_name.clone(); let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { @@ -40,7 +40,7 @@ impl ChainBuildArgs { .ask() }); - ChainBuildArgsFinal { + ChainTransactionArgsFinal { out: self .out .unwrap_or(DEFAULT_OUT_DIR.into()) @@ -52,7 +52,7 @@ impl ChainBuildArgs { } #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct ChainBuildArgsFinal { +pub struct ChainTransactionArgsFinal { pub out: PathBuf, pub forge_args: ForgeScriptArgs, pub l1_rpc_url: String, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index 80300a7b93a3..02858e400b62 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -1,5 +1,5 @@ -use args::build::ChainBuildArgs; pub(crate) use args::create::ChainCreateArgsFinal; +use args::transaction::ChainTransactionArgs; use clap::Subcommand; use common::forge::ForgeScriptArgs; pub(crate) use create::create_chain_inner; @@ -11,20 +11,20 @@ use crate::commands::chain::{ }; pub(crate) mod args; -mod build; mod create; pub mod deploy_l2_contracts; pub mod deploy_paymaster; pub mod genesis; pub(crate) mod init; mod set_token_multiplier_setter; +mod transaction; #[derive(Subcommand, Debug)] pub enum ChainCommands { /// Create a new chain, setting the necessary configurations for later initialization Create(ChainCreateArgs), /// Create unsigned transactions for chain deployment - Build(ChainBuildArgs), + Transaction(ChainTransactionArgs), /// Initialize chain, deploying necessary contracts and performing on-chain operations Init(InitArgs), /// Run server genesis @@ -51,7 +51,7 @@ pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<() match args { ChainCommands::Create(args) => create::run(args, shell), ChainCommands::Init(args) => init::run(args, shell).await, - ChainCommands::Build(args) => build::run(args, shell).await, + ChainCommands::Transaction(args) => transaction::run(args, shell).await, ChainCommands::Genesis(args) => genesis::run(args, shell).await, ChainCommands::DeployL2Contracts(args) => { deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All).await diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/transaction.rs similarity index 80% rename from zk_toolbox/crates/zk_inception/src/commands/chain/build.rs rename to zk_toolbox/crates/zk_inception/src/commands/chain/transaction.rs index bcb2b73f18fe..c9bc5a63ef24 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/transaction.rs @@ -13,23 +13,24 @@ use ethers::utils::hex::ToHex; use xshell::Shell; use crate::{ - commands::chain::args::build::ChainBuildArgs, + commands::chain::args::transaction::ChainTransactionArgs, messages::{ - MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG, - MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, - MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, MSG_WRITING_OUTPUT_FILES_SPINNER, + MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_INITIALIZED, + MSG_CHAIN_NOT_FOUND_ERR, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, + MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, + MSG_WRITING_OUTPUT_FILES_SPINNER, }, }; -const CHAIN_TRANSACTIONS_FILE_SRC: &str = +const CHAIN_TXNS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; -const CHAIN_TRANSACTIONS_FILE_DST: &str = "register-hyperchain-txns.json"; +const CHAIN_TXNS_FILE_DST: &str = "register-hyperchain-txns.json"; const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml"; -pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<()> { +pub(crate) async fn run(args: ChainTransactionArgs, shell: &Shell) -> anyhow::Result<()> { let config = EcosystemConfig::from_file(shell)?; let chain_name = global_config().chain_name.clone(); let chain_config = config @@ -48,7 +49,7 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( // Copy ecosystem contracts let mut contracts_config = config .get_contracts_config() - .context(MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG)?; + .context(MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG)?; contracts_config.l1.base_token_addr = chain_config.base_token.address; let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); @@ -79,11 +80,11 @@ pub(crate) async fn run(args: ChainBuildArgs, shell: &Shell) -> anyhow::Result<( let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); shell .create_dir(&args.out) - .context(MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR)?; + .context(MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR)?; shell.copy_file( - config.link_to_code.join(CHAIN_TRANSACTIONS_FILE_SRC), - args.out.join(CHAIN_TRANSACTIONS_FILE_DST), + config.link_to_code.join(CHAIN_TXNS_FILE_SRC), + args.out.join(CHAIN_TXNS_FILE_DST), )?; shell.copy_file( diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 83546e34f695..3475dec78714 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -230,8 +230,8 @@ pub(super) const MSG_DEPLOYING_PAYMASTER: &str = "Deploying paymaster"; /// Chain build related messages pub(super) const MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER: &str = "Building chain registration transactions..."; -pub(super) const MSG_CHAIN_BUILD_OUT_PATH_INVALID_ERR: &str = "Invalid path"; -pub(super) const MSG_CHAIN_BUILD_MISSING_CONTRACT_CONFIG: &str = +pub(super) const MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR: &str = "Invalid path"; +pub(super) const MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG: &str = "Missing contract.yaml, please be sure to run this command within initialized ecosystem"; /// Run server related messages From 53923d4da84c3d5b41fadea1a005753dceded64d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 10:15:42 +0200 Subject: [PATCH 52/89] refactor: rename `zki ecosystem transaction` to `zki ecosystem build-transactions` --- .../args/{transaction.rs => build_transactions.rs} | 10 +++++----- .../zk_inception/src/commands/ecosystem/args/mod.rs | 2 +- .../{transaction.rs => build_transactions.rs} | 4 ++-- .../crates/zk_inception/src/commands/ecosystem/mod.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) rename zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/{transaction.rs => build_transactions.rs} (86%) rename zk_toolbox/crates/zk_inception/src/commands/ecosystem/{transaction.rs => build_transactions.rs} (96%) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/transaction.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs similarity index 86% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/transaction.rs rename to zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs index a5c65fe390a8..a2f0e4f2b008 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/transaction.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs @@ -13,7 +13,7 @@ use crate::{ const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct EcosystemTransactionArgs { +pub struct BuildTransactions { /// Address of the transaction sender. pub sender: String, #[clap(long, help = MSG_L1_RPC_URL_HELP)] @@ -26,8 +26,8 @@ pub struct EcosystemTransactionArgs { pub forge_args: ForgeScriptArgs, } -impl EcosystemTransactionArgs { - pub fn fill_values_with_prompt(self) -> EcosystemTransactionArgsFinal { +impl BuildTransactions { + pub fn fill_values_with_prompt(self) -> BuildTransactionsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_L1_RPC_URL_PROMPT) .default(LOCAL_RPC_URL) @@ -38,7 +38,7 @@ impl EcosystemTransactionArgs { }) .ask() }); - EcosystemTransactionArgsFinal { + BuildTransactionsFinal { sender: self.sender, out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), forge_args: self.forge_args.clone(), @@ -48,7 +48,7 @@ impl EcosystemTransactionArgs { } #[derive(Debug, Serialize, Deserialize)] -pub struct EcosystemTransactionArgsFinal { +pub struct BuildTransactionsFinal { pub sender: String, pub out: PathBuf, pub forge_args: ForgeScriptArgs, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs index 147ffff99198..c25eebda3d6d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/mod.rs @@ -1,4 +1,4 @@ +pub mod build_transactions; pub mod change_default; pub mod create; pub mod init; -pub mod transaction; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/transaction.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs similarity index 96% rename from zk_toolbox/crates/zk_inception/src/commands/ecosystem/transaction.rs rename to zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs index 69d249810db3..c8e0b65da70d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/transaction.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs @@ -11,7 +11,7 @@ use types::ProverMode; use xshell::Shell; use super::{ - args::transaction::EcosystemTransactionArgs, + args::build_transactions::BuildTransactions, create_configs::create_initial_deployments_config, utils::{build_system_contracts, install_yarn_dependencies}, }; @@ -29,7 +29,7 @@ const DEPLOY_TRANSACTIONS_FILE_DST: &str = "deploy-l1-txns.json"; const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; const SCRIPT_CONFIG_FILE_DST: &str = "config-deploy-l1.toml"; -pub async fn run(args: EcosystemTransactionArgs, shell: &Shell) -> anyhow::Result<()> { +pub async fn run(args: BuildTransactions, shell: &Shell) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(); let ecosystem_config = EcosystemConfig::from_file(shell)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs index d026a63bac5e..0b52f4873221 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs @@ -1,4 +1,4 @@ -use args::transaction::EcosystemTransactionArgs; +use args::build_transactions::BuildTransactions; use clap::Subcommand; use xshell::Shell; @@ -7,12 +7,12 @@ use crate::commands::ecosystem::args::{ }; mod args; +pub(crate) mod build_transactions; mod change_default; mod create; pub mod create_configs; pub(crate) mod init; mod setup_observability; -pub(crate) mod transaction; mod utils; #[derive(Subcommand, Debug)] @@ -22,7 +22,7 @@ pub enum EcosystemCommands { /// setting necessary configurations for later initialization Create(EcosystemCreateArgs), /// Create transactions to build ecosystem contracts - Transaction(EcosystemTransactionArgs), + BuildTransactions(BuildTransactions), /// Initialize ecosystem and chain, /// deploying necessary contracts and performing on-chain operations Init(EcosystemInitArgs), @@ -38,7 +38,7 @@ pub enum EcosystemCommands { pub(crate) async fn run(shell: &Shell, args: EcosystemCommands) -> anyhow::Result<()> { match args { EcosystemCommands::Create(args) => create::run(args, shell), - EcosystemCommands::Transaction(args) => transaction::run(args, shell).await, + EcosystemCommands::BuildTransactions(args) => build_transactions::run(args, shell).await, EcosystemCommands::Init(args) => init::run(args, shell).await, EcosystemCommands::ChangeDefaultChain(args) => change_default::run(args, shell), EcosystemCommands::SetupObservability => setup_observability::run(shell), From c615dbdc7cb3698f58d220e6dccad0904b03f8b1 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 10:21:14 +0200 Subject: [PATCH 53/89] refactor: rename `zki chain transaction` to `zki chain build-transactions` --- .../args/{transaction.rs => build_transactions.rs} | 10 +++++----- .../crates/zk_inception/src/commands/chain/args/mod.rs | 2 +- .../chain/{transaction.rs => build_transactions.rs} | 4 ++-- .../crates/zk_inception/src/commands/chain/mod.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) rename zk_toolbox/crates/zk_inception/src/commands/chain/args/{transaction.rs => build_transactions.rs} (90%) rename zk_toolbox/crates/zk_inception/src/commands/chain/{transaction.rs => build_transactions.rs} (95%) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/transaction.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs similarity index 90% rename from zk_toolbox/crates/zk_inception/src/commands/chain/args/transaction.rs rename to zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs index ed170404b871..12783cedf33c 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/transaction.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs @@ -13,7 +13,7 @@ use crate::{ const DEFAULT_OUT_DIR: &str = "transactions/chain"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct ChainTransactionArgs { +pub struct BuildTransactionsArgs { /// Output directory for the generated files. #[arg(long, short)] pub out: Option, @@ -25,8 +25,8 @@ pub struct ChainTransactionArgs { pub l1_rpc_url: Option, } -impl ChainTransactionArgs { - pub fn fill_values_with_prompt(self, default_chain: String) -> ChainTransactionArgsFinal { +impl BuildTransactionsArgs { + pub fn fill_values_with_prompt(self, default_chain: String) -> BuildTransactionsArgsFinal { let chain_name = global_config().chain_name.clone(); let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { @@ -40,7 +40,7 @@ impl ChainTransactionArgs { .ask() }); - ChainTransactionArgsFinal { + BuildTransactionsArgsFinal { out: self .out .unwrap_or(DEFAULT_OUT_DIR.into()) @@ -52,7 +52,7 @@ impl ChainTransactionArgs { } #[derive(Debug, Serialize, Deserialize, Clone)] -pub struct ChainTransactionArgsFinal { +pub struct BuildTransactionsArgsFinal { pub out: PathBuf, pub forge_args: ForgeScriptArgs, pub l1_rpc_url: String, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs index 7419ecbd1bce..f2a5f6b8be1f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/mod.rs @@ -1,4 +1,4 @@ +pub mod build_transactions; pub mod create; pub mod genesis; pub mod init; -pub mod transaction; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/transaction.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs similarity index 95% rename from zk_toolbox/crates/zk_inception/src/commands/chain/transaction.rs rename to zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index c9bc5a63ef24..a188b0dd658a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/transaction.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -13,7 +13,7 @@ use ethers::utils::hex::ToHex; use xshell::Shell; use crate::{ - commands::chain::args::transaction::ChainTransactionArgs, + commands::chain::args::build_transactions::BuildTransactionsArgs, messages::{ MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_INITIALIZED, MSG_CHAIN_NOT_FOUND_ERR, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, @@ -30,7 +30,7 @@ const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; const SCRIPT_CONFIG_FILE_DST: &str = "register-hyperchain.toml"; -pub(crate) async fn run(args: ChainTransactionArgs, shell: &Shell) -> anyhow::Result<()> { +pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<()> { let config = EcosystemConfig::from_file(shell)?; let chain_name = global_config().chain_name.clone(); let chain_config = config diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index 02858e400b62..89b8952b5b78 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -1,5 +1,5 @@ +use args::build_transactions::BuildTransactionsArgs; pub(crate) use args::create::ChainCreateArgsFinal; -use args::transaction::ChainTransactionArgs; use clap::Subcommand; use common::forge::ForgeScriptArgs; pub(crate) use create::create_chain_inner; @@ -11,20 +11,20 @@ use crate::commands::chain::{ }; pub(crate) mod args; +mod build_transactions; mod create; pub mod deploy_l2_contracts; pub mod deploy_paymaster; pub mod genesis; pub(crate) mod init; mod set_token_multiplier_setter; -mod transaction; #[derive(Subcommand, Debug)] pub enum ChainCommands { /// Create a new chain, setting the necessary configurations for later initialization Create(ChainCreateArgs), /// Create unsigned transactions for chain deployment - Transaction(ChainTransactionArgs), + BuildTransactions(BuildTransactionsArgs), /// Initialize chain, deploying necessary contracts and performing on-chain operations Init(InitArgs), /// Run server genesis @@ -51,7 +51,7 @@ pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<() match args { ChainCommands::Create(args) => create::run(args, shell), ChainCommands::Init(args) => init::run(args, shell).await, - ChainCommands::Transaction(args) => transaction::run(args, shell).await, + ChainCommands::BuildTransactions(args) => build_transactions::run(args, shell).await, ChainCommands::Genesis(args) => genesis::run(args, shell).await, ChainCommands::DeployL2Contracts(args) => { deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All).await From 3b78e5f5b9fdc6dac0449f5d783fab9e428441ee Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 10:21:42 +0200 Subject: [PATCH 54/89] fix: use consistent args naming --- .../src/commands/ecosystem/args/build_transactions.rs | 4 ++-- .../zk_inception/src/commands/ecosystem/build_transactions.rs | 4 ++-- zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs index a2f0e4f2b008..b5bdde38b2cd 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs @@ -13,7 +13,7 @@ use crate::{ const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] -pub struct BuildTransactions { +pub struct BuildTransactionsArgs { /// Address of the transaction sender. pub sender: String, #[clap(long, help = MSG_L1_RPC_URL_HELP)] @@ -26,7 +26,7 @@ pub struct BuildTransactions { pub forge_args: ForgeScriptArgs, } -impl BuildTransactions { +impl BuildTransactionsArgs { pub fn fill_values_with_prompt(self) -> BuildTransactionsFinal { let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_L1_RPC_URL_PROMPT) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs index c8e0b65da70d..5bd78049b402 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs @@ -11,7 +11,7 @@ use types::ProverMode; use xshell::Shell; use super::{ - args::build_transactions::BuildTransactions, + args::build_transactions::BuildTransactionsArgs, create_configs::create_initial_deployments_config, utils::{build_system_contracts, install_yarn_dependencies}, }; @@ -29,7 +29,7 @@ const DEPLOY_TRANSACTIONS_FILE_DST: &str = "deploy-l1-txns.json"; const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/config-deploy-l1.toml"; const SCRIPT_CONFIG_FILE_DST: &str = "config-deploy-l1.toml"; -pub async fn run(args: BuildTransactions, shell: &Shell) -> anyhow::Result<()> { +pub async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(); let ecosystem_config = EcosystemConfig::from_file(shell)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs index 0b52f4873221..7f8f69b295fc 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs @@ -1,4 +1,4 @@ -use args::build_transactions::BuildTransactions; +use args::build_transactions::BuildTransactionsArgs; use clap::Subcommand; use xshell::Shell; @@ -22,7 +22,7 @@ pub enum EcosystemCommands { /// setting necessary configurations for later initialization Create(EcosystemCreateArgs), /// Create transactions to build ecosystem contracts - BuildTransactions(BuildTransactions), + BuildTransactions(BuildTransactionsArgs), /// Initialize ecosystem and chain, /// deploying necessary contracts and performing on-chain operations Init(EcosystemInitArgs), From d4d83594d37d3f72f8d535446b0a9b61014fb400 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 10:55:50 +0200 Subject: [PATCH 55/89] feat: prompt for sender address --- .../ecosystem/args/build_transactions.rs | 21 +++++++++++++++---- .../crates/zk_inception/src/messages.rs | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs index b5bdde38b2cd..2fd6509383d5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs @@ -1,13 +1,17 @@ -use std::path::PathBuf; +use std::{path::PathBuf, str::FromStr}; use clap::Parser; use common::{forge::ForgeScriptArgs, Prompt}; use serde::{Deserialize, Serialize}; use url::Url; +use zksync_basic_types::H160; use crate::{ defaults::LOCAL_RPC_URL, - messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, + messages::{ + MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, + MSG_SENDER_ADDRESS_PROMPT, + }, }; const DEFAULT_OUT_DIR: &str = "transactions"; @@ -15,7 +19,8 @@ const DEFAULT_OUT_DIR: &str = "transactions"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct BuildTransactionsArgs { /// Address of the transaction sender. - pub sender: String, + #[clap(long)] + pub sender: Option, #[clap(long, help = MSG_L1_RPC_URL_HELP)] pub l1_rpc_url: Option, /// Output directory for the generated files. @@ -28,6 +33,14 @@ pub struct BuildTransactionsArgs { impl BuildTransactionsArgs { pub fn fill_values_with_prompt(self) -> BuildTransactionsFinal { + let sender = self.sender.unwrap_or_else(|| { + Prompt::new(MSG_SENDER_ADDRESS_PROMPT) + .validate_with(|val: &String| -> Result<(), String> { + H160::from_str(val).map_or_else(|err| Err(err.to_string()), |_| Ok(())) + }) + .ask() + }); + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_L1_RPC_URL_PROMPT) .default(LOCAL_RPC_URL) @@ -39,7 +52,7 @@ impl BuildTransactionsArgs { .ask() }); BuildTransactionsFinal { - sender: self.sender, + sender, out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), forge_args: self.forge_args.clone(), l1_rpc_url, diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 3475dec78714..f13fa27d74cd 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -123,6 +123,7 @@ pub(super) fn msg_chain_load_err(chain_name: &str) -> String { } /// Build ecosystem transactions related messages +pub(super) const MSG_SENDER_ADDRESS_PROMPT: &str = "What is the address of the transaction sender?"; pub(super) const MSG_BUILDING_ECOSYSTEM: &str = "Building ecosystem transactions"; pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecosystem contracts..."; pub(super) const MSG_WRITING_OUTPUT_FILES_SPINNER: &str = "Writing output files..."; From 6fb8ebf69ab257229232c6307262825b98093f49 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 13:53:39 +0200 Subject: [PATCH 56/89] feat: save contracts.yaml to transaction output --- .../src/commands/ecosystem/build_transactions.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs index 5bd78049b402..0662dce5f699 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs @@ -2,10 +2,11 @@ use anyhow::Context; use common::{forge::Forge, git, logger, spinner::Spinner}; use config::{ forge_interface::{ - deploy_ecosystem::input::DeployL1Config, script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, + deploy_ecosystem::{input::DeployL1Config, output::DeployL1Output}, + script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, }, - traits::{ReadConfigWithBasePath, SaveConfig}, - EcosystemConfig, GenesisConfig, + traits::{ReadConfig, ReadConfigWithBasePath, SaveConfig, SaveConfigWithBasePath}, + ContractsConfig, EcosystemConfig, GenesisConfig, }; use types::ProverMode; use xshell::Shell; @@ -79,6 +80,15 @@ pub async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<( spinner.finish(); let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); + + let script_output = DeployL1Output::read( + shell, + DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code), + )?; + let mut contracts_config = ContractsConfig::default(); + contracts_config.update_from_l1_output(&script_output); + contracts_config.save_with_base_path(shell, &args.out)?; + shell .create_dir(&args.out) .context(MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR)?; From 13d34dd0743a28b94059a8011c0558500d7de6c9 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 17:35:38 +0200 Subject: [PATCH 57/89] feat: draft send_transactions subcommand --- .../zk_inception/src/commands/args/mod.rs | 2 + .../src/commands/args/send_transactions.rs | 25 +++++++ .../crates/zk_inception/src/commands/mod.rs | 1 + .../src/commands/send_transactions.rs | 74 +++++++++++++++++++ zk_toolbox/crates/zk_inception/src/main.rs | 5 +- 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs create mode 100644 zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs index d18b05c910e5..67747ea913e5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs @@ -1,7 +1,9 @@ pub use containers::*; pub use run_server::*; +pub use send_transactions::*; pub use update::*; mod containers; mod run_server; +mod send_transactions; mod update; diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs new file mode 100644 index 000000000000..0df4e699f17d --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs @@ -0,0 +1,25 @@ +use std::path::PathBuf; + +use clap::Parser; +use common::Prompt; + +#[derive(Debug, Parser)] +pub struct SendTransactionsArgs { + #[clap(long)] + pub file: Option, +} + +#[derive(Debug)] +pub struct SendTransactionsArgsFinal { + pub file: PathBuf, +} + +impl SendTransactionsArgs { + pub fn fill_values_with_prompt(self) -> SendTransactionsArgsFinal { + let file = self + .file + .unwrap_or_else(|| Prompt::new("Path to transactions file").ask()); + + SendTransactionsArgsFinal { file } + } +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/mod.rs index 523faea04786..f21e7b007118 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/mod.rs @@ -7,5 +7,6 @@ pub mod explorer; pub mod external_node; pub mod portal; pub mod prover; +pub mod send_transactions; pub mod server; pub mod update; diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs new file mode 100644 index 000000000000..007d0e154f2c --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -0,0 +1,74 @@ +use serde::Deserialize; +use std::fs::File; +use std::io::Read; +use std::process::Command; + +use super::args::SendTransactionsArgs; + +#[derive(Deserialize)] +struct Transaction { + from: String, + gas: String, + value: String, + input: String, + nonce: String, + #[serde(rename = "chainId")] + chain_id: String, +} + +#[derive(Deserialize)] +struct Txn { + #[serde(rename = "contractAddress")] + contract_address: String, + transaction: Transaction, +} + +#[derive(Deserialize)] +struct Txns { + transactions: Vec, +} + +pub fn run(args: SendTransactionsArgs) -> anyhow::Result<()> { + let args = args.fill_values_with_prompt(); + // Read the JSON file + let mut file = File::open(args.file).expect("Unable to open file"); + let mut data = String::new(); + file.read_to_string(&mut data).expect("Unable to read file"); + + // Parse the JSON file + let txns: Txns = serde_json::from_str(&data).expect("Unable to parse JSON"); + + // Iterate over each transaction + for txn in txns.transactions { + let contract_address = txn.contract_address; + let from_address = txn.transaction.from; + let gas = txn.transaction.gas; + let value = txn.transaction.value; + let input_data = txn.transaction.input; + let nonce = txn.transaction.nonce; + let chain_id = txn.transaction.chain_id; + + // Construct the cast send command + let output = Command::new("cast") + .arg("send") + .arg(contract_address) + .arg(input_data) + .arg("--from") + .arg(from_address) + .arg("--gas-limit") + .arg(gas) + .arg("--value") + .arg(value) + .arg("--nonce") + .arg(nonce) + .arg("--chain-id") + .arg(chain_id) + .output() + .expect("Failed to execute command"); + + // Print the output for debugging + println!("Output: {:?}", output); + } + + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zk_toolbox/crates/zk_inception/src/main.rs index f6f7d83dede6..6d5be5a1d365 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zk_toolbox/crates/zk_inception/src/main.rs @@ -1,6 +1,6 @@ use clap::{command, Parser, Subcommand}; use commands::{ - args::{ContainersArgs, UpdateArgs}, + args::{ContainersArgs, SendTransactionsArgs, UpdateArgs}, contract_verifier::ContractVerifierCommands, }; use common::{ @@ -66,6 +66,8 @@ pub enum InceptionSubcommands { Update(UpdateArgs), #[command(hide = true)] Markdown, + /// Send transactions from file + SendTransactions(SendTransactionsArgs), } #[derive(Parser, Debug)] @@ -129,6 +131,7 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res InceptionSubcommands::Markdown => { clap_markdown::print_help_markdown::(); } + InceptionSubcommands::SendTransactions(args) => commands::send_transactions::run(args)?, } Ok(()) } From 0c0804d676a3e73c58d9f3dda8a07cd77e803501 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 18:15:17 +0200 Subject: [PATCH 58/89] refactor: use common::Cmd --- .../src/commands/args/send_transactions.rs | 20 ++++++++++- .../src/commands/send_transactions.rs | 33 +++++-------------- zk_toolbox/crates/zk_inception/src/main.rs | 4 ++- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs index 0df4e699f17d..dd94880cb52a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs @@ -7,11 +7,17 @@ use common::Prompt; pub struct SendTransactionsArgs { #[clap(long)] pub file: Option, + #[clap(long)] + pub private_key: Option, + #[clap(long)] + pub gas_price: Option, } #[derive(Debug)] pub struct SendTransactionsArgsFinal { pub file: PathBuf, + pub private_key: String, + pub gas_price: String, } impl SendTransactionsArgs { @@ -20,6 +26,18 @@ impl SendTransactionsArgs { .file .unwrap_or_else(|| Prompt::new("Path to transactions file").ask()); - SendTransactionsArgsFinal { file } + let private_key = self + .private_key + .unwrap_or_else(|| Prompt::new("Secret key of the sender").ask()); + + let gas_price = self + .gas_price + .unwrap_or_else(|| Prompt::new("Gas price").ask()); + + SendTransactionsArgsFinal { + file, + private_key, + gas_price, + } } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs index 007d0e154f2c..607aa05fd5e3 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -1,7 +1,8 @@ +use common::cmd::Cmd; use serde::Deserialize; use std::fs::File; use std::io::Read; -use std::process::Command; +use xshell::{cmd, Shell}; use super::args::SendTransactionsArgs; @@ -9,11 +10,8 @@ use super::args::SendTransactionsArgs; struct Transaction { from: String, gas: String, - value: String, input: String, nonce: String, - #[serde(rename = "chainId")] - chain_id: String, } #[derive(Deserialize)] @@ -28,7 +26,7 @@ struct Txns { transactions: Vec, } -pub fn run(args: SendTransactionsArgs) -> anyhow::Result<()> { +pub fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(); // Read the JSON file let mut file = File::open(args.file).expect("Unable to open file"); @@ -38,36 +36,21 @@ pub fn run(args: SendTransactionsArgs) -> anyhow::Result<()> { // Parse the JSON file let txns: Txns = serde_json::from_str(&data).expect("Unable to parse JSON"); + let private_key = args.private_key; + let gas_price = args.gas_price; + // Iterate over each transaction for txn in txns.transactions { let contract_address = txn.contract_address; let from_address = txn.transaction.from; let gas = txn.transaction.gas; - let value = txn.transaction.value; let input_data = txn.transaction.input; let nonce = txn.transaction.nonce; - let chain_id = txn.transaction.chain_id; // Construct the cast send command - let output = Command::new("cast") - .arg("send") - .arg(contract_address) - .arg(input_data) - .arg("--from") - .arg(from_address) - .arg("--gas-limit") - .arg(gas) - .arg("--value") - .arg(value) - .arg("--nonce") - .arg(nonce) - .arg("--chain-id") - .arg(chain_id) - .output() - .expect("Failed to execute command"); + let cmd = Cmd::new(cmd!(shell, "cast send --private-key {private_key} --from {from_address} --gas-limit {gas} --nonce {nonce} --gas-price {gas_price} {contract_address} {input_data}")); - // Print the output for debugging - println!("Output: {:?}", output); + cmd.run().expect("Failed to execute command") } Ok(()) diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zk_toolbox/crates/zk_inception/src/main.rs index 6d5be5a1d365..e1763e85bc31 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zk_toolbox/crates/zk_inception/src/main.rs @@ -131,7 +131,9 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res InceptionSubcommands::Markdown => { clap_markdown::print_help_markdown::(); } - InceptionSubcommands::SendTransactions(args) => commands::send_transactions::run(args)?, + InceptionSubcommands::SendTransactions(args) => { + commands::send_transactions::run(shell, args)? + } } Ok(()) } From 4d8ac15907e600ce2b374d849ec2cdc49ab3b539 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 9 Sep 2024 18:19:34 +0200 Subject: [PATCH 59/89] style: format --- .../crates/zk_inception/src/commands/send_transactions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs index 607aa05fd5e3..4bf7300d2d54 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -1,7 +1,7 @@ +use std::{fs::File, io::Read}; + use common::cmd::Cmd; use serde::Deserialize; -use std::fs::File; -use std::io::Read; use xshell::{cmd, Shell}; use super::args::SendTransactionsArgs; From 7af8532d71d4b6429102a893b60e583a2b0299ce Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 10:53:50 +0200 Subject: [PATCH 60/89] refactor: use ethers.rs to send transactions --- zk_toolbox/Cargo.lock | 1 + zk_toolbox/crates/zk_inception/Cargo.toml | 1 + .../src/commands/args/send_transactions.rs | 29 ++++++++++ .../src/commands/send_transactions.rs | 53 +++++++++++++------ zk_toolbox/crates/zk_inception/src/main.rs | 2 +- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/zk_toolbox/Cargo.lock b/zk_toolbox/Cargo.lock index cd5d6a0b280e..8648f6524cf3 100644 --- a/zk_toolbox/Cargo.lock +++ b/zk_toolbox/Cargo.lock @@ -6275,6 +6275,7 @@ dependencies = [ "config", "console", "ethers", + "futures", "human-panic", "lazy_static", "serde", diff --git a/zk_toolbox/crates/zk_inception/Cargo.toml b/zk_toolbox/crates/zk_inception/Cargo.toml index 01d0697d6b6c..689c27738131 100644 --- a/zk_toolbox/crates/zk_inception/Cargo.toml +++ b/zk_toolbox/crates/zk_inception/Cargo.toml @@ -16,6 +16,7 @@ clap.workspace = true cliclack.workspace = true config.workspace = true console.workspace = true +futures.workspace = true human-panic.workspace = true lazy_static.workspace = true serde_yaml.workspace = true diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs index dd94880cb52a..c5d0a01c4450 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs @@ -2,6 +2,12 @@ use std::path::PathBuf; use clap::Parser; use common::Prompt; +use url::Url; + +use crate::{ + defaults::LOCAL_RPC_URL, + messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, +}; #[derive(Debug, Parser)] pub struct SendTransactionsArgs { @@ -11,6 +17,10 @@ pub struct SendTransactionsArgs { pub private_key: Option, #[clap(long)] pub gas_price: Option, + #[clap(long, help = MSG_L1_RPC_URL_HELP)] + pub l1_rpc_url: Option, + #[clap(long)] + pub confirmations: Option, } #[derive(Debug)] @@ -18,6 +28,8 @@ pub struct SendTransactionsArgsFinal { pub file: PathBuf, pub private_key: String, pub gas_price: String, + pub l1_rpc_url: String, + pub confirmations: usize, } impl SendTransactionsArgs { @@ -34,10 +46,27 @@ impl SendTransactionsArgs { .gas_price .unwrap_or_else(|| Prompt::new("Gas price").ask()); + let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { + Prompt::new(MSG_L1_RPC_URL_PROMPT) + .default(LOCAL_RPC_URL) + .validate_with(|val: &String| -> Result<(), String> { + Url::parse(val) + .map(|_| ()) + .map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) + }) + .ask() + }); + + let confirmations = self + .confirmations + .unwrap_or_else(|| Prompt::new("Confirmations").ask()); + SendTransactionsArgsFinal { file, private_key, gas_price, + l1_rpc_url, + confirmations, } } } diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs index 4bf7300d2d54..15b63f07ab10 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -1,8 +1,11 @@ -use std::{fs::File, io::Read}; +use std::{fs::File, io::Read, ops::Add, time::Duration}; -use common::cmd::Cmd; +use common::ethereum::create_ethers_client; +use config::EcosystemConfig; +use ethers::{abi::Bytes, providers::Middleware, types::TransactionRequest, utils::hex}; use serde::Deserialize; -use xshell::{cmd, Shell}; +use xshell::Shell; +use zksync_basic_types::{H160, U256}; use super::args::SendTransactionsArgs; @@ -11,7 +14,6 @@ struct Transaction { from: String, gas: String, input: String, - nonce: String, } #[derive(Deserialize)] @@ -26,8 +28,12 @@ struct Txns { transactions: Vec, } -pub fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<()> { +pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(); + + let ecosystem_config = EcosystemConfig::from_file(shell)?; + let chain_id = ecosystem_config.l1_network.chain_id(); + // Read the JSON file let mut file = File::open(args.file).expect("Unable to open file"); let mut data = String::new(); @@ -36,22 +42,39 @@ pub fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<()> { // Parse the JSON file let txns: Txns = serde_json::from_str(&data).expect("Unable to parse JSON"); - let private_key = args.private_key; - let gas_price = args.gas_price; + let client = create_ethers_client(args.private_key.parse()?, args.l1_rpc_url, Some(chain_id))?; + let mut nonce = client.get_transaction_count(client.address(), None).await?; + let mut pending_txs = vec![]; // Iterate over each transaction for txn in txns.transactions { - let contract_address = txn.contract_address; - let from_address = txn.transaction.from; - let gas = txn.transaction.gas; - let input_data = txn.transaction.input; - let nonce = txn.transaction.nonce; + let to: H160 = txn.contract_address.parse()?; + let from: H160 = txn.transaction.from.parse()?; + let gas_limit: U256 = txn.transaction.gas.parse()?; + let gas_price: U256 = args.gas_price.parse()?; + let input_data: Bytes = hex::decode(txn.transaction.input)?; - // Construct the cast send command - let cmd = Cmd::new(cmd!(shell, "cast send --private-key {private_key} --from {from_address} --gas-limit {gas} --nonce {nonce} --gas-price {gas_price} {contract_address} {input_data}")); + let tx = TransactionRequest::new() + .to(to) + .from(from) + .gas(gas_limit) + .gas_price(gas_price) + .nonce(nonce) + .data(input_data) + .chain_id(chain_id); - cmd.run().expect("Failed to execute command") + nonce = nonce.add(1); + pending_txs.push( + client + .send_transaction(tx, None) + .await? + // It's safe to set such low number of confirmations and low interval for localhost + .confirmations(args.confirmations) + .interval(Duration::from_millis(30)), + ); } + futures::future::join_all(pending_txs).await; + Ok(()) } diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zk_toolbox/crates/zk_inception/src/main.rs index e1763e85bc31..d37fe65f52b9 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zk_toolbox/crates/zk_inception/src/main.rs @@ -132,7 +132,7 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res clap_markdown::print_help_markdown::(); } InceptionSubcommands::SendTransactions(args) => { - commands::send_transactions::run(shell, args)? + commands::send_transactions::run(shell, args).await? } } Ok(()) From a170d21736c04cf606f454b17c1045a4f24af309 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 11:47:03 +0200 Subject: [PATCH 61/89] feat: log transaction receipts --- .../commands/chain/args/build_transactions.rs | 5 ++- .../ecosystem/args/build_transactions.rs | 5 +-- .../src/commands/send_transactions.rs | 45 ++++++++++++++----- zk_toolbox/crates/zk_inception/src/consts.rs | 1 + 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs index 12783cedf33c..793bea487f7e 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/build_transactions.rs @@ -6,11 +6,12 @@ use serde::{Deserialize, Serialize}; use url::Url; use crate::{ + consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, defaults::LOCAL_RPC_URL, messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, }; -const DEFAULT_OUT_DIR: &str = "transactions/chain"; +const CHAIN_SUBDIR: &str = "chain"; #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct BuildTransactionsArgs { @@ -43,7 +44,7 @@ impl BuildTransactionsArgs { BuildTransactionsArgsFinal { out: self .out - .unwrap_or(DEFAULT_OUT_DIR.into()) + .unwrap_or(PathBuf::from(DEFAULT_UNSIGNED_TRANSACTIONS_DIR).join(CHAIN_SUBDIR)) .join(chain_name.unwrap_or(default_chain)), forge_args: self.forge_args, l1_rpc_url, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs index 2fd6509383d5..697fa518b6e4 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/build_transactions.rs @@ -7,6 +7,7 @@ use url::Url; use zksync_basic_types::H160; use crate::{ + consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, defaults::LOCAL_RPC_URL, messages::{ MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT, @@ -14,8 +15,6 @@ use crate::{ }, }; -const DEFAULT_OUT_DIR: &str = "transactions"; - #[derive(Debug, Clone, Serialize, Deserialize, Parser)] pub struct BuildTransactionsArgs { /// Address of the transaction sender. @@ -53,7 +52,7 @@ impl BuildTransactionsArgs { }); BuildTransactionsFinal { sender, - out: self.out.unwrap_or(DEFAULT_OUT_DIR.into()), + out: self.out.unwrap_or(DEFAULT_UNSIGNED_TRANSACTIONS_DIR.into()), forge_args: self.forge_args.clone(), l1_rpc_url, } diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs index 15b63f07ab10..be2ba7019708 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -1,4 +1,10 @@ -use std::{fs::File, io::Read, ops::Add, time::Duration}; +use std::{ + fs::{File, OpenOptions}, + io::{Read, Write}, + ops::Add, + path::PathBuf, + time::Duration, +}; use common::ethereum::create_ethers_client; use config::EcosystemConfig; @@ -7,6 +13,8 @@ use serde::Deserialize; use xshell::Shell; use zksync_basic_types::{H160, U256}; +use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; + use super::args::SendTransactionsArgs; #[derive(Deserialize)] @@ -44,9 +52,7 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() let client = create_ethers_client(args.private_key.parse()?, args.l1_rpc_url, Some(chain_id))?; let mut nonce = client.get_transaction_count(client.address(), None).await?; - let mut pending_txs = vec![]; - // Iterate over each transaction for txn in txns.transactions { let to: H160 = txn.contract_address.parse()?; let from: H160 = txn.transaction.from.parse()?; @@ -64,17 +70,32 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() .chain_id(chain_id); nonce = nonce.add(1); - pending_txs.push( - client - .send_transaction(tx, None) - .await? - // It's safe to set such low number of confirmations and low interval for localhost - .confirmations(args.confirmations) - .interval(Duration::from_millis(30)), + + let receipt = client + .send_transaction(tx, None) + .await? + .confirmations(args.confirmations) + .interval(Duration::from_millis(30)) + .await? + .unwrap(); + + log_receipt( + ecosystem_config + .link_to_code + .join(DEFAULT_UNSIGNED_TRANSACTIONS_DIR), + format!("{:?}", receipt).as_str(), ); } - futures::future::join_all(pending_txs).await; - Ok(()) } + +fn log_receipt(path: PathBuf, receipt: &str) { + let mut file = OpenOptions::new() + .append(true) + .create(true) + .open(path.join("receipt.log")) + .expect("Unable to open file"); + + writeln!(file, "{}", receipt).expect("Unable to write data"); +} diff --git a/zk_toolbox/crates/zk_inception/src/consts.rs b/zk_toolbox/crates/zk_inception/src/consts.rs index 7db976c61033..8a89d411b00b 100644 --- a/zk_toolbox/crates/zk_inception/src/consts.rs +++ b/zk_toolbox/crates/zk_inception/src/consts.rs @@ -6,6 +6,7 @@ pub const PROVER_MIGRATIONS: &str = "prover/crates/lib/prover_dal/migrations"; pub const PROVER_STORE_MAX_RETRIES: u16 = 10; pub const DEFAULT_CREDENTIALS_FILE: &str = "~/.config/gcloud/application_default_credentials.json"; pub const DEFAULT_PROOF_STORE_DIR: &str = "artifacts"; +pub const DEFAULT_UNSIGNED_TRANSACTIONS_DIR: &str = "transactions"; pub const BELLMAN_CUDA_DIR: &str = "era-bellman-cuda"; pub const L2_BASE_TOKEN_ADDRESS: &str = "0x000000000000000000000000000000000000800A"; From c30f41794b1a6a498ad83c6b58580fb6acedb98b Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 11:51:53 +0200 Subject: [PATCH 62/89] style: reorder imports --- .../crates/zk_inception/src/commands/send_transactions.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs index be2ba7019708..4ef111e63fe2 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -13,10 +13,10 @@ use serde::Deserialize; use xshell::Shell; use zksync_basic_types::{H160, U256}; -use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; - use super::args::SendTransactionsArgs; +use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; + #[derive(Deserialize)] struct Transaction { from: String, From 3352e638a0c0a7e25a726e666bf51365d9f5664d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 11:53:27 +0200 Subject: [PATCH 63/89] style: format --- zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs index 4ef111e63fe2..15c077815f8a 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs @@ -14,7 +14,6 @@ use xshell::Shell; use zksync_basic_types::{H160, U256}; use super::args::SendTransactionsArgs; - use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; #[derive(Deserialize)] From b231bcedfa18c2fe9e241db50124ce5d0028c773 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 13:59:27 +0200 Subject: [PATCH 64/89] refactor: move send-transactions from zki to zks --- zk_toolbox/Cargo.lock | 3 ++- zk_toolbox/Cargo.toml | 1 + zk_toolbox/crates/zk_inception/Cargo.toml | 1 - .../zk_inception/src/commands/args/mod.rs | 2 -- .../crates/zk_inception/src/commands/mod.rs | 1 - zk_toolbox/crates/zk_inception/src/main.rs | 7 +---- zk_toolbox/crates/zk_supervisor/Cargo.toml | 2 ++ .../crates/zk_supervisor/src/commands/mod.rs | 1 + .../commands/send_transactions/args/mod.rs} | 11 +++----- .../src/commands/send_transactions/mod.rs} | 27 +++++++++++-------- zk_toolbox/crates/zk_supervisor/src/consts.rs | 1 + .../crates/zk_supervisor/src/defaults.rs | 1 + zk_toolbox/crates/zk_supervisor/src/main.rs | 8 +++++- 13 files changed, 36 insertions(+), 30 deletions(-) rename zk_toolbox/crates/{zk_inception/src/commands/args/send_transactions.rs => zk_supervisor/src/commands/send_transactions/args/mod.rs} (84%) rename zk_toolbox/crates/{zk_inception/src/commands/send_transactions.rs => zk_supervisor/src/commands/send_transactions/mod.rs} (83%) create mode 100644 zk_toolbox/crates/zk_supervisor/src/consts.rs diff --git a/zk_toolbox/Cargo.lock b/zk_toolbox/Cargo.lock index 8648f6524cf3..9dd4936e549d 100644 --- a/zk_toolbox/Cargo.lock +++ b/zk_toolbox/Cargo.lock @@ -6275,7 +6275,6 @@ dependencies = [ "config", "console", "ethers", - "futures", "human-panic", "lazy_static", "serde", @@ -6298,6 +6297,7 @@ name = "zk_supervisor" version = "0.1.0" dependencies = [ "anyhow", + "chrono", "clap", "clap-markdown", "common", @@ -6313,6 +6313,7 @@ dependencies = [ "types", "url", "xshell", + "zksync_basic_types", ] [[package]] diff --git a/zk_toolbox/Cargo.toml b/zk_toolbox/Cargo.toml index 4a08776558ed..fbfc67831411 100644 --- a/zk_toolbox/Cargo.toml +++ b/zk_toolbox/Cargo.toml @@ -38,6 +38,7 @@ clap = { version = "4.4", features = ["derive", "wrap_help", "string"] } slugify-rs = "0.0.3" cliclack = "0.2.5" console = "0.15.8" +chrono = "0.4.38" ethers = "2.0" futures = "0.3.30" human-panic = "2.0" diff --git a/zk_toolbox/crates/zk_inception/Cargo.toml b/zk_toolbox/crates/zk_inception/Cargo.toml index 689c27738131..01d0697d6b6c 100644 --- a/zk_toolbox/crates/zk_inception/Cargo.toml +++ b/zk_toolbox/crates/zk_inception/Cargo.toml @@ -16,7 +16,6 @@ clap.workspace = true cliclack.workspace = true config.workspace = true console.workspace = true -futures.workspace = true human-panic.workspace = true lazy_static.workspace = true serde_yaml.workspace = true diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs index 67747ea913e5..d18b05c910e5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/args/mod.rs @@ -1,9 +1,7 @@ pub use containers::*; pub use run_server::*; -pub use send_transactions::*; pub use update::*; mod containers; mod run_server; -mod send_transactions; mod update; diff --git a/zk_toolbox/crates/zk_inception/src/commands/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/mod.rs index f21e7b007118..523faea04786 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/mod.rs @@ -7,6 +7,5 @@ pub mod explorer; pub mod external_node; pub mod portal; pub mod prover; -pub mod send_transactions; pub mod server; pub mod update; diff --git a/zk_toolbox/crates/zk_inception/src/main.rs b/zk_toolbox/crates/zk_inception/src/main.rs index d37fe65f52b9..f6f7d83dede6 100644 --- a/zk_toolbox/crates/zk_inception/src/main.rs +++ b/zk_toolbox/crates/zk_inception/src/main.rs @@ -1,6 +1,6 @@ use clap::{command, Parser, Subcommand}; use commands::{ - args::{ContainersArgs, SendTransactionsArgs, UpdateArgs}, + args::{ContainersArgs, UpdateArgs}, contract_verifier::ContractVerifierCommands, }; use common::{ @@ -66,8 +66,6 @@ pub enum InceptionSubcommands { Update(UpdateArgs), #[command(hide = true)] Markdown, - /// Send transactions from file - SendTransactions(SendTransactionsArgs), } #[derive(Parser, Debug)] @@ -131,9 +129,6 @@ async fn run_subcommand(inception_args: Inception, shell: &Shell) -> anyhow::Res InceptionSubcommands::Markdown => { clap_markdown::print_help_markdown::(); } - InceptionSubcommands::SendTransactions(args) => { - commands::send_transactions::run(shell, args).await? - } } Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/Cargo.toml b/zk_toolbox/crates/zk_supervisor/Cargo.toml index d9c5c2196fae..4c450a736393 100644 --- a/zk_toolbox/crates/zk_supervisor/Cargo.toml +++ b/zk_toolbox/crates/zk_supervisor/Cargo.toml @@ -15,6 +15,7 @@ anyhow.workspace = true clap.workspace = true common.workspace = true config.workspace = true +chrono.workspace = true ethers.workspace = true human-panic.workspace = true strum.workspace = true @@ -27,3 +28,4 @@ clap-markdown.workspace = true futures.workspace = true types.workspace = true serde_yaml.workspace = true +zksync_basic_types.workspace = true diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs index e45512d50d89..e63edd553d13 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/mod.rs @@ -5,5 +5,6 @@ pub mod fmt; pub mod lint; pub(crate) mod lint_utils; pub mod prover_version; +pub mod send_transactions; pub mod snapshot; pub mod test; diff --git a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs similarity index 84% rename from zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs rename to zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs index c5d0a01c4450..82966a68e69d 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/args/send_transactions.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs @@ -4,10 +4,7 @@ use clap::Parser; use common::Prompt; use url::Url; -use crate::{ - defaults::LOCAL_RPC_URL, - messages::{MSG_L1_RPC_URL_HELP, MSG_L1_RPC_URL_INVALID_ERR, MSG_L1_RPC_URL_PROMPT}, -}; +use crate::defaults::LOCAL_RPC_URL; #[derive(Debug, Parser)] pub struct SendTransactionsArgs { @@ -17,7 +14,7 @@ pub struct SendTransactionsArgs { pub private_key: Option, #[clap(long)] pub gas_price: Option, - #[clap(long, help = MSG_L1_RPC_URL_HELP)] + #[clap(long, help = "L1 RPC URL")] pub l1_rpc_url: Option, #[clap(long)] pub confirmations: Option, @@ -47,12 +44,12 @@ impl SendTransactionsArgs { .unwrap_or_else(|| Prompt::new("Gas price").ask()); let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { - Prompt::new(MSG_L1_RPC_URL_PROMPT) + Prompt::new("L1 RPC URL") .default(LOCAL_RPC_URL) .validate_with(|val: &String| -> Result<(), String> { Url::parse(val) .map(|_| ()) - .map_err(|_| MSG_L1_RPC_URL_INVALID_ERR.to_string()) + .map_err(|_| "Invalid L1 RPC URL".to_string()) }) .ask() }); diff --git a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs similarity index 83% rename from zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs rename to zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 15c077815f8a..a61fc93c8070 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/send_transactions.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -6,6 +6,8 @@ use std::{ time::Duration, }; +use anyhow::Context; +use chrono::Local; use common::ethereum::create_ethers_client; use config::EcosystemConfig; use ethers::{abi::Bytes, providers::Middleware, types::TransactionRequest, utils::hex}; @@ -13,8 +15,10 @@ use serde::Deserialize; use xshell::Shell; use zksync_basic_types::{H160, U256}; -use super::args::SendTransactionsArgs; use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; +use args::SendTransactionsArgs; + +pub mod args; #[derive(Deserialize)] struct Transaction { @@ -49,6 +53,12 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() // Parse the JSON file let txns: Txns = serde_json::from_str(&data).expect("Unable to parse JSON"); + let timestamp = Local::now().format("%Y%m%d_%H%M%S").to_string(); + let log_file = ecosystem_config + .link_to_code + .join(DEFAULT_UNSIGNED_TRANSACTIONS_DIR) + .join(format!("{}_receipt.log", timestamp)); + let client = create_ethers_client(args.private_key.parse()?, args.l1_rpc_url, Some(chain_id))?; let mut nonce = client.get_transaction_count(client.address(), None).await?; @@ -76,24 +86,19 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() .confirmations(args.confirmations) .interval(Duration::from_millis(30)) .await? - .unwrap(); - - log_receipt( - ecosystem_config - .link_to_code - .join(DEFAULT_UNSIGNED_TRANSACTIONS_DIR), - format!("{:?}", receipt).as_str(), - ); + .context("Failed to send transaction")?; + + log_receipt(&log_file, format!("{:?}", receipt).as_str()); } Ok(()) } -fn log_receipt(path: PathBuf, receipt: &str) { +fn log_receipt(path: &PathBuf, receipt: &str) { let mut file = OpenOptions::new() .append(true) .create(true) - .open(path.join("receipt.log")) + .open(path) .expect("Unable to open file"); writeln!(file, "{}", receipt).expect("Unable to write data"); diff --git a/zk_toolbox/crates/zk_supervisor/src/consts.rs b/zk_toolbox/crates/zk_supervisor/src/consts.rs new file mode 100644 index 000000000000..66f00c7553b5 --- /dev/null +++ b/zk_toolbox/crates/zk_supervisor/src/consts.rs @@ -0,0 +1 @@ +pub const DEFAULT_UNSIGNED_TRANSACTIONS_DIR: &str = "transactions"; diff --git a/zk_toolbox/crates/zk_supervisor/src/defaults.rs b/zk_toolbox/crates/zk_supervisor/src/defaults.rs index f4bae739c2d1..d9325402f533 100644 --- a/zk_toolbox/crates/zk_supervisor/src/defaults.rs +++ b/zk_toolbox/crates/zk_supervisor/src/defaults.rs @@ -2,3 +2,4 @@ pub const TEST_DATABASE_SERVER_URL: &str = "postgres://postgres:notsecurepassword@localhost:5433/zksync_local_test"; pub const TEST_DATABASE_PROVER_URL: &str = "postgres://postgres:notsecurepassword@localhost:5433/prover_local_test"; +pub const LOCAL_RPC_URL: &str = "http://127.0.0.1:8545"; diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index a8722787b5ff..d57a39a269a1 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -1,7 +1,7 @@ use clap::{Parser, Subcommand}; use commands::{ contracts::ContractsArgs, database::DatabaseCommands, lint::LintArgs, - snapshot::SnapshotCommands, test::TestCommands, + send_transactions::args::SendTransactionsArgs, snapshot::SnapshotCommands, test::TestCommands, }; use common::{ check_general_prerequisites, @@ -20,6 +20,7 @@ use xshell::Shell; use crate::commands::{clean::CleanCommands, fmt::FmtArgs}; mod commands; +mod consts; mod dals; mod defaults; mod messages; @@ -53,6 +54,8 @@ enum SupervisorSubcommands { ProverVersion, #[command(about = MSG_CONTRACTS_ABOUT)] Contracts(ContractsArgs), + /// Send transactions from file + SendTransactions(SendTransactionsArgs), } #[derive(Parser, Debug)] @@ -111,6 +114,9 @@ async fn run_subcommand(args: Supervisor, shell: &Shell) -> anyhow::Result<()> { SupervisorSubcommands::Fmt(args) => commands::fmt::run(shell.clone(), args).await?, SupervisorSubcommands::ProverVersion => commands::prover_version::run(shell).await?, SupervisorSubcommands::Contracts(args) => commands::contracts::run(shell, args)?, + SupervisorSubcommands::SendTransactions(args) => { + commands::send_transactions::run(shell, args).await? + } } Ok(()) } From 29f95917175432fbaf7bf8e9d1b63d452bea6c75 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 14:01:28 +0200 Subject: [PATCH 65/89] style: lint use statements --- .../crates/zk_supervisor/src/commands/send_transactions/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index a61fc93c8070..86b0d68248e1 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -7,6 +7,7 @@ use std::{ }; use anyhow::Context; +use args::SendTransactionsArgs; use chrono::Local; use common::ethereum::create_ethers_client; use config::EcosystemConfig; @@ -16,7 +17,6 @@ use xshell::Shell; use zksync_basic_types::{H160, U256}; use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; -use args::SendTransactionsArgs; pub mod args; From 97444df3a541f1f8c6c207284fad1f6c45b04c2d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Tue, 10 Sep 2024 14:17:46 +0200 Subject: [PATCH 66/89] refactor: use message constants --- .../commands/send_transactions/args/mod.rs | 22 +++++++++------ .../src/commands/send_transactions/mod.rs | 27 ++++++++++++------- zk_toolbox/crates/zk_supervisor/src/main.rs | 7 ++--- .../crates/zk_supervisor/src/messages.rs | 15 +++++++++++ 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs index 82966a68e69d..defe4a8a7717 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs @@ -4,7 +4,13 @@ use clap::Parser; use common::Prompt; use url::Url; -use crate::defaults::LOCAL_RPC_URL; +use crate::{ + defaults::LOCAL_RPC_URL, + messages::{ + MSG_INVALID_L1_RPC_URL_ERR, MSG_PROMPT_GAS_PRICE, MSG_PROMPT_L1_RPC_URL, + MSG_PROMPT_SECRET_KEY, MSG_PROMPT_TRANSACTION_FILE, MSG_TRANSACTION_CONFIRMATIONS, + }, +}; #[derive(Debug, Parser)] pub struct SendTransactionsArgs { @@ -14,7 +20,7 @@ pub struct SendTransactionsArgs { pub private_key: Option, #[clap(long)] pub gas_price: Option, - #[clap(long, help = "L1 RPC URL")] + #[clap(long)] pub l1_rpc_url: Option, #[clap(long)] pub confirmations: Option, @@ -33,30 +39,30 @@ impl SendTransactionsArgs { pub fn fill_values_with_prompt(self) -> SendTransactionsArgsFinal { let file = self .file - .unwrap_or_else(|| Prompt::new("Path to transactions file").ask()); + .unwrap_or_else(|| Prompt::new(MSG_PROMPT_TRANSACTION_FILE).ask()); let private_key = self .private_key - .unwrap_or_else(|| Prompt::new("Secret key of the sender").ask()); + .unwrap_or_else(|| Prompt::new(MSG_PROMPT_SECRET_KEY).ask()); let gas_price = self .gas_price - .unwrap_or_else(|| Prompt::new("Gas price").ask()); + .unwrap_or_else(|| Prompt::new(MSG_PROMPT_GAS_PRICE).ask()); let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { - Prompt::new("L1 RPC URL") + Prompt::new(MSG_PROMPT_L1_RPC_URL) .default(LOCAL_RPC_URL) .validate_with(|val: &String| -> Result<(), String> { Url::parse(val) .map(|_| ()) - .map_err(|_| "Invalid L1 RPC URL".to_string()) + .map_err(|_| MSG_INVALID_L1_RPC_URL_ERR.to_string()) }) .ask() }); let confirmations = self .confirmations - .unwrap_or_else(|| Prompt::new("Confirmations").ask()); + .unwrap_or_else(|| Prompt::new(MSG_TRANSACTION_CONFIRMATIONS).ask()); SendTransactionsArgsFinal { file, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 86b0d68248e1..0c0bd5296e84 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -16,7 +16,13 @@ use serde::Deserialize; use xshell::Shell; use zksync_basic_types::{H160, U256}; -use crate::consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR; +use crate::{ + consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, + messages::{ + MSG_FAILED_TO_SEND_TXN_ERR, MSG_UNABLE_TO_OPEN_FILE_ERR, MSG_UNABLE_TO_READ_FILE_ERR, + MSG_UNABLE_TO_READ_PARSE_JSON_ERR, MSG_UNABLE_TO_WRITE_FILE_ERR, + }, +}; pub mod args; @@ -46,12 +52,13 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() let chain_id = ecosystem_config.l1_network.chain_id(); // Read the JSON file - let mut file = File::open(args.file).expect("Unable to open file"); + let mut file = File::open(args.file).context(MSG_UNABLE_TO_OPEN_FILE_ERR)?; let mut data = String::new(); - file.read_to_string(&mut data).expect("Unable to read file"); + file.read_to_string(&mut data) + .context(MSG_UNABLE_TO_READ_FILE_ERR)?; // Parse the JSON file - let txns: Txns = serde_json::from_str(&data).expect("Unable to parse JSON"); + let txns: Txns = serde_json::from_str(&data).context(MSG_UNABLE_TO_READ_PARSE_JSON_ERR)?; let timestamp = Local::now().format("%Y%m%d_%H%M%S").to_string(); let log_file = ecosystem_config @@ -86,20 +93,22 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() .confirmations(args.confirmations) .interval(Duration::from_millis(30)) .await? - .context("Failed to send transaction")?; + .context(MSG_FAILED_TO_SEND_TXN_ERR)?; - log_receipt(&log_file, format!("{:?}", receipt).as_str()); + log_receipt(&log_file, format!("{:?}", receipt).as_str())?; } Ok(()) } -fn log_receipt(path: &PathBuf, receipt: &str) { +fn log_receipt(path: &PathBuf, receipt: &str) -> anyhow::Result<()> { let mut file = OpenOptions::new() .append(true) .create(true) .open(path) - .expect("Unable to open file"); + .context(MSG_UNABLE_TO_OPEN_FILE_ERR)?; + + writeln!(file, "{}", receipt).context(MSG_UNABLE_TO_WRITE_FILE_ERR)?; - writeln!(file, "{}", receipt).expect("Unable to write data"); + Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/main.rs b/zk_toolbox/crates/zk_supervisor/src/main.rs index d57a39a269a1..3d5537140eea 100644 --- a/zk_toolbox/crates/zk_supervisor/src/main.rs +++ b/zk_toolbox/crates/zk_supervisor/src/main.rs @@ -12,8 +12,9 @@ use common::{ use config::EcosystemConfig; use messages::{ msg_global_chain_does_not_exist, MSG_CONTRACTS_ABOUT, MSG_PROVER_VERSION_ABOUT, - MSG_SUBCOMMAND_CLEAN, MSG_SUBCOMMAND_DATABASE_ABOUT, MSG_SUBCOMMAND_FMT_ABOUT, - MSG_SUBCOMMAND_LINT_ABOUT, MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, MSG_SUBCOMMAND_TESTS_ABOUT, + MSG_SEND_TXNS_ABOUT, MSG_SUBCOMMAND_CLEAN, MSG_SUBCOMMAND_DATABASE_ABOUT, + MSG_SUBCOMMAND_FMT_ABOUT, MSG_SUBCOMMAND_LINT_ABOUT, MSG_SUBCOMMAND_SNAPSHOTS_CREATOR_ABOUT, + MSG_SUBCOMMAND_TESTS_ABOUT, }; use xshell::Shell; @@ -54,7 +55,7 @@ enum SupervisorSubcommands { ProverVersion, #[command(about = MSG_CONTRACTS_ABOUT)] Contracts(ContractsArgs), - /// Send transactions from file + #[command(about = MSG_SEND_TXNS_ABOUT)] SendTransactions(SendTransactionsArgs), } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index ff9cc104a505..d37a49b4e595 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -199,3 +199,18 @@ pub(super) const MSG_RUNNING_CONTRACTS_FMT_SPINNER: &str = "Running prettier for pub(super) const MSG_TEST_WALLETS_INFO: &str = "Print test wallets information"; pub(super) const MSG_DESERIALIZE_TEST_WALLETS_ERR: &str = "Impossible to deserialize test wallets"; pub(super) const MSG_WALLETS_TEST_SUCCESS: &str = "Wallets test success"; + +// Send transactions related messages +pub(super) const MSG_SEND_TXNS_ABOUT: &str = "Send transactions from file"; +pub(super) const MSG_PROMPT_TRANSACTION_FILE: &str = "Path to transactions file"; +pub(super) const MSG_PROMPT_SECRET_KEY: &str = "Secret key of the sender"; +pub(super) const MSG_PROMPT_GAS_PRICE: &str = "Gas price"; +pub(super) const MSG_PROMPT_L1_RPC_URL: &str = "L1 RPC URL"; +pub(super) const MSG_TRANSACTION_CONFIRMATIONS: &str = "Confirmations"; + +pub(super) const MSG_UNABLE_TO_OPEN_FILE_ERR: &str = "Unable to open file"; +pub(super) const MSG_UNABLE_TO_READ_FILE_ERR: &str = "Unable to read file"; +pub(super) const MSG_UNABLE_TO_WRITE_FILE_ERR: &str = "Unable to write data to file"; +pub(super) const MSG_UNABLE_TO_READ_PARSE_JSON_ERR: &str = "Unable to parse JSON"; +pub(super) const MSG_FAILED_TO_SEND_TXN_ERR: &str = "Failed to send transaction"; +pub(super) const MSG_INVALID_L1_RPC_URL_ERR: &str = "Invalid L1 RPC URL"; From 02dfc634e3ccab922e606974cf21797c29744638 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 11 Sep 2024 11:44:01 +0200 Subject: [PATCH 67/89] refactor: remove register chain's duplicated code --- .../src/commands/chain/build_transactions.rs | 45 +++---- .../zk_inception/src/commands/chain/common.rs | 124 ++++++++++++++++++ .../src/commands/chain/deploy_paymaster.rs | 10 +- .../zk_inception/src/commands/chain/init.rs | 123 ++--------------- .../zk_inception/src/commands/chain/mod.rs | 3 +- 5 files changed, 158 insertions(+), 147 deletions(-) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/chain/common.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index a188b0dd658a..60889d5603b1 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -1,14 +1,6 @@ use anyhow::Context; -use common::{config::global_config, forge::Forge, git, logger, spinner::Spinner}; -use config::{ - copy_configs, - forge_interface::{ - register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, - script_params::REGISTER_CHAIN_SCRIPT_PARAMS, - }, - traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, - EcosystemConfig, -}; +use common::{config::global_config, git, logger, spinner::Spinner}; +use config::{copy_configs, traits::SaveConfigWithBasePath, EcosystemConfig}; use ethers::utils::hex::ToHex; use xshell::Shell; @@ -22,6 +14,8 @@ use crate::{ }, }; +use super::{common::register_chain, deploy_paymaster::deploy_paymaster}; + const CHAIN_TXNS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; const CHAIN_TXNS_FILE_DST: &str = "register-hyperchain-txns.json"; @@ -51,29 +45,22 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R .get_contracts_config() .context(MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG)?; contracts_config.l1.base_token_addr = chain_config.base_token.address; - - let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); - - let deploy_config = RegisterChainL1Config::new(&chain_config, &contracts_config)?; - deploy_config.save(shell, deploy_config_path)?; spinner.finish(); let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER); - Forge::new(&config.path_to_foundry()) - .script( - ®ISTER_CHAIN_SCRIPT_PARAMS.script(), - args.forge_args.clone(), - ) - .with_ffi() - .with_sender(config.get_wallets()?.governor.address.encode_hex_upper()) - .with_rpc_url(args.l1_rpc_url.clone()) - .run(shell)?; - - let register_chain_output = RegisterChainOutput::read( + + register_chain( shell, - REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - contracts_config.set_chain_contracts(®ister_chain_output); + args.forge_args.clone(), + &config, + &chain_config, + &mut contracts_config, + args.l1_rpc_url.clone(), + Some(config.get_wallets()?.governor.address.encode_hex_upper()), + false, + ) + .await?; + contracts_config.save_with_base_path(shell, &args.out)?; spinner.finish(); diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs new file mode 100644 index 000000000000..dc8cfed74398 --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs @@ -0,0 +1,124 @@ +use common::{ + forge::{Forge, ForgeScriptArgs}, + spinner::Spinner, +}; +use config::{ + forge_interface::{ + register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, + script_params::REGISTER_CHAIN_SCRIPT_PARAMS, + }, + traits::{ReadConfig, SaveConfig}, + ChainConfig, ContractsConfig, EcosystemConfig, +}; +use types::{BaseToken, L1Network, WalletCreation}; +use xshell::Shell; + +use crate::{ + consts::AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, + messages::{MSG_DISTRIBUTING_ETH_SPINNER, MSG_MINT_BASE_TOKEN_SPINNER}, + utils::forge::{check_the_balance, fill_forge_private_key}, +}; + +pub async fn register_chain( + shell: &Shell, + forge_args: ForgeScriptArgs, + config: &EcosystemConfig, + chain_config: &ChainConfig, + contracts: &mut ContractsConfig, + l1_rpc_url: String, + sender: Option, + broadcast: bool, +) -> anyhow::Result<()> { + let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); + + let deploy_config = RegisterChainL1Config::new(chain_config, contracts)?; + deploy_config.save(shell, deploy_config_path)?; + + let mut forge = Forge::new(&config.path_to_foundry()) + .script(®ISTER_CHAIN_SCRIPT_PARAMS.script(), forge_args.clone()) + .with_ffi() + .with_rpc_url(l1_rpc_url); + + if broadcast { + forge = forge.with_broadcast(); + } + + if let Some(address) = sender { + forge = forge.with_sender(address); + } else { + forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?; + check_the_balance(&forge).await?; + } + + forge.run(shell)?; + + let register_chain_output = RegisterChainOutput::read( + shell, + REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), + )?; + contracts.set_chain_contracts(®ister_chain_output); + Ok(()) +} + +// Distribute eth to the chain wallets for localhost environment +pub async fn distribute_eth( + ecosystem_config: &EcosystemConfig, + chain_config: &ChainConfig, + l1_rpc_url: String, +) -> anyhow::Result<()> { + if chain_config.wallet_creation == WalletCreation::Localhost + && ecosystem_config.l1_network == L1Network::Localhost + { + let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); + let wallets = ecosystem_config.get_wallets()?; + let chain_wallets = chain_config.get_wallets_config()?; + let mut addresses = vec![ + chain_wallets.operator.address, + chain_wallets.blob_operator.address, + chain_wallets.governor.address, + ]; + if let Some(deployer) = chain_wallets.deployer { + addresses.push(deployer.address) + } + common::ethereum::distribute_eth( + wallets.operator, + addresses, + l1_rpc_url, + ecosystem_config.l1_network.chain_id(), + AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, + ) + .await?; + spinner.finish(); + } + Ok(()) +} + +pub async fn mint_base_token( + ecosystem_config: &EcosystemConfig, + chain_config: &ChainConfig, + l1_rpc_url: String, +) -> anyhow::Result<()> { + if chain_config.wallet_creation == WalletCreation::Localhost + && ecosystem_config.l1_network == L1Network::Localhost + && chain_config.base_token != BaseToken::eth() + { + let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); + let wallets = ecosystem_config.get_wallets()?; + let chain_wallets = chain_config.get_wallets_config()?; + let base_token = &chain_config.base_token; + let addresses = vec![wallets.governor.address, chain_wallets.governor.address]; + let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128 + / base_token.denominator as u128; + common::ethereum::mint_token( + wallets.operator, + base_token.address, + addresses, + l1_rpc_url, + ecosystem_config.l1_network.chain_id(), + amount, + ) + .await?; + spinner.finish(); + } + Ok(()) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs index 81ac457cd884..677247ffbbb3 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs @@ -28,7 +28,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { .load_chain(chain_name) .context(MSG_CHAIN_NOT_INITIALIZED)?; let mut contracts = chain_config.get_contracts_config()?; - deploy_paymaster(shell, &chain_config, &mut contracts, args).await?; + deploy_paymaster(shell, &chain_config, &mut contracts, args, true).await?; contracts.save_with_base_path(shell, chain_config.configs) } @@ -37,6 +37,7 @@ pub async fn deploy_paymaster( chain_config: &ChainConfig, contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, + broadcast: bool, ) -> anyhow::Result<()> { let input = DeployPaymasterInput::new(chain_config)?; let foundry_contracts_path = chain_config.path_to_foundry(); @@ -56,8 +57,11 @@ pub async fn deploy_paymaster( .l1_rpc_url .expose_str() .to_string(), - ) - .with_broadcast(); + ); + + if broadcast { + forge = forge.with_broadcast(); + } forge = fill_forge_private_key( forge, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 793fbbf31aee..45c538c2bae8 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -1,22 +1,9 @@ use anyhow::{bail, Context}; -use common::{ - config::global_config, - forge::{Forge, ForgeScriptArgs}, - git, logger, - spinner::Spinner, -}; +use common::{config::global_config, git, logger, spinner::Spinner}; use config::{ - copy_configs, - forge_interface::{ - register_chain::{input::RegisterChainL1Config, output::RegisterChainOutput}, - script_params::REGISTER_CHAIN_SCRIPT_PARAMS, - }, - ports_config, set_l1_rpc_url, - traits::{ReadConfig, SaveConfig, SaveConfigWithBasePath}, - update_from_chain_config, update_ports, ChainConfig, ContractsConfig, EcosystemConfig, - GeneralConfig, + copy_configs, ports_config, set_l1_rpc_url, traits::SaveConfigWithBasePath, + update_from_chain_config, update_ports, ChainConfig, EcosystemConfig, GeneralConfig, }; -use types::{BaseToken, L1Network, WalletCreation}; use xshell::Shell; use crate::{ @@ -30,17 +17,16 @@ use crate::{ }, portal::update_portal_config, }, - consts::AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, messages::{ msg_initializing_chain, MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_INITIALIZED, - MSG_CHAIN_NOT_FOUND_ERR, MSG_DISTRIBUTING_ETH_SPINNER, MSG_GENESIS_DATABASE_ERR, - MSG_MINT_BASE_TOKEN_SPINNER, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, + MSG_CHAIN_NOT_FOUND_ERR, MSG_GENESIS_DATABASE_ERR, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, }, - utils::forge::{check_the_balance, fill_forge_private_key}, }; +use super::common::{distribute_eth, mint_base_token, register_chain}; + pub(crate) async fn run(args: InitArgs, shell: &Shell) -> anyhow::Result<()> { let chain_name = global_config().chain_name.clone(); let config = EcosystemConfig::from_file(shell)?; @@ -95,6 +81,8 @@ pub async fn init( chain_config, &mut contracts_config, init_args.l1_rpc_url.clone(), + None, + false, ) .await?; contracts_config.save_with_base_path(shell, &chain_config.configs)?; @@ -145,6 +133,7 @@ pub async fn init( chain_config, &mut contracts_config, init_args.forge_args.clone(), + true, ) .await?; contracts_config.save_with_base_path(shell, &chain_config.configs)?; @@ -161,100 +150,6 @@ pub async fn init( Ok(()) } -async fn register_chain( - shell: &Shell, - forge_args: ForgeScriptArgs, - config: &EcosystemConfig, - chain_config: &ChainConfig, - contracts: &mut ContractsConfig, - l1_rpc_url: String, -) -> anyhow::Result<()> { - let deploy_config_path = REGISTER_CHAIN_SCRIPT_PARAMS.input(&config.link_to_code); - - let deploy_config = RegisterChainL1Config::new(chain_config, contracts)?; - deploy_config.save(shell, deploy_config_path)?; - - let mut forge = Forge::new(&config.path_to_foundry()) - .script(®ISTER_CHAIN_SCRIPT_PARAMS.script(), forge_args.clone()) - .with_ffi() - .with_rpc_url(l1_rpc_url) - .with_broadcast(); - - forge = fill_forge_private_key(forge, config.get_wallets()?.governor_private_key())?; - check_the_balance(&forge).await?; - forge.run(shell)?; - - let register_chain_output = RegisterChainOutput::read( - shell, - REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - contracts.set_chain_contracts(®ister_chain_output); - Ok(()) -} - -// Distribute eth to the chain wallets for localhost environment -pub async fn distribute_eth( - ecosystem_config: &EcosystemConfig, - chain_config: &ChainConfig, - l1_rpc_url: String, -) -> anyhow::Result<()> { - if chain_config.wallet_creation == WalletCreation::Localhost - && ecosystem_config.l1_network == L1Network::Localhost - { - let spinner = Spinner::new(MSG_DISTRIBUTING_ETH_SPINNER); - let wallets = ecosystem_config.get_wallets()?; - let chain_wallets = chain_config.get_wallets_config()?; - let mut addresses = vec![ - chain_wallets.operator.address, - chain_wallets.blob_operator.address, - chain_wallets.governor.address, - ]; - if let Some(deployer) = chain_wallets.deployer { - addresses.push(deployer.address) - } - common::ethereum::distribute_eth( - wallets.operator, - addresses, - l1_rpc_url, - ecosystem_config.l1_network.chain_id(), - AMOUNT_FOR_DISTRIBUTION_TO_WALLETS, - ) - .await?; - spinner.finish(); - } - Ok(()) -} - -pub async fn mint_base_token( - ecosystem_config: &EcosystemConfig, - chain_config: &ChainConfig, - l1_rpc_url: String, -) -> anyhow::Result<()> { - if chain_config.wallet_creation == WalletCreation::Localhost - && ecosystem_config.l1_network == L1Network::Localhost - && chain_config.base_token != BaseToken::eth() - { - let spinner = Spinner::new(MSG_MINT_BASE_TOKEN_SPINNER); - let wallets = ecosystem_config.get_wallets()?; - let chain_wallets = chain_config.get_wallets_config()?; - let base_token = &chain_config.base_token; - let addresses = vec![wallets.governor.address, chain_wallets.governor.address]; - let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128 - / base_token.denominator as u128; - common::ethereum::mint_token( - wallets.operator, - base_token.address, - addresses, - l1_rpc_url, - ecosystem_config.l1_network.chain_id(), - amount, - ) - .await?; - spinner.finish(); - } - Ok(()) -} - fn apply_port_offset(port_offset: u16, general_config: &mut GeneralConfig) -> anyhow::Result<()> { let Some(mut ports_config) = ports_config(general_config) else { bail!("Missing ports config"); diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index 89b8952b5b78..251e29d26c58 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -1,7 +1,7 @@ +use ::common::forge::ForgeScriptArgs; use args::build_transactions::BuildTransactionsArgs; pub(crate) use args::create::ChainCreateArgsFinal; use clap::Subcommand; -use common::forge::ForgeScriptArgs; pub(crate) use create::create_chain_inner; use xshell::Shell; @@ -12,6 +12,7 @@ use crate::commands::chain::{ pub(crate) mod args; mod build_transactions; +mod common; mod create; pub mod deploy_l2_contracts; pub mod deploy_paymaster; From a289ef98009135a78416ed1dfaa1d6aec3e7bda8 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 11 Sep 2024 11:45:11 +0200 Subject: [PATCH 68/89] fix: remove unused import --- .../zk_inception/src/commands/chain/build_transactions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index 60889d5603b1..cff6dc0ce258 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -14,7 +14,7 @@ use crate::{ }, }; -use super::{common::register_chain, deploy_paymaster::deploy_paymaster}; +use super::common::register_chain; const CHAIN_TXNS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; From 9f8de091ddcd4ad8d398b7096a8002f1c9f464a0 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 11 Sep 2024 13:33:06 +0200 Subject: [PATCH 69/89] style: format --- zk_toolbox/crates/zk_inception/src/commands/chain/init.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 45c538c2bae8..edf3239f188f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -6,6 +6,7 @@ use config::{ }; use xshell::Shell; +use super::common::{distribute_eth, mint_base_token, register_chain}; use crate::{ accept_ownership::accept_admin, commands::{ @@ -25,8 +26,6 @@ use crate::{ }, }; -use super::common::{distribute_eth, mint_base_token, register_chain}; - pub(crate) async fn run(args: InitArgs, shell: &Shell) -> anyhow::Result<()> { let chain_name = global_config().chain_name.clone(); let config = EcosystemConfig::from_file(shell)?; From 30976c344327f0ab61e1e0a18438afa92ce84cbd Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 11 Sep 2024 13:33:46 +0200 Subject: [PATCH 70/89] style: format --- .../zk_inception/src/commands/chain/build_transactions.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index cff6dc0ce258..705a727d04f5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -4,6 +4,7 @@ use config::{copy_configs, traits::SaveConfigWithBasePath, EcosystemConfig}; use ethers::utils::hex::ToHex; use xshell::Shell; +use super::common::register_chain; use crate::{ commands::chain::args::build_transactions::BuildTransactionsArgs, messages::{ @@ -14,8 +15,6 @@ use crate::{ }, }; -use super::common::register_chain; - const CHAIN_TXNS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; const CHAIN_TXNS_FILE_DST: &str = "register-hyperchain-txns.json"; From 9ddb34dfb7efe96295324b02e4c76e102f86d239 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 11 Sep 2024 14:18:33 +0200 Subject: [PATCH 71/89] refactor: remove duplicated code between ecosystem init and build-contracts --- .../commands/ecosystem/build_transactions.rs | 65 ++++------------ .../src/commands/ecosystem/common.rs | 75 +++++++++++++++++++ .../src/commands/ecosystem/init.rs | 66 +++++----------- .../src/commands/ecosystem/mod.rs | 1 + .../crates/zk_inception/src/messages.rs | 2 - 5 files changed, 109 insertions(+), 100 deletions(-) create mode 100644 zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs index 0662dce5f699..ff7132360972 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/build_transactions.rs @@ -1,26 +1,18 @@ use anyhow::Context; -use common::{forge::Forge, git, logger, spinner::Spinner}; -use config::{ - forge_interface::{ - deploy_ecosystem::{input::DeployL1Config, output::DeployL1Output}, - script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, - }, - traits::{ReadConfig, ReadConfigWithBasePath, SaveConfig, SaveConfigWithBasePath}, - ContractsConfig, EcosystemConfig, GenesisConfig, -}; -use types::ProverMode; +use common::{git, logger, spinner::Spinner}; +use config::{traits::SaveConfigWithBasePath, EcosystemConfig}; use xshell::Shell; use super::{ args::build_transactions::BuildTransactionsArgs, + common::deploy_l1, create_configs::create_initial_deployments_config, utils::{build_system_contracts, install_yarn_dependencies}, }; use crate::messages::{ - MSG_BUILDING_ECOSYSTEM, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, - MSG_ECOSYSTEM_TXN_IMPOSSIBLE_TO_READ_GENESIS_CONFIG, MSG_ECOSYSTEM_TXN_OUTRO, + MSG_BUILDING_ECOSYSTEM, MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER, MSG_ECOSYSTEM_TXN_OUTRO, MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR, MSG_INTALLING_DEPS_SPINNER, - MSG_PREPARING_CONFIG_SPINNER, MSG_WRITING_OUTPUT_FILES_SPINNER, + MSG_WRITING_OUTPUT_FILES_SPINNER, }; const DEPLOY_TRANSACTIONS_FILE_SRC: &str = @@ -48,47 +40,22 @@ pub async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::Result<( build_system_contracts(shell, &ecosystem_config.link_to_code)?; spinner.finish(); - let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); - let default_genesis_config = - GenesisConfig::read_with_base_path(shell, ecosystem_config.get_default_configs_path()) - .context(MSG_ECOSYSTEM_TXN_IMPOSSIBLE_TO_READ_GENESIS_CONFIG)?; - - let wallets_config = ecosystem_config.get_wallets()?; - // For deploying ecosystem we only need genesis batch params - let deploy_config = DeployL1Config::new( - &default_genesis_config, - &wallets_config, - &initial_deployment_config, - ecosystem_config.era_chain_id, - ecosystem_config.prover_version == ProverMode::NoProofs, - ); - let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code); - deploy_config.save(shell, deploy_config_path)?; - spinner.finish(); - let spinner = Spinner::new(MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER); - let forge = Forge::new(&ecosystem_config.path_to_foundry()) - .script( - &DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), - args.forge_args.clone(), - ) - .with_ffi() - .with_rpc_url(args.l1_rpc_url) - .with_sender(args.sender); + let contracts_config = deploy_l1( + shell, + &args.forge_args, + &ecosystem_config, + &initial_deployment_config, + &args.l1_rpc_url, + Some(args.sender), + false, + ) + .await?; - forge.run(shell)?; + contracts_config.save_with_base_path(shell, &args.out)?; spinner.finish(); let spinner = Spinner::new(MSG_WRITING_OUTPUT_FILES_SPINNER); - - let script_output = DeployL1Output::read( - shell, - DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code), - )?; - let mut contracts_config = ContractsConfig::default(); - contracts_config.update_from_l1_output(&script_output); - contracts_config.save_with_base_path(shell, &args.out)?; - shell .create_dir(&args.out) .context(MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs new file mode 100644 index 000000000000..91a57a0ff94a --- /dev/null +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs @@ -0,0 +1,75 @@ +use anyhow::Context; +use common::forge::{Forge, ForgeScriptArgs}; +use config::{ + forge_interface::{ + deploy_ecosystem::{ + input::{DeployL1Config, InitialDeploymentConfig}, + output::DeployL1Output, + }, + script_params::DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, + }, + traits::{ReadConfig, ReadConfigWithBasePath, SaveConfig}, + ContractsConfig, EcosystemConfig, GenesisConfig, +}; +use types::{L1Network, ProverMode}; +use xshell::Shell; + +use crate::utils::forge::{check_the_balance, fill_forge_private_key}; + +pub async fn deploy_l1( + shell: &Shell, + forge_args: &ForgeScriptArgs, + config: &EcosystemConfig, + initial_deployment_config: &InitialDeploymentConfig, + l1_rpc_url: &str, + sender: Option, + broadcast: bool, +) -> anyhow::Result { + let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&config.link_to_code); + let default_genesis_config = + GenesisConfig::read_with_base_path(shell, config.get_default_configs_path()) + .context("Context")?; + + let wallets_config = config.get_wallets()?; + // For deploying ecosystem we only need genesis batch params + let deploy_config = DeployL1Config::new( + &default_genesis_config, + &wallets_config, + initial_deployment_config, + config.era_chain_id, + config.prover_version == ProverMode::NoProofs, + ); + deploy_config.save(shell, deploy_config_path)?; + + let mut forge = Forge::new(&config.path_to_foundry()) + .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) + .with_ffi() + .with_rpc_url(l1_rpc_url.to_string()); + + if broadcast { + forge = forge.with_broadcast(); + } + + if config.l1_network == L1Network::Localhost { + // It's a kludge for reth, just because it doesn't behave properly with large amount of txs + forge = forge.with_slow(); + } + + if let Some(address) = sender { + forge = forge.with_sender(address); + } else { + forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; + check_the_balance(&forge).await?; + } + + forge.run(shell)?; + + let script_output = DeployL1Output::read( + shell, + DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&config.link_to_code), + )?; + let mut contracts_config = ContractsConfig::default(); + contracts_config.update_from_l1_output(&script_output); + + Ok(contracts_config) +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs index 2af70f52c2b4..c200fdf6ab6c 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -11,24 +11,20 @@ use common::{ use config::{ forge_interface::{ deploy_ecosystem::{ - input::{ - DeployErc20Config, DeployL1Config, Erc20DeploymentConfig, InitialDeploymentConfig, - }, - output::{DeployL1Output, ERC20Tokens}, + input::{DeployErc20Config, Erc20DeploymentConfig, InitialDeploymentConfig}, + output::ERC20Tokens, }, - script_params::{DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, DEPLOY_ERC20_SCRIPT_PARAMS}, + script_params::DEPLOY_ERC20_SCRIPT_PARAMS, }, - traits::{ - FileConfigWithDefaultName, ReadConfig, ReadConfigWithBasePath, SaveConfig, - SaveConfigWithBasePath, - }, - ContractsConfig, EcosystemConfig, GenesisConfig, + traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, SaveConfigWithBasePath}, + ContractsConfig, EcosystemConfig, }; -use types::{L1Network, ProverMode}; +use types::L1Network; use xshell::Shell; use super::{ args::init::{EcosystemArgsFinal, EcosystemInitArgs, EcosystemInitArgsFinal}, + common::deploy_l1, setup_observability, utils::{build_system_contracts, install_yarn_dependencies}, }; @@ -277,47 +273,19 @@ async fn deploy_ecosystem_inner( initial_deployment_config: &InitialDeploymentConfig, l1_rpc_url: String, ) -> anyhow::Result { - let deploy_config_path = DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.input(&config.link_to_code); - - let default_genesis_config = - GenesisConfig::read_with_base_path(shell, config.get_default_configs_path()) - .context("Context")?; - - let wallets_config = config.get_wallets()?; - // For deploying ecosystem we only need genesis batch params - let deploy_config = DeployL1Config::new( - &default_genesis_config, - &wallets_config, - initial_deployment_config, - config.era_chain_id, - config.prover_version == ProverMode::NoProofs, - ); - deploy_config.save(shell, deploy_config_path)?; - - let mut forge = Forge::new(&config.path_to_foundry()) - .script(&DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.script(), forge_args.clone()) - .with_ffi() - .with_rpc_url(l1_rpc_url.clone()) - .with_broadcast(); - - if config.l1_network == L1Network::Localhost { - // It's a kludge for reth, just because it doesn't behave properly with large amount of txs - forge = forge.with_slow(); - } - - forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; - let spinner = Spinner::new(MSG_DEPLOYING_ECOSYSTEM_CONTRACTS_SPINNER); - check_the_balance(&forge).await?; - forge.run(shell)?; + let contracts_config = deploy_l1( + shell, + &forge_args, + config, + initial_deployment_config, + &l1_rpc_url, + None, + true, + ) + .await?; spinner.finish(); - let script_output = DeployL1Output::read( - shell, - DEPLOY_ECOSYSTEM_SCRIPT_PARAMS.output(&config.link_to_code), - )?; - let mut contracts_config = ContractsConfig::default(); - contracts_config.update_from_l1_output(&script_output); accept_owner( shell, config, diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs index 7f8f69b295fc..5fa791b97abf 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/mod.rs @@ -9,6 +9,7 @@ use crate::commands::ecosystem::args::{ mod args; pub(crate) mod build_transactions; mod change_default; +mod common; mod create; pub mod create_configs; pub(crate) mod init; diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index f13fa27d74cd..49ebee3fad76 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -129,8 +129,6 @@ pub(super) const MSG_BUILDING_ECOSYSTEM_CONTRACTS_SPINNER: &str = "Building ecos pub(super) const MSG_WRITING_OUTPUT_FILES_SPINNER: &str = "Writing output files..."; pub(super) const MSG_ECOSYSTEM_TXN_OUTRO: &str = "Transactions successfully built"; pub(super) const MSG_ECOSYSTEM_TXN_OUT_PATH_INVALID_ERR: &str = "Invalid path"; -pub(super) const MSG_ECOSYSTEM_TXN_IMPOSSIBLE_TO_READ_GENESIS_CONFIG: &str = - "Impossible to read genesis config from file"; /// Chain create related messages pub(super) const MSG_PROVER_MODE_HELP: &str = "Prover options"; From 8d08bd7d1146e1dc1618ba26cb5e6685f88a084d Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Wed, 11 Sep 2024 15:08:46 +0200 Subject: [PATCH 72/89] fix: check balance only on broadcast --- .../src/commands/chain/build_transactions.rs | 11 ++++---- .../src/commands/chain/deploy_paymaster.rs | 26 +++++++++---------- .../zk_inception/src/commands/chain/init.rs | 7 +++-- .../src/commands/ecosystem/common.rs | 8 +++--- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index 705a727d04f5..e37d09c6473c 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -15,9 +15,9 @@ use crate::{ }, }; -const CHAIN_TXNS_FILE_SRC: &str = +const REGISTER_CHAIN_TXNS_FILE_SRC: &str = "contracts/l1-contracts/broadcast/RegisterHyperchain.s.sol/9/dry-run/run-latest.json"; -const CHAIN_TXNS_FILE_DST: &str = "register-hyperchain-txns.json"; +const REGISTER_CHAIN_TXNS_FILE_DST: &str = "register-hyperchain-txns.json"; const SCRIPT_CONFIG_FILE_SRC: &str = "contracts/l1-contracts/script-config/register-hyperchain.toml"; @@ -47,6 +47,7 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R spinner.finish(); let spinner = Spinner::new(MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER); + let governor: String = config.get_wallets()?.governor.address.encode_hex_upper(); register_chain( shell, @@ -55,7 +56,7 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R &chain_config, &mut contracts_config, args.l1_rpc_url.clone(), - Some(config.get_wallets()?.governor.address.encode_hex_upper()), + Some(governor), false, ) .await?; @@ -69,8 +70,8 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R .context(MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR)?; shell.copy_file( - config.link_to_code.join(CHAIN_TXNS_FILE_SRC), - args.out.join(CHAIN_TXNS_FILE_DST), + config.link_to_code.join(REGISTER_CHAIN_TXNS_FILE_SRC), + args.out.join(REGISTER_CHAIN_TXNS_FILE_DST), )?; shell.copy_file( diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs index 677247ffbbb3..bdac8c06a14b 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs @@ -2,7 +2,6 @@ use anyhow::Context; use common::{ config::global_config, forge::{Forge, ForgeScriptArgs}, - spinner::Spinner, }; use config::{ forge_interface::{ @@ -15,9 +14,7 @@ use config::{ use xshell::Shell; use crate::{ - messages::{ - MSG_CHAIN_NOT_INITIALIZED, MSG_DEPLOYING_PAYMASTER, MSG_L1_SECRETS_MUST_BE_PRESENTED, - }, + messages::{MSG_CHAIN_NOT_INITIALIZED, MSG_L1_SECRETS_MUST_BE_PRESENTED}, utils::forge::{check_the_balance, fill_forge_private_key}, }; @@ -28,7 +25,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> { .load_chain(chain_name) .context(MSG_CHAIN_NOT_INITIALIZED)?; let mut contracts = chain_config.get_contracts_config()?; - deploy_paymaster(shell, &chain_config, &mut contracts, args, true).await?; + deploy_paymaster(shell, &chain_config, &mut contracts, args, None, true).await?; contracts.save_with_base_path(shell, chain_config.configs) } @@ -37,6 +34,7 @@ pub async fn deploy_paymaster( chain_config: &ChainConfig, contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, + sender: Option, broadcast: bool, ) -> anyhow::Result<()> { let input = DeployPaymasterInput::new(chain_config)?; @@ -59,19 +57,21 @@ pub async fn deploy_paymaster( .to_string(), ); + if let Some(address) = sender { + forge = forge.with_sender(address); + } else { + forge = fill_forge_private_key( + forge, + chain_config.get_wallets_config()?.governor_private_key(), + )?; + } + if broadcast { + check_the_balance(&forge).await?; forge = forge.with_broadcast(); } - forge = fill_forge_private_key( - forge, - chain_config.get_wallets_config()?.governor_private_key(), - )?; - - let spinner = Spinner::new(MSG_DEPLOYING_PAYMASTER); - check_the_balance(&forge).await?; forge.run(shell)?; - spinner.finish(); let output = DeployPaymasterOutput::read( shell, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index edf3239f188f..18b35bcd1fa1 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -20,8 +20,8 @@ use crate::{ }, messages::{ msg_initializing_chain, MSG_ACCEPTING_ADMIN_SPINNER, MSG_CHAIN_INITIALIZED, - MSG_CHAIN_NOT_FOUND_ERR, MSG_GENESIS_DATABASE_ERR, MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, - MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, + MSG_CHAIN_NOT_FOUND_ERR, MSG_DEPLOYING_PAYMASTER, MSG_GENESIS_DATABASE_ERR, + MSG_PORTAL_FAILED_TO_CREATE_CONFIG_ERR, MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, }, }; @@ -127,15 +127,18 @@ pub async fn init( contracts_config.save_with_base_path(shell, &chain_config.configs)?; if init_args.deploy_paymaster { + let spinner = Spinner::new(MSG_DEPLOYING_PAYMASTER); deploy_paymaster::deploy_paymaster( shell, chain_config, &mut contracts_config, init_args.forge_args.clone(), + None, true, ) .await?; contracts_config.save_with_base_path(shell, &chain_config.configs)?; + spinner.finish(); } genesis(init_args.genesis_args.clone(), shell, chain_config) diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs index 91a57a0ff94a..d0c261b0d880 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs @@ -46,10 +46,6 @@ pub async fn deploy_l1( .with_ffi() .with_rpc_url(l1_rpc_url.to_string()); - if broadcast { - forge = forge.with_broadcast(); - } - if config.l1_network == L1Network::Localhost { // It's a kludge for reth, just because it doesn't behave properly with large amount of txs forge = forge.with_slow(); @@ -59,7 +55,11 @@ pub async fn deploy_l1( forge = forge.with_sender(address); } else { forge = fill_forge_private_key(forge, wallets_config.deployer_private_key())?; + } + + if broadcast { check_the_balance(&forge).await?; + forge = forge.with_broadcast(); } forge.run(shell)?; From d1859bb34f62e3b9481d4ef6708640b86ac10538 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 12 Sep 2024 11:36:29 +0200 Subject: [PATCH 73/89] style: clippy --- zk_toolbox/crates/zk_inception/src/commands/chain/common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs index dc8cfed74398..068f9db0d0ad 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs @@ -19,6 +19,7 @@ use crate::{ utils::forge::{check_the_balance, fill_forge_private_key}, }; +#[warn(clippy::too_many_arguments)] pub async fn register_chain( shell: &Shell, forge_args: ForgeScriptArgs, From 0a2bf542e02dd659b5f3b28bc6d9079111ec8159 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 12 Sep 2024 11:44:12 +0200 Subject: [PATCH 74/89] fix: check balance order --- .../crates/zk_inception/src/commands/chain/deploy_paymaster.rs | 2 +- zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs index bdac8c06a14b..58c199189bd7 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_paymaster.rs @@ -67,8 +67,8 @@ pub async fn deploy_paymaster( } if broadcast { - check_the_balance(&forge).await?; forge = forge.with_broadcast(); + check_the_balance(&forge).await?; } forge.run(shell)?; diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs index d0c261b0d880..950d39876b09 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/common.rs @@ -58,8 +58,8 @@ pub async fn deploy_l1( } if broadcast { - check_the_balance(&forge).await?; forge = forge.with_broadcast(); + check_the_balance(&forge).await?; } forge.run(shell)?; From 211219f1f9aa19a7b2688c1bfa5ca0f2a587ebf6 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 12 Sep 2024 12:35:00 +0200 Subject: [PATCH 75/89] fix: send register transaction calls --- zk_toolbox/crates/zk_inception/src/commands/chain/init.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 18b35bcd1fa1..970db44da698 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -81,7 +81,7 @@ pub async fn init( &mut contracts_config, init_args.l1_rpc_url.clone(), None, - false, + true, ) .await?; contracts_config.save_with_base_path(shell, &chain_config.configs)?; From c821508dedf28a23877c34d72a224953afdd4ab7 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Thu, 12 Sep 2024 12:44:00 +0200 Subject: [PATCH 76/89] style: format code --- prover/crates/lib/keystore/src/utils.rs | 1 + zk_toolbox/crates/zk_inception/src/commands/chain/common.rs | 2 +- zk_toolbox/crates/zk_inception/src/commands/chain/init.rs | 1 + zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/prover/crates/lib/keystore/src/utils.rs b/prover/crates/lib/keystore/src/utils.rs index d9bb3b47dbb0..10504292d64f 100644 --- a/prover/crates/lib/keystore/src/utils.rs +++ b/prover/crates/lib/keystore/src/utils.rs @@ -115,6 +115,7 @@ pub fn calculate_snark_vk_hash(keystore: &Keystore) -> anyhow::Result { #[cfg(test)] mod tests { use std::str::FromStr; + use zksync_utils::env::Workspace; use super::*; diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs index 068f9db0d0ad..ec70d6122d23 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/common.rs @@ -19,7 +19,7 @@ use crate::{ utils::forge::{check_the_balance, fill_forge_private_key}, }; -#[warn(clippy::too_many_arguments)] +#[allow(clippy::too_many_arguments)] pub async fn register_chain( shell: &Shell, forge_args: ForgeScriptArgs, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index a6d01c9cf173..2c6fae85c4d9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -4,6 +4,7 @@ use config::{ copy_configs, ports_config, set_l1_rpc_url, traits::SaveConfigWithBasePath, update_from_chain_config, update_ports, ChainConfig, EcosystemConfig, GeneralConfig, }; +use types::BaseToken; use xshell::Shell; use super::common::{distribute_eth, mint_base_token, register_chain}; diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs index c42f95e8e3b5..3ac331becc9f 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/test/rust.rs @@ -12,8 +12,8 @@ use crate::{ dals::{Dal, CORE_DAL_PATH, PROVER_DAL_PATH}, defaults::{TEST_DATABASE_PROVER_URL, TEST_DATABASE_SERVER_URL}, messages::{ - MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, - MSG_RESETTING_TEST_DATABASES, MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, + MSG_CHAIN_NOT_FOUND_ERR, MSG_POSTGRES_CONFIG_NOT_FOUND_ERR, MSG_RESETTING_TEST_DATABASES, + MSG_UNIT_TESTS_RUN_SUCCESS, MSG_USING_CARGO_NEXTEST, }, }; From 66a7a1fbcb5d379a200273390efa49baba055bd5 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 14:43:12 +0200 Subject: [PATCH 77/89] feat: do not prompt for gas price --- .../src/commands/send_transactions/args/mod.rs | 12 ++---------- .../src/commands/send_transactions/mod.rs | 4 ++-- zk_toolbox/crates/zk_supervisor/src/messages.rs | 1 - 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs index defe4a8a7717..5246df472062 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs @@ -7,8 +7,8 @@ use url::Url; use crate::{ defaults::LOCAL_RPC_URL, messages::{ - MSG_INVALID_L1_RPC_URL_ERR, MSG_PROMPT_GAS_PRICE, MSG_PROMPT_L1_RPC_URL, - MSG_PROMPT_SECRET_KEY, MSG_PROMPT_TRANSACTION_FILE, MSG_TRANSACTION_CONFIRMATIONS, + MSG_INVALID_L1_RPC_URL_ERR, MSG_PROMPT_L1_RPC_URL, MSG_PROMPT_SECRET_KEY, + MSG_PROMPT_TRANSACTION_FILE, MSG_TRANSACTION_CONFIRMATIONS, }, }; @@ -19,8 +19,6 @@ pub struct SendTransactionsArgs { #[clap(long)] pub private_key: Option, #[clap(long)] - pub gas_price: Option, - #[clap(long)] pub l1_rpc_url: Option, #[clap(long)] pub confirmations: Option, @@ -30,7 +28,6 @@ pub struct SendTransactionsArgs { pub struct SendTransactionsArgsFinal { pub file: PathBuf, pub private_key: String, - pub gas_price: String, pub l1_rpc_url: String, pub confirmations: usize, } @@ -45,10 +42,6 @@ impl SendTransactionsArgs { .private_key .unwrap_or_else(|| Prompt::new(MSG_PROMPT_SECRET_KEY).ask()); - let gas_price = self - .gas_price - .unwrap_or_else(|| Prompt::new(MSG_PROMPT_GAS_PRICE).ask()); - let l1_rpc_url = self.l1_rpc_url.unwrap_or_else(|| { Prompt::new(MSG_PROMPT_L1_RPC_URL) .default(LOCAL_RPC_URL) @@ -67,7 +60,6 @@ impl SendTransactionsArgs { SendTransactionsArgsFinal { file, private_key, - gas_price, l1_rpc_url, confirmations, } diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 0c0bd5296e84..98c8e8417618 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -9,7 +9,7 @@ use std::{ use anyhow::Context; use args::SendTransactionsArgs; use chrono::Local; -use common::ethereum::create_ethers_client; +use common::{ethereum::create_ethers_client, logger}; use config::EcosystemConfig; use ethers::{abi::Bytes, providers::Middleware, types::TransactionRequest, utils::hex}; use serde::Deserialize; @@ -68,12 +68,12 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() let client = create_ethers_client(args.private_key.parse()?, args.l1_rpc_url, Some(chain_id))?; let mut nonce = client.get_transaction_count(client.address(), None).await?; + let gas_price = client.get_gas_price().await?; for txn in txns.transactions { let to: H160 = txn.contract_address.parse()?; let from: H160 = txn.transaction.from.parse()?; let gas_limit: U256 = txn.transaction.gas.parse()?; - let gas_price: U256 = args.gas_price.parse()?; let input_data: Bytes = hex::decode(txn.transaction.input)?; let tx = TransactionRequest::new() diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 0261a4b84adc..918e5dac658f 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -205,7 +205,6 @@ pub(super) const MSG_WALLETS_TEST_SUCCESS: &str = "Wallets test success"; pub(super) const MSG_SEND_TXNS_ABOUT: &str = "Send transactions from file"; pub(super) const MSG_PROMPT_TRANSACTION_FILE: &str = "Path to transactions file"; pub(super) const MSG_PROMPT_SECRET_KEY: &str = "Secret key of the sender"; -pub(super) const MSG_PROMPT_GAS_PRICE: &str = "Gas price"; pub(super) const MSG_PROMPT_L1_RPC_URL: &str = "L1 RPC URL"; pub(super) const MSG_TRANSACTION_CONFIRMATIONS: &str = "Confirmations"; From d350edf2370825c842c4099454e1c780dfbcedbe Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 14:45:03 +0200 Subject: [PATCH 78/89] feat: add outro message to send-transactions --- .../src/commands/send_transactions/mod.rs | 11 +++++++++-- zk_toolbox/crates/zk_supervisor/src/messages.rs | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 98c8e8417618..0da567023037 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -19,8 +19,9 @@ use zksync_basic_types::{H160, U256}; use crate::{ consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, messages::{ - MSG_FAILED_TO_SEND_TXN_ERR, MSG_UNABLE_TO_OPEN_FILE_ERR, MSG_UNABLE_TO_READ_FILE_ERR, - MSG_UNABLE_TO_READ_PARSE_JSON_ERR, MSG_UNABLE_TO_WRITE_FILE_ERR, + MSG_FAILED_TO_SEND_TXN_ERR, MSG_SEND_TXNS_OUTRO, MSG_UNABLE_TO_OPEN_FILE_ERR, + MSG_UNABLE_TO_READ_FILE_ERR, MSG_UNABLE_TO_READ_PARSE_JSON_ERR, + MSG_UNABLE_TO_WRITE_FILE_ERR, }, }; @@ -98,6 +99,12 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() log_receipt(&log_file, format!("{:?}", receipt).as_str())?; } + logger::outro(format!( + "{}: {}", + MSG_SEND_TXNS_OUTRO, + log_file.to_string_lossy() + )); + Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index 918e5dac658f..d7334ca4740b 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -207,6 +207,7 @@ pub(super) const MSG_PROMPT_TRANSACTION_FILE: &str = "Path to transactions file" pub(super) const MSG_PROMPT_SECRET_KEY: &str = "Secret key of the sender"; pub(super) const MSG_PROMPT_L1_RPC_URL: &str = "L1 RPC URL"; pub(super) const MSG_TRANSACTION_CONFIRMATIONS: &str = "Confirmations"; +pub(super) const MSG_SEND_TXNS_OUTRO: &str = "Transaction receipts logged to"; pub(super) const MSG_UNABLE_TO_OPEN_FILE_ERR: &str = "Unable to open file"; pub(super) const MSG_UNABLE_TO_READ_FILE_ERR: &str = "Unable to read file"; From b627bc2ad5ca299d7fa2118a2b676b0954715433 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 14:53:02 +0200 Subject: [PATCH 79/89] refactor: use function message instead of const --- .../src/commands/send_transactions/mod.rs | 12 ++++-------- zk_toolbox/crates/zk_supervisor/src/messages.rs | 4 +++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 0da567023037..34f9eedfe928 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -19,9 +19,9 @@ use zksync_basic_types::{H160, U256}; use crate::{ consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, messages::{ - MSG_FAILED_TO_SEND_TXN_ERR, MSG_SEND_TXNS_OUTRO, MSG_UNABLE_TO_OPEN_FILE_ERR, - MSG_UNABLE_TO_READ_FILE_ERR, MSG_UNABLE_TO_READ_PARSE_JSON_ERR, - MSG_UNABLE_TO_WRITE_FILE_ERR, + msg_send_txns_outro, MSG_FAILED_TO_SEND_TXN_ERR, MSG_SEND_TXNS_OUTRO, + MSG_UNABLE_TO_OPEN_FILE_ERR, MSG_UNABLE_TO_READ_FILE_ERR, + MSG_UNABLE_TO_READ_PARSE_JSON_ERR, MSG_UNABLE_TO_WRITE_FILE_ERR, }, }; @@ -99,11 +99,7 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() log_receipt(&log_file, format!("{:?}", receipt).as_str())?; } - logger::outro(format!( - "{}: {}", - MSG_SEND_TXNS_OUTRO, - log_file.to_string_lossy() - )); + logger::outro(msg_send_txns_outro(log_file.to_string_lossy().as_ref())); Ok(()) } diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index d7334ca4740b..b60740d099c0 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -207,7 +207,9 @@ pub(super) const MSG_PROMPT_TRANSACTION_FILE: &str = "Path to transactions file" pub(super) const MSG_PROMPT_SECRET_KEY: &str = "Secret key of the sender"; pub(super) const MSG_PROMPT_L1_RPC_URL: &str = "L1 RPC URL"; pub(super) const MSG_TRANSACTION_CONFIRMATIONS: &str = "Confirmations"; -pub(super) const MSG_SEND_TXNS_OUTRO: &str = "Transaction receipts logged to"; +pub(super) fn msg_send_txns_outro(log_file: &str) -> String { + format!("Transaction receipts logged to: {}", log_file) +} pub(super) const MSG_UNABLE_TO_OPEN_FILE_ERR: &str = "Unable to open file"; pub(super) const MSG_UNABLE_TO_READ_FILE_ERR: &str = "Unable to read file"; From e3ae8be5db6516cb8a83067998a5c35211d49767 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 15:08:12 +0200 Subject: [PATCH 80/89] refactor: do not prompt for transaction confirmations --- .../src/commands/send_transactions/args/mod.rs | 6 ++++-- .../zk_supervisor/src/commands/send_transactions/mod.rs | 6 +++--- zk_toolbox/crates/zk_supervisor/src/messages.rs | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs index 5246df472062..e3d4f220ff28 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/args/mod.rs @@ -8,10 +8,12 @@ use crate::{ defaults::LOCAL_RPC_URL, messages::{ MSG_INVALID_L1_RPC_URL_ERR, MSG_PROMPT_L1_RPC_URL, MSG_PROMPT_SECRET_KEY, - MSG_PROMPT_TRANSACTION_FILE, MSG_TRANSACTION_CONFIRMATIONS, + MSG_PROMPT_TRANSACTION_FILE, }, }; +const DEFAULT_TRANSACTION_CONFIRMATIONS: usize = 2; + #[derive(Debug, Parser)] pub struct SendTransactionsArgs { #[clap(long)] @@ -55,7 +57,7 @@ impl SendTransactionsArgs { let confirmations = self .confirmations - .unwrap_or_else(|| Prompt::new(MSG_TRANSACTION_CONFIRMATIONS).ask()); + .unwrap_or(DEFAULT_TRANSACTION_CONFIRMATIONS); SendTransactionsArgsFinal { file, diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 34f9eedfe928..99acd3af1c35 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -19,9 +19,9 @@ use zksync_basic_types::{H160, U256}; use crate::{ consts::DEFAULT_UNSIGNED_TRANSACTIONS_DIR, messages::{ - msg_send_txns_outro, MSG_FAILED_TO_SEND_TXN_ERR, MSG_SEND_TXNS_OUTRO, - MSG_UNABLE_TO_OPEN_FILE_ERR, MSG_UNABLE_TO_READ_FILE_ERR, - MSG_UNABLE_TO_READ_PARSE_JSON_ERR, MSG_UNABLE_TO_WRITE_FILE_ERR, + msg_send_txns_outro, MSG_FAILED_TO_SEND_TXN_ERR, MSG_UNABLE_TO_OPEN_FILE_ERR, + MSG_UNABLE_TO_READ_FILE_ERR, MSG_UNABLE_TO_READ_PARSE_JSON_ERR, + MSG_UNABLE_TO_WRITE_FILE_ERR, }, }; diff --git a/zk_toolbox/crates/zk_supervisor/src/messages.rs b/zk_toolbox/crates/zk_supervisor/src/messages.rs index b60740d099c0..26f110103ce4 100644 --- a/zk_toolbox/crates/zk_supervisor/src/messages.rs +++ b/zk_toolbox/crates/zk_supervisor/src/messages.rs @@ -206,7 +206,6 @@ pub(super) const MSG_SEND_TXNS_ABOUT: &str = "Send transactions from file"; pub(super) const MSG_PROMPT_TRANSACTION_FILE: &str = "Path to transactions file"; pub(super) const MSG_PROMPT_SECRET_KEY: &str = "Secret key of the sender"; pub(super) const MSG_PROMPT_L1_RPC_URL: &str = "L1 RPC URL"; -pub(super) const MSG_TRANSACTION_CONFIRMATIONS: &str = "Confirmations"; pub(super) fn msg_send_txns_outro(log_file: &str) -> String { format!("Transaction receipts logged to: {}", log_file) } From 5c92da25ade7e96927ef82754944b991b95a18a8 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 16:28:02 +0200 Subject: [PATCH 81/89] fix: source chain_id from chain_config instead of genesis --- .../config/src/forge_interface/register_chain/input.rs | 3 +-- .../src/commands/chain/build_transactions.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs b/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs index 29494ba5d8f5..e2e60294e867 100644 --- a/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs +++ b/zk_toolbox/crates/config/src/forge_interface/register_chain/input.rs @@ -54,7 +54,6 @@ impl ZkToolboxConfig for RegisterChainL1Config {} impl RegisterChainL1Config { pub fn new(chain_config: &ChainConfig, contracts: &ContractsConfig) -> anyhow::Result { - let genesis_config = chain_config.get_genesis_config()?; let wallets_config = chain_config.get_wallets_config()?; Ok(Self { contracts_config: Contracts { @@ -72,7 +71,7 @@ impl RegisterChainL1Config { validator_timelock_addr: contracts.ecosystem_contracts.validator_timelock_addr, }, chain: ChainL1Config { - chain_chain_id: genesis_config.l2_chain_id, + chain_chain_id: chain_config.chain_id, base_token_gas_price_multiplier_nominator: chain_config.base_token.nominator, base_token_gas_price_multiplier_denominator: chain_config.base_token.denominator, base_token_addr: chain_config.base_token.address, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index e37d09c6473c..b615d4e173b6 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -1,6 +1,8 @@ use anyhow::Context; use common::{config::global_config, git, logger, spinner::Spinner}; -use config::{copy_configs, traits::SaveConfigWithBasePath, EcosystemConfig}; +use config::{ + copy_configs, traits::SaveConfigWithBasePath, update_from_chain_config, EcosystemConfig, +}; use ethers::utils::hex::ToHex; use xshell::Shell; @@ -32,12 +34,15 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R let args = args.fill_values_with_prompt(config.default_chain.clone()); + git::submodule_update(shell, config.link_to_code.clone())?; + let spinner = Spinner::new(MSG_PREPARING_CONFIG_SPINNER); copy_configs(shell, &config.link_to_code, &chain_config.configs)?; logger::note(MSG_SELECTED_CONFIG, logger::object_to_string(&chain_config)); - git::submodule_update(shell, config.link_to_code.clone())?; + let mut genesis_config = chain_config.get_genesis_config()?; + update_from_chain_config(&mut genesis_config, &chain_config); // Copy ecosystem contracts let mut contracts_config = config From 6191ead6fec514723250a53fb5d6372b98d60c4a Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 17:15:38 +0200 Subject: [PATCH 82/89] ci: test offline chain registration --- .github/workflows/ci-zk-toolbox-reusable.yml | 38 ++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-zk-toolbox-reusable.yml b/.github/workflows/ci-zk-toolbox-reusable.yml index 78e1e485cafc..41e1b004c3f2 100644 --- a/.github/workflows/ci-zk-toolbox-reusable.yml +++ b/.github/workflows/ci-zk-toolbox-reusable.yml @@ -23,7 +23,6 @@ jobs: submodules: "recursive" fetch-depth: 0 - - name: Setup environment run: | echo ZKSYNC_HOME=$(pwd) >> $GITHUB_ENV @@ -79,6 +78,41 @@ jobs: --ignore-prerequisites --verbose \ --observability=false + - name: Create and register chain with transactions signed "offline" + run: | + ci_run zk_inception chain create \ + --chain-name offline_chain \ + --chain-id sequential \ + --prover-mode no-proofs \ + --wallet-creation localhost \ + --l1-batch-commit-data-generator-mode rollup \ + --base-token-address 0x0000000000000000000000000000000000000001 \ + --base-token-price-nominator 1 \ + --base-token-price-denominator 1 \ + --set-as-default false \ + --ignore-prerequisites + + ci_run zk_inception chain build-transactions --chain offline_chain --l1-rpc-url http://127.0.0.1:8545 + + governor_pk=$(awk '/governor:/ {flag=1} flag && /private_key:/ {print $2; exit}' ./configs/wallets.yaml) + + ci_run zk_supervisor send-transactions \ + --file ./transactions/chain/offline_chain/register-hyperchain-txns.json \ + --l1-rpc-url http://127.0.0.1:8545 \ + --private-key $governor_pk + + bridge_hub=$(awk '/bridgehub_proxy_addr/ {print $2}' ./configs/contracts.yaml) + chain_id=$(awk '/chain_id:/ {print $2}' ./chains/offline_chain/ZkStack.yaml) + + hyperchain_output=$(cast call $bridge_hub "getHyperchain(uint256)" $chain_id) + + if [[ $hyperchain_output == 0x* && ${#hyperchain_output} -eq 66 ]]; then + echo "Chain successfully registered: $hyperchain_output" + else + echo "Failed to register chain: $hyperchain_output" + exit 1 + fi + - name: Read Custom Token address and set as environment variable run: | address=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml) @@ -244,7 +278,6 @@ jobs: wait $PID2 wait $PID3 - # Upgrade tests should run last, because as soon as they # finish the bootloader will be different # TODO make upgrade tests safe to run multiple times @@ -252,7 +285,6 @@ jobs: run: | ci_run zk_supervisor test upgrade --no-deps --chain era - - name: Upload logs uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0 if: always() From 1ecc53294b6f6a0dacdbf8b801d066bef7ab2ecb Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 17:27:44 +0200 Subject: [PATCH 83/89] style: lint --- infrastructure/zk/src/docker.ts | 6 +++--- zk_toolbox/crates/zk_inception/src/commands/chain/init.rs | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/infrastructure/zk/src/docker.ts b/infrastructure/zk/src/docker.ts index a100d1231da6..035061a8ed0d 100644 --- a/infrastructure/zk/src/docker.ts +++ b/infrastructure/zk/src/docker.ts @@ -1,4 +1,4 @@ -import {Command} from 'commander'; +import { Command } from 'commander'; import * as utils from 'utils'; const IMAGES = [ @@ -31,7 +31,7 @@ async function dockerCommand( dockerOrg: string = 'matterlabs' ) { // Generating all tags for containers. We need 2 tags here: SHA and SHA+TS - const {stdout: COMMIT_SHORT_SHA}: { stdout: string } = await utils.exec('git rev-parse --short HEAD'); + const { stdout: COMMIT_SHORT_SHA }: { stdout: string } = await utils.exec('git rev-parse --short HEAD'); // COMMIT_SHORT_SHA returns with newline, so we need to trim it const imageTagShaTS: string = process.env.IMAGE_TAG_SUFFIX ? process.env.IMAGE_TAG_SUFFIX @@ -126,7 +126,7 @@ async function _build(image: string, tagList: string[], dockerOrg: string, platf } buildArgs += extraArgs; - console.log("Build args: ", buildArgs); + console.log('Build args: ', buildArgs); const buildCommand = `DOCKER_BUILDKIT=1 docker buildx build ${tagsToBuild}` + diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs index 4c5a746df4be..fa2388a69be8 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/init.rs @@ -27,10 +27,7 @@ use crate::{ MSG_REGISTERING_CHAIN_SPINNER, MSG_SELECTED_CONFIG, MSG_UPDATING_TOKEN_MULTIPLIER_SETTER_SPINNER, MSG_WALLET_TOKEN_MULTIPLIER_SETTER_NOT_FOUND, }, - utils::{ - consensus::{generate_consensus_keys, get_consensus_config, get_consensus_secrets}, - forge::{check_the_balance, fill_forge_private_key}, - }, + utils::consensus::{generate_consensus_keys, get_consensus_config, get_consensus_secrets}, }; pub(crate) async fn run(args: InitArgs, shell: &Shell) -> anyhow::Result<()> { From 1c9c2ee1d988047507cc853e1746030ae177d691 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Fri, 13 Sep 2024 18:06:14 +0200 Subject: [PATCH 84/89] fix: prefix cast with ci_run --- .github/workflows/ci-zk-toolbox-reusable.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-zk-toolbox-reusable.yml b/.github/workflows/ci-zk-toolbox-reusable.yml index bd8c1c6873dc..98a44c443581 100644 --- a/.github/workflows/ci-zk-toolbox-reusable.yml +++ b/.github/workflows/ci-zk-toolbox-reusable.yml @@ -104,7 +104,7 @@ jobs: bridge_hub=$(awk '/bridgehub_proxy_addr/ {print $2}' ./configs/contracts.yaml) chain_id=$(awk '/chain_id:/ {print $2}' ./chains/offline_chain/ZkStack.yaml) - hyperchain_output=$(cast call $bridge_hub "getHyperchain(uint256)" $chain_id) + hyperchain_output=$(ci_run cast call $bridge_hub "getHyperchain(uint256)" $chain_id) if [[ $hyperchain_output == 0x* && ${#hyperchain_output} -eq 66 ]]; then echo "Chain successfully registered: $hyperchain_output" From 2915f9f65fc8fd881b2d638e3eb17a3bc808320e Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 16 Sep 2024 13:21:14 +0200 Subject: [PATCH 85/89] style: add EOF newline --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d12f325a62c8..c3de7a2df84d 100644 --- a/.gitignore +++ b/.gitignore @@ -117,4 +117,4 @@ chains/era/configs/* configs/* era-observability/ core/tests/ts-integration/deployments-zk -transactions/ \ No newline at end of file +transactions/ From 875adef5730f63527e67acfc105a4a39e0cba05f Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 16 Sep 2024 14:47:49 +0200 Subject: [PATCH 86/89] fix: add basic retry mechanism to send-transactions --- .../src/commands/send_transactions/mod.rs | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 99acd3af1c35..39f5bf4f6a09 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -13,6 +13,7 @@ use common::{ethereum::create_ethers_client, logger}; use config::EcosystemConfig; use ethers::{abi::Bytes, providers::Middleware, types::TransactionRequest, utils::hex}; use serde::Deserialize; +use tokio::time::sleep; use xshell::Shell; use zksync_basic_types::{H160, U256}; @@ -27,6 +28,8 @@ use crate::{ pub mod args; +const MAX_ATTEMPTS: u32 = 3; + #[derive(Deserialize)] struct Transaction { from: String, @@ -88,13 +91,25 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() nonce = nonce.add(1); - let receipt = client - .send_transaction(tx, None) - .await? - .confirmations(args.confirmations) - .interval(Duration::from_millis(30)) - .await? - .context(MSG_FAILED_TO_SEND_TXN_ERR)?; + let mut attempts = 0; + let receipt = loop { + attempts += 1; + match client + .send_transaction(tx.clone(), None) + .await? + .confirmations(args.confirmations) + .interval(Duration::from_millis(30)) + .await + { + Ok(receipt) => break receipt, + Err(e) if attempts < MAX_ATTEMPTS => { + eprintln!("Attempt {} failed: {:?}", attempts, e); + sleep(Duration::from_secs(1)).await; + continue; + } + Err(e) => return Err(e).context(MSG_FAILED_TO_SEND_TXN_ERR)?, + } + }; log_receipt(&log_file, format!("{:?}", receipt).as_str())?; } From 311c35e36f16c5d8abc01ac06cb54856f22162f7 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 16 Sep 2024 15:20:33 +0200 Subject: [PATCH 87/89] fix: remove duplicated dependency --- zk_toolbox/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/zk_toolbox/Cargo.toml b/zk_toolbox/Cargo.toml index 7bc358ca77cc..d8b84f93adde 100644 --- a/zk_toolbox/Cargo.toml +++ b/zk_toolbox/Cargo.toml @@ -39,7 +39,6 @@ zksync_protobuf = "=0.1.1" # External dependencies anyhow = "1.0.82" clap = { version = "4.4", features = ["derive", "wrap_help", "string"] } -chrono = "0.4" slugify-rs = "0.0.3" cliclack = "0.2.5" console = "0.15.8" From 94f9180de1e649faaa619a80530f3d612edb24f0 Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 16 Sep 2024 15:37:15 +0200 Subject: [PATCH 88/89] fix: log message --- .../zk_inception/src/commands/chain/build_transactions.rs | 6 +++--- zk_toolbox/crates/zk_inception/src/messages.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs index b615d4e173b6..68cb7a9a0742 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/build_transactions.rs @@ -10,8 +10,8 @@ use super::common::register_chain; use crate::{ commands::chain::args::build_transactions::BuildTransactionsArgs, messages::{ - MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_INITIALIZED, - MSG_CHAIN_NOT_FOUND_ERR, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, + MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER, MSG_CHAIN_NOT_FOUND_ERR, + MSG_CHAIN_TRANSACTIONS_BUILT, MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG, MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR, MSG_PREPARING_CONFIG_SPINNER, MSG_SELECTED_CONFIG, MSG_WRITING_OUTPUT_FILES_SPINNER, }, @@ -85,6 +85,6 @@ pub(crate) async fn run(args: BuildTransactionsArgs, shell: &Shell) -> anyhow::R )?; spinner.finish(); - logger::success(MSG_CHAIN_INITIALIZED); + logger::success(MSG_CHAIN_TRANSACTIONS_BUILT); Ok(()) } diff --git a/zk_toolbox/crates/zk_inception/src/messages.rs b/zk_toolbox/crates/zk_inception/src/messages.rs index 8a0e0b5cc46e..b20e8edf8ad9 100644 --- a/zk_toolbox/crates/zk_inception/src/messages.rs +++ b/zk_toolbox/crates/zk_inception/src/messages.rs @@ -234,6 +234,7 @@ pub(super) const MSG_BUILDING_CHAIN_REGISTRATION_TXNS_SPINNER: &str = pub(super) const MSG_CHAIN_TXN_OUT_PATH_INVALID_ERR: &str = "Invalid path"; pub(super) const MSG_CHAIN_TXN_MISSING_CONTRACT_CONFIG: &str = "Missing contract.yaml, please be sure to run this command within initialized ecosystem"; +pub(super) const MSG_CHAIN_TRANSACTIONS_BUILT: &str = "Chain transactions successfully built"; /// Run server related messages pub(super) const MSG_SERVER_COMPONENTS_HELP: &str = "Components of server to run"; From 45dbff4ec9f148648707295398136f48c10a5ebb Mon Sep 17 00:00:00 2001 From: Manuel Mauro Date: Mon, 16 Sep 2024 15:40:26 +0200 Subject: [PATCH 89/89] refactor: log error to terminal --- .../crates/zk_supervisor/src/commands/send_transactions/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs index 39f5bf4f6a09..79d8efc600e8 100644 --- a/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs +++ b/zk_toolbox/crates/zk_supervisor/src/commands/send_transactions/mod.rs @@ -103,7 +103,7 @@ pub async fn run(shell: &Shell, args: SendTransactionsArgs) -> anyhow::Result<() { Ok(receipt) => break receipt, Err(e) if attempts < MAX_ATTEMPTS => { - eprintln!("Attempt {} failed: {:?}", attempts, e); + logger::info(format!("Attempt {} failed: {:?}", attempts, e).as_str()); sleep(Duration::from_secs(1)).await; continue; }