From 1cf298b978fa15fe3ffde64a3973f631f124e715 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:01:53 +0200 Subject: [PATCH 1/7] move chain hardforks --- Cargo.lock | 1 + crates/chainspec/src/spec.rs | 202 +------------------ crates/ethereum-forks/Cargo.toml | 1 + crates/ethereum-forks/src/chains/ethereum.rs | 104 ++++++++++ crates/ethereum-forks/src/chains/mod.rs | 34 ++++ crates/ethereum-forks/src/chains/optimism.rs | 124 ++++++++++++ crates/ethereum-forks/src/lib.rs | 3 + 7 files changed, 278 insertions(+), 191 deletions(-) create mode 100644 crates/ethereum-forks/src/chains/ethereum.rs create mode 100644 crates/ethereum-forks/src/chains/mod.rs create mode 100644 crates/ethereum-forks/src/chains/optimism.rs diff --git a/Cargo.lock b/Cargo.lock index efd35ee3f808..3fe20f44e8d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7061,6 +7061,7 @@ dependencies = [ "alloy-rlp", "arbitrary", "crc", + "once_cell", "proptest", "proptest-derive", "serde", diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index ff2407313c5d..673aad733d3e 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -14,6 +14,7 @@ use alloy_trie::EMPTY_ROOT_HASH; use derive_more::From; use once_cell::sync::Lazy; use reth_ethereum_forks::{ + chains::ethereum::{GOERLI_HARDFORKS, HOLESKY_HARDFORKS, MAINNET_HARDFORKS, SEPOLIA_HARDFORKS}, DisplayHardforks, ForkCondition, ForkFilter, ForkFilterKey, ForkHash, ForkId, Hardfork, Head, }; use reth_network_peers::NodeRecord; @@ -35,6 +36,8 @@ use crate::constants::optimism::{ OP_CANYON_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS, OP_SEPOLIA_CANYON_BASE_FEE_PARAMS, }; pub use alloy_eips::eip1559::BaseFeeParams; +#[cfg(feature = "optimism")] +use reth_ethereum_forks::chains::optimism::*; #[cfg(feature = "optimism")] use crate::net::{base_nodes, base_testnet_nodes, op_nodes, op_testnet_nodes}; @@ -54,31 +57,7 @@ pub static MAINNET: Lazy> = Lazy::new(|| { 15537394, U256::from(58_750_003_716_598_352_816_469u128), )), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(1150000)), - (Hardfork::Dao, ForkCondition::Block(1920000)), - (Hardfork::Tangerine, ForkCondition::Block(2463000)), - (Hardfork::SpuriousDragon, ForkCondition::Block(2675000)), - (Hardfork::Byzantium, ForkCondition::Block(4370000)), - (Hardfork::Constantinople, ForkCondition::Block(7280000)), - (Hardfork::Petersburg, ForkCondition::Block(7280000)), - (Hardfork::Istanbul, ForkCondition::Block(9069000)), - (Hardfork::MuirGlacier, ForkCondition::Block(9200000)), - (Hardfork::Berlin, ForkCondition::Block(12244000)), - (Hardfork::London, ForkCondition::Block(12965000)), - (Hardfork::ArrowGlacier, ForkCondition::Block(13773000)), - (Hardfork::GrayGlacier, ForkCondition::Block(15050000)), - ( - Hardfork::Paris, - ForkCondition::TTD { - fork_block: None, - total_difficulty: U256::from(58_750_000_000_000_000_000_000_u128), - }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), - (Hardfork::Cancun, ForkCondition::Timestamp(1710338135)), - ]), + hardforks: MAINNET_HARDFORKS.clone(), // https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0 deposit_contract: Some(DepositContract::new( address!("00000000219ab540356cbb839cbe05303d7705fa"), @@ -102,25 +81,7 @@ pub static GOERLI: Lazy> = Lazy::new(|| { )), // paris_block_and_final_difficulty: Some((7382818, U256::from(10_790_000))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(1561651)), - (Hardfork::Berlin, ForkCondition::Block(4460644)), - (Hardfork::London, ForkCondition::Block(5062605)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(10_790_000) }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), - (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), - ]), + hardforks: GOERLI_HARDFORKS.clone(), // https://goerli.etherscan.io/tx/0xa3c07dc59bfdb1bfc2d50920fed2ef2c1c4e0a09fe2325dbc14e07702f965a78 deposit_contract: Some(DepositContract::new( address!("ff50ed3d0ec03ac01d4c79aad74928bff48a7b2b"), @@ -144,29 +105,7 @@ pub static SEPOLIA: Lazy> = Lazy::new(|| { )), // paris_block_and_final_difficulty: Some((1450409, U256::from(17_000_018_015_853_232u128))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { - fork_block: Some(1735371), - total_difficulty: U256::from(17_000_000_000_000_000u64), - }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), - (Hardfork::Cancun, ForkCondition::Timestamp(1706655072)), - ]), + hardforks: SEPOLIA_HARDFORKS.clone(), // https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14 deposit_contract: Some(DepositContract::new( address!("7f02c3e3c98b133055b8b348b2ac625669ed295d"), @@ -189,26 +128,7 @@ pub static HOLESKY: Lazy> = Lazy::new(|| { "b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4" )), paris_block_and_final_difficulty: Some((0, U256::from(1))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1696000704)), - (Hardfork::Cancun, ForkCondition::Timestamp(1707305664)), - ]), + hardforks: HOLESKY_HARDFORKS.clone(), deposit_contract: Some(DepositContract::new( address!("4242424242424242424242424242424242424242"), 0, @@ -279,32 +199,7 @@ pub static OP_MAINNET: Lazy> = Lazy::new(|| { "7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(3950000)), - (Hardfork::London, ForkCondition::Block(105235063)), - (Hardfork::ArrowGlacier, ForkCondition::Block(105235063)), - (Hardfork::GrayGlacier, ForkCondition::Block(105235063)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(105235063), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(105235063)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), - (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), - (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), - (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), - ]), + hardforks: OP_MAINNET_HARDFORKS.clone(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, OP_BASE_FEE_PARAMS), @@ -329,32 +224,7 @@ pub static OP_SEPOLIA: Lazy> = Lazy::new(|| { "102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::ArrowGlacier, ForkCondition::Block(0)), - (Hardfork::GrayGlacier, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(0)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), - (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), - (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), - (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), - ]), + hardforks: OP_SEPOLIA_HARDFORKS.clone(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, OP_SEPOLIA_BASE_FEE_PARAMS), @@ -379,32 +249,7 @@ pub static BASE_SEPOLIA: Lazy> = Lazy::new(|| { "0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::ArrowGlacier, ForkCondition::Block(0)), - (Hardfork::GrayGlacier, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(0)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), - (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), - (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), - (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), - ]), + hardforks: BASE_SEPOLIA_HARDFORKS.clone(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, BASE_SEPOLIA_BASE_FEE_PARAMS), @@ -429,32 +274,7 @@ pub static BASE_MAINNET: Lazy> = Lazy::new(|| { "f712aa9241cc24369b143cf6dce85f0902a9731e70d66818a3a5845b296c73dd" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::ArrowGlacier, ForkCondition::Block(0)), - (Hardfork::GrayGlacier, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(0)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), - (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), - (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), - (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), - ]), + hardforks: BASE_MAINNET_HARDFORKS.clone(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, OP_BASE_FEE_PARAMS), diff --git a/crates/ethereum-forks/Cargo.toml b/crates/ethereum-forks/Cargo.toml index ac9836c5438a..08ccdde24d13 100644 --- a/crates/ethereum-forks/Cargo.toml +++ b/crates/ethereum-forks/Cargo.toml @@ -23,6 +23,7 @@ crc = "3" # misc serde = { workspace = true, features = ["derive"], optional = true } thiserror-no-std = { workspace = true, default-features = false } +once_cell.workspace = true # arbitrary utils arbitrary = { workspace = true, features = ["derive"], optional = true } diff --git a/crates/ethereum-forks/src/chains/ethereum.rs b/crates/ethereum-forks/src/chains/ethereum.rs new file mode 100644 index 000000000000..f1939daad3fd --- /dev/null +++ b/crates/ethereum-forks/src/chains/ethereum.rs @@ -0,0 +1,104 @@ +use crate::{ForkCondition, Hardfork}; +use alloy_primitives::U256; +use once_cell::sync::Lazy; +use std::collections::BTreeMap; + +/// Ethereum mainnet hardforks +pub static MAINNET_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(1150000)), + (Hardfork::Dao, ForkCondition::Block(1920000)), + (Hardfork::Tangerine, ForkCondition::Block(2463000)), + (Hardfork::SpuriousDragon, ForkCondition::Block(2675000)), + (Hardfork::Byzantium, ForkCondition::Block(4370000)), + (Hardfork::Constantinople, ForkCondition::Block(7280000)), + (Hardfork::Petersburg, ForkCondition::Block(7280000)), + (Hardfork::Istanbul, ForkCondition::Block(9069000)), + (Hardfork::MuirGlacier, ForkCondition::Block(9200000)), + (Hardfork::Berlin, ForkCondition::Block(12244000)), + (Hardfork::London, ForkCondition::Block(12965000)), + (Hardfork::ArrowGlacier, ForkCondition::Block(13773000)), + (Hardfork::GrayGlacier, ForkCondition::Block(15050000)), + ( + Hardfork::Paris, + ForkCondition::TTD { + fork_block: None, + total_difficulty: U256::from(58_750_000_000_000_000_000_000_u128), + }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710338135)), + ]) +}); + +/// Ethereum Goerli hardforks +pub static GOERLI_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(1561651)), + (Hardfork::Berlin, ForkCondition::Block(4460644)), + (Hardfork::London, ForkCondition::Block(5062605)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(10_790_000) }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), + (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), + ]) +}); + +/// Ethereum Sepolia hardforks +pub static SEPOLIA_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + ( + Hardfork::Paris, + ForkCondition::TTD { + fork_block: Some(1735371), + total_difficulty: U256::from(17_000_000_000_000_000u64), + }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), + (Hardfork::Cancun, ForkCondition::Timestamp(1706655072)), + ]) +}); + +/// Ethereum Holesky hardforks +pub static HOLESKY_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }), + (Hardfork::Shanghai, ForkCondition::Timestamp(1696000704)), + (Hardfork::Cancun, ForkCondition::Timestamp(1707305664)), + ]) +}); diff --git a/crates/ethereum-forks/src/chains/mod.rs b/crates/ethereum-forks/src/chains/mod.rs new file mode 100644 index 000000000000..78f4b7c58e15 --- /dev/null +++ b/crates/ethereum-forks/src/chains/mod.rs @@ -0,0 +1,34 @@ +/// Ethereum chains +pub mod ethereum; + +/// Optimism chains +#[cfg(feature = "optimism")] +pub mod optimism; + +use crate::{ForkCondition, Hardfork}; +use alloy_primitives::U256; +use once_cell::sync::Lazy; +use std::collections::BTreeMap; + +/// Dev hardforks +pub static DEV_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(1561651)), + (Hardfork::Berlin, ForkCondition::Block(4460644)), + (Hardfork::London, ForkCondition::Block(5062605)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(10_790_000) }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), + (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), + ]) +}); diff --git a/crates/ethereum-forks/src/chains/optimism.rs b/crates/ethereum-forks/src/chains/optimism.rs new file mode 100644 index 000000000000..06d987c57421 --- /dev/null +++ b/crates/ethereum-forks/src/chains/optimism.rs @@ -0,0 +1,124 @@ +use crate::{ForkCondition, Hardfork}; +use alloy_primitives::U256; +use once_cell::sync::Lazy; +use std::collections::BTreeMap; + +/// Optimism mainnet hardforks +pub static OP_MAINNET_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(3950000)), + (Hardfork::London, ForkCondition::Block(105235063)), + (Hardfork::ArrowGlacier, ForkCondition::Block(105235063)), + (Hardfork::GrayGlacier, ForkCondition::Block(105235063)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: Some(105235063), total_difficulty: U256::from(0) }, + ), + (Hardfork::Bedrock, ForkCondition::Block(105235063)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), + (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), + (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), + ]) +}); + +/// Optimism Sepolia hardforks +pub static OP_SEPOLIA_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::ArrowGlacier, ForkCondition::Block(0)), + (Hardfork::GrayGlacier, ForkCondition::Block(0)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, + ), + (Hardfork::Bedrock, ForkCondition::Block(0)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), + (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), + (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), + (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), + ]) +}); + +/// Base Sepolia hardforks +pub static BASE_SEPOLIA_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::ArrowGlacier, ForkCondition::Block(0)), + (Hardfork::GrayGlacier, ForkCondition::Block(0)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, + ), + (Hardfork::Bedrock, ForkCondition::Block(0)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), + (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), + (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), + (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), + ]) +}); + +/// Base Mainnet hardforks +pub static BASE_MAINNET_HARDFORKS: Lazy> = Lazy::new(|| { + BTreeMap::from([ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::ArrowGlacier, ForkCondition::Block(0)), + (Hardfork::GrayGlacier, ForkCondition::Block(0)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, + ), + (Hardfork::Bedrock, ForkCondition::Block(0)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), + (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), + (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), + ]) +}); diff --git a/crates/ethereum-forks/src/lib.rs b/crates/ethereum-forks/src/lib.rs index c7831026905f..1a7e0f56e707 100644 --- a/crates/ethereum-forks/src/lib.rs +++ b/crates/ethereum-forks/src/lib.rs @@ -35,5 +35,8 @@ pub use head::Head; pub use display::DisplayHardforks; pub use forkcondition::ForkCondition; +/// Chains hardforks +pub mod chains; + #[cfg(any(test, feature = "arbitrary"))] pub use arbitrary; From 35fa07298f3b6b8bff543d299de7cac0896c125c Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:23:25 +0200 Subject: [PATCH 2/7] turn hardforks const --- Cargo.lock | 1 - crates/chainspec/src/spec.rs | 16 +- crates/ethereum-forks/Cargo.toml | 1 - crates/ethereum-forks/src/chains/ethereum.rs | 195 ++++++++--------- crates/ethereum-forks/src/chains/mod.rs | 43 ++-- crates/ethereum-forks/src/chains/optimism.rs | 209 +++++++++---------- 6 files changed, 223 insertions(+), 242 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3fe20f44e8d8..efd35ee3f808 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7061,7 +7061,6 @@ dependencies = [ "alloy-rlp", "arbitrary", "crc", - "once_cell", "proptest", "proptest-derive", "serde", diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 673aad733d3e..10ec06c2dad4 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -57,7 +57,7 @@ pub static MAINNET: Lazy> = Lazy::new(|| { 15537394, U256::from(58_750_003_716_598_352_816_469u128), )), - hardforks: MAINNET_HARDFORKS.clone(), + hardforks: MAINNET_HARDFORKS.into(), // https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0 deposit_contract: Some(DepositContract::new( address!("00000000219ab540356cbb839cbe05303d7705fa"), @@ -81,7 +81,7 @@ pub static GOERLI: Lazy> = Lazy::new(|| { )), // paris_block_and_final_difficulty: Some((7382818, U256::from(10_790_000))), - hardforks: GOERLI_HARDFORKS.clone(), + hardforks: GOERLI_HARDFORKS.into(), // https://goerli.etherscan.io/tx/0xa3c07dc59bfdb1bfc2d50920fed2ef2c1c4e0a09fe2325dbc14e07702f965a78 deposit_contract: Some(DepositContract::new( address!("ff50ed3d0ec03ac01d4c79aad74928bff48a7b2b"), @@ -105,7 +105,7 @@ pub static SEPOLIA: Lazy> = Lazy::new(|| { )), // paris_block_and_final_difficulty: Some((1450409, U256::from(17_000_018_015_853_232u128))), - hardforks: SEPOLIA_HARDFORKS.clone(), + hardforks: SEPOLIA_HARDFORKS.into(), // https://sepolia.etherscan.io/tx/0x025ecbf81a2f1220da6285d1701dc89fb5a956b62562ee922e1a9efd73eb4b14 deposit_contract: Some(DepositContract::new( address!("7f02c3e3c98b133055b8b348b2ac625669ed295d"), @@ -128,7 +128,7 @@ pub static HOLESKY: Lazy> = Lazy::new(|| { "b5f7f912443c940f21fd611f12828d75b534364ed9e95ca4e307729a4661bde4" )), paris_block_and_final_difficulty: Some((0, U256::from(1))), - hardforks: HOLESKY_HARDFORKS.clone(), + hardforks: HOLESKY_HARDFORKS.into(), deposit_contract: Some(DepositContract::new( address!("4242424242424242424242424242424242424242"), 0, @@ -199,7 +199,7 @@ pub static OP_MAINNET: Lazy> = Lazy::new(|| { "7ca38a1916c42007829c55e69d3e9a73265554b586a499015373241b8a3fa48b" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: OP_MAINNET_HARDFORKS.clone(), + hardforks: OP_MAINNET_HARDFORKS.into(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, OP_BASE_FEE_PARAMS), @@ -224,7 +224,7 @@ pub static OP_SEPOLIA: Lazy> = Lazy::new(|| { "102de6ffb001480cc9b8b548fd05c34cd4f46ae4aa91759393db90ea0409887d" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: OP_SEPOLIA_HARDFORKS.clone(), + hardforks: OP_SEPOLIA_HARDFORKS.into(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, OP_SEPOLIA_BASE_FEE_PARAMS), @@ -249,7 +249,7 @@ pub static BASE_SEPOLIA: Lazy> = Lazy::new(|| { "0dcc9e089e30b90ddfc55be9a37dd15bc551aeee999d2e2b51414c54eaf934e4" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: BASE_SEPOLIA_HARDFORKS.clone(), + hardforks: BASE_SEPOLIA_HARDFORKS.into(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, BASE_SEPOLIA_BASE_FEE_PARAMS), @@ -274,7 +274,7 @@ pub static BASE_MAINNET: Lazy> = Lazy::new(|| { "f712aa9241cc24369b143cf6dce85f0902a9731e70d66818a3a5845b296c73dd" )), paris_block_and_final_difficulty: Some((0, U256::from(0))), - hardforks: BASE_MAINNET_HARDFORKS.clone(), + hardforks: BASE_MAINNET_HARDFORKS.into(), base_fee_params: BaseFeeParamsKind::Variable( vec![ (Hardfork::London, OP_BASE_FEE_PARAMS), diff --git a/crates/ethereum-forks/Cargo.toml b/crates/ethereum-forks/Cargo.toml index 08ccdde24d13..ac9836c5438a 100644 --- a/crates/ethereum-forks/Cargo.toml +++ b/crates/ethereum-forks/Cargo.toml @@ -23,7 +23,6 @@ crc = "3" # misc serde = { workspace = true, features = ["derive"], optional = true } thiserror-no-std = { workspace = true, default-features = false } -once_cell.workspace = true # arbitrary utils arbitrary = { workspace = true, features = ["derive"], optional = true } diff --git a/crates/ethereum-forks/src/chains/ethereum.rs b/crates/ethereum-forks/src/chains/ethereum.rs index f1939daad3fd..12d64b25567e 100644 --- a/crates/ethereum-forks/src/chains/ethereum.rs +++ b/crates/ethereum-forks/src/chains/ethereum.rs @@ -1,104 +1,111 @@ use crate::{ForkCondition, Hardfork}; use alloy_primitives::U256; -use once_cell::sync::Lazy; -use std::collections::BTreeMap; + +const PARIS_TTD_MAINNET: U256 = U256::from_limbs([15566869308787654656, 3184, 0, 0]); +pub(crate) const PARIS_TTD_GOERLI: U256 = U256::from_limbs([10790000, 0, 0, 0]); +const PARIS_TTD_SEPOLIA: U256 = U256::from_limbs([17000000000000000, 0, 0, 0]); /// Ethereum mainnet hardforks -pub static MAINNET_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(1150000)), - (Hardfork::Dao, ForkCondition::Block(1920000)), - (Hardfork::Tangerine, ForkCondition::Block(2463000)), - (Hardfork::SpuriousDragon, ForkCondition::Block(2675000)), - (Hardfork::Byzantium, ForkCondition::Block(4370000)), - (Hardfork::Constantinople, ForkCondition::Block(7280000)), - (Hardfork::Petersburg, ForkCondition::Block(7280000)), - (Hardfork::Istanbul, ForkCondition::Block(9069000)), - (Hardfork::MuirGlacier, ForkCondition::Block(9200000)), - (Hardfork::Berlin, ForkCondition::Block(12244000)), - (Hardfork::London, ForkCondition::Block(12965000)), - (Hardfork::ArrowGlacier, ForkCondition::Block(13773000)), - (Hardfork::GrayGlacier, ForkCondition::Block(15050000)), - ( - Hardfork::Paris, - ForkCondition::TTD { - fork_block: None, - total_difficulty: U256::from(58_750_000_000_000_000_000_000_u128), - }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), - (Hardfork::Cancun, ForkCondition::Timestamp(1710338135)), - ]) -}); +pub const MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 17] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(1150000)), + (Hardfork::Dao, ForkCondition::Block(1920000)), + (Hardfork::Tangerine, ForkCondition::Block(2463000)), + (Hardfork::SpuriousDragon, ForkCondition::Block(2675000)), + (Hardfork::Byzantium, ForkCondition::Block(4370000)), + (Hardfork::Constantinople, ForkCondition::Block(7280000)), + (Hardfork::Petersburg, ForkCondition::Block(7280000)), + (Hardfork::Istanbul, ForkCondition::Block(9069000)), + (Hardfork::MuirGlacier, ForkCondition::Block(9200000)), + (Hardfork::Berlin, ForkCondition::Block(12244000)), + (Hardfork::London, ForkCondition::Block(12965000)), + (Hardfork::ArrowGlacier, ForkCondition::Block(13773000)), + (Hardfork::GrayGlacier, ForkCondition::Block(15050000)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: None, total_difficulty: PARIS_TTD_MAINNET }), + (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710338135)), +]; /// Ethereum Goerli hardforks -pub static GOERLI_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(1561651)), - (Hardfork::Berlin, ForkCondition::Block(4460644)), - (Hardfork::London, ForkCondition::Block(5062605)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(10_790_000) }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), - (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), - ]) -}); +pub static GOERLI_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(1561651)), + (Hardfork::Berlin, ForkCondition::Block(4460644)), + (Hardfork::London, ForkCondition::Block(5062605)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: None, total_difficulty: PARIS_TTD_GOERLI }), + (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), + (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), +]; /// Ethereum Sepolia hardforks -pub static SEPOLIA_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { - fork_block: Some(1735371), - total_difficulty: U256::from(17_000_000_000_000_000u64), - }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), - (Hardfork::Cancun, ForkCondition::Timestamp(1706655072)), - ]) -}); +pub static SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 15] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: Some(1735371), total_difficulty: PARIS_TTD_SEPOLIA }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), + (Hardfork::Cancun, ForkCondition::Timestamp(1706655072)), +]; /// Ethereum Holesky hardforks -pub static HOLESKY_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::Paris, ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }), - (Hardfork::Shanghai, ForkCondition::Timestamp(1696000704)), - (Hardfork::Cancun, ForkCondition::Timestamp(1707305664)), - ]) -}); +pub const HOLESKY_HARDFORKS: [(Hardfork, ForkCondition); 15] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }), + (Hardfork::Shanghai, ForkCondition::Timestamp(1696000704)), + (Hardfork::Cancun, ForkCondition::Timestamp(1707305664)), +]; + +#[cfg(test)] +mod tests { + use super::*; + use alloy_primitives::U256; + + const U_PARIS_TTD_MAINNET: u128 = 58_750_000_000_000_000_000_000; + const U_PARIS_TTD_GOERLI: u64 = 10_790_000; + const U_PARIS_TTD_SEPOLIA: u64 = 17_000_000_000_000_000; + + #[test] + fn paris_u256() { + // mainnet + let ttd = U256::from(U_PARIS_TTD_MAINNET); + assert_eq!(ttd, PARIS_TTD_MAINNET); + + // goerli + let ttd = U256::from(U_PARIS_TTD_GOERLI); + assert_eq!(ttd, PARIS_TTD_GOERLI); + + // sepolia + let ttd = U256::from(U_PARIS_TTD_SEPOLIA); + assert_eq!(ttd, PARIS_TTD_SEPOLIA); + } +} diff --git a/crates/ethereum-forks/src/chains/mod.rs b/crates/ethereum-forks/src/chains/mod.rs index 78f4b7c58e15..534b8abc2842 100644 --- a/crates/ethereum-forks/src/chains/mod.rs +++ b/crates/ethereum-forks/src/chains/mod.rs @@ -6,29 +6,24 @@ pub mod ethereum; pub mod optimism; use crate::{ForkCondition, Hardfork}; -use alloy_primitives::U256; -use once_cell::sync::Lazy; -use std::collections::BTreeMap; /// Dev hardforks -pub static DEV_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(1561651)), - (Hardfork::Berlin, ForkCondition::Block(4460644)), - (Hardfork::London, ForkCondition::Block(5062605)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(10_790_000) }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), - (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), - ]) -}); +pub static DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(1561651)), + (Hardfork::Berlin, ForkCondition::Block(4460644)), + (Hardfork::London, ForkCondition::Block(5062605)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: None, total_difficulty: ethereum::PARIS_TTD_GOERLI }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), + (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), +]; diff --git a/crates/ethereum-forks/src/chains/optimism.rs b/crates/ethereum-forks/src/chains/optimism.rs index 06d987c57421..1640c847f2c5 100644 --- a/crates/ethereum-forks/src/chains/optimism.rs +++ b/crates/ethereum-forks/src/chains/optimism.rs @@ -1,124 +1,105 @@ use crate::{ForkCondition, Hardfork}; use alloy_primitives::U256; -use once_cell::sync::Lazy; -use std::collections::BTreeMap; /// Optimism mainnet hardforks -pub static OP_MAINNET_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(3950000)), - (Hardfork::London, ForkCondition::Block(105235063)), - (Hardfork::ArrowGlacier, ForkCondition::Block(105235063)), - (Hardfork::GrayGlacier, ForkCondition::Block(105235063)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(105235063), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(105235063)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), - (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), - (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), - (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), - ]) -}); +pub static OP_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(3950000)), + (Hardfork::London, ForkCondition::Block(105235063)), + (Hardfork::ArrowGlacier, ForkCondition::Block(105235063)), + (Hardfork::GrayGlacier, ForkCondition::Block(105235063)), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: Some(105235063), total_difficulty: U256::ZERO }, + ), + (Hardfork::Bedrock, ForkCondition::Block(105235063)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), + (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), + (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), +]; /// Optimism Sepolia hardforks -pub static OP_SEPOLIA_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::ArrowGlacier, ForkCondition::Block(0)), - (Hardfork::GrayGlacier, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(0)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), - (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), - (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), - (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), - ]) -}); +pub static OP_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::ArrowGlacier, ForkCondition::Block(0)), + (Hardfork::GrayGlacier, ForkCondition::Block(0)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }), + (Hardfork::Bedrock, ForkCondition::Block(0)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), + (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), + (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), + (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), +]; /// Base Sepolia hardforks -pub static BASE_SEPOLIA_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::ArrowGlacier, ForkCondition::Block(0)), - (Hardfork::GrayGlacier, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(0)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), - (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), - (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), - (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), - ]) -}); +pub static BASE_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::ArrowGlacier, ForkCondition::Block(0)), + (Hardfork::GrayGlacier, ForkCondition::Block(0)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }), + (Hardfork::Bedrock, ForkCondition::Block(0)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1699981200)), + (Hardfork::Canyon, ForkCondition::Timestamp(1699981200)), + (Hardfork::Cancun, ForkCondition::Timestamp(1708534800)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1708534800)), + (Hardfork::Fjord, ForkCondition::Timestamp(1716998400)), +]; /// Base Mainnet hardforks -pub static BASE_MAINNET_HARDFORKS: Lazy> = Lazy::new(|| { - BTreeMap::from([ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(0)), - (Hardfork::MuirGlacier, ForkCondition::Block(0)), - (Hardfork::Berlin, ForkCondition::Block(0)), - (Hardfork::London, ForkCondition::Block(0)), - (Hardfork::ArrowGlacier, ForkCondition::Block(0)), - (Hardfork::GrayGlacier, ForkCondition::Block(0)), - ( - Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::from(0) }, - ), - (Hardfork::Bedrock, ForkCondition::Block(0)), - (Hardfork::Regolith, ForkCondition::Timestamp(0)), - (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), - (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), - (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), - (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), - (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), - ]) -}); +pub static BASE_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(0)), + (Hardfork::MuirGlacier, ForkCondition::Block(0)), + (Hardfork::Berlin, ForkCondition::Block(0)), + (Hardfork::London, ForkCondition::Block(0)), + (Hardfork::ArrowGlacier, ForkCondition::Block(0)), + (Hardfork::GrayGlacier, ForkCondition::Block(0)), + (Hardfork::Paris, ForkCondition::TTD { fork_block: Some(0), total_difficulty: U256::ZERO }), + (Hardfork::Bedrock, ForkCondition::Block(0)), + (Hardfork::Regolith, ForkCondition::Timestamp(0)), + (Hardfork::Shanghai, ForkCondition::Timestamp(1704992401)), + (Hardfork::Canyon, ForkCondition::Timestamp(1704992401)), + (Hardfork::Cancun, ForkCondition::Timestamp(1710374401)), + (Hardfork::Ecotone, ForkCondition::Timestamp(1710374401)), + (Hardfork::Fjord, ForkCondition::Timestamp(1720627201)), +]; From 52823933d53b30448dc7ed7aec436e53ac651bc2 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:03:52 +0200 Subject: [PATCH 3/7] turn remaining const --- crates/ethereum-forks/src/chains/ethereum.rs | 2 +- crates/ethereum-forks/src/chains/mod.rs | 8 ++++++-- crates/ethereum-forks/src/chains/optimism.rs | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/ethereum-forks/src/chains/ethereum.rs b/crates/ethereum-forks/src/chains/ethereum.rs index 12d64b25567e..2fac774bff15 100644 --- a/crates/ethereum-forks/src/chains/ethereum.rs +++ b/crates/ethereum-forks/src/chains/ethereum.rs @@ -2,7 +2,7 @@ use crate::{ForkCondition, Hardfork}; use alloy_primitives::U256; const PARIS_TTD_MAINNET: U256 = U256::from_limbs([15566869308787654656, 3184, 0, 0]); -pub(crate) const PARIS_TTD_GOERLI: U256 = U256::from_limbs([10790000, 0, 0, 0]); +const PARIS_TTD_GOERLI: U256 = U256::from_limbs([10790000, 0, 0, 0]); const PARIS_TTD_SEPOLIA: U256 = U256::from_limbs([17000000000000000, 0, 0, 0]); /// Ethereum mainnet hardforks diff --git a/crates/ethereum-forks/src/chains/mod.rs b/crates/ethereum-forks/src/chains/mod.rs index 534b8abc2842..c029b3bfddc0 100644 --- a/crates/ethereum-forks/src/chains/mod.rs +++ b/crates/ethereum-forks/src/chains/mod.rs @@ -6,9 +6,10 @@ pub mod ethereum; pub mod optimism; use crate::{ForkCondition, Hardfork}; +use alloy_primitives::U256; /// Dev hardforks -pub static DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ +pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Dao, ForkCondition::Block(0)), @@ -22,7 +23,10 @@ pub static DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ (Hardfork::London, ForkCondition::Block(5062605)), ( Hardfork::Paris, - ForkCondition::TTD { fork_block: None, total_difficulty: ethereum::PARIS_TTD_GOERLI }, + ForkCondition::TTD { + fork_block: None, + total_difficulty: U256::from_limbs([10790000, 0, 0, 0]), + }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), diff --git a/crates/ethereum-forks/src/chains/optimism.rs b/crates/ethereum-forks/src/chains/optimism.rs index 1640c847f2c5..37af4a19ffe6 100644 --- a/crates/ethereum-forks/src/chains/optimism.rs +++ b/crates/ethereum-forks/src/chains/optimism.rs @@ -2,7 +2,7 @@ use crate::{ForkCondition, Hardfork}; use alloy_primitives::U256; /// Optimism mainnet hardforks -pub static OP_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ +pub const OP_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Tangerine, ForkCondition::Block(0)), @@ -30,7 +30,7 @@ pub static OP_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ ]; /// Optimism Sepolia hardforks -pub static OP_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ +pub const OP_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Tangerine, ForkCondition::Block(0)), @@ -55,7 +55,7 @@ pub static OP_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ ]; /// Base Sepolia hardforks -pub static BASE_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ +pub const BASE_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Tangerine, ForkCondition::Block(0)), @@ -80,7 +80,7 @@ pub static BASE_SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ ]; /// Base Mainnet hardforks -pub static BASE_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ +pub const BASE_MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 21] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Tangerine, ForkCondition::Block(0)), From 7b815b6ca5fa9634247708e9f2e6daaa69f9b5b9 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:05:28 +0200 Subject: [PATCH 4/7] move to dev --- crates/ethereum-forks/src/chains/dev.rs | 26 +++++++++++++++++++++++ crates/ethereum-forks/src/chains/mod.rs | 28 ++----------------------- 2 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 crates/ethereum-forks/src/chains/dev.rs diff --git a/crates/ethereum-forks/src/chains/dev.rs b/crates/ethereum-forks/src/chains/dev.rs new file mode 100644 index 000000000000..1a29db9a0a69 --- /dev/null +++ b/crates/ethereum-forks/src/chains/dev.rs @@ -0,0 +1,26 @@ +use crate::{ForkCondition, Hardfork}; +use alloy_primitives::U256; + +/// Dev hardforks +pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ + (Hardfork::Frontier, ForkCondition::Block(0)), + (Hardfork::Homestead, ForkCondition::Block(0)), + (Hardfork::Dao, ForkCondition::Block(0)), + (Hardfork::Tangerine, ForkCondition::Block(0)), + (Hardfork::SpuriousDragon, ForkCondition::Block(0)), + (Hardfork::Byzantium, ForkCondition::Block(0)), + (Hardfork::Constantinople, ForkCondition::Block(0)), + (Hardfork::Petersburg, ForkCondition::Block(0)), + (Hardfork::Istanbul, ForkCondition::Block(1561651)), + (Hardfork::Berlin, ForkCondition::Block(4460644)), + (Hardfork::London, ForkCondition::Block(5062605)), + ( + Hardfork::Paris, + ForkCondition::TTD { + fork_block: None, + total_difficulty: U256::from_limbs([10790000, 0, 0, 0]), + }, + ), + (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), + (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), +]; \ No newline at end of file diff --git a/crates/ethereum-forks/src/chains/mod.rs b/crates/ethereum-forks/src/chains/mod.rs index c029b3bfddc0..7de0b375c4fa 100644 --- a/crates/ethereum-forks/src/chains/mod.rs +++ b/crates/ethereum-forks/src/chains/mod.rs @@ -5,29 +5,5 @@ pub mod ethereum; #[cfg(feature = "optimism")] pub mod optimism; -use crate::{ForkCondition, Hardfork}; -use alloy_primitives::U256; - -/// Dev hardforks -pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ - (Hardfork::Frontier, ForkCondition::Block(0)), - (Hardfork::Homestead, ForkCondition::Block(0)), - (Hardfork::Dao, ForkCondition::Block(0)), - (Hardfork::Tangerine, ForkCondition::Block(0)), - (Hardfork::SpuriousDragon, ForkCondition::Block(0)), - (Hardfork::Byzantium, ForkCondition::Block(0)), - (Hardfork::Constantinople, ForkCondition::Block(0)), - (Hardfork::Petersburg, ForkCondition::Block(0)), - (Hardfork::Istanbul, ForkCondition::Block(1561651)), - (Hardfork::Berlin, ForkCondition::Block(4460644)), - (Hardfork::London, ForkCondition::Block(5062605)), - ( - Hardfork::Paris, - ForkCondition::TTD { - fork_block: None, - total_difficulty: U256::from_limbs([10790000, 0, 0, 0]), - }, - ), - (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), - (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), -]; +/// Dev chain +pub mod dev; \ No newline at end of file From 2362a9b04f78e91f82df5cd83ab96ea11910cc43 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:06:22 +0200 Subject: [PATCH 5/7] turn remaining const --- crates/ethereum-forks/src/chains/ethereum.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethereum-forks/src/chains/ethereum.rs b/crates/ethereum-forks/src/chains/ethereum.rs index 2fac774bff15..313a7577d55d 100644 --- a/crates/ethereum-forks/src/chains/ethereum.rs +++ b/crates/ethereum-forks/src/chains/ethereum.rs @@ -27,7 +27,7 @@ pub const MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 17] = [ ]; /// Ethereum Goerli hardforks -pub static GOERLI_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ +pub const GOERLI_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Dao, ForkCondition::Block(0)), @@ -45,7 +45,7 @@ pub static GOERLI_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ ]; /// Ethereum Sepolia hardforks -pub static SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 15] = [ +pub const SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 15] = [ (Hardfork::Frontier, ForkCondition::Block(0)), (Hardfork::Homestead, ForkCondition::Block(0)), (Hardfork::Dao, ForkCondition::Block(0)), From 7a374e3668ed758cc2bc96e71bf298b3f1c86ac4 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:09:08 +0200 Subject: [PATCH 6/7] fmt --- crates/ethereum-forks/src/chains/dev.rs | 2 +- crates/ethereum-forks/src/chains/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ethereum-forks/src/chains/dev.rs b/crates/ethereum-forks/src/chains/dev.rs index 1a29db9a0a69..b8668b583557 100644 --- a/crates/ethereum-forks/src/chains/dev.rs +++ b/crates/ethereum-forks/src/chains/dev.rs @@ -23,4 +23,4 @@ pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ ), (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), -]; \ No newline at end of file +]; diff --git a/crates/ethereum-forks/src/chains/mod.rs b/crates/ethereum-forks/src/chains/mod.rs index 7de0b375c4fa..ef775777f399 100644 --- a/crates/ethereum-forks/src/chains/mod.rs +++ b/crates/ethereum-forks/src/chains/mod.rs @@ -6,4 +6,4 @@ pub mod ethereum; pub mod optimism; /// Dev chain -pub mod dev; \ No newline at end of file +pub mod dev; From 4f76c2c5e3e0f30cc34a8a4a012638393a987d72 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:27:19 +0200 Subject: [PATCH 7/7] use uint macro instead --- crates/ethereum-forks/src/chains/dev.rs | 7 +-- crates/ethereum-forks/src/chains/ethereum.rs | 49 +++++++------------- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/crates/ethereum-forks/src/chains/dev.rs b/crates/ethereum-forks/src/chains/dev.rs index b8668b583557..866be0dd4260 100644 --- a/crates/ethereum-forks/src/chains/dev.rs +++ b/crates/ethereum-forks/src/chains/dev.rs @@ -1,5 +1,5 @@ use crate::{ForkCondition, Hardfork}; -use alloy_primitives::U256; +use alloy_primitives::uint; /// Dev hardforks pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ @@ -16,10 +16,7 @@ pub const DEV_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ (Hardfork::London, ForkCondition::Block(5062605)), ( Hardfork::Paris, - ForkCondition::TTD { - fork_block: None, - total_difficulty: U256::from_limbs([10790000, 0, 0, 0]), - }, + ForkCondition::TTD { fork_block: None, total_difficulty: uint!(10_790_000_U256) }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), diff --git a/crates/ethereum-forks/src/chains/ethereum.rs b/crates/ethereum-forks/src/chains/ethereum.rs index 313a7577d55d..6db4d95fcade 100644 --- a/crates/ethereum-forks/src/chains/ethereum.rs +++ b/crates/ethereum-forks/src/chains/ethereum.rs @@ -1,9 +1,5 @@ use crate::{ForkCondition, Hardfork}; -use alloy_primitives::U256; - -const PARIS_TTD_MAINNET: U256 = U256::from_limbs([15566869308787654656, 3184, 0, 0]); -const PARIS_TTD_GOERLI: U256 = U256::from_limbs([10790000, 0, 0, 0]); -const PARIS_TTD_SEPOLIA: U256 = U256::from_limbs([17000000000000000, 0, 0, 0]); +use alloy_primitives::{uint, U256}; /// Ethereum mainnet hardforks pub const MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 17] = [ @@ -21,7 +17,13 @@ pub const MAINNET_HARDFORKS: [(Hardfork, ForkCondition); 17] = [ (Hardfork::London, ForkCondition::Block(12965000)), (Hardfork::ArrowGlacier, ForkCondition::Block(13773000)), (Hardfork::GrayGlacier, ForkCondition::Block(15050000)), - (Hardfork::Paris, ForkCondition::TTD { fork_block: None, total_difficulty: PARIS_TTD_MAINNET }), + ( + Hardfork::Paris, + ForkCondition::TTD { + fork_block: None, + total_difficulty: uint!(58_750_000_000_000_000_000_000_U256), + }, + ), (Hardfork::Shanghai, ForkCondition::Timestamp(1681338455)), (Hardfork::Cancun, ForkCondition::Timestamp(1710338135)), ]; @@ -39,7 +41,10 @@ pub const GOERLI_HARDFORKS: [(Hardfork, ForkCondition); 14] = [ (Hardfork::Istanbul, ForkCondition::Block(1561651)), (Hardfork::Berlin, ForkCondition::Block(4460644)), (Hardfork::London, ForkCondition::Block(5062605)), - (Hardfork::Paris, ForkCondition::TTD { fork_block: None, total_difficulty: PARIS_TTD_GOERLI }), + ( + Hardfork::Paris, + ForkCondition::TTD { fork_block: None, total_difficulty: uint!(10_790_000_U256) }, + ), (Hardfork::Shanghai, ForkCondition::Timestamp(1678832736)), (Hardfork::Cancun, ForkCondition::Timestamp(1705473120)), ]; @@ -60,7 +65,10 @@ pub const SEPOLIA_HARDFORKS: [(Hardfork, ForkCondition); 15] = [ (Hardfork::London, ForkCondition::Block(0)), ( Hardfork::Paris, - ForkCondition::TTD { fork_block: Some(1735371), total_difficulty: PARIS_TTD_SEPOLIA }, + ForkCondition::TTD { + fork_block: Some(1735371), + total_difficulty: uint!(17_000_000_000_000_000_U256), + }, ), (Hardfork::Shanghai, ForkCondition::Timestamp(1677557088)), (Hardfork::Cancun, ForkCondition::Timestamp(1706655072)), @@ -84,28 +92,3 @@ pub const HOLESKY_HARDFORKS: [(Hardfork, ForkCondition); 15] = [ (Hardfork::Shanghai, ForkCondition::Timestamp(1696000704)), (Hardfork::Cancun, ForkCondition::Timestamp(1707305664)), ]; - -#[cfg(test)] -mod tests { - use super::*; - use alloy_primitives::U256; - - const U_PARIS_TTD_MAINNET: u128 = 58_750_000_000_000_000_000_000; - const U_PARIS_TTD_GOERLI: u64 = 10_790_000; - const U_PARIS_TTD_SEPOLIA: u64 = 17_000_000_000_000_000; - - #[test] - fn paris_u256() { - // mainnet - let ttd = U256::from(U_PARIS_TTD_MAINNET); - assert_eq!(ttd, PARIS_TTD_MAINNET); - - // goerli - let ttd = U256::from(U_PARIS_TTD_GOERLI); - assert_eq!(ttd, PARIS_TTD_GOERLI); - - // sepolia - let ttd = U256::from(U_PARIS_TTD_SEPOLIA); - assert_eq!(ttd, PARIS_TTD_SEPOLIA); - } -}