Skip to content

Commit

Permalink
refactoring changes
Browse files Browse the repository at this point in the history
  • Loading branch information
debjit-bw committed Jan 7, 2025
1 parent e403606 commit 7fb7042
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
18 changes: 11 additions & 7 deletions src/evm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ pub fn mint_basefee_to_collector_address<EXT, DB: Database>(
Ok(())
}

/// Returns a configuration environment for the EVM based on the given chain specification and timestamp.
pub fn get_cfg_env(chain_spec: &ChainSpec, timestamp: u64) -> CfgEnv {
let mut cfg = CfgEnv::default().with_chain_id(chain_spec.chain().id());
if !chain_spec.is_shanghai_active_at_timestamp(timestamp) {
// EIP-170 is enabled at the Shanghai Fork on Gnosis Chain
cfg.limit_contract_code_size = Some(usize::MAX);
}
cfg
}

/// Custom EVM configuration
#[derive(Debug, Clone)]
pub struct GnosisEvmConfig {
Expand Down Expand Up @@ -192,13 +202,7 @@ impl ConfigureEvmEnv for GnosisEvmConfig {
attributes: reth_evm::NextBlockEnvAttributes,
) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> {
// configure evm env based on parent block
let mut cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id());
if !self
.chain_spec
.is_shanghai_active_at_timestamp(attributes.timestamp)
{
cfg.limit_contract_code_size = Some(usize::MAX);
}
let cfg = get_cfg_env(&self.chain_spec, attributes.timestamp);

// ensure we're not missing any timestamp based hardforks
let spec_id = revm_spec_by_timestamp_after_merge(&self.chain_spec, attributes.timestamp);
Expand Down
10 changes: 2 additions & 8 deletions src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern crate alloc;
use crate::evm_config::get_cfg_env;
use crate::evm_config::GnosisEvmConfig;

use crate::gnosis::apply_post_block_system_calls;
Expand Down Expand Up @@ -26,7 +27,6 @@ use reth_node_ethereum::BasicBlockExecutorProvider;
use reth_primitives::EthPrimitives;
use reth_primitives::{BlockWithSenders, Receipt};
use reth_revm::db::State;
use revm_primitives::CfgEnv;
use revm_primitives::{
db::{Database, DatabaseCommit},
BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState, U256,
Expand Down Expand Up @@ -141,13 +141,7 @@ where
///
/// Caution: this does not initialize the tx environment.
fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg {
let mut cfg_env = CfgEnv::default().with_chain_id(self.chain_spec.chain().id());
if !self
.chain_spec
.is_shanghai_active_at_timestamp(header.timestamp)
{
cfg_env.limit_contract_code_size = Some(usize::MAX);
}
let cfg_env = get_cfg_env(&self.chain_spec, header.timestamp);

let mut cfg = CfgEnvWithHandlerCfg::new(cfg_env, Default::default());
let mut block_env = BlockEnv::default();
Expand Down

0 comments on commit 7fb7042

Please sign in to comment.