Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
213 commits
Select commit Hold shift + click to select a range
08d483d
Add fee config encoding
avilagaston9 Oct 27, 2025
b112619
Add fee config decoder
avilagaston9 Oct 27, 2025
8636b88
Update committer and payload builder
avilagaston9 Oct 28, 2025
8e6392a
Update prover
avilagaston9 Oct 29, 2025
50c85a7
Update state reconstruct
avilagaston9 Oct 29, 2025
e56c0b8
Restore blobs
avilagaston9 Oct 30, 2025
ba0db8e
Fix blobs
avilagaston9 Nov 3, 2025
5a94906
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 3, 2025
9fdd474
make osaka activation time optional
avilagaston9 Nov 3, 2025
ddd16bc
Fix
avilagaston9 Nov 3, 2025
dcefba3
Add measurements state diff vs transaction list
gianbelinche Nov 3, 2025
b357ef3
Update block_vs_state_diff_measurements.md
gianbelinche Nov 3, 2025
7eab9ba
wip: sending messages
avilagaston9 Nov 3, 2025
d5c3c8b
Add erc20 block measurements
gianbelinche Nov 4, 2025
b23ee0b
Add erc20 state diff measurements
gianbelinche Nov 4, 2025
2d0bc2c
Add conclusion
gianbelinche Nov 4, 2025
0eb2ae0
final touches
Nov 4, 2025
e4b6530
Update measurements and code
gianbelinche Nov 4, 2025
3cfbc91
Add erc20 state diff
gianbelinche Nov 4, 2025
3e2258a
Add BalanceDiffs
avilagaston9 Nov 4, 2025
cdea5c3
Add eth transfers blocks
gianbelinche Nov 4, 2025
a37aaf6
Update ETH transfer state diff
gianbelinche Nov 4, 2025
771aa23
Implement verifyMessage
avilagaston9 Nov 4, 2025
4cba453
Fix comments
gianbelinche Nov 5, 2025
00542be
Fix solidity compilation
gianbelinche Nov 5, 2025
5e5e5fd
Add deploy router
gianbelinche Nov 5, 2025
4db8571
wip: update watcher to fetch logs from other L2s
avilagaston9 Nov 5, 2025
9752080
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 5, 2025
fa13fa9
Fix linter
avilagaston9 Nov 5, 2025
2292491
Improve state reconstruct
avilagaston9 Nov 5, 2025
0888af5
Store balance diffs
gianbelinche Nov 5, 2025
b43ff95
Fix decode l2 message from log
gianbelinche Nov 5, 2025
a0b69f7
Improve payload builder
avilagaston9 Nov 5, 2025
a89e614
Update last encoded block size
avilagaston9 Nov 5, 2025
54e7962
Fix L2 watch
gianbelinche Nov 5, 2025
697e655
Remove state diff from codebase
avilagaston9 Nov 5, 2025
270392b
Restore state diff docs
avilagaston9 Nov 6, 2025
96cecbc
Update tests
avilagaston9 Nov 6, 2025
b716604
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 6, 2025
186804e
Fix estimate gas
avilagaston9 Nov 6, 2025
2b2358e
Fix tests
avilagaston9 Nov 6, 2025
1f49e3c
Execute privileged transaction
gianbelinche Nov 6, 2025
32f0de9
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 6, 2025
cfc0cec
Restore state diffs doc name
avilagaston9 Nov 6, 2025
6ea663e
Minor improvements
avilagaston9 Nov 6, 2025
9f474a4
Update docs
avilagaston9 Nov 6, 2025
3ce72a0
Restore blobs
avilagaston9 Nov 6, 2025
9aad9e7
Fix docs CI
avilagaston9 Nov 6, 2025
67b1978
Remove unnecesary deploy constract step
avilagaston9 Nov 7, 2025
b133b30
restore convertion from generic to transaction
avilagaston9 Nov 7, 2025
c11deb2
Inspect node logs
avilagaston9 Nov 7, 2025
d46a397
Send tx to mint eth
gianbelinche Nov 7, 2025
37aa9e0
Restore state reconstruct workflow
avilagaston9 Nov 7, 2025
c975b1e
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 7, 2025
4b6ff13
Create checkpoints in state reconstruct
avilagaston9 Nov 7, 2025
71e260a
Dehardcode l2s rpcs
gianbelinche Nov 7, 2025
d57a8e4
Format
gianbelinche Nov 7, 2025
2a7aa7a
Add prints for debugging
avilagaston9 Nov 7, 2025
7fa554c
Fix rollup store path
avilagaston9 Nov 7, 2025
3f625c4
Build docker image with l2-sql
avilagaston9 Nov 7, 2025
51b7a37
Fix balance diffs double send
gianbelinche Nov 10, 2025
ea040ab
Send balances on verify
gianbelinche Nov 10, 2025
6ac9acc
Add verification of l2 messages
gianbelinche Nov 10, 2025
97f665c
Format
gianbelinche Nov 10, 2025
cd31966
Change default on chain proposer
gianbelinche Nov 10, 2025
8f14e43
Add documentation
gianbelinche Nov 11, 2025
d94dadf
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 11, 2025
fb36d17
Add steps for contract call
gianbelinche Nov 11, 2025
3af87fd
Add troubleshooting
gianbelinche Nov 11, 2025
2786006
Merge branch 'feat/l2/commit_blocks_instead_of_state_diffs' into feat…
gianbelinche Nov 11, 2025
95f33dc
Fix compilation
gianbelinche Nov 11, 2025
e2d1414
Fix
gianbelinche Nov 11, 2025
4445666
Fix tests
gianbelinche Nov 11, 2025
f0b13b7
Fix tests
gianbelinche Nov 11, 2025
9d9da06
Fix clippy
gianbelinche Nov 11, 2025
e0a994c
Add source chain id
gianbelinche Nov 11, 2025
d6e567a
Format
gianbelinche Nov 12, 2025
c2dc3fa
Fix gas price
gianbelinche Nov 12, 2025
827ca13
Update calldata for commit
gianbelinche Nov 12, 2025
7bf7fe8
Test EIP1559_DEFAULT_SERIALIZED_LENGTH constant
avilagaston9 Nov 12, 2025
20007fd
Rename BlobKZGVersionedHash
avilagaston9 Nov 12, 2025
ade2665
Reuse cloned tx
avilagaston9 Nov 12, 2025
dc434fd
Update docs/l2/fundamentals/shared_bridge.md
gianbelinche Nov 12, 2025
8dead17
Break if there is no more space for privileged
avilagaston9 Nov 12, 2025
4f0af0d
Fix based commit
gianbelinche Nov 12, 2025
1d144c2
Merge branch 'feat/l2/shared_bridge' of https://github.com/lambdaclas…
gianbelinche Nov 12, 2025
59b845f
Add sanity check on blocks and fee configs length
avilagaston9 Nov 12, 2025
c17173b
Round metric numbers
avilagaston9 Nov 12, 2025
a5dd91c
Fix default on chain proposer
gianbelinche Nov 12, 2025
167cf9b
Merge branch 'main' into feat/l2/commit_blocks_instead_of_state_diffs
avilagaston9 Nov 12, 2025
5f23e66
Remove log
gianbelinche Nov 12, 2025
fa91e96
Format
gianbelinche Nov 12, 2025
872951b
Fix state diff reconstruct
gianbelinche Nov 12, 2025
7d8c2f3
Merge branch 'feat/l2/commit_blocks_instead_of_state_diffs' into feat…
gianbelinche Nov 12, 2025
b38625b
Fix bridge address
gianbelinche Nov 12, 2025
c554b10
Fix state reconstruct
gianbelinche Nov 12, 2025
ce3e847
Format
gianbelinche Nov 12, 2025
3a5df21
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 12, 2025
a084a77
Add more retries
gianbelinche Nov 12, 2025
ad8a459
Update docs
Nov 12, 2025
6ca55a3
Add more retries
gianbelinche Nov 13, 2025
97a7cfa
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 13, 2025
c50c185
Add log
gianbelinche Nov 13, 2025
3be8496
Add more retries
gianbelinche Nov 13, 2025
6a82086
Solve comments
gianbelinche Nov 13, 2025
f0c197c
Change base dir
gianbelinche Nov 13, 2025
db73197
Remove source chain id
gianbelinche Nov 13, 2025
4ce8a69
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 14, 2025
4aaf120
Fix bridge address
gianbelinche Nov 14, 2025
1c1081c
Update blobs state reconstruct
gianbelinche Nov 14, 2025
8dbba54
Fix lint
gianbelinche Nov 14, 2025
de21ae6
Amp retries
gianbelinche Nov 14, 2025
d669f25
Fix router reverts on random chainid
gianbelinche Nov 14, 2025
722fda1
Solve comments
gianbelinche Nov 14, 2025
eb79078
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 14, 2025
f72bb33
Dont add l2tol2 if chain id doesnt exist
gianbelinche Nov 14, 2025
50c9b28
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 14, 2025
d90ce22
Fix merge
gianbelinche Nov 14, 2025
3900768
Fix when no router
gianbelinche Nov 14, 2025
ef53563
Update blobs
gianbelinche Nov 14, 2025
a5bd8dd
Format
gianbelinche Nov 14, 2025
293c5da
clippy
gianbelinche Nov 14, 2025
8f0a8df
Fix clippy
gianbelinche Nov 15, 2025
1ae37aa
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 17, 2025
78e1ca1
Add more docs
gianbelinche Nov 17, 2025
88e9b24
add more docs
gianbelinche Nov 17, 2025
d70e620
Add image
gianbelinche Nov 25, 2025
42a2e8c
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 25, 2025
8224a1e
Update docs/l2/fundamentals/shared_bridge.md
gianbelinche Nov 26, 2025
8d122a8
Update crates/l2/contracts/src/l1/CommonBridge.sol
gianbelinche Nov 26, 2025
28d793c
Update crates/l2/sequencer/l1_watcher.rs
gianbelinche Nov 26, 2025
4c6f005
Update crates/networking/p2p/rlpx/l2/messages.rs
gianbelinche Nov 26, 2025
f23a1c3
Add balance diff doc
gianbelinche Nov 26, 2025
d19ba0f
Remove context clone
gianbelinche Nov 26, 2025
cf00ad8
Differentiate l1 and l2 privileged
gianbelinche Nov 26, 2025
f821ab0
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 26, 2025
1b2beb9
format
gianbelinche Nov 26, 2025
1fc11bc
Fix lint
gianbelinche Nov 26, 2025
d7b3016
Change function name
gianbelinche Nov 27, 2025
7007be8
Remove unneeded count
gianbelinche Nov 27, 2025
9b52e36
Remove comment
gianbelinche Nov 27, 2025
2f9ee96
Change info level
gianbelinche Nov 27, 2025
3bf6a02
Add not l2 source doc
gianbelinche Nov 27, 2025
6f6ce01
Fix state reconstruct
gianbelinche Nov 27, 2025
3022345
Change privileged tx count position
gianbelinche Nov 27, 2025
f754818
Change address
gianbelinche Nov 27, 2025
c54e022
Change to rex
gianbelinche Nov 27, 2025
0168d2d
Change rest of cast
gianbelinche Nov 27, 2025
453ff15
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 27, 2025
eb6192f
Update crates/l2/contracts/src/l1/interfaces/ICommonBridge.sol
gianbelinche Nov 27, 2025
3485ee7
Update crates/l2/contracts/src/l1/interfaces/ICommonBridge.sol
gianbelinche Nov 27, 2025
ac4e25c
Update crates/l2/contracts/src/l1/CommonBridge.sol
gianbelinche Nov 27, 2025
7894cb8
Fix comments
gianbelinche Nov 27, 2025
4ccbb6a
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Nov 28, 2025
29c01e5
Fix comment
gianbelinche Nov 28, 2025
5c633b1
Fix index bug
gianbelinche Nov 28, 2025
084d8e4
Add shared bridge test
gianbelinche Nov 28, 2025
7a8bb5d
Fix compose
gianbelinche Nov 28, 2025
a2ada1b
Add override shared bridge
gianbelinche Nov 28, 2025
72412d7
Fix workflow
gianbelinche Nov 28, 2025
d98f876
More fix workflow
gianbelinche Nov 28, 2025
8435970
Fix compose
gianbelinche Nov 28, 2025
d0d5dc2
Update high-level overview
avilagaston9 Dec 1, 2025
b56dadd
Update overview
avilagaston9 Dec 1, 2025
98b109b
Fix workflow
gianbelinche Dec 1, 2025
376718d
Fix l2 connection
gianbelinche Dec 1, 2025
615a2f9
format
gianbelinche Dec 1, 2025
45e0fbd
Fix workflow
gianbelinche Dec 1, 2025
5f86e18
Finish updating docs
avilagaston9 Dec 1, 2025
faf6051
Fix env volume
gianbelinche Dec 1, 2025
0c9a9a3
Fix register chain
gianbelinche Dec 1, 2025
92e5987
Fix tests step
gianbelinche Dec 1, 2025
fe14547
Solve comments
gianbelinche Dec 1, 2025
83ff794
Rename l2 to l2 messenger
gianbelinche Dec 1, 2025
0aa27cd
Ignore clippy on test
gianbelinche Dec 1, 2025
02818be
Add contract call test
gianbelinche Dec 1, 2025
bbcdc3a
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Dec 1, 2025
e767d18
Push message hashes in the targeted bridges
avilagaston9 Dec 1, 2025
fc06412
Format code
gianbelinche Dec 1, 2025
cbfb64f
Add migrations doc
gianbelinche Dec 1, 2025
4fcc242
Fix clippy
gianbelinche Dec 1, 2025
48f14ad
Fix messenger doc
gianbelinche Dec 1, 2025
49bd28a
Fix ci
gianbelinche Dec 1, 2025
90b2428
Move shared bridge steps
gianbelinche Dec 1, 2025
278beb7
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Dec 1, 2025
02e6b2c
Add message deadline
avilagaston9 Dec 2, 2025
1fe8c31
Merge branch 'main' into feat/l2/shared_bridge
gianbelinche Dec 3, 2025
6d6197a
Fix conflicts
gianbelinche Dec 3, 2025
d0005ce
Make it compile
avilagaston9 Dec 3, 2025
96abf24
Merge branch 'feat/l2/shared_bridge' into feat/l2/shared_bridge_force…
avilagaston9 Dec 3, 2025
e850dd1
fix: integration tests
avilagaston9 Dec 3, 2025
ff5bdfb
Some fixes
avilagaston9 Dec 4, 2025
675b042
Include chain Id to privileged tx hash
avilagaston9 Dec 5, 2025
677b77b
Merge branch 'main' into feat/l2/shared_bridge_forced_inclusion
avilagaston9 Dec 5, 2025
f31ec03
Fix merge
avilagaston9 Dec 5, 2025
a606234
Simplify diff in messages
avilagaston9 Dec 5, 2025
ef2c83d
Rename l1 rolling hash
avilagaston9 Dec 5, 2025
986c975
Rename rolling hash in program output
avilagaston9 Dec 5, 2025
b820244
Rename privileged to l1_in_message
avilagaston9 Dec 5, 2025
9a5b5ae
Fix name
avilagaston9 Dec 5, 2025
25a5e10
Continue renaming
avilagaston9 Dec 5, 2025
9cadfbb
Continue renaming things
avilagaston9 Dec 5, 2025
cb1d750
Rename l1 out message hashes
avilagaston9 Dec 5, 2025
550649b
Continue renaming
avilagaston9 Dec 5, 2025
7808d4b
Fix clippy
avilagaston9 Dec 5, 2025
5c3181c
Improve router and bridge contracts
avilagaston9 Dec 5, 2025
ad349cd
Uncomment functions
avilagaston9 Dec 5, 2025
2dfe22a
Try to improve onChainProposer
avilagaston9 Dec 5, 2025
28c6502
Some improvements to the onchainProposer contract
avilagaston9 Dec 5, 2025
47607a3
Optimize OnChainProposer bytecode
avilagaston9 Dec 5, 2025
328ddd9
Remove print
avilagaston9 Dec 5, 2025
e4ab30e
Fix path to .env
avilagaston9 Dec 5, 2025
5eedb79
Review committer
avilagaston9 Dec 5, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/pr-main_l1_l2_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ jobs:
- name: Show ENVs
run: |
cat .env
cp .env cmd/.env

