Skip to content

Commit

Permalink
remove: cairo_run method
Browse files Browse the repository at this point in the history
  • Loading branch information
whichqua committed Jun 12, 2024
1 parent 1243e26 commit a8f5a83
Showing 1 changed file with 8 additions and 51 deletions.
59 changes: 8 additions & 51 deletions src/cairo_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,25 @@ use cairo_bootloader::{
use cairo_vm::air_private_input::AirPrivateInput;
use cairo_vm::air_public_input::PublicInputError;
use cairo_vm::cairo_run::{
write_encoded_memory, write_encoded_trace, CairoRunConfig, EncodeTraceError,
cairo_run_program_with_initial_scope, write_encoded_memory, write_encoded_trace,
CairoRunConfig, EncodeTraceError,
};
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor;
use cairo_vm::hint_processor::hint_processor_definition::HintProcessor;
use cairo_vm::types::errors::program_errors::ProgramError;
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::program::Program;
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
use cairo_vm::vm::errors::trace_errors::TraceError;
use cairo_vm::vm::errors::vm_exception::VmException;

use cairo_vm::vm::runners::cairo_pie::CairoPie;
use cairo_vm::vm::runners::cairo_runner::CairoRunner;
use cairo_vm::vm::security::verify_secure_runner;
use cairo_vm::{any_box, Felt252};
use thiserror::Error;

use bincode::error::EncodeError;

use crate::models::{Layout, PublicInput};

// Copied from cairo_run.rs and adapted to support injecting the bootloader input.
// TODO: check if modifying CairoRunConfig to specify custom variables is accepted upstream.
pub fn cairo_run(
program: &Program,
cairo_run_config: &CairoRunConfig,
hint_executor: &mut dyn HintProcessor,
variables: HashMap<String, Box<dyn Any>>,
) -> Result<CairoRunner, CairoRunError> {
let secure_run = cairo_run_config
.secure_run
.unwrap_or(!cairo_run_config.proof_mode);

let allow_missing_builtins = cairo_run_config.allow_missing_builtins.unwrap_or(false);

let mut cairo_runner = CairoRunner::new(
program,
cairo_run_config.layout,
cairo_run_config.proof_mode,
cairo_run_config.trace_enabled,
)?;
for (key, value) in variables {
cairo_runner.exec_scopes.insert_box(&key, value);
}

let end = cairo_runner.initialize(allow_missing_builtins)?;
// check step calculation

cairo_runner
.run_until_pc(end, hint_executor)
.map_err(|err| VmException::from_vm_error(&cairo_runner, err))?;
cairo_runner.end_run(cairo_run_config.disable_trace_padding, false, hint_executor)?;

cairo_runner.read_return_values(allow_missing_builtins)?;
if cairo_run_config.proof_mode {
cairo_runner.finalize_segments()?;
}
if secure_run {
verify_secure_runner(&cairo_runner, true, None)?;
}
cairo_runner.relocate(cairo_run_config.relocate_mem)?;

Ok(cairo_runner)
}

/// Run a Cairo program in proof mode.
///
/// * `program_content`: Compiled program content.
Expand Down Expand Up @@ -251,12 +207,13 @@ pub fn run_bootloader_in_proof_mode(
any_box!(bootloader.clone()),
),
]);

let cairo_runner = cairo_run(
let mut scope = ExecutionScopes::new();
scope.enter_scope(variables);
let cairo_runner = cairo_run_program_with_initial_scope(
bootloader,
&cairo_run_config,
&mut hint_processor,
variables,
scope,
)?;

extract_execution_artifacts(cairo_runner)
Expand Down

0 comments on commit a8f5a83

Please sign in to comment.