Skip to content

Commit

Permalink
feat: add osaka hardfork
Browse files Browse the repository at this point in the history
  • Loading branch information
onbjerg committed Oct 23, 2024
1 parent 5e0ba41 commit 791cb84
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ impl From<Genesis> for ChainSpec {
(EthereumHardfork::Shanghai.boxed(), genesis.config.shanghai_time),
(EthereumHardfork::Cancun.boxed(), genesis.config.cancun_time),
(EthereumHardfork::Prague.boxed(), genesis.config.prague_time),
(EthereumHardfork::Osaka.boxed(), genesis.config.osaka_time),
];

let mut time_hardforks = time_hardfork_opts
Expand Down Expand Up @@ -864,6 +865,13 @@ impl ChainSpecBuilder {
self
}

/// Enable Osaka at genesis.
pub fn osaka_activated(mut self) -> Self {
self = self.prague_activated();
self.hardforks.insert(EthereumHardfork::Osaka, ForkCondition::Timestamp(0));
self
}

/// Build the resulting [`ChainSpec`].
///
/// # Panics
Expand Down
2 changes: 2 additions & 0 deletions crates/ethereum-forks/src/hardfork/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ hardfork!(
Cancun,
/// Prague: <https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/prague.md>
Prague,
/// Osaka: <https://eips.ethereum.org/EIPS/eip-7607>
Osaka,
}
);

Expand Down
5 changes: 5 additions & 0 deletions crates/ethereum-forks/src/hardforks/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub trait EthereumHardforks: Hardforks {
self.is_fork_active_at_timestamp(EthereumHardfork::Prague, timestamp)
}

/// Convenience method to check if [`EthereumHardfork::Osaka`] is active at a given timestamp.
fn is_osaka_active_at_timestamp(&self, timestamp: u64) -> bool {
self.is_fork_active_at_timestamp(EthereumHardfork::Osaka, timestamp)
}

/// Convenience method to check if [`EthereumHardfork::Byzantium`] is active at a given block
/// number.
fn is_byzantium_active_at_block(&self, block_number: u64) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion crates/ethereum/cli/src/chainspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ mod tests {
"terminalTotalDifficulty": 0,
"shanghaiTime": 0,
"cancunTime": 0,
"pragueTime": 0
"pragueTime": 0,
"osakaTime": 0
}
}"#;

let spec = <EthereumChainSpecParser as ChainSpecParser>::parse(s).unwrap();
assert!(spec.is_shanghai_active_at_timestamp(0));
assert!(spec.is_cancun_active_at_timestamp(0));
assert!(spec.is_prague_active_at_timestamp(0));
assert!(spec.is_osaka_active_at_timestamp(0));
}
}
4 changes: 3 additions & 1 deletion crates/ethereum/evm/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub fn revm_spec_by_timestamp_after_merge(
chain_spec: &ChainSpec,
timestamp: u64,
) -> revm_primitives::SpecId {
if chain_spec.is_prague_active_at_timestamp(timestamp) {
if chain_spec.is_osaka_active_at_timestamp(timestamp) {
revm_primitives::OSAKA
} else if chain_spec.is_prague_active_at_timestamp(timestamp) {
revm_primitives::PRAGUE
} else if chain_spec.is_cancun_active_at_timestamp(timestamp) {
revm_primitives::CANCUN
Expand Down

0 comments on commit 791cb84

Please sign in to comment.