Skip to content

Commit

Permalink
impl missing hint
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Oct 24, 2024
1 parent 1ecf158 commit 5e48450
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions cairo_vm_hints/src/hints/lib/rlp_little/leading_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,35 @@ pub fn hint_expected_leading_zeroes(

Ok(())
}

pub const HINT_EXPECTED_NIBBLE: &str = "key_hex = ids.key_leading_zeroes_nibbles * '0' + hex(ids.key.low + (2 ** 128) * ids.key.high)[2:]\nexpected_nibble = int(key_hex[ids.nibble_index + ids.key_leading_zeroes_nibbles], 16)";

pub fn hint_expected_nibble(
vm: &mut VirtualMachine,
exec_scope: &mut ExecutionScopes,
hint_data: &HintProcessorData,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let key_low: u128 = utils::get_value("key.low", vm, hint_data)?
.try_into()
.unwrap();
let key_high: u128 = utils::get_value("key.high", vm, hint_data)?
.try_into()
.unwrap();
let key_leading_zeroes_nibbles: usize =
utils::get_value("key_leading_zeroes_nibbles", vm, hint_data)?
.try_into()
.unwrap();
let nibble_index: usize = utils::get_value("nibble_index", vm, hint_data)?
.try_into()
.unwrap();

let hex = hex::encode([key_low.to_be_bytes(), key_high.to_be_bytes()].concat());
let nibble_char = format!("{:0width$}{}", "", hex, width = key_leading_zeroes_nibbles)
.chars()
.nth(nibble_index + key_leading_zeroes_nibbles)
.unwrap();
exec_scope.insert_value("expected_nibble", nibble_char.to_digit(16).unwrap());

Ok(())
}
2 changes: 1 addition & 1 deletion lib/rlp_little.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func extract_nibble_from_key_be{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}(
// print(f"key_nibbles: {ids.key_nibbles}")
// print(f"key_leading_zeroes_nibbles: {ids.key_leading_zeroes_nibbles}")
// %}
%{ //TODO
%{
key_hex = ids.key_leading_zeroes_nibbles * '0' + hex(ids.key.low + (2 ** 128) * ids.key.high)[2:]
expected_nibble = int(key_hex[ids.nibble_index + ids.key_leading_zeroes_nibbles], 16)
%}
Expand Down

0 comments on commit 5e48450

Please sign in to comment.