Skip to content

Commit

Permalink
Fix: update WRITE_USE_ZKG_DA_TO_MEM hint
Browse files Browse the repository at this point in the history
The memory offset and the condition used to determine whether to use KZG
DA were modified in 0.13.2.
  • Loading branch information
odesenfans committed Aug 30, 2024
1 parent a08c1c6 commit 0b5b084
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crates/starknet-os/src/hints/block_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,24 @@ pub fn is_leaf(
}

pub const WRITE_USE_ZKG_DA_TO_MEM: &str = indoc! {r#"
memory[fp + 15] = to_felt_or_relocatable(syscall_handler.block_info.use_kzg_da)"#
memory[fp + 18] = to_felt_or_relocatable(syscall_handler.block_info.use_kzg_da and (
not os_input.full_output
))"#
};
pub fn write_use_zkg_da_to_mem(
vm: &mut VirtualMachine,
_exec_scopes: &mut ExecutionScopes,
exec_scopes: &mut ExecutionScopes,
_ids_data: &HashMap<String, HintReference>,
_ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
// TODO: add use_kzg_da to BlockContext
let value = Felt252::ZERO;
let block_context = exec_scopes.get_ref::<BlockContext>(vars::scopes::BLOCK_CONTEXT)?;
let use_kzg_da = block_context.block_info().use_kzg_da;

let os_input: &StarknetOsInput = exec_scopes.get_ref(vars::scopes::OS_INPUT)?;
let full_output = os_input.full_output;

println!("Warning: skipping kzg_da (use_kzg_da = false)");
let use_kzg_da_felt = if use_kzg_da && !full_output { Felt252::ONE } else { Felt252::ZERO };

vm.insert_value((vm.get_fp() + 15)?, value).map_err(HintError::Memory)
vm.insert_value((vm.get_fp() + 18)?, use_kzg_da_felt).map_err(HintError::Memory)
}
1 change: 1 addition & 0 deletions crates/starknet-os/src/io/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct StarknetOsInput {
pub general_config: StarknetGeneralConfig,
pub transactions: Vec<InternalTransaction>,
pub block_hash: Felt252,
pub full_output: bool,
}

impl StarknetOsInput {
Expand Down
1 change: 1 addition & 0 deletions tests/integration/common/block_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ where
general_config,
transactions,
block_hash: Default::default(),
full_output: false,
};

let execution_helper = ExecutionHelperWrapper::new(
Expand Down

0 comments on commit 0b5b084

Please sign in to comment.