From f487498aab6931801644fa0541f59493256d689a Mon Sep 17 00:00:00 2001 From: whichqua <170323628+whichqua@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:49:06 +0300 Subject: [PATCH 1/9] chore: Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 37a7daf..4fa3ee7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ description = "Rust SDK for the Starkware Stone prover and verifier." [dependencies] bincode = "2.0.0-rc.3" -cairo-vm = { git = "https://github.com/Moonsong-Labs/cairo-vm", rev = "e0a4653aa5634664a3f792b38715a572e9f89b44", features = ["extensive_hints"] } +cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", rev = "05352b1c67859a4d8cd128575c1e68ca7e300341", features = ["extensive_hints"] } serde = { version = "1.0.192", features = ["derive"] } serde_json = "1.0.108" stark_evm_adapter = "0.1.5" From ecf4c48cd7fed8f393e6fa8ea6445b7104c071ae Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:08:23 +0300 Subject: [PATCH 2/9] update: types and dependencies --- Cargo.toml | 1 + src/cairo_vm.rs | 60 +++++++++++++++++++++---------------------------- src/models.rs | 18 +++++++++++++++ 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4fa3ee7..7f2f084 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ stark_evm_adapter = "0.1.5" tempfile = "3.8.1" thiserror = "1.0.50" tokio = { version = "1.34.0", features = ["macros", "process", "rt-multi-thread"] } +cairo-bootloader = { git = "https://github.com/Moonsong-Labs/cairo-bootloader"} [dev-dependencies] diff --git a/src/cairo_vm.rs b/src/cairo_vm.rs index e733897..2198dd3 100644 --- a/src/cairo_vm.rs +++ b/src/cairo_vm.rs @@ -1,18 +1,18 @@ use std::any::Any; use std::collections::HashMap; +use std::io; use std::path::PathBuf; +use cairo_bootloader::{ + BootloaderConfig, BootloaderInput, PackedOutput, SimpleBootloaderInput, Task, TaskSpec, +}; 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, }; -use cairo_vm::hint_processor::builtin_hint_processor::bootloader::types::{ - BootloaderConfig, BootloaderInput, PackedOutput, SimpleBootloaderInput, Task, TaskSpec, -}; 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::cairo_pie_error::CairoPieError; use cairo_vm::types::errors::program_errors::ProgramError; use cairo_vm::types::program::Program; use cairo_vm::vm::errors::cairo_run_errors::CairoRunError; @@ -21,7 +21,6 @@ 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::vm::vm_core::VirtualMachine; use cairo_vm::{any_box, Felt252}; use thiserror::Error; @@ -36,7 +35,7 @@ pub fn cairo_run( cairo_run_config: &CairoRunConfig, hint_executor: &mut dyn HintProcessor, variables: HashMap>, -) -> Result<(CairoRunner, VirtualMachine), CairoRunError> { +) -> Result { let secure_run = cairo_run_config .secure_run .unwrap_or(!cairo_run_config.proof_mode); @@ -47,36 +46,30 @@ pub fn cairo_run( 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 mut vm = VirtualMachine::new(cairo_run_config.trace_enabled); - let end = cairo_runner.initialize(&mut vm, allow_missing_builtins)?; + let end = cairo_runner.initialize(allow_missing_builtins)?; // check step calculation cairo_runner - .run_until_pc(end, &mut vm, hint_executor) - .map_err(|err| VmException::from_vm_error(&cairo_runner, &vm, err))?; - cairo_runner.end_run( - cairo_run_config.disable_trace_padding, - false, - &mut vm, - hint_executor, - )?; + .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)?; - vm.verify_auto_deductions()?; - cairo_runner.read_return_values(&mut vm)?; + cairo_runner.read_return_values(allow_missing_builtins)?; if cairo_run_config.proof_mode { - cairo_runner.finalize_segments(&mut vm)?; + cairo_runner.finalize_segments()?; } if secure_run { - verify_secure_runner(&cairo_runner, true, None, &mut vm)?; + verify_secure_runner(&cairo_runner, true, None)?; } - cairo_runner.relocate(&mut vm, cairo_run_config.relocate_mem)?; + cairo_runner.relocate(cairo_run_config.relocate_mem)?; - Ok((cairo_runner, vm)) + Ok(cairo_runner) } /// Run a Cairo program in proof mode. @@ -86,14 +79,13 @@ pub fn run_in_proof_mode( program_content: &[u8], layout: Layout, allow_missing_builtins: Option, -) -> Result<(CairoRunner, VirtualMachine), CairoRunError> { +) -> Result { let proof_mode = true; - let cairo_run_config = CairoRunConfig { entrypoint: "main", trace_enabled: true, relocate_mem: true, - layout: &layout.to_string(), + layout: layout.into(), proof_mode, secure_run: None, disable_trace_padding: false, @@ -102,7 +94,9 @@ pub fn run_in_proof_mode( let mut hint_processor = BuiltinHintProcessor::new_empty(); - cairo_vm::cairo_run::cairo_run(program_content, &cairo_run_config, &mut hint_processor) + let runner = + cairo_vm::cairo_run::cairo_run(program_content, &cairo_run_config, &mut hint_processor)?; + Ok(runner) } #[derive(thiserror::Error, Debug)] @@ -111,7 +105,7 @@ pub enum BootloaderTaskError { Program(#[from] ProgramError), #[error("Failed to read PIE: {0}")] - Pie(#[from] CairoPieError), + Pie(#[from] io::Error), } pub fn make_bootloader_tasks( @@ -183,10 +177,8 @@ impl bincode::enc::write::Writer for MemWriter { /// Extracts execution artifacts from the runner and VM (after execution). /// /// * `cairo_runner` Cairo runner object. -/// * `vm`: Cairo VM object. pub fn extract_execution_artifacts( cairo_runner: CairoRunner, - vm: VirtualMachine, ) -> Result { let memory = &cairo_runner.relocated_memory; let trace = cairo_runner @@ -202,10 +194,10 @@ pub fn extract_execution_artifacts( write_encoded_trace(trace, &mut trace_writer).map_err(ExecutionError::EncodeTrace)?; let trace_raw = trace_writer.buf; - let cairo_vm_public_input = cairo_runner.get_air_public_input(&vm)?; + let cairo_vm_public_input = cairo_runner.get_air_public_input()?; let public_input = PublicInput::try_from(cairo_vm_public_input)?; - let private_input = cairo_runner.get_air_private_input(&vm); + let private_input = cairo_runner.get_air_private_input(); Ok(ExecutionArtifacts { public_input, @@ -229,7 +221,7 @@ pub fn run_bootloader_in_proof_mode( entrypoint: "main", trace_enabled: true, relocate_mem: true, - layout: &layout.to_string(), + layout: layout.into(), proof_mode, secure_run: None, disable_trace_padding: false, @@ -260,12 +252,12 @@ pub fn run_bootloader_in_proof_mode( ), ]); - let (cairo_runner, vm) = cairo_run( + let cairo_runner = cairo_run( bootloader, &cairo_run_config, &mut hint_processor, variables, )?; - extract_execution_artifacts(cairo_runner, vm) + extract_execution_artifacts(cairo_runner) } diff --git a/src/models.rs b/src/models.rs index 4bcf772..7f1e2a8 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,4 +1,5 @@ use cairo_vm::air_private_input::AirPrivateInputSerializable; +use cairo_vm::types::layout_name::LayoutName; use stark_evm_adapter::annotation_parser::SplitProofs; use std::collections::HashMap; use std::fmt::{Display, Formatter}; @@ -89,6 +90,7 @@ pub struct ProverParameters { pub use_extension_field: bool, } +// TODO: Should we remove this and just us LayoutName? #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)] pub enum Layout { #[serde(rename = "plain")] @@ -119,6 +121,22 @@ impl FromStr for Layout { } } +impl Into for Layout { + fn into(self) -> LayoutName { + match self { + Layout::AllCairo => LayoutName::all_cairo, + Layout::AllSolidity => LayoutName::all_solidity, + Layout::Dex => LayoutName::dex, + Layout::Plain => LayoutName::plain, + Layout::Recursive => LayoutName::recursive, + Layout::RecursiveLargeOutput => LayoutName::recursive_large_output, + Layout::Small => LayoutName::small, + Layout::Starknet => LayoutName::starknet, + Layout::StarknetWithKeccak => LayoutName::starknet_with_keccak + } + } +} + impl Display for Layout { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let value = serde_json::to_value(self).map_err(|_| std::fmt::Error)?; From 1243e26366f012a273c77ac400eff64b41a05d33 Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:08:24 +0300 Subject: [PATCH 3/9] lint: clippy and fmt --- src/models.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/models.rs b/src/models.rs index 7f1e2a8..09b2d26 100644 --- a/src/models.rs +++ b/src/models.rs @@ -121,9 +121,9 @@ impl FromStr for Layout { } } -impl Into for Layout { - fn into(self) -> LayoutName { - match self { +impl From for LayoutName { + fn from(val: Layout) -> Self { + match val { Layout::AllCairo => LayoutName::all_cairo, Layout::AllSolidity => LayoutName::all_solidity, Layout::Dex => LayoutName::dex, @@ -132,7 +132,7 @@ impl Into for Layout { Layout::RecursiveLargeOutput => LayoutName::recursive_large_output, Layout::Small => LayoutName::small, Layout::Starknet => LayoutName::starknet, - Layout::StarknetWithKeccak => LayoutName::starknet_with_keccak + Layout::StarknetWithKeccak => LayoutName::starknet_with_keccak, } } } From a8f5a83ad36364afb787d201911371e5972b258b Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:13:40 +0300 Subject: [PATCH 4/9] remove: cairo_run method --- src/cairo_vm.rs | 59 +++++++------------------------------------------ 1 file changed, 8 insertions(+), 51 deletions(-) diff --git a/src/cairo_vm.rs b/src/cairo_vm.rs index 2198dd3..7cd983b 100644 --- a/src/cairo_vm.rs +++ b/src/cairo_vm.rs @@ -9,18 +9,18 @@ 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; @@ -28,50 +28,6 @@ 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>, -) -> Result { - 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. @@ -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) From c42664d3da86e58cfcc8393972012114b0a94fa4 Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:20:00 +0300 Subject: [PATCH 5/9] api: remove repeated apis --- src/cairo_vm.rs | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/src/cairo_vm.rs b/src/cairo_vm.rs index 7cd983b..5e48553 100644 --- a/src/cairo_vm.rs +++ b/src/cairo_vm.rs @@ -1,10 +1,9 @@ use std::any::Any; use std::collections::HashMap; -use std::io; use std::path::PathBuf; use cairo_bootloader::{ - BootloaderConfig, BootloaderInput, PackedOutput, SimpleBootloaderInput, Task, TaskSpec, + BootloaderConfig, BootloaderInput, PackedOutput, SimpleBootloaderInput, TaskSpec, }; use cairo_vm::air_private_input::AirPrivateInput; use cairo_vm::air_public_input::PublicInputError; @@ -13,13 +12,10 @@ use cairo_vm::cairo_run::{ CairoRunConfig, EncodeTraceError, }; use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; -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::runners::cairo_pie::CairoPie; use cairo_vm::vm::runners::cairo_runner::CairoRunner; use cairo_vm::{any_box, Felt252}; use thiserror::Error; @@ -55,39 +51,6 @@ pub fn run_in_proof_mode( Ok(runner) } -#[derive(thiserror::Error, Debug)] -pub enum BootloaderTaskError { - #[error("Failed to read program: {0}")] - Program(#[from] ProgramError), - - #[error("Failed to read PIE: {0}")] - Pie(#[from] io::Error), -} - -pub fn make_bootloader_tasks( - programs: &[Vec], - pies: &[Vec], -) -> Result, BootloaderTaskError> { - let program_tasks = programs.iter().map(|program_bytes| { - let program = Program::from_bytes(program_bytes, Some("main")); - program - .map(|program| TaskSpec { - task: Task::Program(program), - }) - .map_err(BootloaderTaskError::Program) - }); - - let cairo_pie_tasks = pies.iter().map(|pie_bytes| { - let pie = CairoPie::from_bytes(pie_bytes); - pie.map(|pie| TaskSpec { - task: Task::Pie(pie), - }) - .map_err(BootloaderTaskError::Pie) - }); - - program_tasks.chain(cairo_pie_tasks).collect() -} - pub struct ExecutionArtifacts { pub public_input: PublicInput, pub private_input: AirPrivateInput, From dfeb3a7dd6c56db506b732af2da8ec43fbe4d722 Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Thu, 13 Jun 2024 03:52:05 +0200 Subject: [PATCH 6/9] fix: private input issue --- src/test_utils.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/test_utils.rs b/src/test_utils.rs index ae57c69..943182e 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use std::path::{Path, PathBuf}; use cairo_vm::air_private_input::{AirPrivateInput, AirPrivateInputSerializable}; +use cairo_vm::types::builtin_name::BuiltinName; use rstest::fixture; use tempfile::NamedTempFile; @@ -84,10 +85,31 @@ pub fn prover_cli_test_case(prover_test_case: ProverTestCase) -> ProverCliTestCa // Generate the private input in a temporary file let private_input_file = NamedTempFile::new().expect("Creating temporary private input file failed"); - let private_input = AirPrivateInput(HashMap::new()).to_serializable( - prover_test_case.trace_file.to_string_lossy().into_owned(), - prover_test_case.memory_file.to_string_lossy().into_owned(), - ); + let private_input = { + let mut private_input = AirPrivateInput(HashMap::new()); + + // Fix: a recent version of cairo-vm does not serialize unspecified fields anymore. + // This is not supported by Stone and triggers an exception. Here we set a default value + // for each builtin required by Stone to work around the issue. + let private_input_builtins = [ + BuiltinName::pedersen, + BuiltinName::range_check, + BuiltinName::ecdsa, + BuiltinName::bitwise, + BuiltinName::ec_op, + BuiltinName::keccak, + BuiltinName::poseidon, + ]; + + for builtin_name in private_input_builtins { + private_input.0.insert(builtin_name, vec![]); + } + + private_input.to_serializable( + prover_test_case.trace_file.to_string_lossy().into_owned(), + prover_test_case.memory_file.to_string_lossy().into_owned(), + ) + }; serde_json::to_writer(&private_input_file, &private_input) .expect("Writing private input file failed"); From 9c3cf45793b940eff8c15c8419909d03064e0a82 Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Thu, 13 Jun 2024 19:13:50 +0300 Subject: [PATCH 7/9] fix: add bootloader hint process --- src/cairo_vm.rs | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/cairo_vm.rs b/src/cairo_vm.rs index 5e48553..f1fc192 100644 --- a/src/cairo_vm.rs +++ b/src/cairo_vm.rs @@ -1,9 +1,10 @@ +/// TODO: Move all this to cairo_bootloader repo? use std::any::Any; use std::collections::HashMap; use std::path::PathBuf; use cairo_bootloader::{ - BootloaderConfig, BootloaderInput, PackedOutput, SimpleBootloaderInput, TaskSpec, + insert_bootloader_input, BootloaderConfig, BootloaderHintProcessor, BootloaderInput, PackedOutput, SimpleBootloaderInput, TaskSpec }; use cairo_vm::air_private_input::AirPrivateInput; use cairo_vm::air_public_input::PublicInputError; @@ -11,7 +12,6 @@ use cairo_vm::cairo_run::{ 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::types::exec_scope::ExecutionScopes; use cairo_vm::types::program::Program; use cairo_vm::vm::errors::cairo_run_errors::CairoRunError; @@ -24,6 +24,8 @@ use bincode::error::EncodeError; use crate::models::{Layout, PublicInput}; + + /// Run a Cairo program in proof mode. /// /// * `program_content`: Compiled program content. @@ -44,7 +46,7 @@ pub fn run_in_proof_mode( allow_missing_builtins, }; - let mut hint_processor = BuiltinHintProcessor::new_empty(); + let mut hint_processor = BootloaderHintProcessor::new(); let runner = cairo_vm::cairo_run::cairo_run(program_content, &cairo_run_config, &mut hint_processor)?; @@ -162,22 +164,37 @@ pub fn run_bootloader_in_proof_mode( packed_outputs: vec![PackedOutput::Plain(vec![]); n_tasks], }; - let mut hint_processor = BuiltinHintProcessor::new_empty(); - let variables = HashMap::>::from([ - ("bootloader_input".to_string(), any_box!(bootloader_input)), - ( - "bootloader_program".to_string(), - any_box!(bootloader.clone()), - ), - ]); - let mut scope = ExecutionScopes::new(); - scope.enter_scope(variables); + let mut hint_processor = BootloaderHintProcessor::new(); + // let variables = HashMap::>::from([ + // ("bootloader_input".to_string(), any_box!(bootloader_input)), + // ( + // "bootloader_program".to_string(), + // any_box!(bootloader.clone()), + // ), + // ]); + // let scope = ExecutionScopes { + // data: vec![variables], + // }; + + let bootloader_identifiers = HashMap::from( + [ + ("starkware.cairo.bootloaders.simple_bootloader.execute_task.execute_task.ret_pc_label".to_string(), 10usize), + ("starkware.cairo.bootloaders.simple_bootloader.execute_task.execute_task.call_task".to_string(), 8usize) + ] + ); + let mut exec_scopes = ExecutionScopes::new(); + insert_bootloader_input(&mut exec_scopes, bootloader_input); + exec_scopes.insert_value("bootloader_program_identifiers", bootloader_identifiers); + exec_scopes.insert_value("bootloader_program", bootloader.clone()); + let cairo_runner = cairo_run_program_with_initial_scope( bootloader, &cairo_run_config, &mut hint_processor, - scope, + exec_scopes, )?; extract_execution_artifacts(cairo_runner) } + + From e18c8bec0d8f8bafaa89637439e8cc280447fd29 Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:08:33 +0300 Subject: [PATCH 8/9] fix: bootloader_program_identifiers for proving --- src/cairo_vm.rs | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/cairo_vm.rs b/src/cairo_vm.rs index f1fc192..d16d088 100644 --- a/src/cairo_vm.rs +++ b/src/cairo_vm.rs @@ -1,10 +1,10 @@ /// TODO: Move all this to cairo_bootloader repo? -use std::any::Any; use std::collections::HashMap; use std::path::PathBuf; use cairo_bootloader::{ - insert_bootloader_input, BootloaderConfig, BootloaderHintProcessor, BootloaderInput, PackedOutput, SimpleBootloaderInput, TaskSpec + insert_bootloader_input, BootloaderConfig, BootloaderHintProcessor, BootloaderInput, + PackedOutput, SimpleBootloaderInput, TaskSpec, }; use cairo_vm::air_private_input::AirPrivateInput; use cairo_vm::air_public_input::PublicInputError; @@ -17,15 +17,13 @@ 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::runners::cairo_runner::CairoRunner; -use cairo_vm::{any_box, Felt252}; +use cairo_vm::Felt252; use thiserror::Error; use bincode::error::EncodeError; use crate::models::{Layout, PublicInput}; - - /// Run a Cairo program in proof mode. /// /// * `program_content`: Compiled program content. @@ -165,27 +163,17 @@ pub fn run_bootloader_in_proof_mode( }; let mut hint_processor = BootloaderHintProcessor::new(); - // let variables = HashMap::>::from([ - // ("bootloader_input".to_string(), any_box!(bootloader_input)), - // ( - // "bootloader_program".to_string(), - // any_box!(bootloader.clone()), - // ), - // ]); - // let scope = ExecutionScopes { - // data: vec![variables], - // }; - - let bootloader_identifiers = HashMap::from( - [ - ("starkware.cairo.bootloaders.simple_bootloader.execute_task.execute_task.ret_pc_label".to_string(), 10usize), - ("starkware.cairo.bootloaders.simple_bootloader.execute_task.execute_task.call_task".to_string(), 8usize) - ] - ); let mut exec_scopes = ExecutionScopes::new(); insert_bootloader_input(&mut exec_scopes, bootloader_input); - exec_scopes.insert_value("bootloader_program_identifiers", bootloader_identifiers); - exec_scopes.insert_value("bootloader_program", bootloader.clone()); + + let bootloader_identifiers: HashMap<_, _> = bootloader + .iter_identifiers() + .map(|(key, val)| (key.to_owned(), val.clone())) + .collect(); + exec_scopes.insert_value( + "bootloader_program_identifiers", + bootloader_identifiers.clone(), + ); let cairo_runner = cairo_run_program_with_initial_scope( bootloader, @@ -196,5 +184,3 @@ pub fn run_bootloader_in_proof_mode( extract_execution_artifacts(cairo_runner) } - - From 9699c605dadaf5d0314c857f3600c081248f51bc Mon Sep 17 00:00:00 2001 From: Whichqua <170323628+whichqua@users.noreply.github.com> Date: Fri, 14 Jun 2024 18:09:40 +0300 Subject: [PATCH 9/9] lint: clippy --- src/prover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prover.rs b/src/prover.rs index b61740b..27cdae5 100644 --- a/src/prover.rs +++ b/src/prover.rs @@ -244,7 +244,7 @@ mod test { let output_file = NamedTempFile::new().expect("Creating output file failed"); run_prover_from_command_line( &prover_cli_test_case.public_input_file, - &prover_cli_test_case.private_input_file.path(), + prover_cli_test_case.private_input_file.path(), &prover_cli_test_case.prover_config_file, &prover_cli_test_case.prover_parameter_file, output_file.path(),