Skip to content

Commit

Permalink
Add most of prove_rpc.rs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Nov 15, 2024
1 parent ce812b0 commit 7b1a611
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 5 deletions.
81 changes: 79 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions scripts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ anyhow.workspace = true
clap = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
sysinfo = "0.32.0"

[lints]
workspace = true
Expand Down
116 changes: 113 additions & 3 deletions scripts/prove_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::{
env::set_var,
fs::create_dir_all,
fmt::Display,
fs::{create_dir_all, File},
path::{Path, PathBuf},
process::{Command, Stdio},
};

use alloy::{eips::BlockId, transports::http::reqwest::Url};
use anyhow::Result;
use anyhow::{Context as _, Result};
use clap::{arg, Args, ValueEnum, ValueHint};

#[derive(ValueEnum, Clone)]
Expand All @@ -14,6 +16,15 @@ enum RpcType {
Native,
}

impl Display for RpcType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RpcType::Jerigon => write!(f, "jerigon"),
RpcType::Native => write!(f, "native"),
}
}
}

#[derive(ValueEnum, Clone)]
enum RunMode {
/// Dummy proof is generated. Useful for quickly testing decoding and
Expand Down Expand Up @@ -69,6 +80,19 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> {
// See also .cargo/config.toml.
set_var("RUSTFLAGS", "-C target-cpu=native -Zlinker-features=-lld");

// TODO: move this logic below when full match is done
if let RunMode::Test = args.mode {
set_var("ARITHMETIC_CIRCUIT_SIZE", "16..21");
set_var("BYTE_PACKING_CIRCUIT_SIZE", "8..21");
set_var("CPU_CIRCUIT_SIZE", "8..21");
set_var("KECCAK_CIRCUIT_SIZE", "4..20");
set_var("KECCAK_SPONGE_CIRCUIT_SIZE", "8..17");
set_var("LOGIC_CIRCUIT_SIZE", "4..21");
set_var("MEMORY_CIRCUIT_SIZE", "17..24");
set_var("MEMORY_BEFORE_CIRCUIT_SIZE", "16..23");
set_var("MEMORY_AFTER_CIRCUIT_SIZE", "7..23");
}

// Handle optional block inputs.
let start_block = args.start_block;
let end_block = args.end_block.unwrap_or(start_block);
Expand All @@ -92,6 +116,92 @@ pub fn prove_via_rpc(args: ProveRpcArgs) -> Result<()> {
}
let output_log_path =
proof_output_dirpath.join(format!("b{}_{}.log", args.start_block, end_block));
let log_out = File::create(&output_log_path).context("couldn't create log file")?;
let log_err = log_out.try_clone().context("couldn't clone log file")?;

todo!()
/// Set file handle limit.
const RECOMMENDED_FILE_LIMIT: isize = 8192;
if !sysinfo::set_open_files_limit(RECOMMENDED_FILE_LIMIT) {
eprintln!("WARNING: Unable to set file descriptor limit to recommended value: {RECOMMENDED_FILE_LIMIT}.");
}

let runner = Runner::new("cargo")
.args(&[
"run",
"--release",
"--package=zero",
"--bin=leader",
"--",
"--runtime=in-memory",
"--load-strategy=on-demand",
"--proof-output-dir",
proof_output_dirpath.to_str().unwrap(),
"--block-batch-size",
&args.block_batch_size.to_string(),
"rpc",
"--rpc-type",
&args.rpc_type.to_string(),
"--rpc-url",
args.rpc_url.as_ref(),
"--start-block",
&start_block.to_string(),
"--checkpoint-block",
&checkpoint_block.to_string(),
"--end-block",
&end_block.to_string(),
"--backoff",
&args.backoff.to_string(),
"--max-retries",
&args.max_retries.to_string(),
])
.out(log_out)
.err(log_err);
match args.mode {
RunMode::Test => runner.args(&["--use-test-config"]).run(),
RunMode::Prove => todo!(),
RunMode::Verify => todo!(),
}
}

struct Runner {
cmd: String,
args: Vec<String>,
out: Stdio,
err: Stdio,
}

impl Runner {
fn new(cmd: impl Into<String>) -> Self {
Self {
cmd: cmd.into(),
args: vec![],
out: Stdio::piped(),
err: Stdio::piped(),
}
}

fn args(mut self, args: &[&str]) -> Self {
self.args.extend(args.iter().map(|s| s.to_string()));
self
}

fn out(mut self, out: impl Into<Stdio>) -> Self {
self.out = out.into();
self
}

fn err(mut self, err: impl Into<Stdio>) -> Self {
self.err = err.into();
self
}

fn run(self) -> Result<()> {
let output = Command::new(&self.cmd)

Check failure on line 199 in scripts/prove_rpc.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `output`

Check failure on line 199 in scripts/prove_rpc.rs

View workflow job for this annotation

GitHub Actions / outdated

unused variable: `output`

Check failure on line 199 in scripts/prove_rpc.rs

View workflow job for this annotation

GitHub Actions / udeps

unused variable: `output`
.args(&self.args)
.stdout(self.out)
.stderr(self.err)
.output()
.context(format!("couldn't exec `{}`", &self.cmd))?;
todo!()
}
}

0 comments on commit 7b1a611

Please sign in to comment.