From aca4c87b59d34a7690ebfd93fbac74d6c1aea757 Mon Sep 17 00:00:00 2001 From: water Date: Sat, 7 Sep 2024 00:40:52 +0800 Subject: [PATCH] update func compute_message_hash_sn_to_appc --- src/messaging/component.cairo | 18 ++++++------------ src/messaging/hash.cairo | 10 ++++++++-- src/messaging/tests/test_messaging.cairo | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) 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..870ccb3 100644 --- a/src/messaging/hash.cairo +++ b/src/messaging/hash.cairo @@ -19,9 +19,15 @@ use starknet::ContractAddress; /// /// 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();