Skip to content

Commit

Permalink
update func compute_message_hash_sn_to_appc
Browse files Browse the repository at this point in the history
  • Loading branch information
suiwater committed Sep 6, 2024
1 parent a40db0b commit aca4c87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
18 changes: 6 additions & 12 deletions src/messaging/component.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 8 additions & 2 deletions src/messaging/hash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<felt252>
from_address: ContractAddress,
to_address: ContractAddress,
selector: felt252,
payload: Span<felt252>,
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 {
Expand Down
4 changes: 2 additions & 2 deletions src/messaging/tests/test_messaging.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit aca4c87

Please sign in to comment.