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

Commit

Permalink
Add assert_all_accesses_used (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
matias-gonz authored Apr 28, 2023
1 parent 5ffa275 commit aca6a5f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/cairo-1-hint-processor/src/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,34 @@ impl Cairo1HintProcessor {
Ok(())
}

fn assert_all_accesses_used(
&self,
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
n_used_accesses: &CellRef,
) -> Result<(), HintError> {
let key = exec_scopes.get::<Felt252>("key")?;
let n = get_cell_val(vm, n_used_accesses)?;

let dict_squash_exec_scope: &mut DictSquashExecScope =
exec_scopes.get_mut_ref("dict_squash_exec_scope")?;

let access_indices_at_key = dict_squash_exec_scope
.access_indices
.get(&key.clone())
.ok_or_else(|| HintError::NoKeyInAccessIndices(key.clone()))?;

if n != Felt252::new(access_indices_at_key.len()) {
return Err(HintError::NumUsedAccessesAssertFail(
n,
access_indices_at_key.len(),
key,
));
}

Ok(())
}

fn should_skip_squash_loop(
&self,
vm: &mut VirtualMachine,
Expand Down Expand Up @@ -679,6 +707,10 @@ impl HintProcessor for Cairo1HintProcessor {
skip_exclude_a_flag,
}) => self.assert_le_if_first_arc_exclueded(vm, skip_exclude_a_flag, exec_scopes),

Hint::Core(CoreHint::AssertAllAccessesUsed { n_used_accesses }) => {
self.assert_all_accesses_used(vm, exec_scopes, n_used_accesses)
}

Hint::Core(CoreHint::AssertLeIsSecondArcExcluded {
skip_exclude_b_minus_a,
}) => self.assert_le_is_second_excluded(vm, skip_exclude_b_minus_a, exec_scopes),
Expand Down

0 comments on commit aca6a5f

Please sign in to comment.