diff --git a/src/appchain.cairo b/src/appchain.cairo index 5b97284..55e592a 100644 --- a/src/appchain.cairo +++ b/src/appchain.cairo @@ -5,6 +5,7 @@ mod errors { const INVALID_ADDRESS: felt252 = 'Config: invalid address'; const SNOS_INVALID_PROGRAM_OUTPUT_SIZE: felt252 = 'snos: invalid output size'; + const SNOS_INVALID_CONFIG_HASH: felt252 = 'snos: invalid config hash'; const SNOS_INVALID_MESSAGES_SEGMENTS: felt252 = 'snos: invalid messages segments'; } @@ -25,6 +26,7 @@ mod appchain { messaging_cpt, messaging_cpt::InternalTrait as MessagingInternal, IMessaging, output_process, output_process::{MessageToStarknet, MessageToAppchain}, }; + use piltover::snos_output::ProgramOutput; use piltover::snos_output; use piltover::state::component::state_cpt::HasComponent; use piltover::state::{state_cpt, state_cpt::InternalTrait as StateInternal, IState}; @@ -129,6 +131,15 @@ mod appchain { errors::SNOS_INVALID_PROGRAM_OUTPUT_SIZE ); + let mut program_output_mut = program_output; + let program_output_struct: ProgramOutput = Serde::deserialize(ref program_output_mut) + .unwrap(); + let (_, current_config_hash): (felt252, felt252) = self.config.program_info.read(); + assert( + program_output_struct.config_hash == current_config_hash, + errors::SNOS_INVALID_CONFIG_HASH + ); + let mut offset = snos_output::HEADER_SIZE; // TODO(#7): We should update SNOS output to have the messages count diff --git a/src/config/component.cairo b/src/config/component.cairo index c2471e8..5f04a95 100644 --- a/src/config/component.cairo +++ b/src/config/component.cairo @@ -20,7 +20,7 @@ mod config_cpt { interface::IOwnable, }; use piltover::config::interface::IConfig; - use starknet::{ContractAddress, get_caller_address}; + use starknet::ContractAddress; use super::errors; #[storage] @@ -79,7 +79,7 @@ mod config_cpt { self .emit( ProgramInfoChanged { - changed_by: get_caller_address(), + changed_by: starknet::get_caller_address(), old_program_hash: old_program_hash, new_program_hash: program_hash, old_config_hash: old_config_hash, diff --git a/tests/test_appchain.cairo b/tests/test_appchain.cairo index 677cccf..c30694a 100644 --- a/tests/test_appchain.cairo +++ b/tests/test_appchain.cairo @@ -136,6 +136,7 @@ fn update_state_ok() { ); let imsg = IMessagingDispatcher { contract_address: appchain.contract_address }; + let iconfig = IConfigDispatcher { contract_address: appchain.contract_address }; let contract_sn = starknet::contract_address_const::< 993696174272377493693496825928908586134624850969 @@ -156,6 +157,13 @@ fn update_state_ok() { ] .span(); + snf::start_prank(CheatTarget::One(appchain.contract_address), c::OWNER()); + iconfig + .set_program_info( + program_hash: 0x11, + config_hash: 2590421891839256512113614983194993186457498815986333310670788206383913888162 + ); + // The state update contains a message to appchain, therefore, before // being sealed, it must be sent first. // The nonce must be adjusted to ensure the correct message to be sent.