From 97c3ef91be3c0655b1568cdb1223d18c87944762 Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Tue, 24 Oct 2023 17:53:13 +0300 Subject: [PATCH 1/2] feat(cfg): optionall disable beneficiary reward --- crates/interpreter/Cargo.toml | 1 + crates/primitives/Cargo.toml | 2 ++ crates/primitives/src/env.rs | 15 +++++++++++++++ crates/revm/Cargo.toml | 2 ++ crates/revm/src/evm_impl.rs | 4 +++- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/interpreter/Cargo.toml b/crates/interpreter/Cargo.toml index bc233bec39..155deacb02 100644 --- a/crates/interpreter/Cargo.toml +++ b/crates/interpreter/Cargo.toml @@ -38,3 +38,4 @@ optional_block_gas_limit = ["revm-primitives/optional_block_gas_limit"] optional_eip3607 = ["revm-primitives/optional_eip3607"] optional_gas_refund = ["revm-primitives/optional_gas_refund"] optional_no_base_fee = ["revm-primitives/optional_no_base_fee"] +optional_beneficiary_reward = ["revm-primitives/optional_beneficiary_reward"] diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 2254973b09..7662ded708 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -65,6 +65,7 @@ dev = [ "optional_eip3607", "optional_gas_refund", "optional_no_base_fee", + "optional_beneficiary_reward", ] memory_limit = [] no_gas_measuring = [] @@ -73,6 +74,7 @@ optional_block_gas_limit = [] optional_eip3607 = [] optional_gas_refund = [] optional_no_base_fee = [] +optional_beneficiary_reward = [] # See comments in `revm-precompile` c-kzg = ["dep:c-kzg", "dep:once_cell", "dep:derive_more"] diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index e93c571630..37e576e371 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -283,8 +283,13 @@ pub struct CfgEnv { pub disable_gas_refund: bool, /// Disables base fee checks for EIP-1559 transactions. /// This is useful for testing method calls with zero gas price. + /// By default, it is set to `false`. #[cfg(feature = "optional_no_base_fee")] pub disable_base_fee: bool, + /// Disables the payout of the reward to the beneficiary. + /// By default, it is set to `false`. + #[cfg(feature = "optional_beneficiary_reward")] + pub disable_beneficiary_reward: bool, /// Enables Optimism's execution changes for deposit transactions and fee /// collection. Hot toggling the optimism field gives applications built /// on revm the ability to switch optimism execution on and off at runtime, @@ -346,6 +351,16 @@ impl CfgEnv { false } + #[cfg(feaure = "optional_beneficiary_reward")] + pub fn is_beneficiary_reward_disabled(&self) -> bool { + self.disable_beneficiary_reward + } + + #[cfg(not(feaure = "optional_beneficiary_reward"))] + pub fn is_beneficiary_reward_disabled(&self) -> bool { + false + } + #[cfg(feature = "optimism")] pub fn is_optimism(&self) -> bool { self.optimism diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 984ed9cb55..697de5047b 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -51,6 +51,7 @@ dev = [ "optional_eip3607", "optional_gas_refund", "optional_no_base_fee", + "optional_beneficiary_reward", ] memory_limit = ["revm-interpreter/memory_limit"] no_gas_measuring = ["revm-interpreter/no_gas_measuring"] @@ -59,6 +60,7 @@ optional_block_gas_limit = ["revm-interpreter/optional_block_gas_limit"] optional_eip3607 = ["revm-interpreter/optional_eip3607"] optional_gas_refund = ["revm-interpreter/optional_gas_refund"] optional_no_base_fee = ["revm-interpreter/optional_no_base_fee"] +optional_beneficiary_reward = ["revm-interpreter/optional_beneficiary_reward"] # See comments in `revm-precompile` secp256k1 = ["revm-precompile/secp256k1"] diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 62ef731b71..58dd221fb3 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -348,7 +348,9 @@ impl<'a, GSPEC: Spec + 'static, DB: Database> Transact for EVMImpl<'a handler.reimburse_caller(data, &gas)?; // Reward beneficiary - handler.reward_beneficiary(data, &gas)?; + if !data.env.cfg.is_beneficiary_reward_disabled() { + handler.reward_beneficiary(data, &gas)?; + } // main return handler.main_return(data, call_result, output, &gas) From a5ce8dc10001ba347ab887b42ff6329c1a5a115b Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Tue, 24 Oct 2023 17:57:40 +0300 Subject: [PATCH 2/2] init field in default impl --- crates/primitives/src/env.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 37e576e371..a6b3917d95 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -393,6 +393,8 @@ impl Default for CfgEnv { disable_gas_refund: false, #[cfg(feature = "optional_no_base_fee")] disable_base_fee: false, + #[cfg(feature = "optional_beneficiary_reward")] + disable_beneficiary_reward: false, #[cfg(feature = "optimism")] optimism: false, }