Skip to content

Commit

Permalink
fix compute compress_state_updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ftheirs committed Dec 16, 2024
1 parent 0d05fc5 commit c181ef4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions crates/starknet-os/src/hints/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,15 @@ pub fn set_state_updates_start(
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let use_kzg_da_felt = get_integer_from_var_name(vars::ids::USE_KZG_DA, vm, ids_data, ap_tracking)?;
let compress_state_updates =
get_integer_from_var_name(vars::ids::COMPRESS_STATE_UPDATES, vm, ids_data, ap_tracking)?;

// The evaluator handles "complex" expressions and simplifies them.
// Given an expression returns a type-simplified expression and its Cairo type.
// This includes checking types in operations, removing casts, and expanding dot and subscript operators.
// https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/cairo/lang/vm/vm_consts.py#L224
// https://github.com/starkware-libs/cairo-lang/blob/8e11b8cc65ae1d0959328b1b4a40b92df8b58595/src/starkware/cairo/lang/compiler/type_system_visitor.py#L395-L415
// To improve code readability and maintenance, let's define `compress_state_updates` as it's defined in cairo code instead of reading it.
let full_output = get_integer_from_var_name(vars::ids::FULL_OUTPUT, vm, ids_data, ap_tracking)?;
let compress_state_updates = Felt252::ONE - full_output;

let use_kzg_da = if use_kzg_da_felt == Felt252::ONE {
Ok(true)
Expand All @@ -132,8 +139,13 @@ pub fn set_state_updates_start(
Err(HintError::CustomHint("ids.use_kzg_da is not a boolean".to_string().into_boxed_str()))
}?;

// TODO: check why compress_state_updates = 2 :/
let use_compress_state_updates = compress_state_updates == Felt252::ONE;
let use_compress_state_updates = if compress_state_updates == Felt252::ONE {
Ok(true)
} else if compress_state_updates == Felt252::ZERO {
Ok(false)
} else {
Err(HintError::CustomHint("ids.compress_state_updates is not a boolean".to_string().into_boxed_str()))
}?;

if use_kzg_da || use_compress_state_updates {
insert_value_from_var_name(vars::ids::STATE_UPDATES_START, vm.add_memory_segment(), vm, ids_data, ap_tracking)?;
Expand Down
1 change: 1 addition & 0 deletions crates/starknet-os/src/hints/vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub mod ids {
pub const N_ACTUAL_UPDATES: &str = "n_actual_updates";
pub const N_UPDATES_SMALL_PACKING_BOUND: &str =
"starkware.starknet.core.os.state.output.N_UPDATES_SMALL_PACKING_BOUND";
pub const FULL_OUTPUT: &str = "full_output";
}

pub mod constants {
Expand Down

0 comments on commit c181ef4

Please sign in to comment.