diff --git a/stwo_cairo_prover/Cargo.lock b/stwo_cairo_prover/Cargo.lock index c883a547..c5b01f6a 100644 --- a/stwo_cairo_prover/Cargo.lock +++ b/stwo_cairo_prover/Cargo.lock @@ -16,6 +16,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "ahash" version = "0.8.11" @@ -420,6 +426,7 @@ dependencies = [ "nom", "num-bigint", "num-integer", + "num-prime", "num-traits", "rand", "rust_decimal", @@ -431,6 +438,7 @@ dependencies = [ "starknet-types-core", "thiserror-no-std", "wasm-bindgen", + "zip", ] [[package]] @@ -509,6 +517,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-deque" version = "0.8.6" @@ -689,6 +706,16 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "flate2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "foldhash" version = "0.1.4" @@ -868,6 +895,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" dependencies = [ "lambdaworks-math", + "serde", "sha2", "sha3", ] @@ -877,6 +905,10 @@ name = "lambdaworks-math" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1bd2632acbd9957afc5aeec07ad39f078ae38656654043bf16e046fa2730e23" +dependencies = [ + "serde", + "serde_json", +] [[package]] name = "lazy_static" @@ -905,6 +937,15 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "lru" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +dependencies = [ + "hashbrown 0.15.2", +] + [[package]] name = "memchr" version = "2.7.4" @@ -917,6 +958,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" +dependencies = [ + "adler2", +] + [[package]] name = "nom" version = "7.1.3" @@ -958,6 +1008,33 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-modular" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a5fe11d4135c3bcdf3a95b18b194afa9608a5f6ff034f5d857bc9a27fb0119" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-prime" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e238432a7881ec7164503ccc516c014bf009be7984cde1ba56837862543bdec3" +dependencies = [ + "bitvec", + "either", + "lru", + "num-bigint", + "num-integer", + "num-modular", + "num-traits", + "rand", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -2068,3 +2145,15 @@ dependencies = [ "quote", "syn 2.0.93", ] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "byteorder", + "crc32fast", + "crossbeam-utils", + "flate2", +] diff --git a/stwo_cairo_prover/crates/utils/Cargo.toml b/stwo_cairo_prover/crates/utils/Cargo.toml index 9911b178..5108335b 100644 --- a/stwo_cairo_prover/crates/utils/Cargo.toml +++ b/stwo_cairo_prover/crates/utils/Cargo.toml @@ -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 diff --git a/stwo_cairo_prover/crates/utils/src/vm_utils.rs b/stwo_cairo_prover/crates/utils/src/vm_utils.rs index adc4b287..c501e60f 100644 --- a/stwo_cairo_prover/crates/utils/src/vm_utils.rs +++ b/stwo_cairo_prover/crates/utils/src/vm_utils.rs @@ -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; @@ -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. @@ -74,15 +76,24 @@ pub fn run_vm(args: &VmArgs) -> Result { ..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)); } };