Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

GetCurrentAccessDelta #444

Merged
merged 6 commits into from
Apr 28, 2023
Merged
Changes from 4 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
38 changes: 37 additions & 1 deletion crates/cairo-1-hint-processor/src/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ impl Cairo1HintProcessor {
let dict_address = get_ptr(vm, dict_base, &dict_offset)?;
let dict_manager_exec_scope = exec_scopes
.get_ref::<DictManagerExecScope>("dict_manager_exec_scope")
.expect("Trying to read from a dict while dict manager was not initialized.");
.map_err(|_| {
HintError::CustomHint(
"Trying to read from a dict while dict manager was not initialized."
.to_string(),
)
})?;
let dict_infos_index = dict_manager_exec_scope.get_dict_infos_index(dict_address);
vm.insert_value(
cell_ref_to_relocatable(dict_index, vm),
Expand Down Expand Up @@ -533,6 +538,32 @@ impl Cairo1HintProcessor {
println!();
Ok(())
}

fn get_current_access_delta(
&self,
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
index_delta_minus1: &CellRef,
) -> Result<(), HintError> {
let dict_squash_exec_scope: &mut DictSquashExecScope =
exec_scopes.get_mut_ref("dict_squash_exec_scope")?;
let prev_access_index = dict_squash_exec_scope
.pop_current_access_index()
.ok_or(HintError::CustomHint("no accessed index".to_string()))?;
let index_delta_minus_1_val = dict_squash_exec_scope
.current_access_index()
.ok_or(HintError::CustomHint("no index accessed".to_string()))?
.clone()
- prev_access_index
- 1_u32;

vm.insert_value(
cell_ref_to_relocatable(index_delta_minus1, vm),
index_delta_minus_1_val,
)?;

Ok(())
}
}

impl HintProcessor for Cairo1HintProcessor {
Expand Down Expand Up @@ -658,6 +689,11 @@ impl HintProcessor for Cairo1HintProcessor {
a,
b,
}) => self.assert_le_find_small_arcs(vm, exec_scopes, range_check_ptr, a, b),

Hint::Core(CoreHint::GetCurrentAccessDelta { index_delta_minus1 }) => {
self.get_current_access_delta(vm, exec_scopes, index_delta_minus1)
}

_ => todo!(),
}
}
Expand Down