Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Prover CLI Scaffoldings #1609

Merged
merged 10 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ members = [
"witness_vector_generator",
"prover_fri_gateway",
"proof_fri_compressor",
"tools",
"prover_cli",
]

resolver = "2"
Expand Down
18 changes: 15 additions & 3 deletions prover/tools/Cargo.toml → prover/prover_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "tools"
name = "prover_cli"
version.workspace = true
edition.workspace = true
authors.workspace = true
Expand All @@ -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"
Comment on lines +13 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Is there a reason not to use workspace deps here?
  2. Why do we need env_logger and log when we use tracing and vlog (or tracing-subscriber, if you have to) now?


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
prover_dal.workspace = true

4 changes: 2 additions & 2 deletions prover/tools/README.md → prover/prover_cli/README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
26 changes: 26 additions & 0 deletions prover/prover_cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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<usize>, Option<usize>)) {
Expand Down Expand Up @@ -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();
Expand All @@ -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<FriProofWrapper> = 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.");

Expand All @@ -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(())
}
1 change: 1 addition & 0 deletions prover/prover_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod get_file_info;
2 changes: 2 additions & 0 deletions prover/prover_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod cli;
mod commands;
10 changes: 10 additions & 0 deletions prover/prover_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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();
}
Loading