Skip to content

refactor(chains): move embedded genesis JSON into base-common-genesis-json - #6690

Open
BrianBland wants to merge 3 commits into
mainfrom
brian/extract-genesis-json
Open

BrianBland wants to merge 3 commits into
mainfrom
brian/extract-genesis-json

Conversation

@BrianBland

Copy link
Copy Markdown
Contributor

Summary

Move the embedded execution-layer genesis JSON files (base.json, sepolia_base.json, dev.json, zeronet_base.json — ~26.3 MiB total) out of base-common-chains (ChainConfig.genesis_json) into a dedicated #![no_std] crate base-common-genesis-json (crates/common/genesis-json) backed by statics.

Why

  • Only two files in the entire repository read the embedded genesis JSON (crates/execution/chainspec/src/spec.rs and crates/execution/evm/benches/fixtures/mainnet_block.rs).
  • Because ChainConfig::MAINNET / SEPOLIA / ZERONET are consts with genesis_json: &'static str, rustc/LLVM was embedding and duplicating the ~26.3 MiB of uncompressed JSON across codegen units in every downstream crate and binary—including non-execution binaries that never touch genesis JSON (libbasectl_cli.rlib was 110 MiB; basectl had 74.5 MiB of __TEXT.__const, shrinking from 92.6 MiB → 18.2 MiB (-80%); base-consensus had the same ~74 MiB bloat).
  • Backing GenesisJson with statics in its own crate also ensures execution binaries (base, base-reth-node, base-builder) emit each genesis JSON once instead of duplicating it across CGUs.
  • Zero new feature flags.

Changes

  • Create crates/common/genesis-json (base-common-genesis-json, #![no_std], zero dependencies) with GenesisJson::{mainnet, sepolia, devnet, zeronet, for_chain_id}.
  • Move crates/common/chains/res/genesis/*.json → crates/common/genesis-json/res/*.json and remove ChainConfig.genesis_json.
  • Update base-execution-chainspec and base-execution-evm (dev-dependency for benchmark fixture) to read from base_common_genesis_json::GenesisJson.

Verification

  • cargo test -p base-common-chains (60 passed) and cargo test -p base-execution-chainspec embedded_genesis (passed).
  • cargo clippy -p base-common-genesis-json -p base-common-chains -p base-execution-chainspec --lib -- -D warnings: clean.
  • cargo check -p base-common-genesis-json -p base-common-chains --no-default-features: clean.
  • zepter format features, ./etc/scripts/ci/check-crate-deps.sh, cargo deny check bans, root & SP1 guest cargo metadata --locked: clean.

@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

Comment thread crates/common/genesis-json/src/lib.rs Outdated
Comment on lines +41 to +47
pub fn for_chain_id(chain_id: u64) -> &'static str {
match chain_id {
8453 => MAINNET_GENESIS_JSON,
84532 => SEPOLIA_GENESIS_JSON,
763360 => ZERONET_GENESIS_JSON,
_ => DEVNET_GENESIS_JSON,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The silent _ => DEVNET_GENESIS_JSON fallback breaks the old link between a ChainConfig and its own genesis JSON. Now BaseChainSpec::try_from(&ChainConfig) (spec.rs:584) loads devnet's alloc for any config with an unknown chain_id, while still using that config's genesis_l2_hash in SealedHeader::new. The result is a chainspec whose genesis contents don't match its sealed hash, and nothing reports an error.

This already happens in runtime_registry_overrides_execution_fee_and_blob_params, which clones mainnet with chain_id = 9_100_006: it now gets devnet genesis sealed with mainnet's hash. Suggest returning Option<&'static str> and mapping None to a BaseChainSpecError. Also reuse the chain-ID constants from base-common-chains (or key on the chain name) instead of repeating 8453/84532/763360 as literals that can drift from ChainConfig.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great catch — fixed in c419390: replaced for_chain_id (and its silent devnet fallback and literal chain IDs) with a 1-byte GenesisKind enum (Mainnet | Sepolia | Devnet | Zeronet) on ChainConfig and an exhaustive GenesisJson::for_kind(cfg.genesis_kind). Cloned configs with overridden chain_id now retain their exact original genesis JSON.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants