Skip to content

Commit

Permalink
reverted cairo pie handling change
Browse files Browse the repository at this point in the history
  • Loading branch information
ohad-starkware committed Jan 13, 2025
1 parent 26cb576 commit 73b7c1c
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 9 deletions.
89 changes: 89 additions & 0 deletions stwo_cairo_prover/Cargo.lock

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

2 changes: 1 addition & 1 deletion stwo_cairo_prover/crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
cairo-vm.workspace = true
cairo-vm = { workspace = true, default-features = true }
clap.workspace = true
env_logger.workspace = true
log.workspace = true
Expand Down
27 changes: 19 additions & 8 deletions stwo_cairo_prover/crates/utils/src/vm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::path::PathBuf;
use cairo_vm::cairo_run;
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor;
use cairo_vm::types::layout_name::LayoutName;
use cairo_vm::vm::runners::cairo_runner::CairoRunner;
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
use cairo_vm::vm::runners::cairo_pie::CairoPie;
use cairo_vm::vm::runners::cairo_runner::{CairoRunner, RunResources};
use clap::{Parser, ValueHint};
use thiserror::Error;
use tracing::span;
Expand Down Expand Up @@ -55,8 +57,8 @@ pub struct VmArgs {
pub enum VmError {
#[error("Failed to interact with the file system")]
IO(#[from] std::io::Error),
#[error("Cairo program execution failed: {0}")]
Runner(String),
#[error("The cairo program execution failed")]
Runner(#[from] CairoRunError),
}

// This function's logic is copied-then-modified from cairo-vm-cli/src/main.rs:run in cairo-vm repo.
Expand All @@ -74,15 +76,24 @@ pub fn run_vm(args: &VmArgs) -> Result<CairoRunner, VmError> {
..Default::default()
};

let program_content = std::fs::read(args.filename.clone()).map_err(VmError::IO)?;
let mut hint_processor = BuiltinHintProcessor::new_empty();
let cairo_runner_result =
cairo_run::cairo_run(&program_content, &cairo_run_config, &mut hint_processor);
let cairo_runner_result = if args.run_from_cairo_pie {
let pie = CairoPie::read_zip_file(&args.filename)?;
let mut hint_processor = BuiltinHintProcessor::new(
Default::default(),
RunResources::new(pie.execution_resources.n_steps),
);
cairo_run::cairo_run_pie(&pie, &cairo_run_config, &mut hint_processor)
} else {
let program_content = std::fs::read(args.filename.clone()).map_err(VmError::IO)?;
let mut hint_processor = BuiltinHintProcessor::new_empty();
cairo_run::cairo_run(&program_content, &cairo_run_config, &mut hint_processor)
};

let cairo_runner = match cairo_runner_result {
Ok(runner) => runner,
Err(error) => {
return Err(VmError::Runner(error.to_string()));
eprintln!("{error}");
return Err(VmError::Runner(error));
}
};

Expand Down

0 comments on commit 73b7c1c

Please sign in to comment.