From b97eeda652fcc450b24ca2104b9a0b9b674f6558 Mon Sep 17 00:00:00 2001 From: Debjit Bhowal Date: Tue, 7 Jan 2025 17:42:46 +0530 Subject: [PATCH] fix - Activate EIP-170 at Shanghai (#45) * contract code size limit change * refactoring changes --- src/evm_config.rs | 14 ++++++++++++-- src/execute.rs | 5 ++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/evm_config.rs b/src/evm_config.rs index a9a3b6c..ab214d6 100644 --- a/src/evm_config.rs +++ b/src/evm_config.rs @@ -2,7 +2,7 @@ use alloy_consensus::Header; use alloy_primitives::{Address, U256}; use reth::revm::{inspector_handle_register, Database, GetInspector}; use reth::revm::{Evm, EvmBuilder}; -use reth_chainspec::{ChainSpec, Head}; +use reth_chainspec::{ChainSpec, EthereumHardforks, Head}; use reth_evm::{ConfigureEvm, ConfigureEvmEnv}; use reth_evm_ethereum::{revm_spec, revm_spec_by_timestamp_after_merge}; use reth_primitives::{transaction::FillTxEnv, TransactionSigned}; @@ -56,6 +56,16 @@ pub fn mint_basefee_to_collector_address( 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 { @@ -192,7 +202,7 @@ impl ConfigureEvmEnv for GnosisEvmConfig { attributes: reth_evm::NextBlockEnvAttributes, ) -> Result<(CfgEnvWithHandlerCfg, BlockEnv), Self::Error> { // configure evm env based on parent block - let cfg = CfgEnv::default().with_chain_id(self.chain_spec.chain().id()); + 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); diff --git a/src/execute.rs b/src/execute.rs index 2b49333..a759b1e 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -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; @@ -140,7 +141,9 @@ where /// /// Caution: this does not initialize the tx environment. fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg { - let mut cfg = CfgEnvWithHandlerCfg::new(Default::default(), Default::default()); + 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(); self.evm_config .fill_cfg_and_block_env(&mut cfg, &mut block_env, header, total_difficulty);