From 90e8ed498770ee808f1490314ecedd07f8b0df09 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 11:55:25 -0300 Subject: [PATCH 01/13] Hash Relocatables over compact form --- vm/src/types/relocatable.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vm/src/types/relocatable.rs b/vm/src/types/relocatable.rs index 14f3c1bbdf..cad22d7c6f 100644 --- a/vm/src/types/relocatable.rs +++ b/vm/src/types/relocatable.rs @@ -1,5 +1,6 @@ use crate::stdlib::{ fmt::{self, Display}, + hash::{Hash, Hasher}, ops::{Add, AddAssign, Sub}, prelude::*, }; @@ -15,12 +16,18 @@ use serde::{Deserialize, Serialize}; use arbitrary::Arbitrary; #[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] -#[derive(Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Copy, Debug, Serialize, Deserialize)] +#[derive(Eq, Ord, PartialEq, PartialOrd, Clone, Copy, Debug, Serialize, Deserialize)] pub struct Relocatable { pub segment_index: isize, pub offset: usize, } +impl Hash for Relocatable { + fn hash(&self, state: &mut H) { + (((self.segment_index as u64) << 48) | (self.offset as u64)).hash(state); + } +} + #[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))] #[derive(Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize)] pub enum MaybeRelocatable { From 5c3a53e99c1f8bb0c6f7d3025d08446d42ae2b00 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 12:18:48 -0300 Subject: [PATCH 02/13] try fxhash --- Cargo.lock | 21 +++++++++++++++++++++ vm/Cargo.toml | 3 +++ vm/src/types/program.rs | 12 +++++++++--- vm/src/vm/vm_core.rs | 4 ++-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54f18a5b90..688fe961d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -714,6 +715,7 @@ dependencies = [ name = "cairo-vm" version = "0.9.1" dependencies = [ + "ahash 0.8.6", "anyhow", "arbitrary", "ark-ff", @@ -725,6 +727,7 @@ dependencies = [ "cairo-lang-casm", "cairo-lang-starknet", "criterion", + "fnv_rs", "generic-array", "hashbrown 0.14.2", "hex", @@ -739,6 +742,7 @@ dependencies = [ "num-traits 0.2.17", "proptest", "rand", + "ritehash", "rstest", "serde", "serde_json", @@ -1161,6 +1165,17 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fnv_rs" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d1a20ad5887f117a162e550abf373f3913617e0e392e3fb859610da7e9092b" +dependencies = [ + "hex", + "paste", + "rustc_version", +] + [[package]] name = "funty" version = "2.0.0" @@ -2181,6 +2196,12 @@ dependencies = [ "subtle", ] +[[package]] +name = "ritehash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80eb5f11ebcdd09266eb7897503d7451c2fceea3881538c63dd2651e2c5ebe0c" + [[package]] name = "rstest" version = "0.17.0" diff --git a/vm/Cargo.toml b/vm/Cargo.toml index ed3e45a2df..09dfb15000 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -40,6 +40,9 @@ hooks = [] print = ["std"] [dependencies] +ahash = "*" +fnv_rs = "*" +ritehash = "*" mimalloc = { workspace = true, optional = true } num-bigint = { workspace = true } rand = { workspace = true } diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index b6ccf89a11..dc75c4ee70 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -104,11 +104,17 @@ impl<'a> Arbitrary<'a> for SharedProgramData { } } +use ritehash::FxHasher; +use std::hash::BuildHasherDefault; + +pub type FxBuildHasher = BuildHasherDefault; +pub type FxHashMap = HashMap; + #[derive(Clone, Default, Debug, PartialEq, Eq)] pub(crate) struct HintsCollection { hints: Vec, /// This maps a PC to the range of hints in `hints` that correspond to it. - pub(crate) hints_ranges: HashMap, + pub(crate) hints_ranges: FxHashMap, } impl HintsCollection { @@ -124,7 +130,7 @@ impl HintsCollection { let Some((max_hint_pc, full_len)) = bounds else { return Ok(HintsCollection { hints: Vec::new(), - hints_ranges: HashMap::new(), + hints_ranges: FxHashMap::default(), }); }; @@ -133,7 +139,7 @@ impl HintsCollection { } let mut hints_values = Vec::with_capacity(full_len); - let mut hints_ranges = HashMap::new(); + let mut hints_ranges = FxHashMap::default(); for (pc, hs) in hints.iter().filter(|(_, hs)| !hs.is_empty()) { let range = ( diff --git a/vm/src/vm/vm_core.rs b/vm/src/vm/vm_core.rs index 8e18713eb1..b20283b2ba 100644 --- a/vm/src/vm/vm_core.rs +++ b/vm/src/vm/vm_core.rs @@ -445,7 +445,7 @@ impl VirtualMachine { hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec>, - hint_ranges: &mut HashMap, + hint_ranges: &mut crate::types::program::FxHashMap, constants: &HashMap, ) -> Result<(), VirtualMachineError> { // Check if there is a hint range for the current pc @@ -518,7 +518,7 @@ impl VirtualMachine { hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec>, - hint_ranges: &mut HashMap, + hint_ranges: &mut crate::types::program::FxHashMap, constants: &HashMap, ) -> Result<(), VirtualMachineError> { self.step_hint( From 43f88ef1077ac67fa3c0d1350c8e0e5a64beb12d Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 12:37:00 -0300 Subject: [PATCH 03/13] try ahash --- vm/src/types/program.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index dc75c4ee70..4fbd6f37ec 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -104,11 +104,15 @@ impl<'a> Arbitrary<'a> for SharedProgramData { } } +/* use ritehash::FxHasher; use std::hash::BuildHasherDefault; pub type FxBuildHasher = BuildHasherDefault; pub type FxHashMap = HashMap; +*/ +use ahash::AHashMap; +pub type FxHashMap = AHashMap; #[derive(Clone, Default, Debug, PartialEq, Eq)] pub(crate) struct HintsCollection { From a36994174dbde9e6664e2ea8332be25a87e3ee38 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 12:39:42 -0300 Subject: [PATCH 04/13] try fnv --- vm/src/types/program.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index 4fbd6f37ec..d1b8b22150 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -111,8 +111,12 @@ use std::hash::BuildHasherDefault; pub type FxBuildHasher = BuildHasherDefault; pub type FxHashMap = HashMap; */ +/* use ahash::AHashMap; pub type FxHashMap = AHashMap; +*/ +use fnv_rs::FnvHashMap; +pub type FxHashMap = FnvHashMap; #[derive(Clone, Default, Debug, PartialEq, Eq)] pub(crate) struct HintsCollection { From e74e133de6ac83ecd6d3d7c37060b8408430b237 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 13:32:34 -0300 Subject: [PATCH 05/13] Revert "try fnv" This reverts commit a36994174dbde9e6664e2ea8332be25a87e3ee38. --- vm/src/types/program.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index d1b8b22150..4fbd6f37ec 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -111,12 +111,8 @@ use std::hash::BuildHasherDefault; pub type FxBuildHasher = BuildHasherDefault; pub type FxHashMap = HashMap; */ -/* use ahash::AHashMap; pub type FxHashMap = AHashMap; -*/ -use fnv_rs::FnvHashMap; -pub type FxHashMap = FnvHashMap; #[derive(Clone, Default, Debug, PartialEq, Eq)] pub(crate) struct HintsCollection { From ed2afee1924c649b20520505c44a7ae5293ca464 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 15:44:50 -0300 Subject: [PATCH 06/13] some cleanup --- Cargo.lock | 19 ------------------- vm/Cargo.toml | 2 -- vm/src/types/program.rs | 22 ++++++---------------- vm/src/vm/vm_core.rs | 26 ++++++++++++++------------ 4 files changed, 20 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 688fe961d2..087c770890 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -727,7 +727,6 @@ dependencies = [ "cairo-lang-casm", "cairo-lang-starknet", "criterion", - "fnv_rs", "generic-array", "hashbrown 0.14.2", "hex", @@ -742,7 +741,6 @@ dependencies = [ "num-traits 0.2.17", "proptest", "rand", - "ritehash", "rstest", "serde", "serde_json", @@ -1165,17 +1163,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fnv_rs" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d1a20ad5887f117a162e550abf373f3913617e0e392e3fb859610da7e9092b" -dependencies = [ - "hex", - "paste", - "rustc_version", -] - [[package]] name = "funty" version = "2.0.0" @@ -2196,12 +2183,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "ritehash" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80eb5f11ebcdd09266eb7897503d7451c2fceea3881538c63dd2651e2c5ebe0c" - [[package]] name = "rstest" version = "0.17.0" diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 09dfb15000..8ef18b4205 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -41,8 +41,6 @@ print = ["std"] [dependencies] ahash = "*" -fnv_rs = "*" -ritehash = "*" mimalloc = { workspace = true, optional = true } num-bigint = { workspace = true } rand = { workspace = true } diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index 4fbd6f37ec..0f57ca731e 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -104,21 +104,11 @@ impl<'a> Arbitrary<'a> for SharedProgramData { } } -/* -use ritehash::FxHasher; -use std::hash::BuildHasherDefault; - -pub type FxBuildHasher = BuildHasherDefault; -pub type FxHashMap = HashMap; -*/ -use ahash::AHashMap; -pub type FxHashMap = AHashMap; - #[derive(Clone, Default, Debug, PartialEq, Eq)] pub(crate) struct HintsCollection { hints: Vec, /// This maps a PC to the range of hints in `hints` that correspond to it. - pub(crate) hints_ranges: FxHashMap, + pub(crate) hints_ranges: HashMap, } impl HintsCollection { @@ -134,7 +124,7 @@ impl HintsCollection { let Some((max_hint_pc, full_len)) = bounds else { return Ok(HintsCollection { hints: Vec::new(), - hints_ranges: FxHashMap::default(), + hints_ranges: HashMap::default(), }); }; @@ -143,7 +133,7 @@ impl HintsCollection { } let mut hints_values = Vec::with_capacity(full_len); - let mut hints_ranges = FxHashMap::default(); + let mut hints_ranges = HashMap::default(); for (pc, hs) in hints.iter().filter(|(_, hs)| !hs.is_empty()) { let range = ( @@ -491,7 +481,7 @@ mod tests { ); assert_eq!( program.shared_program_data.hints_collection.hints_ranges, - HashMap::new() + HashMap::default() ); } @@ -537,7 +527,7 @@ mod tests { ); assert_eq!( program.shared_program_data.hints_collection.hints_ranges, - HashMap::new() + HashMap::default() ); } @@ -1246,7 +1236,7 @@ mod tests { fn default_program() { let hints_collection = HintsCollection { hints: Vec::new(), - hints_ranges: HashMap::new(), + hints_ranges: HashMap::default(), }; let shared_program_data = SharedProgramData { diff --git a/vm/src/vm/vm_core.rs b/vm/src/vm/vm_core.rs index b20283b2ba..abe85def53 100644 --- a/vm/src/vm/vm_core.rs +++ b/vm/src/vm/vm_core.rs @@ -445,7 +445,7 @@ impl VirtualMachine { hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec>, - hint_ranges: &mut crate::types::program::FxHashMap, + hint_ranges: &mut HashMap, constants: &HashMap, ) -> Result<(), VirtualMachineError> { // Check if there is a hint range for the current pc @@ -518,7 +518,7 @@ impl VirtualMachine { hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec>, - hint_ranges: &mut crate::types::program::FxHashMap, + hint_ranges: &mut HashMap, constants: &HashMap, ) -> Result<(), VirtualMachineError> { self.step_hint( @@ -2692,7 +2692,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new(), ), Ok(()) @@ -2922,7 +2922,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new(), ), Ok(()) @@ -3005,7 +3005,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new() ), Ok(()) @@ -3108,7 +3108,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new() ), Ok(()) @@ -3130,7 +3130,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new() ), Ok(()) @@ -3153,7 +3153,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new() ), Ok(()) @@ -3716,10 +3716,12 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut hint_data, - &mut HashMap::from([( + &mut [( Relocatable::from((0, 0)), (0_usize, NonZeroUsize::new(1).unwrap()) - )]), + )] + .into_iter() + .collect(), &HashMap::new(), ), Ok(()) @@ -4354,7 +4356,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new() ), Ok(()) @@ -4440,7 +4442,7 @@ mod tests { &mut hint_processor, exec_scopes_ref!(), &mut Vec::new(), - &mut HashMap::new(), + &mut HashMap::default(), &HashMap::new() ), Ok(()) From 7f87e329ec7775e6b3433f82ffbc6fbda8fccd4c Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 16:00:59 -0300 Subject: [PATCH 07/13] signed --- vm/src/types/relocatable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/types/relocatable.rs b/vm/src/types/relocatable.rs index cad22d7c6f..ee8f539ccb 100644 --- a/vm/src/types/relocatable.rs +++ b/vm/src/types/relocatable.rs @@ -24,7 +24,7 @@ pub struct Relocatable { impl Hash for Relocatable { fn hash(&self, state: &mut H) { - (((self.segment_index as u64) << 48) | (self.offset as u64)).hash(state); + (((self.segment_index as i64) << 48) | (self.offset as i64)).hash(state); } } From 1c497322b866764b566d919b44684b32267606c3 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Tue, 5 Dec 2023 16:30:18 -0300 Subject: [PATCH 08/13] fix version --- vm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 8ef18b4205..14ca70afbb 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -40,7 +40,7 @@ hooks = [] print = ["std"] [dependencies] -ahash = "*" +ahash = { version = "0.8.6", default-features = false } mimalloc = { workspace = true, optional = true } num-bigint = { workspace = true } rand = { workspace = true } From 011ae6feb92d8a85499f6269ccec418bff47d138 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 9 May 2024 08:21:19 -0300 Subject: [PATCH 09/13] Remove mimalloc dep from vm crate --- vm/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 663e543fa8..b4114620fa 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -38,7 +38,6 @@ extensive_hints = [] [dependencies] ahash = { version = "0.8.6", default-features = false } -mimalloc = { workspace = true, optional = true } zip = {version = "0.6.6", optional = true } num-bigint = { workspace = true } rand = { workspace = true } From 650cf9b7ccacbfad9bb8f4865681f7ef450b9ae2 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 9 May 2024 08:27:54 -0300 Subject: [PATCH 10/13] Fix build --- vm/src/vm/vm_core.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vm/src/vm/vm_core.rs b/vm/src/vm/vm_core.rs index f124957a2f..78af932fd6 100644 --- a/vm/src/vm/vm_core.rs +++ b/vm/src/vm/vm_core.rs @@ -3818,9 +3818,7 @@ mod tests { &mut HashMap::from([( Relocatable::from((0, 0)), (0_usize, NonZeroUsize::new(1).unwrap()) - )] - .into_iter() - .collect(), + )]), &HashMap::new(), ), Ok(()) From c42cfc286d5949f1d46cd7cb986f908dda7515f4 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 9 May 2024 08:37:30 -0300 Subject: [PATCH 11/13] Remove extensive_hints feature, always on --- .github/workflows/rust.yml | 32 +------------------ vm/Cargo.toml | 3 -- .../hint_processor_definition.rs | 3 +- ...un_deprecated_contract_class_simplified.rs | 1 - vm/src/vm/vm_core.rs | 19 ----------- 5 files changed, 2 insertions(+), 56 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 390d212339..cf9379854f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -323,7 +323,7 @@ jobs: strategy: fail-fast: false matrix: - special_features: ["", "extensive_hints", "mod_builtin"] + special_features: ["", "mod_builtin"] target: [ test#1, test#2, test#3, test#4, test-no_std#1, test-no_std#2, test-no_std#3, test-no_std#4, test-wasm ] name: Run tests runs-on: ubuntu-22.04 @@ -569,36 +569,6 @@ jobs: path: lcov-test-no_std-.info key: codecov-cache-test-no_std--${{ github.sha }} fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 1) - uses: actions/cache/restore@v3 - with: - path: lcov-test#1-extensive_hints.info - key: codecov-cache-test#1-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 2) - uses: actions/cache/restore@v3 - with: - path: lcov-test#2-extensive_hints.info - key: codecov-cache-test#2-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 3) - uses: actions/cache/restore@v3 - with: - path: lcov-test#3-extensive_hints.info - key: codecov-cache-test#3-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests with stdlib (w/extensive_hints; part. 4) - uses: actions/cache/restore@v3 - with: - path: lcov-test#4-extensive_hints.info - key: codecov-cache-test#4-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - - name: Fetch results for tests without stdlib (w/extensive_hints) - uses: actions/cache/restore@v3 - with: - path: lcov-no_std-extensive_hints.info - key: codecov-cache-test-no_std-extensive_hints-${{ github.sha }} - fail-on-cache-miss: true - name: Upload coverage to codecov.io diff --git a/vm/Cargo.toml b/vm/Cargo.toml index b4114620fa..801af747fb 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -32,9 +32,6 @@ mod_builtin = [] # Note that these features are not retro-compatible with the cairo Python VM. test_utils = ["std", "dep:arbitrary", "starknet-types-core/arbitrary", "starknet-types-core/std"] # This feature will reference every test-oriented feature -# Allows extending the set of hints for the current vm run from within a hint. -# For a usage example checkout vm/src/tests/run_deprecated_contract_class_simplified.rs -extensive_hints = [] [dependencies] ahash = { version = "0.8.6", default-features = false } diff --git a/vm/src/hint_processor/hint_processor_definition.rs b/vm/src/hint_processor/hint_processor_definition.rs index 496e8b1428..309d78fc39 100644 --- a/vm/src/hint_processor/hint_processor_definition.rs +++ b/vm/src/hint_processor/hint_processor_definition.rs @@ -20,7 +20,7 @@ use arbitrary::Arbitrary; pub trait HintProcessorLogic { // Executes the hint which's data is provided by a dynamic structure previously created by compile_hint - // Note: if the `extensive_hints` feature is activated the method used by the vm to execute hints is `execute_hint_extensive`, which's default implementation calls this method. + // Note: the method used by the vm to execute hints is `execute_hint_extensive`, which's default implementation calls this method. fn execute_hint( &mut self, vm: &mut VirtualMachine, @@ -51,7 +51,6 @@ pub trait HintProcessorLogic { })) } - #[cfg(feature = "extensive_hints")] // Executes the hint which's data is provided by a dynamic structure previously created by compile_hint // Also returns a map of hints to be loaded after the current hint is executed // Note: This is the method used by the vm to execute hints, diff --git a/vm/src/tests/run_deprecated_contract_class_simplified.rs b/vm/src/tests/run_deprecated_contract_class_simplified.rs index 6a46e46cb4..1508334f8d 100644 --- a/vm/src/tests/run_deprecated_contract_class_simplified.rs +++ b/vm/src/tests/run_deprecated_contract_class_simplified.rs @@ -1,4 +1,3 @@ -#![cfg(feature = "extensive_hints")] /* This file contains a test that runs the program: cairo_programs/starknet_os_deprecated_cc.cairo For testsing purposes, the contract ran by this program is hardcoded, with values taken from compiling: diff --git a/vm/src/vm/vm_core.rs b/vm/src/vm/vm_core.rs index 78af932fd6..a89ce82651 100644 --- a/vm/src/vm/vm_core.rs +++ b/vm/src/vm/vm_core.rs @@ -1,7 +1,6 @@ use crate::math_utils::signed_felt; use crate::stdlib::{any::Any, borrow::Cow, collections::HashMap, prelude::*}; use crate::types::builtin_name::BuiltinName; -#[cfg(feature = "extensive_hints")] use crate::types::program::HintRange; use crate::{ hint_processor::hint_processor_definition::HintProcessor, @@ -453,23 +452,6 @@ impl VirtualMachine { decode_instruction(instruction) } - #[cfg(not(feature = "extensive_hints"))] - pub fn step_hint( - &mut self, - hint_processor: &mut dyn HintProcessor, - exec_scopes: &mut ExecutionScopes, - hint_datas: &[Box], - constants: &HashMap, - ) -> Result<(), VirtualMachineError> { - for (hint_index, hint_data) in hint_datas.iter().enumerate() { - hint_processor - .execute_hint(self, exec_scopes, hint_data, constants) - .map_err(|err| VirtualMachineError::Hint(Box::new((hint_index, err))))? - } - Ok(()) - } - - #[cfg(feature = "extensive_hints")] pub fn step_hint( &mut self, hint_processor: &mut dyn HintProcessor, @@ -3805,7 +3787,6 @@ mod tests { ((1, 1), (3, 0)) ]; - #[cfg(feature = "extensive_hints")] let mut hint_data = hint_data; //Run Steps From 6b8d53ee9141528ad1c426eeb5497aec16108f04 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 9 May 2024 08:39:51 -0300 Subject: [PATCH 12/13] No derive debug --- Cargo.lock | 3 +-- vm/src/types/relocatable.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76a6d898e6..59c838202c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,7 +46,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" dependencies = [ "cfg-if", - "getrandom", "once_cell", "version_check", "zerocopy", @@ -905,7 +904,7 @@ dependencies = [ name = "cairo-vm" version = "1.0.0-rc2" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.9", "anyhow", "arbitrary", "ark-ff", diff --git a/vm/src/types/relocatable.rs b/vm/src/types/relocatable.rs index dca1012cac..bf01c05e7e 100644 --- a/vm/src/types/relocatable.rs +++ b/vm/src/types/relocatable.rs @@ -29,7 +29,7 @@ impl Hash for Relocatable { } #[cfg_attr(feature = "test_utils", derive(Arbitrary))] -#[derive(Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize)] +#[derive(Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Serialize, Deserialize)] pub enum MaybeRelocatable { RelocatableValue(Relocatable), Int(Felt252), From 6667d8920ac07ca88dcf2b73efcdf71a832f0d87 Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 9 May 2024 08:47:42 -0300 Subject: [PATCH 13/13] Fix build --- Cargo.lock | 9 +++++---- vm/Cargo.toml | 2 +- vm/src/vm/runners/cairo_runner.rs | 33 ------------------------------- 3 files changed, 6 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59c838202c..cccaa891f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,11 +41,12 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.9" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", "zerocopy", @@ -904,7 +905,7 @@ dependencies = [ name = "cairo-vm" version = "1.0.0-rc2" dependencies = [ - "ahash 0.8.9", + "ahash 0.8.11", "anyhow", "arbitrary", "ark-ff", @@ -1603,7 +1604,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.9", + "ahash 0.8.11", "allocator-api2", "serde", ] diff --git a/vm/Cargo.toml b/vm/Cargo.toml index 801af747fb..5e2222ade4 100644 --- a/vm/Cargo.toml +++ b/vm/Cargo.toml @@ -34,7 +34,7 @@ mod_builtin = [] test_utils = ["std", "dep:arbitrary", "starknet-types-core/arbitrary", "starknet-types-core/std"] # This feature will reference every test-oriented feature [dependencies] -ahash = { version = "0.8.6", default-features = false } +ahash = { version = "0.8.11", default-features = false, features = ["runtime-rng"] } zip = {version = "0.6.6", optional = true } num-bigint = { workspace = true } rand = { workspace = true } diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 9592d77f2a..2d6bbc80dc 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -661,11 +661,7 @@ impl CairoRunner { hint_processor: &mut dyn HintProcessor, ) -> Result<(), VirtualMachineError> { let references = &self.program.shared_program_data.reference_manager; - #[cfg(not(feature = "extensive_hints"))] - let hint_data = self.get_hint_data(references, hint_processor)?; - #[cfg(feature = "extensive_hints")] let mut hint_data = self.get_hint_data(references, hint_processor)?; - #[cfg(feature = "extensive_hints")] let mut hint_ranges = self .program .shared_program_data @@ -678,18 +674,7 @@ impl CairoRunner { vm.step( hint_processor, &mut self.exec_scopes, - #[cfg(feature = "extensive_hints")] &mut hint_data, - #[cfg(not(feature = "extensive_hints"))] - self.program - .shared_program_data - .hints_collection - .get_hint_range_for_pc(vm.run_context.pc.offset) - .and_then(|range| { - range.and_then(|(start, length)| hint_data.get(start..start + length.get())) - }) - .unwrap_or(&[]), - #[cfg(feature = "extensive_hints")] &mut hint_ranges, &self.program.constants, )?; @@ -712,27 +697,13 @@ impl CairoRunner { hint_processor: &mut dyn HintProcessor, ) -> Result<(), VirtualMachineError> { let references = &self.program.shared_program_data.reference_manager; - #[cfg(not(feature = "extensive_hints"))] - let hint_data = self.get_hint_data(references, hint_processor)?; - #[cfg(feature = "extensive_hints")] let mut hint_data = self.get_hint_data(references, hint_processor)?; - #[cfg(feature = "extensive_hints")] let mut hint_ranges = self .program .shared_program_data .hints_collection .hints_ranges .clone(); - #[cfg(not(feature = "extensive_hints"))] - let hint_data = &self - .program - .shared_program_data - .hints_collection - .get_hint_range_for_pc(vm.run_context.pc.offset) - .and_then(|range| { - range.and_then(|(start, length)| hint_data.get(start..start + length.get())) - }) - .unwrap_or(&[]); for remaining_steps in (1..=steps).rev() { if self.final_pc.as_ref() == Some(&vm.run_context.pc) { @@ -742,11 +713,7 @@ impl CairoRunner { vm.step( hint_processor, &mut self.exec_scopes, - #[cfg(feature = "extensive_hints")] &mut hint_data, - #[cfg(not(feature = "extensive_hints"))] - hint_data, - #[cfg(feature = "extensive_hints")] &mut hint_ranges, &self.program.constants, )?;