diff --git a/zk_toolbox/Cargo.toml b/zk_toolbox/Cargo.toml index 5a25df26a4a9..f2ade7a48294 100644 --- a/zk_toolbox/Cargo.toml +++ b/zk_toolbox/Cargo.toml @@ -40,3 +40,4 @@ toml = "0.8.12" url = { version = "2.5.0", features = ["serde"] } xshell = "0.2.6" futures = "0.3.30" +thiserror = "1.0.57" diff --git a/zk_toolbox/README.md b/zk_toolbox/README.md index 5631da8a13f5..f04a4ee8fc47 100644 --- a/zk_toolbox/README.md +++ b/zk_toolbox/README.md @@ -56,3 +56,9 @@ If contracts were deployed by a third party (e.g., MatterLabs), you may need to `zk_inception chain genesis` This ensures proper initialization of the server. + +### Zk Server + +For running the chain: `zk_inception server` + +You can specify the chain you are running by providing `--chain ` argument diff --git a/zk_toolbox/crates/common/src/lib.rs b/zk_toolbox/crates/common/src/lib.rs index a173d1acfbc8..349cd751c5f6 100644 --- a/zk_toolbox/crates/common/src/lib.rs +++ b/zk_toolbox/crates/common/src/lib.rs @@ -7,9 +7,11 @@ pub mod files; pub mod forge; mod prerequisites; mod prompt; +mod slugify; mod term; pub mod wallets; pub use prerequisites::check_prerequisites; pub use prompt::{init_prompt_theme, Prompt, PromptConfirm, PromptSelect}; +pub use slugify::slugify; pub use term::{logger, spinner}; diff --git a/zk_toolbox/crates/common/src/slugify.rs b/zk_toolbox/crates/common/src/slugify.rs new file mode 100644 index 000000000000..a934a56b5527 --- /dev/null +++ b/zk_toolbox/crates/common/src/slugify.rs @@ -0,0 +1,3 @@ +pub fn slugify(data: &str) -> String { + data.trim().replace(" ", "-") +} diff --git a/zk_toolbox/crates/zk_inception/Cargo.toml b/zk_toolbox/crates/zk_inception/Cargo.toml index ac4ede6cc78b..5ae3dd20e64b 100644 --- a/zk_toolbox/crates/zk_inception/Cargo.toml +++ b/zk_toolbox/crates/zk_inception/Cargo.toml @@ -26,5 +26,5 @@ tokio.workspace = true strum_macros.workspace = true strum.workspace = true toml.workspace = true -url = "2.5.0" -thiserror = "1.0.57" +url.workspace = true +thiserror.workspace = true diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs index f6c6a7c00db2..6afb46cbfb60 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs @@ -1,7 +1,7 @@ use std::{path::PathBuf, str::FromStr}; use clap::Parser; -use common::{Prompt, PromptConfirm, PromptSelect}; +use common::{slugify, Prompt, PromptConfirm, PromptSelect}; use ethers::types::H160; use serde::{Deserialize, Serialize}; use strum::IntoEnumIterator; @@ -39,9 +39,10 @@ pub struct ChainCreateArgs { impl ChainCreateArgs { pub fn fill_values_with_prompt(self, number_of_chains: u32) -> ChainCreateArgsFinal { - let chain_name = self + let mut chain_name = self .chain_name .unwrap_or_else(|| Prompt::new("How do you want to name the chain?").ask()); + chain_name = slugify(&chain_name); let chain_id = self.chain_id.unwrap_or_else(|| { Prompt::new("What's the chain id?") diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs index 3d2589e379b1..b24956c70c12 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/args/genesis.rs @@ -1,5 +1,5 @@ use clap::Parser; -use common::Prompt; +use common::{slugify, Prompt}; use serde::{Deserialize, Serialize}; use url::Url; @@ -47,13 +47,13 @@ impl GenesisArgs { .default(DATABASE_SERVER_URL) .ask() }); - let server_db_name = self.server_db_name.unwrap_or_else(|| { + let server_db_name = slugify(&self.server_db_name.unwrap_or_else(|| { Prompt::new(&format!( "Please provide server database name for chain {chain_name}" )) .default(&server_name) .ask() - }); + })); let prover_db_url = self.prover_db_url.unwrap_or_else(|| { Prompt::new(&format!( "Please provide prover database url for chain {chain_name}" @@ -61,13 +61,13 @@ impl GenesisArgs { .default(DATABASE_PROVER_URL) .ask() }); - let prover_db_name = self.prover_db_name.unwrap_or_else(|| { + let prover_db_name = slugify(&self.prover_db_name.unwrap_or_else(|| { Prompt::new(&format!( "Please provide prover database name for chain {chain_name}" )) .default(&prover_name) .ask() - }); + })); GenesisArgsFinal { server_db_url, server_db_name, diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs index be6a541a083b..160d7d6b96df 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/genesis.rs @@ -70,7 +70,9 @@ pub async fn genesis( .await?; spinner.finish(); - let spinner = Spinner::new("Running server genesis..."); + let spinner = Spinner::new( + "Starting the genesis of the server. Building the entire server may take a lot of time...", + ); run_server_genesis(config, shell)?; spinner.finish(); diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs index 577e8fed798a..d5e20bc3881f 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/create.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use clap::Parser; -use common::{Prompt, PromptConfirm, PromptSelect}; +use common::{slugify, Prompt, PromptConfirm, PromptSelect}; use serde::{Deserialize, Serialize}; use strum::IntoEnumIterator; use strum_macros::{Display, EnumIter}; @@ -33,9 +33,10 @@ pub struct EcosystemCreateArgs { impl EcosystemCreateArgs { pub fn fill_values_with_prompt(mut self) -> EcosystemCreateArgsFinal { - let ecosystem_name = self + let mut ecosystem_name = self .ecosystem_name .unwrap_or_else(|| Prompt::new("How do you want to name the ecosystem?").ask()); + ecosystem_name = slugify(&ecosystem_name); let link_to_code = self.link_to_code.unwrap_or_else(|| { let link_to_code_selection = PromptSelect::new( diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs index 5c6583b2bb9b..6be1a9ca1778 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/args/init.rs @@ -64,7 +64,7 @@ impl EcosystemInitArgs { .ask() }); let deploy_erc20 = self.deploy_erc20.unwrap_or_else(|| { - PromptConfirm::new("Do you want to deploy ERC20?") + PromptConfirm::new("Do you want to deploy test ERC20?") .default(true) .ask() }); diff --git a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs index 380ed9acad0c..f1e6d98192d5 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/create.rs @@ -1,3 +1,4 @@ +use std::path::Path; use std::{path::PathBuf, str::FromStr}; use anyhow::bail; @@ -48,7 +49,9 @@ fn create(args: EcosystemCreateArgs, shell: &Shell) -> anyhow::Result<()> { spinner.finish(); link_to_code } else { - PathBuf::from_str(&args.link_to_code)? + let path = PathBuf::from_str(&args.link_to_code)?; + update_submodules_recursive(shell, &path)?; + path }; let spinner = Spinner::new("Creating initial configurations..."); @@ -108,3 +111,14 @@ fn clone_era_repo(shell: &Shell) -> anyhow::Result { .run()?; Ok(shell.current_dir().join("zksync-era")) } + +fn update_submodules_recursive(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { + let _dir_guard = shell.push_dir(link_to_code); + Cmd::new(cmd!( + shell, + "git submodule update --init --recursive +" + )) + .run()?; + Ok(()) +} 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 869ed48308d0..8665388eab33 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs @@ -155,6 +155,7 @@ fn init( let spinner = Spinner::new("Installing and building dependencies..."); install_yarn_dependencies(shell, &ecosystem_config.link_to_code)?; build_system_contracts(shell, &ecosystem_config.link_to_code)?; + build_l1_contracts(shell, &ecosystem_config.link_to_code)?; spinner.finish(); let contracts = deploy_ecosystem( @@ -322,3 +323,9 @@ fn build_system_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result< let _dir_guard = shell.push_dir(link_to_code.join("contracts")); Cmd::new(cmd!(shell, "yarn sc build")).run() } + +// TODO remove it and use proper paths in constants +fn build_l1_contracts(shell: &Shell, link_to_code: &Path) -> anyhow::Result<()> { + let _dir_guard = shell.push_dir(link_to_code.join("contracts")); + Cmd::new(cmd!(shell, "yarn l1 build")).run() +}