From 725546dc90b5fe2733fe14a28ed072bf073aab34 Mon Sep 17 00:00:00 2001 From: j75689 Date: Mon, 3 Jun 2024 15:16:44 +0800 Subject: [PATCH] feat: add opbnb Haber fork spec id --- crates/precompile/src/lib.rs | 31 ++++++++++++++++++++++++-- crates/primitives/src/specification.rs | 12 ++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index ef8c04c2..e2f875b6 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -11,9 +11,9 @@ extern crate alloc as std; pub mod blake2; #[cfg(feature = "blst")] pub mod bls12_381; -mod bls; +pub mod bls; +pub mod cometbft; pub mod bn128; -mod cometbft; pub mod hash; pub mod identity; #[cfg(feature = "c-kzg")] @@ -68,9 +68,12 @@ impl Precompiles { PrecompileSpecId::BYZANTIUM => Self::byzantium(), PrecompileSpecId::ISTANBUL => Self::istanbul(), PrecompileSpecId::BERLIN => Self::berlin(), + #[cfg(feature = "opbnb")] PrecompileSpecId::FERMAT => Self::fermat(), PrecompileSpecId::CANCUN => Self::cancun(), PrecompileSpecId::PRAGUE => Self::prague(), + #[cfg(feature = "opbnb")] + PrecompileSpecId::HABER => Self::haber(), PrecompileSpecId::LATEST => Self::latest(), } } @@ -141,6 +144,7 @@ impl Precompiles { /// Returns precompiles for Fermat spec. /// /// effectively making this the same as Berlin. + #[cfg(feature = "opbnb")] pub fn fermat() -> &'static Self { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { @@ -204,6 +208,26 @@ impl Precompiles { }) } + /// Returns precompiles for Haber spec. + /// + /// effectively making this the same as Berlin. + #[cfg(all(feature = "opbnb", feature = "secp256r1"))] + pub fn haber() -> &'static Self { + static INSTANCE: OnceBox = OnceBox::new(); + INSTANCE.get_or_init(|| { + let precompiles = Self::cancun().clone(); + let precompiles = { + let mut precompiles = precompiles; + precompiles.extend([ + secp256r1::P256VERIFY, + ]); + precompiles + }; + + Box::new(precompiles) + }) + } + /// Returns the precompiles for the latest spec. pub fn latest() -> &'static Self { Self::prague() @@ -281,6 +305,7 @@ pub enum PrecompileSpecId { FERMAT, CANCUN, PRAGUE, + HABER, LATEST, } @@ -304,6 +329,8 @@ impl PrecompileSpecId { ECOTONE | FJORD => Self::CANCUN, #[cfg(feature = "opbnb")] FERMAT => Self::FERMAT, + #[cfg(feature = "opbnb")] + HABER => Self::HABER, } } } diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index 5b193fe0..f4a646d5 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -66,6 +66,7 @@ pub enum SpecId { ECOTONE = 22, FJORD = 23, PRAGUE = 24, + HABER = 25, #[default] LATEST = u8::MAX, } @@ -120,6 +121,8 @@ impl From<&str> for SpecId { "Ecotone" => SpecId::ECOTONE, #[cfg(feature = "optimism")] "Fjord" => SpecId::FJORD, + #[cfg(feature = "opbnb")] + "Haber" => SpecId::HABER, _ => Self::LATEST, } } @@ -159,6 +162,8 @@ impl From for &'static str { SpecId::ECOTONE => "Ecotone", #[cfg(feature = "optimism")] SpecId::FJORD => "Fjord", + #[cfg(feature = "opbnb")] + SpecId::HABER => "Haber", SpecId::LATEST => "Latest", } } @@ -221,6 +226,8 @@ spec!(ECOTONE, EcotoneSpec); spec!(FJORD, FjordSpec); #[cfg(feature = "opbnb")] spec!(FERMAT, FermatSpec); +#[cfg(feature = "opbnb")] +spec!(HABER, HaberSpec); #[cfg(not(feature = "optimism"))] #[macro_export] @@ -376,6 +383,11 @@ macro_rules! spec_to_generic { use $crate::FermatSpec as SPEC; $e } + #[cfg(feature = "opbnb")] + $crate::SpecId::HABER => { + use $crate::HaberSpec as SPEC; + $e + } } }}; }