Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
fix: from_address in l1 message calldata (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshalshukla authored Feb 19, 2024
1 parent a332df6 commit 8c498ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,4 @@
- dev: Get the block status from the actual block in get_block_with_tx_hashes
- fix: l1-l2 messaging
- dev : clean contracts and compiled files
- fix: add from_address in calldata of l1 message
12 changes: 11 additions & 1 deletion crates/client/l1-messages/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ pub enum L1EventToTransactionError {
InvalidContractAddress(Felt252WrapperError),
#[error("Failed to convert Entrypoint Selector from L1 Event: `{0}`")]
InvalidEntryPointSelector(Felt252WrapperError),
#[error("Failed to convert From Address from L1 Event: `{0}`")]
InvalidFromAddress(Felt252WrapperError),
#[error("Failed to convert Nonce param from L1 Event: `{0}`")]
InvalidNonce(Felt252WrapperError),
}

pub fn parse_handle_l1_message_transaction(
event: LogMessageToL2Filter,
) -> Result<HandleL1MessageTransaction, L1EventToTransactionError> {
// L1 from address.
let from_address = Felt252Wrapper::try_from(sp_core::U256::from_big_endian(event.from_address.as_bytes()))
.map_err(L1EventToTransactionError::InvalidFromAddress)?;

// L2 contract to call.
let contract_address = Felt252Wrapper::try_from(sp_core::U256(event.to_address.0))
.map_err(L1EventToTransactionError::InvalidContractAddress)?;
Expand All @@ -32,12 +38,16 @@ pub fn parse_handle_l1_message_transaction(
.try_into()
.map_err(L1EventToTransactionError::InvalidNonce)?;

let calldata: Vec<Felt252Wrapper> = event
let event_payload: Vec<Felt252Wrapper> = event
.payload
.iter()
.map(|param| Felt252Wrapper::try_from(sp_core::U256(param.0)))
.collect::<Result<Vec<Felt252Wrapper>, Felt252WrapperError>>()
.map_err(L1EventToTransactionError::InvalidCalldata)?;

let mut calldata: Vec<Felt252Wrapper> = Vec::with_capacity(event.payload.len() + 1);
calldata.push(from_address);
event_payload.iter().collect_into(&mut calldata);

Ok(HandleL1MessageTransaction { nonce, contract_address, entry_point_selector, calldata })
}
2 changes: 2 additions & 0 deletions crates/client/l1-messages/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(iter_collect_into)]

pub mod config;
pub mod error;
pub mod worker;
Expand Down

0 comments on commit 8c498ea

Please sign in to comment.