Skip to content

Commit

Permalink
Fix: GET_CONTRACT_ADDRESS_STATE_ENTRY assigned to wrong hint
Browse files Browse the repository at this point in the history
This hint is not supposed to allocate a new segment.
  • Loading branch information
odesenfans committed Apr 11, 2024
1 parent 5eec53e commit 4d48ba5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/hints/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use crate::execution::syscall_handler::OsSyscallHandlerWrapper;
use crate::execution::syscall_utils::SyscallSelector;
use crate::hints::types::{DescentMap, PatriciaSkipValidationRunner, Preimage};
use crate::hints::vars;
use crate::hints::vars::constants::BLOCK_HASH_CONTRACT_ADDRESS;
use crate::hints::vars::ids::{
ENTRY_POINT_RETURN_VALUES, EXECUTION_CONTEXT, INITIAL_GAS, REQUIRED_GAS, SELECTOR, SIGNATURE_LEN, SIGNATURE_START,
};
Expand Down Expand Up @@ -229,6 +228,22 @@ pub const GET_CONTRACT_ADDRESS_STATE_ENTRY: &str = indoc! {r#"
# of this function.
ids.state_entry = __dict_manager.get_dict(ids.contract_state_changes)[ids.contract_address]"#
};

pub fn get_contract_address_state_entry(
vm: &mut VirtualMachine,
exec_scopes: &mut ExecutionScopes,
ids_data: &HashMap<String, HintReference>,
ap_tracking: &ApTracking,
_constants: &HashMap<String, Felt252>,
) -> Result<(), HintError> {
let dict_ptr = get_ptr_from_var_name(vars::ids::CONTRACT_STATE_CHANGES, vm, ids_data, ap_tracking)?;
let key = get_integer_from_var_name(vars::ids::CONTRACT_ADDRESS, vm, ids_data, ap_tracking)?;

get_state_entry(dict_ptr, key, vm, exec_scopes, ids_data, ap_tracking)?;

Ok(())
}

fn get_state_entry_and_set_new_state_entry(
dict_ptr: Relocatable,
key: Felt252,
Expand Down Expand Up @@ -262,7 +277,7 @@ pub fn get_block_hash_contract_address_state_entry_and_set_new_state_entry(
let dict_ptr = get_ptr_from_var_name(vars::ids::CONTRACT_STATE_CHANGES, vm, ids_data, ap_tracking)?;
let key = constants
.get(vars::constants::BLOCK_HASH_CONTRACT_ADDRESS)
.ok_or_else(|| HintError::MissingConstant(Box::new(BLOCK_HASH_CONTRACT_ADDRESS)))?;
.ok_or_else(|| HintError::MissingConstant(Box::new(vars::constants::BLOCK_HASH_CONTRACT_ADDRESS)))?;

get_state_entry_and_set_new_state_entry(dict_ptr, *key, vm, exec_scopes, ids_data, ap_tracking)?;

Expand Down Expand Up @@ -1560,8 +1575,8 @@ pub fn write_old_block_to_storage(
let mut execution_helper: ExecutionHelperWrapper = exec_scopes.get(vars::scopes::EXECUTION_HELPER)?;

let block_hash_contract_address = constants
.get(BLOCK_HASH_CONTRACT_ADDRESS)
.ok_or_else(|| HintError::MissingConstant(Box::new(BLOCK_HASH_CONTRACT_ADDRESS)))?;
.get(vars::constants::BLOCK_HASH_CONTRACT_ADDRESS)
.ok_or_else(|| HintError::MissingConstant(Box::new(vars::constants::BLOCK_HASH_CONTRACT_ADDRESS)))?;
let old_block_number = get_integer_from_var_name(vars::ids::OLD_BLOCK_NUMBER, vm, ids_data, ap_tracking)?;
let old_block_hash = get_integer_from_var_name(vars::ids::OLD_BLOCK_HASH, vm, ids_data, ap_tracking)?;

Expand Down
2 changes: 1 addition & 1 deletion src/hints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static HINTS: [(&str, HintImpl); 156] = [
(execution::GEN_CLASS_HASH_ARG, execution::gen_class_hash_arg),
(execution::GEN_SIGNATURE_ARG, execution::gen_signature_arg),
(execution::GET_BLOCK_HASH_CONTRACT_ADDRESS_STATE_ENTRY_AND_SET_NEW_STATE_ENTRY, execution::get_block_hash_contract_address_state_entry_and_set_new_state_entry),
(execution::GET_CONTRACT_ADDRESS_STATE_ENTRY, execution::get_contract_address_state_entry_and_set_new_state_entry),
(execution::GET_CONTRACT_ADDRESS_STATE_ENTRY, execution::get_contract_address_state_entry),
(execution::GET_CONTRACT_ADDRESS_STATE_ENTRY_AND_SET_NEW_STATE_ENTRY, execution::get_contract_address_state_entry_and_set_new_state_entry),
(execution::GET_CONTRACT_ADDRESS_STATE_ENTRY_AND_SET_NEW_STATE_ENTRY_2, execution::get_contract_address_state_entry_and_set_new_state_entry),
(execution::GET_OLD_BLOCK_NUMBER_AND_HASH, execution::get_old_block_number_and_hash),
Expand Down

0 comments on commit 4d48ba5

Please sign in to comment.