Skip to content

Commit

Permalink
set_decompressed_dst hint
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Dec 20, 2024
1 parent d7f698e commit 2ca652b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion crates/starknet-os/src/hints/compression.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String, HintReference>,
ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> 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(())
}
1 change: 1 addition & 0 deletions crates/starknet-os/src/hints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ fn hints<PCS>() -> HashMap<String, HintImpl> 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
}

Expand Down
3 changes: 3 additions & 0 deletions crates/starknet-os/src/hints/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2ca652b

Please sign in to comment.