Skip to content

Commit 8972bc2

Browse files
authored
feat(op-revm): Add an option to disable "fee-charge" on op-revm (#2980)
An option to disable fee charges, only meaningful on `op-revm` is added, which doesn't charge additional fees, in addition from the default fee from the gas limit and gas price. This is useful for `eth_call`s which should disable all fees. See paradigmxyz/reth#18470
1 parent f4c87bf commit 8972bc2

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

crates/context/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ dev = [
6767
"optional_eip3607",
6868
"optional_no_base_fee",
6969
"optional_priority_fee_check",
70+
"optional_fee_charge",
7071
]
7172
memory_limit = []
7273
optional_balance_check = []
@@ -75,3 +76,4 @@ optional_eip3541 = []
7576
optional_eip3607 = []
7677
optional_no_base_fee = []
7778
optional_priority_fee_check = []
79+
optional_fee_charge = []

crates/context/interface/src/cfg.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub trait Cfg {
5858

5959
/// Returns whether the priority fee check is disabled.
6060
fn is_priority_fee_check_disabled(&self) -> bool;
61+
62+
/// Returns whether the fee charge is disabled.
63+
fn is_fee_charge_disabled(&self) -> bool;
6164
}
6265

6366
/// What bytecode analysis to perform

crates/context/src/cfg.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ pub struct CfgEnv<SPEC = SpecId> {
104104
/// By default, it is set to `false`.
105105
#[cfg(feature = "optional_priority_fee_check")]
106106
pub disable_priority_fee_check: bool,
107+
/// Disables fee charging for transactions.
108+
/// This is useful when executing `eth_call` for example, on OP-chains where setting the base fee
109+
/// to 0 isn't sufficient.
110+
/// By default, it is set to `false`.
111+
#[cfg(feature = "optional_fee_charge")]
112+
pub disable_fee_charge: bool,
107113
}
108114

109115
impl CfgEnv {
@@ -159,6 +165,8 @@ impl<SPEC> CfgEnv<SPEC> {
159165
disable_base_fee: false,
160166
#[cfg(feature = "optional_priority_fee_check")]
161167
disable_priority_fee_check: false,
168+
#[cfg(feature = "optional_fee_charge")]
169+
disable_fee_charge: false,
162170
}
163171
}
164172

@@ -206,6 +214,8 @@ impl<SPEC> CfgEnv<SPEC> {
206214
disable_base_fee: self.disable_base_fee,
207215
#[cfg(feature = "optional_priority_fee_check")]
208216
disable_priority_fee_check: self.disable_priority_fee_check,
217+
#[cfg(feature = "optional_fee_charge")]
218+
disable_fee_charge: self.disable_fee_charge,
209219
}
210220
}
211221

@@ -231,6 +241,13 @@ impl<SPEC> CfgEnv<SPEC> {
231241
self.disable_priority_fee_check = disable;
232242
self
233243
}
244+
245+
/// Sets the disable fee charge flag.
246+
#[cfg(feature = "optional_fee_charge")]
247+
pub fn with_disable_fee_charge(mut self, disable: bool) -> Self {
248+
self.disable_fee_charge = disable;
249+
self
250+
}
234251
}
235252

236253
impl<SPEC: Into<SpecId> + Copy> Cfg for CfgEnv<SPEC> {
@@ -344,6 +361,16 @@ impl<SPEC: Into<SpecId> + Copy> Cfg for CfgEnv<SPEC> {
344361
}
345362
}
346363
}
364+
365+
fn is_fee_charge_disabled(&self) -> bool {
366+
cfg_if::cfg_if! {
367+
if #[cfg(feature = "optional_fee_charge")] {
368+
self.disable_fee_charge
369+
} else {
370+
false
371+
}
372+
}
373+
}
347374
}
348375

349376
impl<SPEC: Default> Default for CfgEnv<SPEC> {

crates/op-revm/src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
let mut additional_cost = U256::ZERO;
116116

117117
// The L1-cost fee is only computed for Optimism non-deposit transactions.
118-
if !is_deposit {
118+
if !is_deposit && !ctx.cfg().is_fee_charge_disabled() {
119119
// L1 block info is stored in the context for later use.
120120
// and it will be reloaded from the database if it is not for the current block.
121121
if ctx.chain().l2_block != block_number {

0 commit comments

Comments
 (0)