Skip to content

Commit

Permalink
feat: add genesis and system contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed May 7, 2024
1 parent ac29b4b commit 15767f7
Show file tree
Hide file tree
Showing 106 changed files with 713 additions and 29 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,10 @@ proptest-derive = "0.4"
serial_test = "3"
similar-asserts = "1.5.0"
test-fuzz = "5"


[patch.crates-io]
revm = { git = "https://github.com/bnb-chain/revm.git", rev = "76d842a", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { git = "https://github.com/bnb-chain/revm.git", rev = "76d842a", features = ["std"], default-features = false }
alloy-chains = { git = "https://github.com/bnb-chain/alloy-chains-rs.git", branch = "feat/v0.1.15-opbnb", feature = ["serde", "rlp", "arbitrary"] }
alloy-genesis = { git = "https://github.com/forcodedancing/alloy", branch = "feat/parlia-config" }
1 change: 1 addition & 0 deletions crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ default = ["serde"]
serde = ["dep:serde"]
arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
optimism = []
bsc = []
70 changes: 59 additions & 11 deletions crates/ethereum-forks/src/hardfork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,54 @@ pub enum Hardfork {
// Upcoming
/// Prague: <https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/prague.md>
Prague,

/// BSC Ramanujan hardfork
Ramanujan,

/// BSC Niels hardfork
Niels,

/// BSC MirrorSync hardfork
MirrorSync,

/// BSC Bruno hardfork
Bruno,

/// BSC Euler hardfork
Euler,

/// BSC Nano hardfork
Nano,

/// BSC Moran hardfork
Moran,

/// BSC Gibbs hardfork
Gibbs,

/// BSC Planck hardfork
Planck,

/// BSC Luban hardfork
Luban,

/// BSC Plato hardfork
Plato,

/// BSC Hertz hardfork
Hertz,

/// BSC Hertzfix hardfork
Hertzfix,

/// BSC Kepler hardfork
Kepler,

/// BSC Feynman hardfork
Feynman,

/// BSC FeynmanFix hardfork
FeynmanFix,
}

impl Hardfork {
Expand All @@ -98,22 +146,22 @@ impl Hardfork {
/// Retrieves the activation block for the specified hardfork on the given chain.
pub fn activation_block(&self, chain: Chain) -> Option<u64> {
if chain == Chain::mainnet() {
return self.mainnet_activation_block()
return self.mainnet_activation_block();
}
if chain == Chain::sepolia() {
return self.sepolia_activation_block()
return self.sepolia_activation_block();
}
if chain == Chain::holesky() {
return self.holesky_activation_block()
return self.holesky_activation_block();
}

#[cfg(feature = "optimism")]
{
if chain == Chain::base_sepolia() {
return self.base_sepolia_activation_block()
return self.base_sepolia_activation_block();
}
if chain == Chain::base_mainnet() {
return self.base_mainnet_activation_block()
return self.base_mainnet_activation_block();
}
}

Expand Down Expand Up @@ -311,21 +359,21 @@ impl Hardfork {
/// Retrieves the activation timestamp for the specified hardfork on the given chain.
pub fn activation_timestamp(&self, chain: Chain) -> Option<u64> {
if chain == Chain::mainnet() {
return self.mainnet_activation_timestamp()
return self.mainnet_activation_timestamp();
}
if chain == Chain::sepolia() {
return self.sepolia_activation_timestamp()
return self.sepolia_activation_timestamp();
}
if chain == Chain::holesky() {
return self.holesky_activation_timestamp()
return self.holesky_activation_timestamp();
}
#[cfg(feature = "optimism")]
{
if chain == Chain::base_sepolia() {
return self.base_sepolia_activation_timestamp()
return self.base_sepolia_activation_timestamp();
}
if chain == Chain::base_mainnet() {
return self.base_mainnet_activation_timestamp()
return self.base_mainnet_activation_timestamp();
}
}

Expand Down Expand Up @@ -662,7 +710,7 @@ mod tests {
let pos_hardforks = [Hardfork::Paris, Hardfork::Shanghai, Hardfork::Cancun];

#[cfg(feature = "optimism")]
let op_hardforks =
let op_hardforks =
[Hardfork::Bedrock, Hardfork::Regolith, Hardfork::Canyon, Hardfork::Ecotone];

for hardfork in pow_hardforks.iter() {
Expand Down
7 changes: 6 additions & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
strum = { workspace = true, features = ["derive"] }

include_dir = "0.7.3"
log = "0.4.21"
lazy_static = "1.4.0"

[dev-dependencies]
# eth
revm-primitives = { workspace = true, features = ["arbitrary"] }
Expand Down Expand Up @@ -93,7 +97,7 @@ pprof = { workspace = true, features = ["flamegraph", "frame-pointer", "criterio
secp256k1.workspace = true

[features]
default = ["c-kzg", "zstd-codec"]
default = ["c-kzg", "zstd-codec", "secp256k1/rand"]
asm-keccak = ["alloy-primitives/asm-keccak"]
arbitrary = [
"revm-primitives/arbitrary",
Expand All @@ -120,6 +124,7 @@ optimism = [
"revm/optimism",
]
test-utils = ["dep:plain_hasher", "dep:hash-db"]
bsc = ["revm-primitives/bsc", "revm/bsc"]

[[bench]]
name = "recover_ecdsa_crit"
Expand Down
82 changes: 82 additions & 0 deletions crates/primitives/res/genesis/bsc_mainnet.json

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions crates/primitives/res/genesis/bsc_testnet.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions crates/primitives/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};
#[cfg(test)]
pub(crate) use spec::{OP_BASE_FEE_PARAMS, OP_SEPOLIA_BASE_FEE_PARAMS};

#[cfg(feature = "bsc")]
pub use spec::{BSC_MAINNET, BSC_TESTNET};

// The chain spec module.
mod spec;
// The chain info module.
Expand Down
Loading

0 comments on commit 15767f7

Please sign in to comment.