From cb3a59e66b4341bea1c8b55eddd324a407ef8ef8 Mon Sep 17 00:00:00 2001 From: 0xsensei Date: Wed, 30 Oct 2024 07:23:03 +0530 Subject: [PATCH] feat: support for rip 7212 (#29) * support for rip 7212 * fix tests * remove println --------- Co-authored-by: Aditya Pandey Co-authored-by: lightsing --- crates/precompile/Cargo.toml | 2 +- crates/precompile/src/lib.rs | 20 +++++++++++++++++++ crates/primitives/src/specification.rs | 27 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 0ed0858444..f9a25a1222 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -96,7 +96,7 @@ negate-optimism-default-handler = [ "revm-primitives/negate-optimism-default-handler", ] -scroll = ["revm-primitives/scroll"] +scroll = ["revm-primitives/scroll", "secp256r1"] # Scroll default handler enabled Scroll handler register by default in EvmBuilder. scroll-default-handler = [ "scroll", diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 3f9584f88a..e2efaaac68 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -64,6 +64,8 @@ impl Precompiles { PrecompileSpecId::PRE_BERNOULLI => Self::pre_bernoulli(), #[cfg(feature = "scroll")] PrecompileSpecId::BERNOULLI => Self::bernoulli(), + #[cfg(feature = "scroll")] + PrecompileSpecId::EUCLID => Self::euclid(), PrecompileSpecId::CANCUN => Self::cancun(), PrecompileSpecId::PRAGUE => Self::prague(), PrecompileSpecId::LATEST => Self::latest(), @@ -213,6 +215,20 @@ impl Precompiles { precompiles.extend([ hash::SHA256, // 0x02 ]); + + Box::new(precompiles) + }) + } + + /// Returns precompiles for Scroll + #[cfg(feature = "scroll")] + pub fn euclid() -> &'static Self { + static INSTANCE: OnceBox = OnceBox::new(); + INSTANCE.get_or_init(|| { + let mut precompiles = Self::bernoulli().clone(); + precompiles.extend([ + secp256r1::P256VERIFY, // 0x100 + ]); Box::new(precompiles) }) } @@ -318,6 +334,8 @@ pub enum PrecompileSpecId { PRE_BERNOULLI, #[cfg(feature = "scroll")] BERNOULLI, + #[cfg(feature = "scroll")] + EUCLID, CANCUN, PRAGUE, LATEST, @@ -345,6 +363,8 @@ impl PrecompileSpecId { PRE_BERNOULLI => Self::PRE_BERNOULLI, #[cfg(feature = "scroll")] BERNOULLI | CURIE => Self::BERNOULLI, + #[cfg(feature = "scroll")] + EUCLID => Self::EUCLID, } } } diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index de91cadaf6..8be8705d37 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -114,6 +114,9 @@ pub enum SpecId { CANCUN = 20, PRAGUE = 21, OSAKA = 22, + /// Euclid update introduces: + /// - Support `p256_verify` precompile. + EUCLID = 23, #[default] LATEST = u8::MAX, } @@ -177,6 +180,8 @@ impl From<&str> for SpecId { "Bernoulli" => SpecId::BERNOULLI, #[cfg(feature = "scroll")] "Curie" => SpecId::CURIE, + #[cfg(feature = "scroll")] + "Euclid" => SpecId::EUCLID, _ => Self::LATEST, } } @@ -225,6 +230,8 @@ impl From for &'static str { SpecId::BERNOULLI => "Bernoulli", #[cfg(feature = "scroll")] SpecId::CURIE => "Curie", + #[cfg(feature = "scroll")] + SpecId::EUCLID => "Euclid", SpecId::LATEST => "Latest", } } @@ -298,6 +305,8 @@ spec!(PRE_BERNOULLI, PreBernoulliSpec); spec!(BERNOULLI, BernoulliSpec); #[cfg(feature = "scroll")] spec!(CURIE, CurieSpec); +#[cfg(feature = "scroll")] +spec!(EUCLID, EuclidSpec); #[cfg(not(any(feature = "optimism", feature = "scroll")))] #[macro_export] @@ -549,6 +558,11 @@ macro_rules! spec_to_generic { use $crate::CurieSpec as SPEC; $e } + #[cfg(feature = "scroll")] + $crate::SpecId::EUCLID => { + use $crate::EuclidSpec as SPEC; + $e + } } }}; } @@ -590,6 +604,8 @@ mod tests { spec_to_generic!(BERNOULLI, assert_eq!(SPEC::SPEC_ID, BERNOULLI)); #[cfg(feature = "scroll")] spec_to_generic!(CURIE, assert_eq!(SPEC::SPEC_ID, CURIE)); + #[cfg(feature = "scroll")] + spec_to_generic!(EUCLID, assert_eq!(SPEC::SPEC_ID, EUCLID)); spec_to_generic!(CANCUN, assert_eq!(SPEC::SPEC_ID, CANCUN)); #[cfg(feature = "optimism")] spec_to_generic!(ECOTONE, assert_eq!(SPEC::SPEC_ID, ECOTONE)); @@ -807,4 +823,15 @@ mod scroll_tests { assert!(!CurieSpec::enabled(SpecId::CANCUN)); assert!(!CurieSpec::enabled(SpecId::LATEST)); } + + #[test] + fn test_euclid_post_merge_hardforks() { + assert!(EuclidSpec::enabled(SpecId::MERGE)); + assert!(EuclidSpec::enabled(SpecId::SHANGHAI)); + assert!(EuclidSpec::enabled(SpecId::PRE_BERNOULLI)); + assert!(EuclidSpec::enabled(SpecId::BERNOULLI)); + assert!(EuclidSpec::enabled(SpecId::CURIE)); + assert!(EuclidSpec::enabled(SpecId::CANCUN)); + assert!(!EuclidSpec::enabled(SpecId::LATEST)); + } }