From 4f6d4ae0c50c3dd3d1f06c562c08c633fc5d0846 Mon Sep 17 00:00:00 2001 From: Zhang Zhuo Date: Fri, 7 Jun 2024 12:58:57 +0800 Subject: [PATCH] fix: use correct chain id for l1 fee (#1325) --- bus-mapping/src/circuit_input_builder.rs | 9 ++++++++- bus-mapping/src/circuit_input_builder/block.rs | 2 +- bus-mapping/src/circuit_input_builder/transaction.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/bus-mapping/src/circuit_input_builder.rs b/bus-mapping/src/circuit_input_builder.rs index 43df286af0..1d9c582a6e 100644 --- a/bus-mapping/src/circuit_input_builder.rs +++ b/bus-mapping/src/circuit_input_builder.rs @@ -239,7 +239,14 @@ impl<'a> CircuitInputBuilder { ), ); - Transaction::new(call_id, &self.sdb, &mut self.code_db, eth_tx, is_success) + Transaction::new( + call_id, + self.block.chain_id(), + &self.sdb, + &mut self.code_db, + eth_tx, + is_success, + ) } /// Iterate over all generated CallContext RwCounterEndOfReversion diff --git a/bus-mapping/src/circuit_input_builder/block.rs b/bus-mapping/src/circuit_input_builder/block.rs index 2582f44af4..d13d4433f3 100644 --- a/bus-mapping/src/circuit_input_builder/block.rs +++ b/bus-mapping/src/circuit_input_builder/block.rs @@ -292,7 +292,7 @@ impl Block { self.relax_mode } - /// .. + /// State root after all blocks in this chunk pub fn end_state_root(&self) -> Word { self.headers .last_key_value() diff --git a/bus-mapping/src/circuit_input_builder/transaction.rs b/bus-mapping/src/circuit_input_builder/transaction.rs index 4d5c780ccf..deb7b3a613 100644 --- a/bus-mapping/src/circuit_input_builder/transaction.rs +++ b/bus-mapping/src/circuit_input_builder/transaction.rs @@ -283,12 +283,13 @@ impl Transaction { /// Create a new Self. pub fn new( call_id: usize, + chain_id: u64, sdb: &StateDB, code_db: &mut CodeDB, eth_tx: ð_types::Transaction, is_success: bool, ) -> Result { - let chain_id = eth_tx.chain_id.unwrap_or_default().as_u64(); + let tx_chain_id = eth_tx.chain_id.unwrap_or_default().as_u64(); let block_num = eth_tx.block_number.unwrap().as_u64(); let (found, _) = sdb.get_account(ð_tx.from); if !found { @@ -354,6 +355,9 @@ impl Transaction { let (l1_fee, l1_fee_committed) = if tx_type.is_l1_msg() { Default::default() } else { + // tx.chain_id can be zero for legacy tx. + // So we should not use that. + // We need to use "global" chain id. ( TxL1Fee::get_current_values_from_state_db(sdb, chain_id, block_num), TxL1Fee::get_committed_values_from_state_db(sdb, chain_id, block_num), @@ -371,7 +375,7 @@ impl Transaction { Ok(Self { block_num, hash: eth_tx.hash, - chain_id, + chain_id: tx_chain_id, tx_type, rlp_bytes: eth_tx.rlp().to_vec(), rlp_unsigned_bytes: get_rlp_unsigned(eth_tx),