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

Felt252 dict entry update #443

Merged
merged 5 commits into from
Apr 28, 2023
Merged
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
27 changes: 27 additions & 0 deletions crates/cairo-1-hint-processor/src/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,29 @@ impl Cairo1HintProcessor {
Ok(())
}

fn felt_252_dict_entry_update(
&self,
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
dict_ptr: &ResOperand,
value: &ResOperand,
) -> Result<(), HintError> {
let (dict_base, dict_offset) = extract_buffer(dict_ptr)?;
let dict_address = get_ptr(vm, dict_base, &dict_offset)?;
let key = get_double_deref_val(vm, dict_base, &(dict_offset + Felt252::from(-3)))?;
let value = res_operand_get_val(vm, value)?;
let dict_manager_exec_scope = exec_scopes
.get_mut_ref::<DictManagerExecScope>("dict_manager_exec_scope")
.map_err(|_| {
HintError::CustomHint(
"Trying to write to a dict while dict manager was not initialized.".to_string(),
)
})?;
dict_manager_exec_scope.insert_to_tracker(dict_address, key, value);

Ok(())
}

fn get_current_access_index(
&self,
vm: &mut VirtualMachine,
Expand Down Expand Up @@ -964,6 +987,10 @@ impl HintProcessor for Cairo1HintProcessor {
b,
}) => self.assert_le_find_small_arcs(vm, exec_scopes, range_check_ptr, a, b),

Hint::Core(CoreHint::Felt252DictEntryUpdate { dict_ptr, value }) => {
self.felt_252_dict_entry_update(vm, exec_scopes, dict_ptr, value)
}

Hint::Core(CoreHint::GetCurrentAccessIndex { range_check_ptr }) => {
self.get_current_access_index(vm, exec_scopes, range_check_ptr)
}
Expand Down