- name: Run test
run: |
cd crates/l2
tail -n +1 -f /tmp/ethrex.log &
tail -n +1 -f /tmp/prover.log &
export $(xargs < .env)
PROPOSER_COINBASE_ADDRESS=0x0007a881CD95B1484fca47615B64803dad620C8d \
cargo test l2 --release -- --nocapture --test-threads=1
3 changes: 3 additions & 0 deletions cmd/ethrex/l2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ impl Command {
)
.await?;

let chain_id = store.get_chain_config().chain_id;

let rollup_store =
StoreRollup::new(&store_path.join("rollup_store"), rollup_store_type)?;
rollup_store
Expand Down Expand Up @@ -517,6 +519,7 @@ impl Command {
U256::from(batch_number),
None,
blobs_bundle,
chain_id,
)
.await?;

Expand Down
3 changes: 2 additions & 1 deletion cmd/ethrex/l2/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ const INITIALIZE_ON_CHAIN_PROPOSER_SIGNATURE: &str = "initialize(bool,address,bo
const INITIALIZE_BRIDGE_ADDRESS_SIGNATURE: &str = "initializeBridgeAddress(address)";
const TRANSFER_OWNERSHIP_SIGNATURE: &str = "transferOwnership(address)";
const ACCEPT_OWNERSHIP_SIGNATURE: &str = "acceptOwnership()";
const BRIDGE_INITIALIZER_SIGNATURE: &str = "initialize(address,address,uint256,address)";
const BRIDGE_INITIALIZER_SIGNATURE: &str = "initialize(address,address,uint256,address, uint256)";
const ROUTER_INITIALIZER_SIGNATURE: &str = "initialize(address)";
const ROUTER_REGISTER_SIGNATURE: &str = "register(uint256,address)";

