Skip to content

Commit 0e0c754

Browse files
committed
Add a function for proving a cairo pie from objects (not files)
1 parent c24e1a8 commit 0e0c754

File tree

1 file changed

+30
-5
lines changed
  • crates/stwo_run_and_prove/src

1 file changed

+30
-5
lines changed

crates/stwo_run_and_prove/src/main.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use cairo_program_runner_lib::utils::{
66
};
77
use cairo_vm::types::errors::program_errors::ProgramError;
88
use cairo_vm::types::layout_name::LayoutName;
9+
use cairo_vm::types::program::Program;
910
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
1011
use cairo_vm::vm::errors::runner_errors::RunnerError;
1112
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
@@ -132,7 +133,8 @@ fn run() -> Result<(), StwoRunAndProveError> {
132133
Ok(())
133134
}
134135

135-
/// Runs the program and generates a proof for it, then saves the proof to the given path.
136+
/// Runs the program and prover_input from a file path and generates a proof for it, then saves the
137+
/// proof to the given path.
136138
/// If `debug_data_dir` is provided, and there is a proving error or the `save_debug_data` flag is
137139
/// enabled, saves the debug data to that path.
138140
/// If `program_output` is provided, the program output to that path.
@@ -146,6 +148,33 @@ fn stwo_run_and_prove(
146148
save_debug_data: bool,
147149
) -> Result<(), StwoRunAndProveError> {
148150
let _span = span!(Level::INFO, "stwo_run_and_prove").entered();
151+
let program = get_program(program_path.as_path())
152+
.map_err(|e| StwoRunAndProveError::Program(e, program_path))?;
153+
let program_input = get_program_input(&program_input)
154+
.map_err(|e| StwoRunAndProveError::PathIO(e, program_input.unwrap_or_default()))?;
155+
156+
stwo_run_and_prove_in_memory(
157+
program,
158+
program_input,
159+
program_output,
160+
prove_config,
161+
prover,
162+
debug_data_dir,
163+
save_debug_data,
164+
)
165+
}
166+
167+
/// Runs the program and generates a proof for it using deserialized objects directly.
168+
/// If `program_output` is provided, saves the program output to that path.
169+
fn stwo_run_and_prove_in_memory(
170+
program: Program,
171+
program_input: Option<String>,
172+
program_output: Option<PathBuf>,
173+
prove_config: ProveConfig,
174+
prover: Box<dyn ProverTrait>,
175+
debug_data_dir: Option<PathBuf>,
176+
save_debug_data: bool,
177+
) -> Result<(), StwoRunAndProveError> {
149178
let cairo_run_config = get_cairo_run_config(
150179
// we don't use dynamic layout in stwo
151180
&None,
@@ -161,10 +190,6 @@ fn stwo_run_and_prove(
161190
false,
162191
)?;
163192

164-
let program = get_program(program_path.as_path())
165-
.map_err(|e| StwoRunAndProveError::Program(e, program_path))?;
166-
let program_input = get_program_input(&program_input)
167-
.map_err(|e| StwoRunAndProveError::PathIO(e, program_input.unwrap_or_default()))?;
168193
let mut runner = cairo_run_program(&program, program_input, cairo_run_config)?;
169194
let prover_input = adapt(&runner)?;
170195
let result = prove(prover_input.clone(), prove_config, prover);

0 commit comments

Comments
 (0)