Skip to content

Commit

Permalink
fix - Activate EIP-170 at Shanghai (gnosischain#45)
Browse files Browse the repository at this point in the history
* contract code size limit change

* refactoring changes
  • Loading branch information
debjit-bw authored Jan 7, 2025
1 parent fd46614 commit b97eeda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/evm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down 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,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);
Expand Down
5 changes: 4 additions & 1 deletion 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 @@ -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);
Expand Down

0 comments on commit b97eeda

Please sign in to comment.