Skip to content

Commit 1fabb7c

Browse files
[ENG-2202]: handle InboxMessageDeliveredFromOrigin event (#891)
* InboxMessageDeliveredFromOrigin - translator part * InboxMessageDeliveredFromOrigin - proposer part WIP * InboxMessageDeliveredFromOrigin - proposer part * fix helper * fix script * WIP * fixed outbox execution test * cleanup * attempt to improve test flakyness * PR cleanup * PR cleanup * separate delayed_msgs from partial block --------- Co-authored-by: Eric Velazquez <ericvelmar95@gmail.com>
1 parent 2407da0 commit 1fabb7c

File tree

17 files changed

+540
-293
lines changed

17 files changed

+540
-293
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared/src/types.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ use alloy::{
44
consensus::Eip658Value,
55
hex,
66
network::EthereumWallet,
7-
primitives::{Address, Bloom, Log, B256},
7+
primitives::{Address, Bloom, Bytes, FixedBytes, Log, B256, U256},
88
providers::{
99
fillers::{
1010
BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller,
1111
WalletFiller,
1212
},
1313
Identity, ProviderBuilder, RootProvider,
1414
},
15-
rpc::types::Block,
1615
signers::local::PrivateKeySigner,
1716
};
1817
use async_trait::async_trait;
1918
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
2019
use std::{
20+
collections::HashMap,
2121
fmt::{Display, Formatter},
2222
str::FromStr as _,
2323
};
@@ -28,11 +28,14 @@ pub trait GetBlockRef {
2828
fn block_ref(&self) -> &BlockRef;
2929
}
3030

31+
/// auxiliary data for delayed messages in a hashmap by sequence number to msg contents
32+
pub type DelayedMsgsData = HashMap<U256, Bytes>;
33+
3134
/// A trait for building blocks from the sequencing and settlement chains.
3235
#[async_trait]
3336
pub trait BlockBuilder<T>: Send {
3437
/// Process a single slot
35-
fn build_block(&self, block: &PartialBlock) -> eyre::Result<T>;
38+
fn build_block(&self, block: &PartialBlock, msgs_data: DelayedMsgsData) -> eyre::Result<T>;
3639
}
3740

3841
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
@@ -86,27 +89,16 @@ pub struct Receipt {
8689
}
8790

8891
/// `PartialBlock` contains block transactions, event logs, and metadata
89-
#[allow(missing_docs)]
9092
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
9193
pub struct PartialBlock {
94+
/// reference to the block that this partial block was built from
9295
pub block_ref: BlockRef,
96+
/// hash of the parent block
9397
pub parent_hash: B256,
98+
/// log data
9499
pub logs: Vec<Log>,
95-
}
96-
97-
/// Convert a block and its receipts to a `PartialBlock`
98-
pub fn convert_block_to_partial_block(block: &Block, receipts: &[Receipt]) -> PartialBlock {
99-
let filtered_logs: Vec<Log> =
100-
receipts.iter().flat_map(|receipt| receipt.logs.clone()).collect();
101-
PartialBlock {
102-
block_ref: BlockRef {
103-
number: block.header.number,
104-
hash: block.header.hash,
105-
timestamp: block.header.timestamp,
106-
},
107-
parent_hash: block.header.parent_hash,
108-
logs: filtered_logs,
109-
}
100+
/// associated transaction hashes for each log
101+
pub log_tx_hashes: Vec<FixedBytes<32>>,
110102
}
111103

112104
impl GetBlockRef for PartialBlock {

shared/test-utils/src/nitro_chain.rs

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{chain_info::PRIVATE_KEY, docker::E2EProcess};
44
use alloy::{
55
consensus::{EthereumTxEnvelope, TxEip4844Variant},
66
network::TransactionBuilder,
7-
primitives::{address, Address, Bytes, B256, U256},
7+
primitives::{address, Address, Bytes, B256, U160, U256},
88
providers::{Provider, WalletProvider},
99
};
1010
use contract_bindings::synd::{
@@ -126,6 +126,19 @@ pub struct NitroBlock {
126126
pub timestamp: U256,
127127
}
128128

129+
const L1_TO_L2_ALIAS_OFFSET: Address = address!("0x1111000000000000000000000000000000001111");
130+
/// Computes the L2 alias of an L1 address.
131+
///
132+
/// When a contract on L1 sends a message to L2 via the Inbox, the sender address
133+
/// on L2 is aliased by adding this offset. This prevents address collisions and
134+
/// distinguishes L1-originated messages from native L2 messages.
135+
pub fn apply_l1_to_l2_alias(l1_address: Address) -> Address {
136+
Address::from(
137+
U160::from_be_slice(&l1_address[..])
138+
.wrapping_add(U160::from_be_slice(&L1_TO_L2_ALIAS_OFFSET[..])),
139+
)
140+
}
141+
129142
pub async fn init_withdrawal_tx(
130143
to_address: Address,
131144
withdrawal_value: U256,
@@ -147,51 +160,68 @@ pub async fn init_withdrawal_tx(
147160
Ok(tx)
148161
}
149162

150-
pub async fn execute_withdrawal(
151-
to_address: Address,
152-
withdrawal_value: U256,
153-
bridge_address: Address,
154-
settlement_provider: &FilledProvider,
155-
appchain_provider: &FilledProvider,
156-
) -> eyre::Result<()> {
163+
pub struct ExecuteWithdrawalParams<'a> {
164+
pub to_address: Address,
165+
pub withdrawal_value: U256,
166+
pub appchain_block_hash_to_prove: B256,
167+
pub bridge_address: Address,
168+
pub settlement_provider: &'a FilledProvider,
169+
pub appchain_provider: &'a FilledProvider,
170+
pub l2_sender: Address,
171+
pub send_root_size: u64,
172+
pub withdrawal_position: u64,
173+
}
174+
175+
pub async fn execute_withdrawal(params: ExecuteWithdrawalParams<'_>) {
157176
// Generate proof
158-
let node_interface = NodeInterface::new(NODE_INTERFACE_PRECOMPILE_ADDRESS, &appchain_provider);
159-
let proof = node_interface.constructOutboxProof(1, 0).call().await?;
177+
let node_interface =
178+
NodeInterface::new(NODE_INTERFACE_PRECOMPILE_ADDRESS, &params.appchain_provider);
179+
let proof = node_interface
180+
.constructOutboxProof(params.send_root_size, params.withdrawal_position)
181+
.call()
182+
.await
183+
.unwrap();
160184

161185
// Execute withdrawal
162-
let bridge = IBridge::new(bridge_address, &settlement_provider);
186+
let bridge = IBridge::new(params.bridge_address, &params.settlement_provider);
163187
let outbox = IOutbox::new(
164-
IRollupCore::new(bridge.rollup().call().await?, &settlement_provider)
188+
IRollupCore::new(bridge.rollup().call().await.unwrap(), &params.settlement_provider)
165189
.outbox()
166190
.call()
167-
.await?,
168-
&settlement_provider,
191+
.await
192+
.unwrap(),
193+
&params.settlement_provider,
169194
);
170195

171-
let block: NitroBlock =
172-
appchain_provider.raw_request("eth_getBlockByNumber".into(), ("latest", false)).await?;
196+
let block: NitroBlock = params
197+
.appchain_provider
198+
.raw_request("eth_getBlockByHash".into(), (params.appchain_block_hash_to_prove, false))
199+
.await
200+
.unwrap();
173201

174202
let _ = outbox
175203
.executeTransaction(
176-
proof.proof, // proof
177-
U256::from(0), // index
178-
settlement_provider.default_signer_address(), // l2Sender
179-
to_address, // to
180-
block.number, // l2Block,
181-
block.l1_block_number, // l1Block,
182-
block.timestamp, // l2Timestamp,
183-
withdrawal_value, // value
184-
Bytes::new(), // data (always empty)
204+
proof.proof, // proof
205+
U256::from(params.withdrawal_position), // index
206+
params.l2_sender, // l2Sender
207+
params.to_address, // to
208+
block.number, // l2Block,
209+
block.l1_block_number, // l1Block,
210+
block.timestamp, // l2Timestamp,
211+
params.withdrawal_value, // value
212+
Bytes::new(), // data (always empty)
185213
)
186-
// NOTE: manually setting the nonce shouldn't be necessary, likey an artifact of: https://github.com/alloy-rs/alloy/issues/2668
214+
// NOTE: manually setting the nonce shouldn't be necessary, likely an artifact of: https://github.com/alloy-rs/alloy/issues/2668
187215
.nonce(
188-
settlement_provider
189-
.get_transaction_count(settlement_provider.default_signer_address())
190-
.await?,
216+
params
217+
.settlement_provider
218+
.get_transaction_count(params.settlement_provider.default_signer_address())
219+
.await
220+
.unwrap(),
191221
)
192222
.send()
193-
.await?;
194-
Ok(())
223+
.await
224+
.unwrap();
195225
}
196226

197227
#[allow(dead_code)]

synd-chain-ingestor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ version.workspace = true
1111
[dependencies]
1212
alloy = { workspace = true, features = ["provider-ws"] }
1313
clap = { workspace = true, features = ["derive", "env"] }
14+
contract-bindings = { workspace = true }
1415
derivative = { workspace = true }
1516
eyre = { workspace = true }
1617
fs2 = { workspace = true }

0 commit comments

Comments
 (0)