Skip to content

Commit

Permalink
add from_address in func compute_message_hash_sn_to_appc (#41)
Browse files Browse the repository at this point in the history
* update func compute_message_hash_sn_to_appc

* update comment
  • Loading branch information
suiwater authored Sep 9, 2024
1 parent a40db0b commit a9c015e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 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
13 changes: 10 additions & 3 deletions src/messaging/hash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 a9c015e

Please sign in to comment.