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

Implement ChainSpec and HardForks #12

Closed
Tracked by #16
frisitano opened this issue Oct 7, 2024 · 3 comments
Closed
Tracked by #16

Implement ChainSpec and HardForks #12

frisitano opened this issue Oct 7, 2024 · 3 comments
Assignees
Milestone

Comments

@frisitano
Copy link
Collaborator

frisitano commented Oct 7, 2024

Overview

We must implement a ChainSpec and HardForks for scroll and also scroll sepolia testnet.

Hardfork

The Hardfork is used to determine the block number and timestamp at which features / functionality is changed. An example of a Hardfork implementation for Optimism can be found here. It should be noted that there is an expectation for hardforks to be mixed with ethereum hardforks as stated here:

/// The name of an optimism hardfork.
///
/// When building a list of hardforks for a chain, it's still expected to mix with
/// [`EthereumHardfork`].
OpHardfork {
/// Bedrock: <https://blog.oplabs.co/introducing-optimism-bedrock>.
Bedrock,
/// Regolith: <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#regolith>.
Regolith,
/// <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#canyon>.
Canyon,
/// Ecotone: <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#ecotone>.
Ecotone,
/// Fjord: <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#fjord>
Fjord,
/// Granite: <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#granite>
Granite,
/// Holocene: <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#holocene>
Holocene,
}

We should review the hardforks introduce in scrolls fork of revm which are feature gated in the link provided. We should then implement a pattern similar to optimism by creating a crate to define these in reth for scroll. These will then be subsequently integrated with the revm hardfork type as seen below in the optimism example (this is outside of the scope of this issue and should be handled in #5):

/// Returns the revm [`SpecId`](revm_primitives::SpecId) at the given timestamp.
///
/// # Note
///
/// This is only intended to be used after the Bedrock, when hardforks are activated by
/// timestamp.
pub fn revm_spec_by_timestamp_after_bedrock(
chain_spec: &OpChainSpec,
timestamp: u64,
) -> revm_primitives::SpecId {
if chain_spec.fork(OpHardfork::Holocene).active_at_timestamp(timestamp) {
revm_primitives::HOLOCENE
} else if chain_spec.fork(OpHardfork::Granite).active_at_timestamp(timestamp) {
revm_primitives::GRANITE
} else if chain_spec.fork(OpHardfork::Fjord).active_at_timestamp(timestamp) {
revm_primitives::FJORD
} else if chain_spec.fork(OpHardfork::Ecotone).active_at_timestamp(timestamp) {
revm_primitives::ECOTONE
} else if chain_spec.fork(OpHardfork::Canyon).active_at_timestamp(timestamp) {
revm_primitives::CANYON
} else if chain_spec.fork(OpHardfork::Regolith).active_at_timestamp(timestamp) {
revm_primitives::REGOLITH
} else {
revm_primitives::BEDROCK
}
}

ChainSpec

The ChainSpec defines the core primitives of the chain such as the chain id, state genesis data, hardforks and other properties relating to the chain. A comprehensive view of the ChainSpec can be seen by observing the data structure:

/// An Ethereum chain specification.
///
/// A chain specification describes:
///
/// - Meta-information about the chain (the chain ID)
/// - The genesis block of the chain ([`Genesis`])
/// - What hardforks are activated, and under which conditions
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChainSpec {
/// The chain ID
pub chain: Chain,
/// The genesis block.
pub genesis: Genesis,
/// The hash of the genesis block.
///
/// This is either stored at construction time if it is known using [`once_cell_set`], or
/// computed once on the first access.
pub genesis_hash: OnceLock<B256>,
/// The header corresponding to the genesis block.
///
/// This is either stored at construction time if it is known using [`once_cell_set`], or
/// computed once on the first access.
pub genesis_header: OnceLock<Header>,
/// The block at which [`EthereumHardfork::Paris`] was activated and the final difficulty at
/// this block.
pub paris_block_and_final_difficulty: Option<(u64, U256)>,
/// The active hard forks and their activation conditions
pub hardforks: ChainHardforks,
/// The deposit contract deployed for `PoS`
pub deposit_contract: Option<DepositContract>,
/// The parameters that configure how a block's base fee is computed
pub base_fee_params: BaseFeeParamsKind,
/// The maximum gas limit
pub max_gas_limit: u64,
/// The delete limit for pruner, per run.
pub prune_delete_limit: usize,
}

We should follow a similar pattern as Optimism and implement a crate for scrolls ChainSpec associated types. The Optimism example can be found here. We should implement a spec for both scroll mainnet and scroll sepolia.

@frisitano frisitano moved this to Todo in Reth Oct 7, 2024
@frisitano frisitano added this to Reth Oct 7, 2024
@frisitano frisitano added this to the Milestone 1 milestone Oct 7, 2024
@frisitano frisitano mentioned this issue Oct 8, 2024
10 tasks
@greged93
Copy link
Collaborator

Should we add the fee_vault_address as part of the ScrollChainSpec?

This would follow the pattern used in l2geth and allow us to introduce ScrollEvmConfig and implement ConfigureEvmEnv, where we can set the coinbase for the block to the vault address.

@georgehao
Copy link
Member

I think we need to add.

@greged93
Copy link
Collaborator

Closed by #56.

@github-project-automation github-project-automation bot moved this from Todo to Done in Reth Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants