diff --git a/src/messaging/component.cairo b/src/messaging/component.cairo index 92758c0..29f18c5 100644 --- a/src/messaging/component.cairo +++ b/src/messaging/component.cairo @@ -168,20 +168,14 @@ mod messaging_cpt { let nonce = self.sn_to_appc_nonce.read() + 1; self.sn_to_appc_nonce.write(nonce); + let from = starknet::get_caller_address(); let message_hash = hash::compute_message_hash_sn_to_appc( - nonce, to_address, selector, payload + from, to_address, selector, payload, nonce ); self .emit( - MessageSent { - message_hash, - from: starknet::get_caller_address(), - to: to_address, - selector, - nonce, - payload, - } + MessageSent { message_hash, from, to: to_address, selector, nonce, payload, } ); self.sn_to_appc_messages.write(message_hash, nonce); @@ -244,7 +238,7 @@ mod messaging_cpt { let from = starknet::get_caller_address(); let message_hash = hash::compute_message_hash_sn_to_appc( - nonce, to_address, selector, payload + from, to_address, selector, payload, nonce ); assert( @@ -273,7 +267,7 @@ mod messaging_cpt { let from = starknet::get_caller_address(); let message_hash = hash::compute_message_hash_sn_to_appc( - nonce, to_address, selector, payload + from, to_address, selector, payload, nonce ); assert( @@ -366,7 +360,7 @@ mod messaging_cpt { let nonce = *m.nonce; let message_hash = hash::compute_message_hash_sn_to_appc( - nonce, to, selector, payload + from, to, selector, payload, nonce ); assert( self.sn_to_appc_messages.read(message_hash).is_non_zero(), diff --git a/src/messaging/hash.cairo b/src/messaging/hash.cairo index 67cd408..7d8633a 100644 --- a/src/messaging/hash.cairo +++ b/src/messaging/hash.cairo @@ -9,19 +9,26 @@ use starknet::ContractAddress; /// /// # Arguments /// -/// * `nonce` - Nonce of the message. +/// * `from_address` - Contract address of the message sender on the Appchain. /// * `to_address` - Contract address to send the message to on the Appchain. /// * `selector` - The `l1_handler` function selector of the contract on the Appchain /// to execute. /// * `payload` - The message payload. +/// * `nonce` - Nonce of the message. /// /// # Returns /// /// The hash of the message from Starknet to the Appchain. fn compute_message_hash_sn_to_appc( - nonce: felt252, to_address: ContractAddress, selector: felt252, payload: Span + from_address: ContractAddress, + to_address: ContractAddress, + selector: felt252, + payload: Span, + nonce: felt252 ) -> felt252 { - let mut hash_data = array![nonce, to_address.into(), selector,]; + let mut hash_data = array![ + from_address.into(), to_address.into(), nonce, selector, payload.len().into(), + ]; let mut i = 0_usize; loop { diff --git a/src/messaging/tests/test_messaging.cairo b/src/messaging/tests/test_messaging.cairo index 7dd1963..2a9ef68 100644 --- a/src/messaging/tests/test_messaging.cairo +++ b/src/messaging/tests/test_messaging.cairo @@ -190,7 +190,7 @@ fn sn_to_appchain_messages_ok() { // Calculate the message_hash let message_hash = hash::compute_message_hash_sn_to_appc( - nonce: 1, to_address: to, :selector, payload: payload.span() + from_address: from, to_address: to, :selector, payload: payload.span(), nonce: 1 ); let is_pending_before = mock.sn_to_appchain_messages(message_hash); assert( @@ -413,7 +413,7 @@ fn process_messages_to_appchain_ok() { }; let _message_hash = hash::compute_message_hash_sn_to_appc( - m.nonce, m.to_address, m.selector, m.payload + m.from_address, m.to_address, m.selector, m.payload, m.nonce ); let messages = array![m].span();