diff --git a/prover/Cargo.lock b/prover/Cargo.lock index a0f470ce63e..45f591dbfe6 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -1756,7 +1756,11 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ + "humantime", + "is-terminal", "log", + "regex", + "termcolor", ] [[package]] @@ -2748,6 +2752,17 @@ dependencies = [ "serde", ] +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi 0.3.6", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -4315,6 +4330,30 @@ dependencies = [ "thiserror", ] +[[package]] +name = "prover_cli" +version = "0.1.0" +dependencies = [ + "anyhow", + "bincode", + "clap 4.4.6", + "colored", + "env_logger 0.10.2", + "hex", + "log", + "prover_dal", + "tokio", + "tracing", + "tracing-subscriber", + "zksync_basic_types", + "zksync_config", + "zksync_db_connection", + "zksync_env_config", + "zksync_prover_fri_types", + "zksync_prover_interface", + "zksync_types", +] + [[package]] name = "prover_dal" version = "0.1.0" @@ -6246,20 +6285,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tools" -version = "0.1.0" -dependencies = [ - "bincode", - "clap 4.4.6", - "colored", - "hex", - "tracing", - "tracing-subscriber", - "zksync_prover_fri_types", - "zksync_prover_interface", -] - [[package]] name = "tower" version = "0.4.13" diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 5968bdccf65..11412ec5289 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -12,7 +12,7 @@ members = [ "witness_vector_generator", "prover_fri_gateway", "proof_fri_compressor", - "tools", + "prover_cli", ] resolver = "2" diff --git a/prover/tools/Cargo.toml b/prover/prover_cli/Cargo.toml similarity index 58% rename from prover/tools/Cargo.toml rename to prover/prover_cli/Cargo.toml index 66df1e99db4..994a8f93a84 100644 --- a/prover/tools/Cargo.toml +++ b/prover/prover_cli/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "tools" +name = "prover_cli" version.workspace = true edition.workspace = true authors.workspace = true @@ -10,11 +10,23 @@ keywords.workspace = true categories.workspace = true [dependencies] +tokio = { version = "1", features = ["rt-multi-thread", "macros"] } +env_logger = "0.10" +log = "0.4" + clap = { workspace = true, features = ["derive"] } tracing.workspace = true tracing-subscriber = { workspace = true, features = ["env-filter"] } -zksync_prover_fri_types.workspace = true bincode.workspace = true colored.workspace = true +hex.workspace = true +anyhow.workspace = true +zksync_config.workspace = true +zksync_env_config.workspace = true +zksync_db_connection.workspace = true +zksync_basic_types.workspace = true +zksync_types.workspace = true +zksync_prover_fri_types.workspace = true zksync_prover_interface.workspace = true -hex.workspace = true \ No newline at end of file +prover_dal.workspace = true + diff --git a/prover/tools/README.md b/prover/prover_cli/README.md similarity index 93% rename from prover/tools/README.md rename to prover/prover_cli/README.md index 35778faa687..25bbe95fc4d 100644 --- a/prover/tools/README.md +++ b/prover/prover_cli/README.md @@ -1,9 +1,9 @@ -# Tool to better understand and debug provers +# CLI to better understand and debug provers For now, it has only one command 'file-info' ``` -cargo run --release file-info /zksync-era/prover/artifacts/proofs_fri/l1_batch_proof_1.bin +cargo run -- file-info --file-path /zksync-era/prover/artifacts/proofs_fri/l1_batch_proof_1.bin ``` Example outputs: diff --git a/prover/prover_cli/src/cli.rs b/prover/prover_cli/src/cli.rs new file mode 100644 index 00000000000..844387f983e --- /dev/null +++ b/prover/prover_cli/src/cli.rs @@ -0,0 +1,26 @@ +use clap::{command, Parser, Subcommand}; + +use crate::commands::get_file_info; + +pub const VERSION_STRING: &str = env!("CARGO_PKG_VERSION"); + +#[derive(Parser)] +#[command(name="prover-cli", version=VERSION_STRING, about, long_about = None)] +struct ProverCLI { + #[command(subcommand)] + command: ProverCommand, +} + +#[derive(Subcommand)] +enum ProverCommand { + FileInfo(get_file_info::Args), +} + +pub async fn start() -> anyhow::Result<()> { + let ProverCLI { command } = ProverCLI::parse(); + match command { + ProverCommand::FileInfo(args) => get_file_info::run(args).await?, + }; + + Ok(()) +} diff --git a/prover/tools/src/main.rs b/prover/prover_cli/src/commands/get_file_info.rs similarity index 90% rename from prover/tools/src/main.rs rename to prover/prover_cli/src/commands/get_file_info.rs index f7df2147fac..ff32f56a22c 100644 --- a/prover/tools/src/main.rs +++ b/prover/prover_cli/src/commands/get_file_info.rs @@ -1,8 +1,7 @@ use std::fs; -use clap::{Parser, Subcommand}; +use clap::Args as ClapArgs; use colored::Colorize; -use tracing::level_filters::LevelFilter; use zksync_prover_fri_types::{ circuit_definitions::{ boojum::{ @@ -18,23 +17,10 @@ use zksync_prover_fri_types::{ }; use zksync_prover_interface::outputs::L1BatchProofForL1; -#[derive(Debug, Parser)] -#[command( - author = "Matter Labs", - version, - about = "Debugging tools for prover related things", - long_about = None -)] - -struct Cli { - #[command(subcommand)] - command: Command, -} - -#[derive(Debug, Subcommand)] -enum Command { - #[command(name = "file-info")] - FileInfo { file_path: String }, +#[derive(ClapArgs)] +pub(crate) struct Args { + #[clap(short, long)] + file_path: String, } fn pretty_print_size_hint(size_hint: (Option, Option)) { @@ -204,7 +190,8 @@ fn pretty_print_l1_proof(result: &L1BatchProofForL1) { println!(" This proof will pass on L1, if L1 executor computes the block commitment that is matching exactly the Inputs value above"); } -fn file_info(path: String) { +pub(crate) async fn run(args: Args) -> anyhow::Result<()> { + let path = args.file_path; println!("Reading file {} and guessing the type.", path.bold()); let bytes = fs::read(path).unwrap(); @@ -214,14 +201,14 @@ fn file_info(path: String) { if let Some(circuit) = maybe_circuit { println!(" Parsing file as CircuitWrapper."); pretty_print_circuit_wrapper(&circuit); - return; + return Ok(()); } println!(" NOT a CircuitWrapper."); let maybe_fri_proof: Option = bincode::deserialize(&bytes).ok(); if let Some(fri_proof) = maybe_fri_proof { println!(" Parsing file as FriProofWrapper."); pretty_print_proof(&fri_proof); - return; + return Ok(()); } println!(" NOT a FriProofWrapper."); @@ -232,19 +219,5 @@ fn file_info(path: String) { } else { println!(" NOT a L1BatchProof."); } -} - -fn main() { - tracing_subscriber::fmt() - .with_env_filter( - tracing_subscriber::EnvFilter::builder() - .with_default_directive(LevelFilter::INFO.into()) - .from_env_lossy(), - ) - .init(); - - let opt = Cli::parse(); - match opt.command { - Command::FileInfo { file_path } => file_info(file_path), - } + Ok(()) } diff --git a/prover/prover_cli/src/commands/mod.rs b/prover/prover_cli/src/commands/mod.rs new file mode 100644 index 00000000000..3e9a45cb72a --- /dev/null +++ b/prover/prover_cli/src/commands/mod.rs @@ -0,0 +1 @@ +pub(crate) mod get_file_info; diff --git a/prover/prover_cli/src/lib.rs b/prover/prover_cli/src/lib.rs new file mode 100644 index 00000000000..3ef8b313f0c --- /dev/null +++ b/prover/prover_cli/src/lib.rs @@ -0,0 +1,2 @@ +pub mod cli; +mod commands; diff --git a/prover/prover_cli/src/main.rs b/prover/prover_cli/src/main.rs new file mode 100644 index 00000000000..f2a7dd71026 --- /dev/null +++ b/prover/prover_cli/src/main.rs @@ -0,0 +1,10 @@ +use prover_cli::cli; + +#[tokio::main] +async fn main() { + env_logger::builder() + .filter_level(log::LevelFilter::Debug) + .init(); + + cli::start().await.unwrap(); +}