From 80879a82fd2435fc55c3091f6cb3b7d9d5f5cd66 Mon Sep 17 00:00:00 2001 From: YairVaknin-starkware Date: Sun, 24 Nov 2024 17:20:02 +0200 Subject: [PATCH 1/3] Changes_for_using_hint_extention_feature --- CHANGELOG.md | 2 ++ .../builtin_hint_processor_definition.rs | 3 +++ .../cairo_1_hint_processor/hint_processor.rs | 4 ++++ .../hint_processor/hint_processor_definition.rs | 1 + .../run_deprecated_contract_class_simplified.rs | 5 +++++ vm/src/types/program.rs | 16 ++++++++-------- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e843ee992..03373a39be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ #### Upcoming Changes #### [2.0.0-rc1] - 2024-11-20 +* chore: [#1855](https://github.com/lambdaclass/cairo-vm/pull/1880): + * Refactor vm crate to make it possible to use hint extension feature for nested programs with hints. * feat: add `EvalCircuit` and `TestLessThanOrEqualAddress` hints [#1843](https://github.com/lambdaclass/cairo-vm/pull/1843) diff --git a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index fcc6ad0dcc..bc1519d5f3 100644 --- a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -180,6 +180,9 @@ impl BuiltinHintProcessor { } impl HintProcessorLogic for BuiltinHintProcessor { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } fn execute_hint( &mut self, vm: &mut VirtualMachine, diff --git a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs index 9b6e4b8651..ae3f16e91d 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs @@ -1286,6 +1286,10 @@ impl HintProcessorLogic for Cairo1HintProcessor { } Ok(()) } + + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } } impl ResourceTracker for Cairo1HintProcessor { diff --git a/vm/src/hint_processor/hint_processor_definition.rs b/vm/src/hint_processor/hint_processor_definition.rs index 496e8b1428..05b1db2cdc 100644 --- a/vm/src/hint_processor/hint_processor_definition.rs +++ b/vm/src/hint_processor/hint_processor_definition.rs @@ -51,6 +51,7 @@ pub trait HintProcessorLogic { })) } + fn as_any_mut(&mut self) -> &mut dyn Any; #[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 diff --git a/vm/src/tests/run_deprecated_contract_class_simplified.rs b/vm/src/tests/run_deprecated_contract_class_simplified.rs index c097cf7428..3b00fc66b2 100644 --- a/vm/src/tests/run_deprecated_contract_class_simplified.rs +++ b/vm/src/tests/run_deprecated_contract_class_simplified.rs @@ -16,6 +16,7 @@ */ use crate::stdlib::{collections::HashMap, prelude::*}; +use crate::stdlib::any::Any; use crate::Felt252; use num_traits::Zero; #[cfg(target_arch = "wasm32")] @@ -123,6 +124,10 @@ impl HintProcessorLogic for SimplifiedOsHintProcessor { code => Err(HintError::UnknownHint(code.to_string().into_boxed_str())), } } + + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } } // Hints & Hint impls diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs index 477f996577..1c97580ee0 100644 --- a/vm/src/types/program.rs +++ b/vm/src/types/program.rs @@ -60,9 +60,9 @@ use arbitrary::{Arbitrary, Unstructured}; // failures. // Fields in `Program` (other than `SharedProgramData` itself) are used by the main logic. #[derive(Clone, Default, Debug, PartialEq, Eq)] -pub(crate) struct SharedProgramData { +pub struct SharedProgramData { pub(crate) data: Vec, - pub(crate) hints_collection: HintsCollection, + pub hints_collection: HintsCollection, pub(crate) main: Option, //start and end labels will only be used in proof-mode pub(crate) start: Option, @@ -70,7 +70,7 @@ pub(crate) struct SharedProgramData { pub(crate) error_message_attributes: Vec, pub(crate) instruction_locations: Option>, pub(crate) identifiers: HashMap, - pub(crate) reference_manager: Vec, + pub reference_manager: Vec, } #[cfg(feature = "test_utils")] @@ -107,13 +107,13 @@ impl<'a> Arbitrary<'a> for SharedProgramData { } #[derive(Clone, Default, Debug, PartialEq, Eq)] -pub(crate) struct HintsCollection { - hints: Vec, +pub struct HintsCollection { + pub hints: Vec, /// This maps a PC to the range of hints in `hints` that correspond to it. #[cfg(not(feature = "extensive_hints"))] pub(crate) hints_ranges: Vec, #[cfg(feature = "extensive_hints")] - pub(crate) hints_ranges: HashMap, + pub hints_ranges: HashMap, } impl HintsCollection { @@ -200,8 +200,8 @@ pub type HintRange = (usize, NonZeroUsize); #[cfg_attr(feature = "test_utils", derive(Arbitrary))] #[derive(Clone, Debug, PartialEq, Eq)] pub struct Program { - pub(crate) shared_program_data: Arc, - pub(crate) constants: HashMap, + pub shared_program_data: Arc, + pub constants: HashMap, pub(crate) builtins: Vec, } From 5b287e4891e6789cb6a00f285b0c5a8423dc9139 Mon Sep 17 00:00:00 2001 From: YairVaknin-starkware Date: Mon, 2 Dec 2024 16:51:35 +0200 Subject: [PATCH 2/3] changelog fix --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2238f6d297..88f3e4b959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,11 @@ * chore: bump pip `cairo-lang` 0.13.3 [#1884](https://github.com/lambdaclass/cairo-vm/pull/1884) -#### [2.0.0-rc1] - 2024-11-20 -* chore: [#1855](https://github.com/lambdaclass/cairo-vm/pull/1880): +* chore: [#1880](https://github.com/lambdaclass/cairo-vm/pull/1880): * Refactor vm crate to make it possible to use hint extension feature for nested programs with hints. +#### [2.0.0-rc1] - 2024-11-20 + * feat: add `EvalCircuit` and `TestLessThanOrEqualAddress` hints [#1843](https://github.com/lambdaclass/cairo-vm/pull/1843) * fix: [#1873](https://github.com/lambdaclass/cairo-vm/pull/1873) From db5e47ac73a13fbb57679934da0a0c346eb9dfd8 Mon Sep 17 00:00:00 2001 From: YairVaknin-starkware Date: Mon, 2 Dec 2024 19:55:22 +0200 Subject: [PATCH 3/3] remove `as_any_mut` --- .../builtin_hint_processor_definition.rs | 3 --- .../hint_processor/cairo_1_hint_processor/hint_processor.rs | 4 ---- vm/src/hint_processor/hint_processor_definition.rs | 1 - vm/src/tests/run_deprecated_contract_class_simplified.rs | 5 ----- 4 files changed, 13 deletions(-) diff --git a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index bc1519d5f3..fcc6ad0dcc 100644 --- a/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -180,9 +180,6 @@ impl BuiltinHintProcessor { } impl HintProcessorLogic for BuiltinHintProcessor { - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } fn execute_hint( &mut self, vm: &mut VirtualMachine, diff --git a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs index ae3f16e91d..9b6e4b8651 100644 --- a/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs +++ b/vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs @@ -1286,10 +1286,6 @@ impl HintProcessorLogic for Cairo1HintProcessor { } Ok(()) } - - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } } impl ResourceTracker for Cairo1HintProcessor { diff --git a/vm/src/hint_processor/hint_processor_definition.rs b/vm/src/hint_processor/hint_processor_definition.rs index 05b1db2cdc..496e8b1428 100644 --- a/vm/src/hint_processor/hint_processor_definition.rs +++ b/vm/src/hint_processor/hint_processor_definition.rs @@ -51,7 +51,6 @@ pub trait HintProcessorLogic { })) } - fn as_any_mut(&mut self) -> &mut dyn Any; #[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 diff --git a/vm/src/tests/run_deprecated_contract_class_simplified.rs b/vm/src/tests/run_deprecated_contract_class_simplified.rs index 3b00fc66b2..c097cf7428 100644 --- a/vm/src/tests/run_deprecated_contract_class_simplified.rs +++ b/vm/src/tests/run_deprecated_contract_class_simplified.rs @@ -16,7 +16,6 @@ */ use crate::stdlib::{collections::HashMap, prelude::*}; -use crate::stdlib::any::Any; use crate::Felt252; use num_traits::Zero; #[cfg(target_arch = "wasm32")] @@ -124,10 +123,6 @@ impl HintProcessorLogic for SimplifiedOsHintProcessor { code => Err(HintError::UnknownHint(code.to_string().into_boxed_str())), } } - - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } } // Hints & Hint impls