Skip to content

feat(breaking): add support for hint accessible scopes #2042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions hint_accountant/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,34 @@ 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()
.flatten()
.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,),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub struct HintProcessorData {
pub code: String,
pub ap_tracking: ApTracking,
pub ids_data: HashMap<String, HintReference>,
pub accessible_scopes: Vec<String>,
}

impl HintProcessorData {
Expand All @@ -140,6 +141,7 @@ impl HintProcessorData {
code,
ap_tracking: ApTracking::default(),
ids_data,
accessible_scopes: vec![],
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ impl HintProcessorLogic for Cairo1HintProcessor {
_reference_ids: &HashMap<String, usize>,
//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<Box<dyn Any>, VirtualMachineError> {
let data = hint_code.parse().ok().and_then(|x: usize| self.hints.get(&x).cloned())
.ok_or_else(|| VirtualMachineError::CompileHintFail(
Expand Down
3 changes: 3 additions & 0 deletions vm/src/hint_processor/hint_processor_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ pub trait HintProcessorLogic {
reference_ids: &HashMap<String, usize>,
//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<Box<dyn Any>, 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(),
}))
}

Expand Down
5 changes: 5 additions & 0 deletions vm/src/tests/run_deprecated_contract_class_simplified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions vm/src/vm/runners/cairo_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
})
Expand Down
Loading