From cae850282f81fc415859ab0b7493da63aae8d052 Mon Sep 17 00:00:00 2001 From: Keemosty12 Date: Thu, 13 Nov 2025 09:57:43 +0800 Subject: [PATCH 1/3] fix(op-revm): return error when enveloped_tx is missing --- crates/op-revm/src/handler.rs | 4 +++- crates/op-revm/src/l1block.rs | 10 +++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/op-revm/src/handler.rs b/crates/op-revm/src/handler.rs index 5f4f4ed16d..76f8e3fc3c 100644 --- a/crates/op-revm/src/handler.rs +++ b/crates/op-revm/src/handler.rs @@ -152,7 +152,9 @@ where let mut balance = caller_account.info.balance; if !cfg.is_fee_charge_disabled() { - let additional_cost = chain.tx_cost_with_tx(tx, spec); + let Some(additional_cost) = chain.tx_cost_with_tx(tx, spec) else { + return Err(ERROR::from_string("[OPTIMISM] Failed to load enveloped transaction.".into())); + }; let Some(new_balance) = balance.checked_sub(additional_cost) else { return Err(InvalidTransaction::LackOfFundForMaxFee { fee: Box::new(additional_cost), diff --git a/crates/op-revm/src/l1block.rs b/crates/op-revm/src/l1block.rs index 67f52b6b60..4a36cdf02b 100644 --- a/crates/op-revm/src/l1block.rs +++ b/crates/op-revm/src/l1block.rs @@ -264,15 +264,11 @@ impl L1BlockInfo { /// Calculate additional transaction cost with OpTxTr. /// /// Internally calls [`L1BlockInfo::tx_cost`]. - #[track_caller] - pub fn tx_cost_with_tx(&mut self, tx: impl OpTxTr, spec: OpSpecId) -> U256 { + pub fn tx_cost_with_tx(&mut self, tx: impl OpTxTr, spec: OpSpecId) -> Option { // account for additional cost of l1 fee and operator fee - let enveloped_tx = tx - .enveloped_tx() - .expect("all not deposit tx have enveloped tx") - .clone(); + let enveloped_tx = tx.enveloped_tx().cloned()?; let gas_limit = U256::from(tx.gas_limit()); - self.tx_cost(&enveloped_tx, gas_limit, spec) + Some(self.tx_cost(&enveloped_tx, gas_limit, spec)) } /// Calculate additional transaction cost. From 1917b2bbe84ea58be31b02799fa1a178aecadfab Mon Sep 17 00:00:00 2001 From: Keemosty12 Date: Thu, 13 Nov 2025 10:08:38 +0800 Subject: [PATCH 2/3] fmt --- crates/op-revm/src/handler.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/op-revm/src/handler.rs b/crates/op-revm/src/handler.rs index 76f8e3fc3c..cb3dd27764 100644 --- a/crates/op-revm/src/handler.rs +++ b/crates/op-revm/src/handler.rs @@ -153,7 +153,9 @@ where if !cfg.is_fee_charge_disabled() { let Some(additional_cost) = chain.tx_cost_with_tx(tx, spec) else { - return Err(ERROR::from_string("[OPTIMISM] Failed to load enveloped transaction.".into())); + return Err(ERROR::from_string( + "[OPTIMISM] Failed to load enveloped transaction.".into(), + )); }; let Some(new_balance) = balance.checked_sub(additional_cost) else { return Err(InvalidTransaction::LackOfFundForMaxFee { From 319fc71ee2447e3c014235b84a2acb6ace9c12dd Mon Sep 17 00:00:00 2001 From: Keemosty12 Date: Thu, 13 Nov 2025 10:16:17 +0800 Subject: [PATCH 3/3] Remove unnecessary clone --- crates/op-revm/src/l1block.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/op-revm/src/l1block.rs b/crates/op-revm/src/l1block.rs index 4a36cdf02b..3912a789ab 100644 --- a/crates/op-revm/src/l1block.rs +++ b/crates/op-revm/src/l1block.rs @@ -266,9 +266,9 @@ impl L1BlockInfo { /// Internally calls [`L1BlockInfo::tx_cost`]. pub fn tx_cost_with_tx(&mut self, tx: impl OpTxTr, spec: OpSpecId) -> Option { // account for additional cost of l1 fee and operator fee - let enveloped_tx = tx.enveloped_tx().cloned()?; + let enveloped_tx = tx.enveloped_tx()?; let gas_limit = U256::from(tx.gas_limit()); - Some(self.tx_cost(&enveloped_tx, gas_limit, spec)) + Some(self.tx_cost(enveloped_tx, gas_limit, spec)) } /// Calculate additional transaction cost.