Skip to content

Commit

Permalink
feat: support for skipping first n slices proving
Browse files Browse the repository at this point in the history
  • Loading branch information
junyu0312 committed Jul 4, 2024
1 parent ad43fde commit 85d6412
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
25 changes: 23 additions & 2 deletions crates/cli/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ impl ArgBuilder<bool> for MockTestArg {
}
}

struct SkipArg;
impl ArgBuilder<usize> for SkipArg {
fn builder() -> Arg<'static> {
arg!(--skip [SKIP_SIZE] "Skip first SKIP_SIZE slice(s) proving")
.default_value("0")
.value_parser(value_parser!(usize))
.multiple_values(false)
}

fn parse(matches: &ArgMatches) -> usize {
matches.get_one("skip").cloned().unwrap_or_default()
}
}

fn setup_command() -> Command<'static> {
let command = Command::new("setup")
.about("Setup a new zkWasm circuit for provided Wasm image")
Expand Down Expand Up @@ -180,7 +194,7 @@ fn dry_run_command() -> Command<'static> {
}

fn prove_command() -> Command<'static> {
Command::new("prove")
let command = Command::new("prove")
.about("Execute the Wasm image and generate a proof")
.arg(WasmImageArg::builder())
.arg(PublicInputsArg::builder())
Expand All @@ -189,7 +203,13 @@ fn prove_command() -> Command<'static> {
.arg(ContextOutputArg::builder())
.arg(OutputDirArg::builder())
.arg(MockTestArg::builder())
.arg(FileBackendArg::builder())
.arg(FileBackendArg::builder());

if cfg!(feature = "continuation") {
command.arg(SkipArg::builder())
} else {
command
}
}

fn verify_command() -> Command<'static> {
Expand Down Expand Up @@ -259,6 +279,7 @@ impl From<&ArgMatches> for ProveArg {
running_arg: val.into(),
mock_test: MockTestArg::parse(val),
file_backend: FileBackendArg::parse(val),
skip: SkipArg::parse(val),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ pub(crate) struct ProveArg {
pub(crate) running_arg: RunningArg,
pub(crate) mock_test: bool,
pub(crate) file_backend: bool,
// skip first n slice(s) proving.
pub(crate) skip: usize,
}

/// Verify the proof.
Expand Down
11 changes: 10 additions & 1 deletion crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl Config {
context_output_filename: Option<String>,
mock_test: bool,
table_backend: TraceBackend,
skip: usize,
) -> anyhow::Result<()> {
let mut cached_proving_key = None;

Expand Down Expand Up @@ -321,7 +322,15 @@ impl Config {

let progress_bar = ProgressBar::new(tables.execution_tables.etable.len() as u64);

let mut slices = Slices::new(self.k, tables)?.enumerate().peekable();
if skip != 0 {
progress_bar.inc(skip as u64);
println!("skip first {} slice(s)", skip);
}

let mut slices = Slices::new(self.k, tables)?
.enumerate()
.skip(skip)
.peekable();
while let Some((index, circuit)) = slices.next() {
let circuit = circuit?;

Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn main() -> Result<()> {
arg.running_arg.context_output,
arg.mock_test,
trace_backend,
arg.skip,
)?;
}
Subcommands::Verify(arg) => {
Expand Down

0 comments on commit 85d6412

Please sign in to comment.