diff --git a/stwo_cairo_prover/Cargo.lock b/stwo_cairo_prover/Cargo.lock index 0dee7b9d..c883a547 100644 --- a/stwo_cairo_prover/Cargo.lock +++ b/stwo_cairo_prover/Cargo.lock @@ -12,16 +12,10 @@ dependencies = [ "stwo-prover", "stwo_cairo_prover", "stwo_cairo_utils", - "thiserror 1.0.69", + "thiserror 2.0.10", "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" @@ -412,21 +406,20 @@ dependencies = [ [[package]] name = "cairo-vm" -version = "1.0.1" -source = "git+https://github.com/lambdaclass/cairo-vm?rev=3fb0344c#3fb0344ce038b3a68cae897c403d1f561cfe8da7" +version = "2.0.0-rc2" +source = "git+https://github.com/lambdaclass/cairo-vm?rev=83bfdcf#83bfdcf1cc971e36f7d545c1fc48655df954ecdd" dependencies = [ "anyhow", "bincode", "bitvec", "generic-array", - "hashbrown 0.14.5", + "hashbrown 0.15.2", "hex", "keccak", "lazy_static", "nom", "num-bigint", "num-integer", - "num-prime", "num-traits", "rand", "rust_decimal", @@ -434,11 +427,10 @@ dependencies = [ "serde_json", "sha2", "sha3", - "starknet-crypto", + "starknet-crypto 0.7.3", "starknet-types-core", "thiserror-no-std", "wasm-bindgen", - "zip", ] [[package]] @@ -517,15 +509,6 @@ 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" @@ -694,18 +677,6 @@ dependencies = [ "bytes", ] -[[package]] -name = "faststr" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9154486833a83cb5d99de8c4d831314b8ae810dd4ef18d89ceb7a9c7c728dd74" -dependencies = [ - "bytes", - "rkyv", - "serde", - "simdutf8", -] - [[package]] name = "fixed-hash" version = "0.8.0" @@ -718,16 +689,6 @@ 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" @@ -783,6 +744,7 @@ dependencies = [ "allocator-api2", "equivalent", "foldhash", + "serde", ] [[package]] @@ -906,7 +868,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbc2a4da0d9e52ccfe6306801a112e81a8fc0c76aa3e4449fefeda7fef72bb34" dependencies = [ "lambdaworks-math", - "serde", "sha2", "sha3", ] @@ -916,10 +877,6 @@ 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" @@ -948,15 +905,6 @@ 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" @@ -969,35 +917,6 @@ 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 = "munge" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64142d38c84badf60abf06ff9bd80ad2174306a5b11bd4706535090a30a419df" -dependencies = [ - "munge_macro", -] - -[[package]] -name = "munge_macro" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb5c1d8184f13f7d0ccbeeca0def2f9a181bce2624302793005f5ca8aa62e5e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.93", -] - [[package]] name = "nom" version = "7.1.3" @@ -1039,33 +958,6 @@ 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" @@ -1127,7 +1019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 2.0.9", + "thiserror 2.0.10", "ucd-trie", ] @@ -1207,26 +1099,6 @@ dependencies = [ "stwo_cairo_utils", ] -[[package]] -name = "ptr_meta" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9e76f66d3f9606f44e45598d155cb13ecf09f4a28199e48daf8c8fc937ea90" -dependencies = [ - "ptr_meta_derive", -] - -[[package]] -name = "ptr_meta_derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca414edb151b4c8d125c12566ab0d74dc9cdba36fb80eb7b848c15f495fd32d1" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.93", -] - [[package]] name = "quote" version = "1.0.38" @@ -1242,15 +1114,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rancor" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "caf5f7161924b9d1cea0e4cabc97c372cea92b5f927fc13c6bca67157a0ad947" -dependencies = [ - "ptr_meta", -] - [[package]] name = "rand" version = "0.8.5" @@ -1320,38 +1183,12 @@ dependencies = [ "stwo_cairo_prover", ] -[[package]] -name = "ref-cast" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf0a6f84d5f1d581da8b41b47ec8600871962f2a528115b542b362d4b744931" -dependencies = [ - "ref-cast-impl", -] - -[[package]] -name = "ref-cast-impl" -version = "1.0.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.93", -] - [[package]] name = "regex-syntax" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "rend" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a35e8a6bf28cd121053a66aa2e6a2e3eaffad4a60012179f0e864aa5ffeff215" - [[package]] name = "rfc6979" version = "0.4.0" @@ -1362,35 +1199,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rkyv" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b11a153aec4a6ab60795f8ebe2923c597b16b05bb1504377451e705ef1a45323" -dependencies = [ - "bytes", - "hashbrown 0.15.2", - "indexmap", - "munge", - "ptr_meta", - "rancor", - "rend", - "rkyv_derive", - "tinyvec", - "uuid", -] - -[[package]] -name = "rkyv_derive" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beb382a4d9f53bd5c0be86b10d8179c3f8a14c30bf774ff77096ed6581e35981" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.93", -] - [[package]] name = "rlp" version = "0.5.2" @@ -1443,7 +1251,7 @@ dependencies = [ "stwo-prover", "stwo_cairo_prover", "stwo_cairo_utils", - "thiserror 1.0.69", + "thiserror 2.0.10", "tracing", ] @@ -1579,56 +1387,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "simdutf8" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" - [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "sonic-number" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a74044c092f4f43ca7a6cfd62854cf9fb5ac8502b131347c990bf22bef1dfe" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "sonic-rs" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0275f9f2f07d47556fe60c2759da8bc4be6083b047b491b2d476aa0bfa558eb1" -dependencies = [ - "bumpalo", - "bytes", - "cfg-if", - "faststr", - "itoa", - "ref-cast", - "ryu", - "serde", - "simdutf8", - "sonic-number", - "sonic-simd", - "thiserror 2.0.9", -] - -[[package]] -name = "sonic-simd" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "940a24e82c9a97483ef66cef06b92160a8fa5cd74042c57c10b24d99d169d2fc" -dependencies = [ - "cfg-if", -] - [[package]] name = "spin" version = "0.9.8" @@ -1650,18 +1414,37 @@ dependencies = [ "rfc6979", "sha2", "starknet-crypto-codegen", - "starknet-curve", + "starknet-curve 0.4.2", "starknet-ff", "zeroize", ] +[[package]] +name = "starknet-crypto" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded22ccf4cb9e572ce3f77de6066af53560cd2520d508876c83bb1e6b29d5cbc" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits", + "rfc6979", + "sha2", + "starknet-curve 0.5.1", + "starknet-types-core", + "zeroize", +] + [[package]] name = "starknet-crypto-codegen" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ - "starknet-curve", + "starknet-curve 0.4.2", "starknet-ff", "syn 2.0.93", ] @@ -1675,6 +1458,15 @@ dependencies = [ "starknet-ff", ] +[[package]] +name = "starknet-curve" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcde6bd74269b8161948190ace6cf069ef20ac6e79cd2ba09b320efa7500b6de" +dependencies = [ + "starknet-types-core", +] + [[package]] name = "starknet-ff" version = "0.3.7" @@ -1772,7 +1564,7 @@ dependencies = [ "rand", "rayon", "serde", - "starknet-crypto", + "starknet-crypto 0.6.2", "starknet-ff", "thiserror 1.0.69", "tracing", @@ -1794,14 +1586,14 @@ dependencies = [ "rand", "rayon", "serde", - "sonic-rs", + "serde_json", "starknet-ff", "stwo-air-utils", "stwo-air-utils-derive", "stwo-cairo-serialize", "stwo-prover", "stwo_cairo_utils", - "thiserror 1.0.69", + "thiserror 2.0.10", "tracing", ] @@ -1813,7 +1605,7 @@ dependencies = [ "clap", "env_logger", "log", - "thiserror 1.0.69", + "thiserror 2.0.10", "tracing", "tracing-subscriber", ] @@ -1827,7 +1619,7 @@ dependencies = [ "serde_json", "stwo_cairo_prover", "stwo_cairo_utils", - "thiserror 1.0.69", + "thiserror 2.0.10", "tracing", ] @@ -1876,11 +1668,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.9" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +checksum = "a3ac7f54ca534db81081ef1c1e7f6ea8a3ef428d2fc069097c079443d24124d3" dependencies = [ - "thiserror-impl 2.0.9", + "thiserror-impl 2.0.10", ] [[package]] @@ -1896,9 +1688,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.9" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +checksum = "9e9465d30713b56a37ede7185763c3492a91be2f5fa68d958c44e41ab9248beb" dependencies = [ "proc-macro2", "quote", @@ -1935,21 +1727,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tinyvec" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "022db8904dfa342efe721985167e9fcd16c29b226db4397ed752a761cfce81e8" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "toml_datetime" version = "0.6.8" @@ -2066,12 +1843,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "uuid" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" - [[package]] name = "valuable" version = "0.1.0" @@ -2297,15 +2068,3 @@ 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/Cargo.toml b/stwo_cairo_prover/Cargo.toml index 4cd49ad1..b5e5f2d4 100644 --- a/stwo_cairo_prover/Cargo.toml +++ b/stwo_cairo_prover/Cargo.toml @@ -21,9 +21,9 @@ edition = "2021" bytemuck = { version = "1.20.0", features = ["derive"] } cairo-lang-casm = "2.7.1" # TODO(yuval): Use an official version, not a specific commit. -cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", rev = "3fb0344c", features = [ +cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm", rev = "83bfdcf", features = [ "mod_builtin", -] } +], default-features = false } clap = { version = "4.3.10", features = ["derive"] } env_logger = { version = "0.11.5", default-features = false } hex = "0.4.3" @@ -33,14 +33,13 @@ num-traits = "0.2.17" rand = "0.8.5" serde = "1.0.207" serde_json = "1.0.1" -sonic-rs = "0.3.10" stwo_cairo_prover = { path = "crates/prover", version = "~0.1.0" } stwo_cairo_utils = { path = "crates/utils", version = "~0.1.0" } # TODO(ShaharS): take stwo version from the source repository. stwo-prover = { git = "https://github.com/starkware-libs/stwo", rev = "af5475cb", features = [ "parallel", -] } -thiserror = "1.0.63" +], default-features = false } +thiserror = { version = "2.0.10", default-features = false } tracing = "0.1.40" tracing-subscriber = "0.3.18" paste = "1.0" diff --git a/stwo_cairo_prover/crates/prover/Cargo.toml b/stwo_cairo_prover/crates/prover/Cargo.toml index 6382606e..74e3036b 100644 --- a/stwo_cairo_prover/crates/prover/Cargo.toml +++ b/stwo_cairo_prover/crates/prover/Cargo.toml @@ -21,7 +21,7 @@ paste.workspace = true prover_types = { path = "../prover_types" } rayon = { version = "1.10.0" } serde.workspace = true -sonic-rs.workspace = true +serde_json.workspace = true starknet-ff.workspace = true stwo_cairo_utils = { path = "../utils" } stwo-cairo-serialize = { path = "../cairo-serialize" } diff --git a/stwo_cairo_prover/crates/prover/src/input/builtin_segments.rs b/stwo_cairo_prover/crates/prover/src/input/builtin_segments.rs index c80902bc..488cd72e 100644 --- a/stwo_cairo_prover/crates/prover/src/input/builtin_segments.rs +++ b/stwo_cairo_prover/crates/prover/src/input/builtin_segments.rs @@ -1,10 +1,10 @@ -use std::collections::HashMap; - use cairo_vm::air_public_input::MemorySegmentAddresses; +use cairo_vm::stdlib::collections::HashMap; use cairo_vm::types::builtin_name::BuiltinName; +use serde::{Deserialize, Serialize}; /// This struct holds the builtins used in a Cairo program. -#[derive(Debug, Default)] +#[derive(Debug, Default, Serialize, Deserialize)] pub struct BuiltinSegments { pub add_mod: Option, pub bitwise: Option, @@ -80,7 +80,7 @@ mod test_builtin_segments { let pub_data_string = std::fs::read_to_string(&path) .unwrap_or_else(|_| panic!("Unable to read file: {}", path.display())); let pub_data: PublicInput<'_> = - sonic_rs::from_str(&pub_data_string).expect("Unable to parse JSON"); + serde_json::from_str(&pub_data_string).expect("Unable to parse JSON"); let builtin_segments = BuiltinSegments::from_memory_segments(&pub_data.memory_segments); assert_eq!(builtin_segments.add_mod, None); diff --git a/stwo_cairo_prover/crates/prover/src/input/memory.rs b/stwo_cairo_prover/crates/prover/src/input/memory.rs index 27567aeb..5d814b23 100644 --- a/stwo_cairo_prover/crates/prover/src/input/memory.rs +++ b/stwo_cairo_prover/crates/prover/src/input/memory.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::ops::{Deref, DerefMut}; use itertools::Itertools; +use serde::{Deserialize, Serialize}; use super::vm_import::MemoryEntry; use crate::components::memory::memory_id_to_big::component::N_M31_IN_SMALL_FELT252; @@ -29,7 +30,7 @@ pub const P_MIN_2: [u32; 8] = [ 0x0800_0000, ]; -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct MemoryConfig { pub small_max: u128, } @@ -49,7 +50,7 @@ impl Default for MemoryConfig { // TODO(spapini): Add U26 for addresses and U128 for range checks. // TODO(spapini): Use some struct for Felt252 (that is still memory efficient). -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct Memory { pub config: MemoryConfig, pub address_to_id: Vec, @@ -184,7 +185,7 @@ impl DerefMut for MemoryBuilder { } pub const LARGE_MEMORY_VALUE_ID_TAG: u32 = 0x4000_0000; -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] pub struct EncodedMemoryValueId(pub u32); impl EncodedMemoryValueId { pub fn encode(value: MemoryValueId) -> EncodedMemoryValueId { diff --git a/stwo_cairo_prover/crates/prover/src/input/mod.rs b/stwo_cairo_prover/crates/prover/src/input/mod.rs index 1bfb4119..fc74e63e 100644 --- a/stwo_cairo_prover/crates/prover/src/input/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/input/mod.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use builtin_segments::BuiltinSegments; use memory::Memory; use prover_types::cpu::M31; +use serde::{Deserialize, Serialize}; use state_transitions::StateTransitions; pub mod builtin_segments; @@ -16,7 +17,7 @@ pub mod vm_import; pub const N_REGISTERS: usize = 3; /// Externally provided inputs for the Stwo prover. -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct ProverInput { pub state_transitions: StateTransitions, pub instruction_by_pc: HashMap, diff --git a/stwo_cairo_prover/crates/prover/src/input/plain.rs b/stwo_cairo_prover/crates/prover/src/input/plain.rs index da3b147a..159ea248 100644 --- a/stwo_cairo_prover/crates/prover/src/input/plain.rs +++ b/stwo_cairo_prover/crates/prover/src/input/plain.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; - use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor; +use cairo_vm::stdlib::collections::HashMap; use cairo_vm::types::layout_name::LayoutName; use cairo_vm::types::relocatable::MaybeRelocatable; use cairo_vm::vm::runners::cairo_runner::CairoRunner; diff --git a/stwo_cairo_prover/crates/prover/src/input/state_transitions.rs b/stwo_cairo_prover/crates/prover/src/input/state_transitions.rs index cc0d844a..d1590c0e 100644 --- a/stwo_cairo_prover/crates/prover/src/input/state_transitions.rs +++ b/stwo_cairo_prover/crates/prover/src/input/state_transitions.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fmt::Display; use prover_types::cpu::CasmState; +use serde::{Deserialize, Serialize}; use stwo_prover::core::fields::m31::M31; use super::decode::Instruction; @@ -19,7 +20,7 @@ const SMALL_MUL_MIN_VALUE: u64 = 0; // TODO (Stav): Ensure it stays synced with that opcdode AIR's list. /// This struct holds the components used to prove the opcodes in a Cairo program, /// and should match the opcode's air used by `stwo-cairo-air`. -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct CasmStatesByOpcode { pub generic_opcode: Vec, pub add_ap_opcode_is_imm_f_op_1_base_fp_f: Vec, @@ -183,7 +184,7 @@ impl From for CasmState { /// Holds the state transitions of a Cairo program, split according to the components responsible /// for proving each transition. -#[derive(Debug, Default)] +#[derive(Debug, Default, Serialize, Deserialize)] pub struct StateTransitions { pub initial_state: CasmState, pub final_state: CasmState, diff --git a/stwo_cairo_prover/crates/prover/src/input/vm_import/mod.rs b/stwo_cairo_prover/crates/prover/src/input/vm_import/mod.rs index f3b187dd..f98842f3 100644 --- a/stwo_cairo_prover/crates/prover/src/input/vm_import/mod.rs +++ b/stwo_cairo_prover/crates/prover/src/input/vm_import/mod.rs @@ -1,11 +1,11 @@ mod json; -use std::collections::HashMap; use std::io::Read; use std::path::Path; use bytemuck::{bytes_of_mut, Pod, Zeroable}; use cairo_vm::air_public_input::{MemorySegmentAddresses, PublicInput}; +use cairo_vm::stdlib::collections::HashMap; use cairo_vm::vm::trace::trace_entry::RelocatedTraceEntry; use json::PrivateInput; use thiserror::Error; @@ -15,6 +15,7 @@ use super::builtin_segments::BuiltinSegments; use super::memory::MemoryConfig; use super::state_transitions::StateTransitions; use super::ProverInput; +use crate::components::memory::MEMORY_ADDRESS_BOUND; use crate::input::memory::MemoryBuilder; #[derive(Debug, Error)] @@ -22,7 +23,7 @@ pub enum VmImportError { #[error("IO error: {0}")] Io(#[from] std::io::Error), #[error("JSON error: {0}")] - Json(#[from] sonic_rs::Error), + Json(#[from] serde_json::Error), #[error("No memory segments")] NoMemorySegments, } @@ -36,9 +37,9 @@ pub fn adapt_vm_output( ) -> Result { let _span = span!(Level::INFO, "adapt_vm_output").entered(); let public_input_string = std::fs::read_to_string(public_input_json)?; - let public_input: PublicInput<'_> = sonic_rs::from_str(&public_input_string)?; + let public_input: PublicInput<'_> = serde_json::from_str(&public_input_string)?; let private_input: PrivateInput = - sonic_rs::from_str(&std::fs::read_to_string(private_input_json)?)?; + serde_json::from_str(&std::fs::read_to_string(private_input_json)?)?; let end_addr = public_input .memory_segments @@ -46,7 +47,7 @@ pub fn adapt_vm_output( .map(|v| v.stop_ptr) .max() .ok_or(VmImportError::NoMemorySegments)?; - assert!(end_addr < (1 << 32)); + assert!(end_addr < MEMORY_ADDRESS_BOUND); let memory_path = private_input_json .parent() diff --git a/stwo_cairo_prover/crates/utils/src/vm_utils.rs b/stwo_cairo_prover/crates/utils/src/vm_utils.rs index c501e60f..adc4b287 100644 --- a/stwo_cairo_prover/crates/utils/src/vm_utils.rs +++ b/stwo_cairo_prover/crates/utils/src/vm_utils.rs @@ -3,9 +3,7 @@ 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::errors::cairo_run_errors::CairoRunError; -use cairo_vm::vm::runners::cairo_pie::CairoPie; -use cairo_vm::vm::runners::cairo_runner::{CairoRunner, RunResources}; +use cairo_vm::vm::runners::cairo_runner::CairoRunner; use clap::{Parser, ValueHint}; use thiserror::Error; use tracing::span; @@ -57,8 +55,8 @@ pub struct VmArgs { pub enum VmError { #[error("Failed to interact with the file system")] IO(#[from] std::io::Error), - #[error("The cairo program execution failed")] - Runner(#[from] CairoRunError), + #[error("Cairo program execution failed: {0}")] + Runner(String), } // This function's logic is copied-then-modified from cairo-vm-cli/src/main.rs:run in cairo-vm repo. @@ -76,24 +74,15 @@ pub fn run_vm(args: &VmArgs) -> Result { ..Default::default() }; - 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 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 = match cairo_runner_result { Ok(runner) => runner, Err(error) => { - eprintln!("{error}"); - return Err(VmError::Runner(error)); + return Err(VmError::Runner(error.to_string())); } };