Expand Down Expand Up @@ -1307,6 +1307,7 @@ async fn initialize_contracts(
Value::Address(contract_addresses.on_chain_proposer_address),
Value::Uint(opts.inclusion_max_wait.into()),
Value::Address(contract_addresses.router.unwrap_or_default()),
Value::Uint(genesis.config.chain_id.into()),
];
let bridge_initialization_calldata =
encode_calldata(BRIDGE_INITIALIZER_SIGNATURE, &calldata_values)?;
Expand Down
14 changes: 12 additions & 2 deletions crates/common/types/l2/balance_diff.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bytes::BufMut;
use ethereum_types::U256;
use ethereum_types::{H256, U256};
use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode, error::RLPDecodeError};
use serde::{Deserialize, Serialize};

Expand All @@ -8,19 +8,29 @@ use serde::{Deserialize, Serialize};
pub struct BalanceDiff {
pub chain_id: U256,
pub value: U256,
pub message_hashes: Vec<H256>,
}

impl RLPEncode for BalanceDiff {
fn encode(&self, buf: &mut dyn BufMut) {
self.chain_id.encode(buf);
self.value.encode(buf);
self.message_hashes.encode(buf);
}
}

impl RLPDecode for BalanceDiff {
fn decode_unfinished(rlp: &[u8]) -> Result<(Self, &[u8]), RLPDecodeError> {
let (chain_id, rlp) = U256::decode_unfinished(rlp)?;
let (value, rlp) = U256::decode_unfinished(rlp)?;
Ok((BalanceDiff { chain_id, value }, rlp))
let (message_hashes, rlp) = Vec::<H256>::decode_unfinished(rlp)?;
Ok((
BalanceDiff {
chain_id,
value,
message_hashes,
},
rlp,
))
}
}
6 changes: 3 additions & 3 deletions crates/common/types/l2/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub struct Batch {
pub first_block: u64,
pub last_block: u64,
pub state_root: H256,
pub privileged_transactions_hash: H256,
pub l1_message_hashes: Vec<H256>,
pub l2_message_hashes: Vec<H256>,
pub l1_in_messages_rolling_hash: H256,
pub l2_in_message_rolling_hashes: Vec<(u64, H256)>,
pub l1_out_message_hashes: Vec<H256>,
pub balance_diffs: Vec<BalanceDiff>,
pub blobs_bundle: BlobsBundle,
pub commit_tx: Option<H256>,
Expand Down
1 change: 1 addition & 0 deletions crates/common/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,7 @@ impl PrivilegedL2Transaction {

Some(crate::utils::keccak(
[
U256::from(self.chain_id).to_big_endian().as_ref(),
self.from.as_bytes(),
to.as_bytes(),
&nonce,
Expand Down
2 changes: 2 additions & 0 deletions crates/l2/based/block_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,14 @@ impl BlockFetcher {
batch_number: U256,
commit_tx: H256,
) -> Result<(), BlockFetcherError> {
let chain_id = self.store.get_chain_config().chain_id;
let batch = get_batch(
&self.store,
batch,
batch_number,
Some(commit_tx),
BlobsBundle::default(),
chain_id,
)
.await?;

Expand Down
52 changes: 27 additions & 25 deletions crates/l2/common/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,13 @@ pub fn get_block_l1_messages(receipts: &[Receipt]) -> Vec<L1Message> {
.collect()
}

#[derive(Serialize, Deserialize, Debug)]
pub struct L2MessageProof {
pub batch_number: u64,
pub message_hash: H256,
pub merkle_proof: Vec<H256>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
/// Represents a message from the L2 to another L2
pub struct L2Message {
/// Chain id of the destination chain
pub chain_id: U256,
pub dest_chain_id: U256,
/// Chain id of the source chain
pub source_chain_id: u64,
/// Address that originated the transaction
pub from: Address,
/// Address of the recipient in the destination chain
Expand All @@ -113,17 +108,19 @@ pub struct L2Message {

impl L2Message {
pub fn encode(&self) -> Vec<u8> {
let mut bytes = Vec::new();
bytes.extend_from_slice(&self.chain_id.to_big_endian());
bytes.extend_from_slice(&self.from.to_fixed_bytes());
bytes.extend_from_slice(&self.to.to_fixed_bytes());
bytes.extend_from_slice(&self.value.to_big_endian());
bytes.extend_from_slice(&self.gas_limit.to_big_endian());
bytes.extend_from_slice(&self.data);
bytes
[
U256::from(self.source_chain_id).to_big_endian().as_ref(),
self.from.as_bytes(),
self.to.as_bytes(),
&self.tx_id.to_big_endian(),
&self.value.to_big_endian(),
&self.gas_limit.to_big_endian(),
keccak(&self.data).as_bytes(),
]
.concat()
}
pub fn from_log(log: &ethrex_common::types::Log) -> Option<L2Message> {
let chain_id = U256::from_big_endian(&log.topics.get(1)?.0);
pub fn from_log(log: &ethrex_common::types::Log, source_chain_id: u64) -> Option<L2Message> {
let dest_chain_id = U256::from_big_endian(&log.topics.get(1)?.0);
let from = H256::from_slice(log.data.get(0..32)?);
let from = Address::from_slice(&from.as_fixed_bytes()[12..]);
let to = H256::from_slice(log.data.get(32..64)?);
Expand All @@ -136,7 +133,8 @@ impl L2Message {
let calldata = log.data.get(224..224 + calldata_len.as_usize())?;

Some(L2Message {
chain_id,
dest_chain_id,
source_chain_id,
from,
to,
value,
Expand All @@ -147,7 +145,7 @@ impl L2Message {
}
}

pub fn get_block_l2_messages(receipts: &[Receipt]) -> Vec<L2Message> {
pub fn get_block_l2_out_messages(receipts: &[Receipt], source_chain_id: u64) -> Vec<L2Message> {
receipts
.iter()
.flat_map(|receipt| {
Expand All @@ -159,24 +157,28 @@ pub fn get_block_l2_messages(receipts: &[Receipt]) -> Vec<L2Message> {
&& log.topics.first() == Some(&*L2MESSAGE_EVENT_SELECTOR)
&& log.topics.len() >= 2 // need chainId
})
.filter_map(L2Message::from_log)
.filter_map(|log| L2Message::from_log(log, source_chain_id))
})
.collect()
}

pub fn get_balance_diffs(messages: &[L2Message]) -> Vec<BalanceDiff> {
let mut balance_diffs: BTreeMap<U256, BalanceDiff> = BTreeMap::new();
for message in messages {
let mut value = message.value;
if message.to == BRIDGE_ADDRESS && message.from == BRIDGE_ADDRESS {
continue;
// This is the mint transaction, ignore the value
value = U256::zero();
}
let entry = balance_diffs
.entry(message.chain_id)
.entry(message.dest_chain_id)
.or_insert(BalanceDiff {
chain_id: message.chain_id,
chain_id: message.dest_chain_id,
value: U256::zero(),
message_hashes: Vec::new(),
});
entry.value += message.value;
entry.value += value;
entry.message_hashes.push(get_l2_message_hash(message));
}
balance_diffs.into_values().collect()
}
22 changes: 21 additions & 1 deletion crates/l2/common/src/privileged_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ pub enum PrivilegedTransactionError {
LengthTooLarge(#[from] std::num::TryFromIntError),
}

pub fn get_block_l1_privileged_transactions(
pub fn get_block_l1_in_messages(
txs: &[Transaction],
chain_id: u64,
) -> Vec<PrivilegedL2Transaction> {
txs.iter()
.filter_map(|tx| {
if let Transaction::PrivilegedL2Transaction(tx) = tx {
// The chain id of the L1-in message should match the chain id of the current chain
if tx.chain_id == chain_id {
return Some(tx.clone());
}
Expand All @@ -48,6 +49,25 @@ pub fn get_block_l1_privileged_transactions(
.collect()
}

pub fn get_block_l2_in_messages(
txs: &[Transaction],
chain_id: u64,
) -> Vec<PrivilegedL2Transaction> {
txs.iter()
.filter_map(|tx| {
if let Transaction::PrivilegedL2Transaction(tx) = tx {
// The chain id of the L2-in message is the chain id of the source chain
if tx.chain_id != chain_id {
return Some(tx.clone());
}
None
} else {
None
}
})
.collect()
}

pub fn compute_privileged_transactions_hash(
privileged_transaction_hashes: Vec<H256>,
) -> Result<H256, PrivilegedTransactionError> {
Expand Down
Loading
Loading