Skip to content

Commit

Permalink
feat(starknet_os): implement compression hint
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavGrs committed Mar 4, 2025
1 parent 13fbe1d commit 2bcc562
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod implementation;
#[cfg(test)]
pub mod tests;
#[allow(dead_code)]
pub mod utils;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{
use cairo_vm::types::relocatable::MaybeRelocatable;
use starknet_types_core::felt::Felt;

use super::utils::compress;
use crate::hints::error::OsHintResult;
use crate::hints::hint_implementation::stateless_compression::utils::TOTAL_N_BUCKETS;
use crate::hints::types::HintArgs;
Expand Down Expand Up @@ -41,8 +42,23 @@ pub(crate) fn get_prev_offset<S: StateReader>(
Ok(())
}

pub(crate) fn compression_hint<S: StateReader>(HintArgs { .. }: HintArgs<'_, S>) -> OsHintResult {
todo!()
pub(crate) fn compression_hint<S: StateReader>(
HintArgs { vm, ids_data, ap_tracking, .. }: HintArgs<'_, S>,
) -> OsHintResult {
let data_start = get_ptr_from_var_name(Ids::DataStart.into(), vm, ids_data, ap_tracking)?;
let data_end = get_ptr_from_var_name(Ids::DataEnd.into(), vm, ids_data, ap_tracking)?;
let data_size = (data_end - data_start)?;

let compressed_dst =
get_ptr_from_var_name(Ids::CompressedDst.into(), vm, ids_data, ap_tracking)?;
let data =
vm.get_integer_range(data_start, data_size)?.into_iter().map(|f| *f).collect::<Vec<_>>();
let compress_result =
compress(&data).into_iter().map(MaybeRelocatable::Int).collect::<Vec<_>>();

vm.write_arg(compressed_dst, &compress_result)?;

Ok(())
}

pub(crate) fn set_decompressed_dst<S: StateReader>(
Expand Down
6 changes: 6 additions & 0 deletions crates/starknet_os/src/hints/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ pub enum Ids {
BucketIndex,
CompiledClass,
CompiledClassFact,
CompressedDst,
CompressedStart,
ContractStateChanges,
DataEnd,
DataStart,
DictPtr,
FullOutput,
Hash,
Expand All @@ -73,8 +76,11 @@ impl From<Ids> for &'static str {
Ids::BucketIndex => "bucket_index",
Ids::CompiledClass => "compiled_class",
Ids::CompiledClassFact => "compiled_class_fact",
Ids::CompressedDst => "compressed_dst",
Ids::CompressedStart => "compressed_start",
Ids::ContractStateChanges => "contract_state_changes",
Ids::DataEnd => "data_end",
Ids::DataStart => "data_start",
Ids::DictPtr => "dict_ptr",
Ids::FullOutput => "full_output",
Ids::Hash => "hash",
Expand Down

0 comments on commit 2bcc562

Please sign in to comment.