Skip to content

Commit 39f5bd5

Browse files
Add support for accessible scopes
Co-authored-by: Mathieu <60658558+enitrat@users.noreply.github.com>
1 parent 620c68d commit 39f5bd5

File tree

7 files changed

+34
-75
lines changed

7 files changed

+34
-75
lines changed

fuzzer/Cargo.lock

Lines changed: 19 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hint_accountant/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ 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) = (
54+
let (ap_tracking_data, reference_ids, references, mut exec_scopes, accessible_scopes) = (
5555
ApTracking::default(),
5656
HashMap::new(),
5757
Vec::new(),
5858
ExecutionScopes::new(),
59+
Vec::new(),
5960
);
6061
let missing_hints: HashSet<_> = whitelists
6162
.into_iter()
@@ -69,6 +70,7 @@ fn run() {
6970
&reference_ids,
7071
&references,
7172
Default::default(),
73+
&accessible_scopes,
7274
)
7375
.expect("this implementation is infallible");
7476
matches!(

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
@@ -133,6 +133,7 @@ pub struct HintProcessorData {
133133
pub ap_tracking: ApTracking,
134134
pub ids_data: HashMap<String, HintReference>,
135135
pub constants: Rc<HashMap<String, Felt252>>,
136+
pub accessible_scopes: Vec<String>,
136137
}
137138

138139
impl HintProcessorData {
@@ -142,6 +143,7 @@ impl HintProcessorData {
142143
ap_tracking: ApTracking::default(),
143144
ids_data,
144145
constants: Default::default(),
146+
accessible_scopes: Default::default(),
145147
}
146148
}
147149
}

vm/src/hint_processor/cairo_1_hint_processor/hint_processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,7 @@ impl HintProcessorLogic for Cairo1HintProcessor {
12661266
_references: &[HintReference],
12671267
// Identifiers stored in the hint's program.
12681268
_constants: Rc<HashMap<String, Felt252>>,
1269+
_accessible_scopes: &[String],
12691270
) -> Result<Box<dyn Any>, VirtualMachineError> {
12701271
let data = hint_code.parse().ok().and_then(|x: usize| self.hints.get(&x).cloned())
12711272
.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,12 +43,15 @@ pub trait HintProcessorLogic {
4343
references: &[HintReference],
4444
// Identifiers stored in the hint's program.
4545
constants: Rc<HashMap<String, Felt252>>,
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)?,
5153
constants,
54+
accessible_scopes: accessible_scopes.to_vec(),
5255
}))
5356
}
5457

vm/src/tests/run_deprecated_contract_class_simplified.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,18 @@ pub fn vm_load_program(
290290
let hint_ap_tracking_data = ApTracking::default();
291291
let reference_ids = HashMap::default();
292292
let references = vec![];
293+
let accessible_scopes = vec![
294+
String::from("__main__"),
295+
String::from("__main__.get_number"),
296+
];
293297
// Compile the hint
294298
let compiled_hint = hint_processor.compile_hint(
295299
hint_code,
296300
&hint_ap_tracking_data,
297301
&reference_ids,
298302
&references,
299303
Default::default(),
304+
&accessible_scopes,
300305
)?;
301306
// Create the hint extension
302307
// 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
@@ -658,6 +658,7 @@ impl CairoRunner {
658658
&hint.flow_tracking_data.reference_ids,
659659
references,
660660
constants.clone(),
661+
&hint.accessible_scopes,
661662
)
662663
.map_err(|_| VirtualMachineError::CompileHintFail(hint.code.clone().into()))
663664
})

0 commit comments

Comments
 (0)