Skip to content
Merged
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
20 changes: 17 additions & 3 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
hardfork::{MorphHardfork, MorphHardforks},
};
use alloy_chains::Chain;
use alloy_consensus::Sealable;
use alloy_eips::eip7840::BlobParams;
use alloy_evm::eth::spec::EthExecutorSpec;
use alloy_genesis::Genesis;
Expand Down Expand Up @@ -37,7 +38,12 @@ pub(crate) fn make_genesis_header(genesis: &Genesis, state_root: B256) -> MorphH
let base_spec = ChainSpec::from_genesis(genesis.clone());
let mut inner = base_spec.genesis_header.header().clone();
inner.state_root = state_root;

// morph-geth defaults to MORPH_BASE_FEE (1_000_000) when baseFeePerGas is
// absent, not Ethereum's INITIAL_BASE_FEE (1_000_000_000). Apply the same
// default so the genesis block header hash matches.
if genesis.base_fee_per_gas.is_none() {
inner.base_fee_per_gas = Some(MORPH_BASE_FEE);
}
MorphHeader::from(inner)
}

Expand Down Expand Up @@ -260,8 +266,16 @@ impl MorphChainSpec {
None => {
// Compute MPT state root from alloc (for CLI-provided genesis)
let base_spec = ChainSpec::from_genesis(genesis.clone());
let header = MorphHeader::from(base_spec.genesis_header.header().clone());
let hash = base_spec.genesis_hash();
let mut header = base_spec.genesis_header.header().clone();
// morph-geth defaults to MORPH_BASE_FEE (1_000_000) when
// baseFeePerGas is absent, not Ethereum's INITIAL_BASE_FEE
// (1_000_000_000). Override to match.
if genesis.base_fee_per_gas.is_none() {
header.base_fee_per_gas = Some(MORPH_BASE_FEE);
}
let header = MorphHeader::from(header);
// Recompute genesis hash with the corrected base fee
let hash = header.hash_slow();
SealedHeader::new(header, hash)
Comment on lines +269 to 279
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add regression tests for omitted vs explicit baseFeePerGas in genesis.

This branch changes consensus-critical genesis header/hash behavior, but there’s no accompanying test in this module asserting: (1) omitted baseFeePerGas becomes MORPH_BASE_FEE, and (2) explicit baseFeePerGas is preserved. Please add both cases to prevent future hash regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/chainspec/src/spec.rs` around lines 269 - 279, Add two unit tests in
this module covering genesis baseFeePerGas: one that builds a spec where
genesis.base_fee_per_gas is None and asserts the resulting header (via
base_spec.genesis_header.header().clone(), then MorphHeader::from(...) and
SealedHeader::new(...)) has header.base_fee_per_gas == Some(MORPH_BASE_FEE) and
computes the expected hash, and another where genesis.base_fee_per_gas is set
explicitly and assert that the explicit value is preserved in the header and
that the resulting hash differs from the omitted case; use the existing helper
construction (base_spec, genesis, MorphHeader::from, header.hash_slow,
SealedHeader::new) to create the headers and compare expected values.

}
};
Expand Down
Loading