Skip to content

Commit

Permalink
Dedupe command call logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sergerad committed Nov 30, 2024
1 parent cc6b0d3 commit 6937c5a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions scripts/prove_stdio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{env::set_var, fs::File, path::PathBuf, process::Command};
use std::{fs::File, path::PathBuf, process::Command};

use anyhow::{ensure, Ok};
use anyhow::ensure;
use clap::{arg, Args, ValueEnum, ValueHint};

#[derive(ValueEnum, Copy, Clone)]
Expand Down Expand Up @@ -90,7 +90,10 @@ pub fn prove_via_stdio(args: ProveStdioArgs) -> anyhow::Result<()> {
]);
}

run_proof(args, envs)
let mut cmd = prove_command(args, envs)?;
let status = cmd.spawn()?.wait()?;
ensure!(status.success(), "command failed with {}", status);
Ok(())
}
RunMode::Verify => {
// Build the targets before timing.
Expand All @@ -101,17 +104,20 @@ pub fn prove_via_stdio(args: ProveStdioArgs) -> anyhow::Result<()> {
.wait()?;
ensure!(status.success(), "command failed with {}", status);

// Time the proof.
// Construct the command to run.
let mut cmd = prove_command(args, envs)?;
// Time the proving.
let start = std::time::Instant::now();
run_proof(args, envs)?;
let status = cmd.spawn()?.wait()?;
ensure!(status.success(), "command failed with {}", status);
let elapsed = start.elapsed();
println!("Elapsed: {:?}", elapsed);
println!("Proving duration: {elapsed:?}");
Ok(())
}
}
}

fn run_proof(args: ProveStdioArgs, envs: Vec<(&str, &str)>) -> anyhow::Result<()> {
fn prove_command(args: ProveStdioArgs, envs: Vec<(&str, &str)>) -> anyhow::Result<Command> {
let witness_file = File::open(&args.input_witness_file)?;
let mut cmd = Command::new("cargo");
cmd.envs(envs).stdin(witness_file);
Expand All @@ -130,13 +136,13 @@ fn run_proof(args: ProveStdioArgs, envs: Vec<(&str, &str)>) -> anyhow::Result<()
"--block-batch-size",
args.block_batch_size.to_string().as_str(),
"--proof-output-dir",
args.output_dir.to_str().unwrap(),
args.output_dir
.to_str()
.ok_or(anyhow::anyhow!("Invalid output dir path"))?,
"stdio",
]);
if args.use_test_config {
cmd.arg("--use-test-config");
}
let status = cmd.spawn()?.wait()?;
ensure!(status.success(), "command failed with {}", status);
Ok(())
Ok(cmd)
}

0 comments on commit 6937c5a

Please sign in to comment.