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

fix - Activate EIP-170 at Shanghai #45

Merged
merged 2 commits into from
Jan 7, 2025
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
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
Loading