diff --git a/CHANGELOG.md b/CHANGELOG.md index 8724213dd4..efdd337dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ #### Upcoming Changes +* feat(BREAKING): add support for accessible scopes in hint processor [#2042](https://github.com/lambdaclass/cairo-vm/pull/2042) + * dev: add Memory::get_maybe_relocatable [#2039](https://github.com/lambdaclass/cairo-vm/pull/2039) * refactor: remove duplicated get_val function [#2065](https://github.com/lambdaclass/cairo-vm/pull/2065) diff --git a/hint_accountant/src/main.rs b/hint_accountant/src/main.rs index d639dd3e4f..83800a423d 100644 --- a/hint_accountant/src/main.rs +++ b/hint_accountant/src/main.rs @@ -51,12 +51,20 @@ fn run() { } let mut vm = VirtualMachine::new(false, false); let mut hint_executor = BuiltinHintProcessor::new_empty(); - let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = ( + let ( + ap_tracking_data, + reference_ids, + references, + mut exec_scopes, + constants, + accessible_scopes, + ) = ( ApTracking::default(), HashMap::new(), Vec::new(), ExecutionScopes::new(), HashMap::new(), + Vec::new(), ); let missing_hints: HashSet<_> = whitelists .into_iter() @@ -64,7 +72,13 @@ fn run() { .map(|ahe| ahe.hint_lines.join("\n")) .filter(|h| { let hint_data = hint_executor - .compile_hint(h, &ap_tracking_data, &reference_ids, &references) + .compile_hint( + h, + &ap_tracking_data, + &reference_ids, + &references, + &accessible_scopes, + ) .expect("this implementation is infallible"); matches!( hint_executor.execute_hint(&mut vm, &mut exec_scopes, &hint_data, &constants,), 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 f5ae7a96c4..638197c9eb 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 @@ -132,6 +132,7 @@ pub struct HintProcessorData { pub code: String, pub ap_tracking: ApTracking, pub ids_data: HashMap, + pub accessible_scopes: Vec, } impl HintProcessorData { @@ -140,6 +141,7 @@ impl HintProcessorData { code, ap_tracking: ApTracking::default(), ids_data, + accessible_scopes: vec![], } } } 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 9fd5007eef..e79fcdbfab 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 @@ -1263,6 +1263,8 @@ impl HintProcessorLogic for Cairo1HintProcessor { _reference_ids: &HashMap, //List of all references (key corresponds to element of the previous dictionary) _references: &[HintReference], + // List of accessible scopes in the hint + _accessible_scopes: &[String], ) -> Result, VirtualMachineError> { let data = hint_code.parse().ok().and_then(|x: usize| self.hints.get(&x).cloned()) .ok_or_else(|| VirtualMachineError::CompileHintFail( diff --git a/vm/src/hint_processor/hint_processor_definition.rs b/vm/src/hint_processor/hint_processor_definition.rs index d4c871903a..dbd4a8389c 100644 --- a/vm/src/hint_processor/hint_processor_definition.rs +++ b/vm/src/hint_processor/hint_processor_definition.rs @@ -43,11 +43,14 @@ pub trait HintProcessorLogic { reference_ids: &HashMap, //List of all references (key corresponds to element of the previous dictionary) references: &[HintReference], + // List of accessible scopes in the hint + accessible_scopes: &[String], ) -> Result, VirtualMachineError> { Ok(any_box!(HintProcessorData { code: hint_code.to_string(), ap_tracking: ap_tracking_data.clone(), ids_data: get_ids_data(reference_ids, references)?, + accessible_scopes: accessible_scopes.to_vec(), })) } diff --git a/vm/src/tests/run_deprecated_contract_class_simplified.rs b/vm/src/tests/run_deprecated_contract_class_simplified.rs index c097cf7428..d3c07b02a2 100644 --- a/vm/src/tests/run_deprecated_contract_class_simplified.rs +++ b/vm/src/tests/run_deprecated_contract_class_simplified.rs @@ -296,12 +296,17 @@ pub fn vm_load_program( let hint_ap_tracking_data = ApTracking::default(); let reference_ids = HashMap::default(); let references = vec![]; + let accessible_scopes = vec![ + String::from("__main__"), + String::from("__main__.get_number"), + ]; // Compile the hint let compiled_hint = hint_processor.compile_hint( hint_code, &hint_ap_tracking_data, &reference_ids, &references, + &accessible_scopes, )?; // Create the hint extension // As the hint from the compiled constract has offset 0, the hint pc will be equal to the loaded contract's program base: diff --git a/vm/src/vm/runners/cairo_runner.rs b/vm/src/vm/runners/cairo_runner.rs index 1c5fabd466..3435cf00c3 100644 --- a/vm/src/vm/runners/cairo_runner.rs +++ b/vm/src/vm/runners/cairo_runner.rs @@ -654,6 +654,7 @@ impl CairoRunner { &hint.flow_tracking_data.ap_tracking, &hint.flow_tracking_data.reference_ids, references, + &hint.accessible_scopes, ) .map_err(|_| VirtualMachineError::CompileHintFail(hint.code.clone().into())) })