Skip to content

Commit 3b99e12

Browse files
feat(breaking): add support for hint accessible scopes (#2042)
* feat: add support for hint accessible scopes update changelog * Update vm/src/hint_processor/hint_processor_definition.rs Co-authored-by: Julian Gonzalez Calderon <[email protected]> --------- Co-authored-by: Julian Gonzalez Calderon <[email protected]>
1 parent 7ba282c commit 3b99e12

File tree

7 files changed

+31
-2
lines changed

7 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* feat(BREAKING): add support for accessible scopes in hint processor [#2042](https://github.com/lambdaclass/cairo-vm/pull/2042)
6+
57
* dev: add Memory::get_maybe_relocatable [#2039](https://github.com/lambdaclass/cairo-vm/pull/2039)
68

79
* refactor: remove duplicated get_val function [#2065](https://github.com/lambdaclass/cairo-vm/pull/2065)

hint_accountant/src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,34 @@ fn run() {
5151
}
5252
let mut vm = VirtualMachine::new(false, false);
5353
let mut hint_executor = BuiltinHintProcessor::new_empty();
54-
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
54+
let (
55+
ap_tracking_data,
56+
reference_ids,
57+
references,
58+
mut exec_scopes,
59+
constants,
60+
accessible_scopes,
61+
) = (
5562
ApTracking::default(),
5663
HashMap::new(),
5764
Vec::new(),
5865
ExecutionScopes::new(),
5966
HashMap::new(),
67+
Vec::new(),
6068
);
6169
let missing_hints: HashSet<_> = whitelists
6270
.into_iter()
6371
.flatten()
6472
.map(|ahe| ahe.hint_lines.join("\n"))
6573
.filter(|h| {
6674
let hint_data = hint_executor
67-
.compile_hint(h, &ap_tracking_data, &reference_ids, &references)
75+
.compile_hint(
76+
h,
77+
&ap_tracking_data,
78+
&reference_ids,
79+
&references,
80+
&accessible_scopes,
81+
)
6882
.expect("this implementation is infallible");
6983
matches!(
7084
hint_executor.execute_hint(&mut vm, &mut exec_scopes, &hint_data, &constants,),

vm/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub struct HintProcessorData {
132132
pub code: String,
133133
pub ap_tracking: ApTracking,
134134
pub ids_data: HashMap<String, HintReference>,
135+
pub accessible_scopes: Vec<String>,
135136
}
136137

137138
impl HintProcessorData {
@@ -140,6 +141,7 @@ impl HintProcessorData {
140141
code,
141142
ap_tracking: ApTracking::default(),
142143
ids_data,
144+
accessible_scopes: vec![],
143145
}
144146
}
145147
}

vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,8 @@ impl HintProcessorLogic for Cairo1HintProcessor {
12631263
_reference_ids: &HashMap<String, usize>,
12641264
//List of all references (key corresponds to element of the previous dictionary)
12651265
_references: &[HintReference],
1266+
// List of accessible scopes in the hint
1267+
_accessible_scopes: &[String],
12661268
) -> Result<Box<dyn Any>, VirtualMachineError> {
12671269
let data = hint_code.parse().ok().and_then(|x: usize| self.hints.get(&x).cloned())
12681270
.ok_or_else(|| VirtualMachineError::CompileHintFail(

vm/src/hint_processor/hint_processor_definition.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ pub trait HintProcessorLogic {
4343
reference_ids: &HashMap<String, usize>,
4444
//List of all references (key corresponds to element of the previous dictionary)
4545
references: &[HintReference],
46+
// List of accessible scopes in the hint
47+
accessible_scopes: &[String],
4648
) -> Result<Box<dyn Any>, VirtualMachineError> {
4749
Ok(any_box!(HintProcessorData {
4850
code: hint_code.to_string(),
4951
ap_tracking: ap_tracking_data.clone(),
5052
ids_data: get_ids_data(reference_ids, references)?,
53+
accessible_scopes: accessible_scopes.to_vec(),
5154
}))
5255
}
5356

vm/src/tests/run_deprecated_contract_class_simplified.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,17 @@ pub fn vm_load_program(
296296
let hint_ap_tracking_data = ApTracking::default();
297297
let reference_ids = HashMap::default();
298298
let references = vec![];
299+
let accessible_scopes = vec![
300+
String::from("__main__"),
301+
String::from("__main__.get_number"),
302+
];
299303
// Compile the hint
300304
let compiled_hint = hint_processor.compile_hint(
301305
hint_code,
302306
&hint_ap_tracking_data,
303307
&reference_ids,
304308
&references,
309+
&accessible_scopes,
305310
)?;
306311
// Create the hint extension
307312
// As the hint from the compiled constract has offset 0, the hint pc will be equal to the loaded contract's program base:

vm/src/vm/runners/cairo_runner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ impl CairoRunner {
654654
&hint.flow_tracking_data.ap_tracking,
655655
&hint.flow_tracking_data.reference_ids,
656656
references,
657+
&hint.accessible_scopes,
657658
)
658659
.map_err(|_| VirtualMachineError::CompileHintFail(hint.code.clone().into()))
659660
})

0 commit comments

Comments
 (0)