Skip to content

Commit 61b3cfb

Browse files
implement run and adapt in run_and_prove (#166)
## Type - [ ] feature - [ ] bugfix - [ ] dev (no functional changes, no API changes) - [ ] fmt (formatting, renaming) - [ ] build - [ ] docs - [ ] testing ## Description ## Breaking changes? - [ ] yes - [ ] no <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/bootloader-hints/166) <!-- Reviewable:end -->
1 parent e546f98 commit 61b3cfb

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

crates/run_and_prove/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ name = "run_and_prove"
33
version = "0.1.0"
44
edition = "2024"
55

6-
[dependencies]
6+
[dependencies]
7+
cairo-vm.workspace = true
8+
clap.workspace = true
9+
thiserror.workspace = true
10+
cairo-program-runner-lib.workspace = true
11+
stwo-cairo-adapter.workspace = true

crates/run_and_prove/src/main.rs

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,79 @@
1-
fn main() {}
1+
use cairo_program_runner_lib::cairo_run_program;
2+
use cairo_program_runner_lib::utils::{get_cairo_run_config, get_program, get_program_input};
3+
use cairo_vm::types::errors::program_errors::ProgramError;
4+
use cairo_vm::types::layout_name::LayoutName;
5+
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
6+
use cairo_vm::vm::errors::runner_errors::RunnerError;
7+
use clap::Parser;
8+
use std::env;
9+
use std::path::PathBuf;
10+
use stwo_cairo_adapter::adapter::adapter;
11+
use stwo_cairo_adapter::vm_import::VmImportError;
12+
use thiserror::Error;
13+
14+
#[derive(Parser, Debug)]
15+
#[clap(author, version, about, long_about = None)]
16+
struct Args {
17+
// cairo run args:
18+
#[clap(long = "program", help = "Path to the compiled program")]
19+
program: PathBuf,
20+
#[clap(long = "program_input", help = "Path to the program input file.")]
21+
program_input: Option<PathBuf>,
22+
}
23+
24+
#[derive(Debug, Error)]
25+
enum StwoRunAndProveError {
26+
#[error(transparent)]
27+
Cli(#[from] clap::Error),
28+
#[error(transparent)]
29+
IO(#[from] std::io::Error),
30+
#[error(transparent)]
31+
VmImport(#[from] VmImportError),
32+
#[error(transparent)]
33+
CairoRun(Box<CairoRunError>),
34+
#[error(transparent)]
35+
Program(#[from] ProgramError),
36+
#[error(transparent)]
37+
Runner(#[from] RunnerError),
38+
}
39+
40+
// Implement From<Box<CairoRunError>> manually
41+
// TODO(Nitsan, 03/07/2025): check why this error is so big and if it can be boxed where it was
42+
// created.
43+
impl From<CairoRunError> for StwoRunAndProveError {
44+
fn from(err: CairoRunError) -> Self {
45+
StwoRunAndProveError::CairoRun(Box::new(err))
46+
}
47+
}
48+
49+
#[allow(unused_variables)]
50+
// TODO(Nitsan, 03/07/2025): The prove part is not implemented yet, so we keep this unused variable
51+
// to avoid warnings.
52+
fn main() -> Result<(), StwoRunAndProveError> {
53+
let args = Args::try_parse_from(env::args())?;
54+
let program = get_program(args.program.as_path())?;
55+
56+
let program_input_contents = get_program_input(&args.program_input)?;
57+
let cairo_run_config = get_cairo_run_config(
58+
// we don't use dynamic layout in stwo
59+
&None,
60+
LayoutName::all_cairo_stwo,
61+
true,
62+
// in stwo when proof_mode==true, trace padding is redundant work
63+
true,
64+
// we allow missing builtins because all_cairo_stwo doesn't include all builtins, and
65+
// the bootloader will simulate the missing builtins.
66+
true,
67+
// we don't need to relocate memory in the VM because we later call the adapter that does
68+
// relocation.
69+
false,
70+
)?;
71+
72+
let runner = cairo_run_program(&program, program_input_contents, cairo_run_config)?;
73+
let mut prover_input_info = runner.get_prover_input_info()?;
74+
let prover_input = adapter(&mut prover_input_info)?;
75+
76+
// TODO(Nitsan, 03/07/2025): prove will be implemented in next PR
77+
78+
Ok(())
79+
}

0 commit comments

Comments
 (0)