Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cfg): optionally disable beneficiary reward #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dev = [
"optional_eip3607",
"optional_gas_refund",
"optional_no_base_fee",
"optional_beneficiary_reward",
]
memory_limit = []
no_gas_measuring = []
Expand All @@ -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"]
17 changes: 17 additions & 0 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -378,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,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down
4 changes: 3 additions & 1 deletion crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,9 @@ impl<'a, GSPEC: Spec + 'static, DB: Database> Transact<DB::Error> 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)
Expand Down