Skip to content

Commit

Permalink
feat: support for rip 7212 (#29)
Browse files Browse the repository at this point in the history
* support for rip 7212

* fix tests

* remove println

---------

Co-authored-by: Aditya Pandey <[email protected]>
Co-authored-by: lightsing <[email protected]>
  • Loading branch information
3 people authored Oct 30, 2024
1 parent 229ead9 commit cb3a59e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
let mut precompiles = Self::bernoulli().clone();
precompiles.extend([
secp256r1::P256VERIFY, // 0x100
]);
Box::new(precompiles)
})
}
Expand Down Expand Up @@ -318,6 +334,8 @@ pub enum PrecompileSpecId {
PRE_BERNOULLI,
#[cfg(feature = "scroll")]
BERNOULLI,
#[cfg(feature = "scroll")]
EUCLID,
CANCUN,
PRAGUE,
LATEST,
Expand Down Expand Up @@ -345,6 +363,8 @@ impl PrecompileSpecId {
PRE_BERNOULLI => Self::PRE_BERNOULLI,
#[cfg(feature = "scroll")]
BERNOULLI | CURIE => Self::BERNOULLI,
#[cfg(feature = "scroll")]
EUCLID => Self::EUCLID,
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -225,6 +230,8 @@ impl From<SpecId> for &'static str {
SpecId::BERNOULLI => "Bernoulli",
#[cfg(feature = "scroll")]
SpecId::CURIE => "Curie",
#[cfg(feature = "scroll")]
SpecId::EUCLID => "Euclid",
SpecId::LATEST => "Latest",
}
}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
}
}};
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
}
}

0 comments on commit cb3a59e

Please sign in to comment.