Skip to content

Commit

Permalink
feat: add opbnb Haber fork spec id
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jun 3, 2024
1 parent 1f88ae2 commit 725546d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
31 changes: 29 additions & 2 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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(),
}
}
Expand Down Expand Up @@ -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<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
Expand Down Expand Up @@ -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<Precompiles> = 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()
Expand Down Expand Up @@ -281,6 +305,7 @@ pub enum PrecompileSpecId {
FERMAT,
CANCUN,
PRAGUE,
HABER,
LATEST,
}

Expand All @@ -304,6 +329,8 @@ impl PrecompileSpecId {
ECOTONE | FJORD => Self::CANCUN,
#[cfg(feature = "opbnb")]
FERMAT => Self::FERMAT,
#[cfg(feature = "opbnb")]
HABER => Self::HABER,
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub enum SpecId {
ECOTONE = 22,
FJORD = 23,
PRAGUE = 24,
HABER = 25,
#[default]
LATEST = u8::MAX,
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -159,6 +162,8 @@ impl From<SpecId> for &'static str {
SpecId::ECOTONE => "Ecotone",
#[cfg(feature = "optimism")]
SpecId::FJORD => "Fjord",
#[cfg(feature = "opbnb")]
SpecId::HABER => "Haber",
SpecId::LATEST => "Latest",
}
}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
}
}};
}
Expand Down

0 comments on commit 725546d

Please sign in to comment.