From d3b37576e113a3a18186d01b57251678bea85e2f Mon Sep 17 00:00:00 2001 From: Julian Meyer Date: Wed, 15 Jan 2025 11:48:13 -0800 Subject: [PATCH] feat: add precompiles for BLS12-381 to isthmus --- crates/revm/src/optimism/handler_register.rs | 4 +++- crates/revm/src/optimism/precompile.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/revm/src/optimism/handler_register.rs b/crates/revm/src/optimism/handler_register.rs index da692f5201..5980e8613a 100644 --- a/crates/revm/src/optimism/handler_register.rs +++ b/crates/revm/src/optimism/handler_register.rs @@ -310,7 +310,9 @@ pub fn reimburse_caller( /// Load precompiles for Optimism chain. #[inline] pub fn load_precompiles() -> ContextPrecompiles { - if SPEC::enabled(SpecId::GRANITE) { + if SPEC::enabled(SpecId::ISTHMUS) { + ContextPrecompiles::from_static_precompiles(optimism::precompile::isthmus()) + } else if SPEC::enabled(SpecId::GRANITE) { ContextPrecompiles::from_static_precompiles(optimism::precompile::granite()) } else if SPEC::enabled(SpecId::FJORD) { ContextPrecompiles::from_static_precompiles(optimism::precompile::fjord()) diff --git a/crates/revm/src/optimism/precompile.rs b/crates/revm/src/optimism/precompile.rs index 3d79ef6531..88580a476e 100644 --- a/crates/revm/src/optimism/precompile.rs +++ b/crates/revm/src/optimism/precompile.rs @@ -1,4 +1,6 @@ use once_cell::race::OnceBox; +#[cfg(feature = "blst")] +use revm_precompile::bls12_381; use revm_precompile::{secp256r1, Precompiles}; use std::boxed::Box; @@ -31,3 +33,21 @@ pub(crate) fn granite() -> &'static Precompiles { Box::new(precompiles) }) } + +/// Returns precompiles for isthmus +pub(crate) fn isthmus() -> &'static Self { + static INSTANCE: OnceBox = OnceBox::new(); + INSTANCE.get_or_init(|| { + let precompiles = Self::cancun().clone(); + + // Don't include BLS12-381 precompiles in no_std builds. + #[cfg(feature = "blst")] + let precompiles = { + let mut precompiles = precompiles; + precompiles.extend(bls12_381::precompiles()); + precompiles + }; + + Box::new(precompiles) + }) +}