Skip to content

Commit

Permalink
feat: Prover CLI Scaffoldings (#1609)
Browse files Browse the repository at this point in the history
## What ❔

This PR implements the scaffolding for a CLI to interact with the
prover. Additionally, it integrates the functionality of the `tool`
crate.

## Why ❔

The purpose of this CLI is to simplify the process of interacting with
the prover and enhance its usability. Users can easily interact with the
prover without requiring specialized insider knowledge, ensuring that it
can managed without direct database access and complex manual queries.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [ ] Spellcheck has been run via `zk spellcheck`.
- [ ] Linkcheck has been run via `zk linkcheck`.

---------

Co-authored-by: Lech <88630083+Artemka374@users.noreply.github.com>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 11, 2024
1 parent 932b14b commit 9a22fa0
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 57 deletions.
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"

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();
}

0 comments on commit 9a22fa0

Please sign in to comment.