From c4426ee7f38fd157847c0a2de8029510b1afa288 Mon Sep 17 00:00:00 2001 From: Dori Medini Date: Sun, 26 Jan 2025 16:08:35 +0200 Subject: [PATCH] feat(starknet_os): integrate math hints --- crates/starknet_os/src/hints.rs | 1 + .../starknet_os/src/hints/enum_definition.rs | 8 ++++++++ crates/starknet_os/src/hints/math.rs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 crates/starknet_os/src/hints/math.rs diff --git a/crates/starknet_os/src/hints.rs b/crates/starknet_os/src/hints.rs index 8fdeefcdd3..b441ce3252 100644 --- a/crates/starknet_os/src/hints.rs +++ b/crates/starknet_os/src/hints.rs @@ -10,5 +10,6 @@ pub mod execute_transactions; pub mod execution; pub mod find_element; pub mod kzg; +pub mod math; pub mod stateless_compression; pub mod types; diff --git a/crates/starknet_os/src/hints/enum_definition.rs b/crates/starknet_os/src/hints/enum_definition.rs index 32d5517cd1..edd0ea8777 100644 --- a/crates/starknet_os/src/hints/enum_definition.rs +++ b/crates/starknet_os/src/hints/enum_definition.rs @@ -110,6 +110,7 @@ use crate::hints::execution::{ }; use crate::hints::find_element::search_sorted_optimistic; use crate::hints::kzg::store_da_segment; +use crate::hints::math::log2_ceil; use crate::hints::stateless_compression::{ compression_hint, dictionary_from_bucket, @@ -979,6 +980,13 @@ segments.write_arg(ids.sha256_ptr_end, padding)"#} ids.evals = segments.add_temp_segment() segments.write_arg(ids.kzg_commitments.address_, list(itertools.chain(*kzg_commitments)))"#} + ), + ( + Log2Ceil, + log2_ceil, + indoc! {r#"from starkware.python.math_utils import log2_ceil + ids.res = log2_ceil(ids.value)"# + } ) ); diff --git a/crates/starknet_os/src/hints/math.rs b/crates/starknet_os/src/hints/math.rs new file mode 100644 index 0000000000..f79f9d75a9 --- /dev/null +++ b/crates/starknet_os/src/hints/math.rs @@ -0,0 +1,19 @@ +use std::collections::HashMap; + +use cairo_vm::hint_processor::hint_processor_definition::HintReference; +use cairo_vm::serde::deserialize_program::ApTracking; +use cairo_vm::types::exec_scope::ExecutionScopes; +use cairo_vm::vm::vm_core::VirtualMachine; +use starknet_types_core::felt::Felt; + +use crate::hints::error::HintResult; + +pub fn log2_ceil( + _vm: &mut VirtualMachine, + _exec_scopes: &mut ExecutionScopes, + _ids_data: &HashMap, + _ap_tracking: &ApTracking, + _constants: &HashMap, +) -> HintResult { + todo!() +}