diff --git a/crates/starknet-os/src/hints/compression.rs b/crates/starknet-os/src/hints/compression.rs index 133a0be9..808a34f2 100644 --- a/crates/starknet-os/src/hints/compression.rs +++ b/crates/starknet-os/src/hints/compression.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::get_ptr_from_var_name; +use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{get_integer_from_var_name, get_ptr_from_var_name}; use cairo_vm::hint_processor::hint_processor_definition::HintReference; use cairo_vm::hint_processor::hint_processor_utils::felt_to_usize; use cairo_vm::serde::deserialize_program::ApTracking; @@ -253,3 +253,22 @@ pub fn compress( Ok(()) } + +pub const SET_DECOMPRESSED_DST: &str = indoc! {r#"memory[ids.decompressed_dst] = ids.packed_felt % ids.elm_bound"# +}; + +pub fn set_decompressed_dst( + vm: &mut VirtualMachine, + _exec_scopes: &mut ExecutionScopes, + ids_data: &HashMap, + ap_tracking: &ApTracking, + _constants: &HashMap, +) -> Result<(), HintError> { + let decompressed_dst = get_ptr_from_var_name(vars::ids::DECOMPRESSED_DST, vm, ids_data, ap_tracking)?; + + let packed_felt = get_integer_from_var_name(vars::ids::PACKED_FELT, vm, ids_data, ap_tracking)?.to_biguint(); + let elm_bound = get_integer_from_var_name(vars::ids::ELM_BOUND, vm, ids_data, ap_tracking)?.to_biguint(); + + vm.insert_value(decompressed_dst, Felt252::from(packed_felt % elm_bound))?; + Ok(()) +} diff --git a/crates/starknet-os/src/hints/mod.rs b/crates/starknet-os/src/hints/mod.rs index 4ceedcdb..f98aa2c8 100644 --- a/crates/starknet-os/src/hints/mod.rs +++ b/crates/starknet-os/src/hints/mod.rs @@ -256,6 +256,7 @@ fn hints() -> HashMap where hints.insert(secp::READ_EC_POINT_ADDRESS.into(), secp::read_ec_point_from_address); hints.insert(execute_transactions::SHA2_FINALIZE.into(), execute_transactions::sha2_finalize); hints.insert(compression::COMPRESS.into(), compression::compress); + hints.insert(compression::SET_DECOMPRESSED_DST.into(), compression::set_decompressed_dst); hints } diff --git a/crates/starknet-os/src/hints/vars.rs b/crates/starknet-os/src/hints/vars.rs index e36550be..01eac3c1 100644 --- a/crates/starknet-os/src/hints/vars.rs +++ b/crates/starknet-os/src/hints/vars.rs @@ -166,6 +166,9 @@ pub mod ids { pub const COMPRESSED_DST: &str = "compressed_dst"; pub const DATA_START: &str = "data_start"; pub const DATA_END: &str = "data_end"; + pub const DECOMPRESSED_DST: &str = "decompressed_dst"; + pub const PACKED_FELT: &str = "packed_felt"; + pub const ELM_BOUND: &str = "elm_bound"; } pub mod constants {