Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add from_address in func compute_message_hash_sn_to_appc #41

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
glihm marked this conversation as resolved.
Show resolved Hide resolved
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