Skip to content

Commit

Permalink
block_header impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Oct 23, 2024
1 parent e154342 commit 4ca4672
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cairo_vm_hints/src/hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ fn run_hint(
vm, exec_scope, hint_data, constants,
)
}
lib::block_header::HINT_RLP_BIGINT_SIZE => {
lib::block_header::hint_rlp_bigint_size(vm, exec_scope, hint_data, constants)
}
_ => Err(HintError::UnknownHint(
hint_data.code.to_string().into_boxed_str(),
)),
Expand Down
31 changes: 31 additions & 0 deletions cairo_vm_hints/src/hints/lib/block_header/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::HintProcessorData;
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{
get_integer_from_var_name, insert_value_into_ap,
};
use cairo_vm::types::exec_scope::ExecutionScopes;
use cairo_vm::types::relocatable::MaybeRelocatable;
use cairo_vm::vm::{errors::hint_errors::HintError, vm_core::VirtualMachine};
use cairo_vm::Felt252;
use std::cmp::Ordering;
use std::collections::HashMap;

pub const HINT_RLP_BIGINT_SIZE: &str = "memory[ap] = 1 if ids.byte <= 127 else 0";

const FELT_127: Felt252 = Felt252::from_hex_unchecked("0x7F");

pub fn hint_rlp_bigint_size(
vm: &mut VirtualMachine,
_exec_scope: &mut ExecutionScopes,
hint_data: &HintProcessorData,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
match get_integer_from_var_name("byte", vm, &hint_data.ids_data, &hint_data.ap_tracking)?
.cmp(&FELT_127)
{
Ordering::Less | Ordering::Equal => {
insert_value_into_ap(vm, MaybeRelocatable::Int(Felt252::ONE))?
}
Ordering::Greater => insert_value_into_ap(vm, MaybeRelocatable::Int(Felt252::ZERO))?,
};

Ok(())
}

0 comments on commit 4ca4672

Please sign in to comment.