From a740f3d8086395c00fa77fad5474bc4fde5b195d Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Wed, 4 Dec 2024 10:37:38 +0100 Subject: [PATCH] feat: mutually exclusive features `scroll` and `optimism` --- Cargo.lock | 109 +++++++---- bins/revm-test/Cargo.toml | 4 +- crates/interpreter/src/instructions/host.rs | 12 +- .../interpreter/src/instructions/host_env.rs | 2 +- crates/interpreter/src/instructions/memory.rs | 3 +- crates/precompile/src/lib.rs | 10 +- crates/primitives/src/env/handler_cfg.rs | 4 +- crates/primitives/src/specification.rs | 175 +++++++++--------- crates/revm/Cargo.toml | 6 +- crates/revm/src/builder.rs | 4 +- crates/revm/src/context/evm_context.rs | 8 +- crates/revm/src/context/inner_evm_context.rs | 24 ++- crates/revm/src/handler.rs | 14 +- crates/revm/src/lib.rs | 2 +- crates/revm/src/optimism.rs | 1 + crates/revm/src/scroll.rs | 2 + 16 files changed, 224 insertions(+), 156 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b34198fa1e..23c252488d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addchain" @@ -139,9 +139,8 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded610181f3dad5810f6ff12d1a99994cf9b42d2fcb7709029352398a5da5ae6" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -199,9 +198,8 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd58d377699e6cfeab52c4a9d28bdc4ef37e2bd235ff2db525071fe37a2e9af5" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" dependencies = [ "alloy-rlp", "arbitrary", @@ -231,9 +229,9 @@ dependencies = [ [[package]] name = "alloy-provider" -version = "0.5.4" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4814d141ede360bb6cd1b4b064f1aab9de391e7c4d0d4d50ac89ea4bc1e25fbd" +checksum = "c45dbc0e3630becef9e988b69d43339f68d67e32a854e3c855bc28bd5031895b" dependencies = [ "alloy-chains", "alloy-consensus", @@ -365,27 +363,57 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-sol-macro" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" +dependencies = [ + "alloy-sol-macro-expander 0.8.10", + "alloy-sol-macro-input 0.8.10", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "alloy-sol-macro" version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a1b42ac8f45e2f49f4bcdd72cbfde0bb148f5481d403774ffa546e48b83efc1" dependencies = [ - "alloy-sol-macro-expander", - "alloy-sol-macro-input", + "alloy-sol-macro-expander 0.8.11", + "alloy-sol-macro-input 0.8.11", "proc-macro-error2", "proc-macro2", "quote", "syn 2.0.79", ] +[[package]] +name = "alloy-sol-macro-expander" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" +dependencies = [ + "alloy-sol-macro-input 0.8.10", + "const-hex", + "heck 0.5.0", + "indexmap", + "proc-macro-error2", + "proc-macro2", + "quote", + "syn 2.0.79", + "syn-solidity 0.8.10", + "tiny-keccak", +] + [[package]] name = "alloy-sol-macro-expander" version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06318f1778e57f36333e850aa71bd1bb5e560c10279e236622faae0470c50412" dependencies = [ - "alloy-sol-macro-input", + "alloy-sol-macro-input 0.8.11", "const-hex", "heck 0.5.0", "indexmap", @@ -393,10 +421,24 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.79", - "syn-solidity", + "syn-solidity 0.8.11", "tiny-keccak", ] +[[package]] +name = "alloy-sol-macro-input" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.79", + "syn-solidity 0.8.10", +] + [[package]] name = "alloy-sol-macro-input" version = "0.8.11" @@ -409,14 +451,13 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.79", - "syn-solidity", + "syn-solidity 0.8.11", ] [[package]] name = "alloy-sol-type-parser" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12c71028bfbfec210e24106a542aad3def7caf1a70e2c05710e92a98481980d3" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" dependencies = [ "serde", "winnow", @@ -424,13 +465,12 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d7fb042d68ddfe79ccb23359de3007f6d4d53c13f703b64fb0db422132111" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" dependencies = [ "alloy-json-abi", "alloy-primitives", - "alloy-sol-macro", + "alloy-sol-macro 0.8.10", "const-hex", "serde", ] @@ -1524,7 +1564,7 @@ dependencies = [ [[package]] name = "ff" version = "0.13.0" -source = "git+https://github.com/scroll-tech/ff?branch=feat/sp1#244b1098f6be1d19c5fd3f0ec60117ac2940e6ca" +source = "git+https://github.com/scroll-tech/ff?branch=feat%2Fsp1#244b1098f6be1d19c5fd3f0ec60117ac2940e6ca" dependencies = [ "bitvec", "byteorder", @@ -1536,7 +1576,7 @@ dependencies = [ [[package]] name = "ff_derive" version = "0.13.0" -source = "git+https://github.com/scroll-tech/ff?branch=feat/sp1#244b1098f6be1d19c5fd3f0ec60117ac2940e6ca" +source = "git+https://github.com/scroll-tech/ff?branch=feat%2Fsp1#244b1098f6be1d19c5fd3f0ec60117ac2940e6ca" dependencies = [ "addchain", "cfg-if", @@ -3308,7 +3348,7 @@ dependencies = [ name = "revm-test" version = "1.0.0" dependencies = [ - "alloy-sol-macro", + "alloy-sol-macro 0.8.11", "alloy-sol-types", "bytes", "eyre", @@ -4083,6 +4123,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn-solidity" +version = "0.8.10" +source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" +dependencies = [ + "paste", + "proc-macro2", + "quote", + "syn 2.0.79", +] + [[package]] name = "syn-solidity" version = "0.8.11" @@ -5041,13 +5092,3 @@ dependencies = [ "quote", "syn 2.0.79", ] - -[[patch.unused]] -name = "alloy-primitives" -version = "0.8.10" -source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" - -[[patch.unused]] -name = "alloy-sol-types" -version = "0.8.10" -source = "git+https://github.com/scroll-tech/alloy-core?branch=v0.8.10#66d76d8f7e17501ce13df584122887bee088c6bb" diff --git a/bins/revm-test/Cargo.toml b/bins/revm-test/Cargo.toml index 811ce67f12..2ef9b904e9 100644 --- a/bins/revm-test/Cargo.toml +++ b/bins/revm-test/Cargo.toml @@ -9,8 +9,8 @@ bytes = "1.7" hex = "0.4" revm = { path = "../../crates/revm", version = "18.0.0", default-features=false } microbench = "0.5" -alloy-sol-macro = "0.8.11" -alloy-sol-types = "0.8.11" +alloy-sol-macro = "0.8.10" +alloy-sol-types = "0.8.10" regex = "1.10.6" eyre = "0.6.12" diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index ced1b1fa90..75e4035ff9 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -134,7 +134,7 @@ pub fn extcodecopy(interpreter: &mut Interpreter, .set_data(memory_offset, code_offset, len, &code); } -#[cfg(not(feature = "scroll"))] +#[cfg(any(not(feature = "scroll"), feature = "optimism"))] pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { gas!(interpreter, gas::BLOCKHASH); pop_top!(interpreter, number); @@ -147,7 +147,7 @@ pub fn blockhash(interpreter: &mut Interpreter, ho *number = U256::from_be_bytes(hash.0); } -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] pub fn blockhash(interpreter: &mut Interpreter, host: &mut H) { use revm_primitives::BLOCK_HASH_HISTORY; @@ -228,7 +228,8 @@ pub fn sstore(interpreter: &mut Interpreter, host: /// Store value to transient storage pub fn tstore(interpreter: &mut Interpreter, host: &mut H) { cfg_if::cfg_if! { - if #[cfg(feature = "scroll")] { + if #[cfg(all(feature = "scroll", not(feature = "optimism")))] + { check!(interpreter, CURIE); } else { check!(interpreter, CANCUN); @@ -247,7 +248,8 @@ pub fn tstore(interpreter: &mut Interpreter, host: /// Load value from transient storage pub fn tload(interpreter: &mut Interpreter, host: &mut H) { cfg_if::cfg_if! { - if #[cfg(feature = "scroll")] { + if #[cfg(all(feature = "scroll", not(feature = "optimism")))] + { check!(interpreter, CURIE); } else { check!(interpreter, CANCUN); @@ -298,7 +300,7 @@ pub fn selfdestruct(interpreter: &mut Interpreter, require_non_staticcall!(interpreter); pop_address!(interpreter, target); - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] if SPEC::enabled(PRE_BERNOULLI) { interpreter.instruction_result = InstructionResult::NotActivated; return; diff --git a/crates/interpreter/src/instructions/host_env.rs b/crates/interpreter/src/instructions/host_env.rs index 1ea849eab7..13a2d52f6f 100644 --- a/crates/interpreter/src/instructions/host_env.rs +++ b/crates/interpreter/src/instructions/host_env.rs @@ -47,7 +47,7 @@ pub fn gasprice(interpreter: &mut Interpreter, host: &mut H) { /// EIP-3198: BASEFEE opcode pub fn basefee(interpreter: &mut Interpreter, host: &mut H) { - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] if !SPEC::enabled(CURIE) { interpreter.instruction_result = crate::InstructionResult::NotActivated; return; diff --git a/crates/interpreter/src/instructions/memory.rs b/crates/interpreter/src/instructions/memory.rs index 972720a14b..92540b931d 100644 --- a/crates/interpreter/src/instructions/memory.rs +++ b/crates/interpreter/src/instructions/memory.rs @@ -37,7 +37,8 @@ pub fn msize(interpreter: &mut Interpreter, _host: &mut H) { // EIP-5656: MCOPY - Memory copying instruction pub fn mcopy(interpreter: &mut Interpreter, _host: &mut H) { cfg_if::cfg_if! { - if #[cfg(feature = "scroll")] { + if #[cfg(all(feature = "scroll", not(feature = "optimism")))] + { check!(interpreter, CURIE); } else { check!(interpreter, CANCUN); diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index bc490c7507..80d644e935 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -355,15 +355,15 @@ impl PrecompileSpecId { CANCUN => Self::CANCUN, PRAGUE | OSAKA => Self::PRAGUE, LATEST => Self::LATEST, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] BEDROCK | REGOLITH | CANYON => Self::BERLIN, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] ECOTONE | FJORD | GRANITE | HOLOCENE => Self::CANCUN, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] PRE_BERNOULLI => Self::PRE_BERNOULLI, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] BERNOULLI | CURIE => Self::BERNOULLI, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] EUCLID => Self::EUCLID, } } diff --git a/crates/primitives/src/env/handler_cfg.rs b/crates/primitives/src/env/handler_cfg.rs index 48a287b70d..06003195d7 100644 --- a/crates/primitives/src/env/handler_cfg.rs +++ b/crates/primitives/src/env/handler_cfg.rs @@ -52,7 +52,7 @@ impl HandlerCfg { } /// Creates new `HandlerCfg` instance with the optimism feature. - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] pub fn new_with_optimism(spec_id: SpecId, is_optimism: bool) -> Self { Self { spec_id, @@ -61,7 +61,7 @@ impl HandlerCfg { } /// Creates new `HandlerCfg` instance with the scroll feature. - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] pub fn new_with_scroll(spec_id: SpecId, is_scroll: bool) -> Self { Self { spec_id, is_scroll } } diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index cc98dfaff7..0b04590f65 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -5,7 +5,10 @@ pub use SpecId::*; /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(not(any(feature = "optimism", feature = "scroll")))] +#[cfg(any( + not(any(feature = "optimism", feature = "scroll")), + all(feature = "scroll", feature = "optimism") +))] #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -37,7 +40,7 @@ pub enum SpecId { /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -76,7 +79,7 @@ pub enum SpecId { /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -160,27 +163,27 @@ impl From<&str> for SpecId { "Cancun" => Self::CANCUN, "Prague" => Self::PRAGUE, "Osaka" => Self::OSAKA, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Bedrock" => SpecId::BEDROCK, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Regolith" => SpecId::REGOLITH, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Canyon" => SpecId::CANYON, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Ecotone" => SpecId::ECOTONE, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Fjord" => SpecId::FJORD, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Granite" => SpecId::GRANITE, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] "Holocene" => SpecId::HOLOCENE, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] "PreBernoulli" => SpecId::PRE_BERNOULLI, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] "Bernoulli" => SpecId::BERNOULLI, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] "Curie" => SpecId::CURIE, - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] "Euclid" => SpecId::EUCLID, _ => Self::LATEST, } @@ -210,27 +213,27 @@ impl From for &'static str { SpecId::CANCUN => "Cancun", SpecId::PRAGUE => "Prague", SpecId::OSAKA => "Osaka", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::BEDROCK => "Bedrock", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::REGOLITH => "Regolith", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::CANYON => "Canyon", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::ECOTONE => "Ecotone", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::FJORD => "Fjord", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::GRANITE => "Granite", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] SpecId::HOLOCENE => "Holocene", - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] SpecId::PRE_BERNOULLI => "PreBernoulli", - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] SpecId::BERNOULLI => "Bernoulli", - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] SpecId::CURIE => "Curie", - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] SpecId::EUCLID => "Euclid", SpecId::LATEST => "Latest", } @@ -283,32 +286,35 @@ spec!(OSAKA, OsakaSpec); spec!(LATEST, LatestSpec); // Optimism Hardforks -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(BEDROCK, BedrockSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(REGOLITH, RegolithSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(CANYON, CanyonSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(ECOTONE, EcotoneSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(FJORD, FjordSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(GRANITE, GraniteSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] spec!(HOLOCENE, HoloceneSpec); // Scroll Hardforks -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] spec!(PRE_BERNOULLI, PreBernoulliSpec); -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] spec!(BERNOULLI, BernoulliSpec); -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] spec!(CURIE, CurieSpec); -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] spec!(EUCLID, EuclidSpec); -#[cfg(not(any(feature = "optimism", feature = "scroll")))] +#[cfg(any( + not(any(feature = "optimism", feature = "scroll")), + all(feature = "scroll", feature = "optimism") +))] #[macro_export] macro_rules! spec_to_generic { ($spec_id:expr, $e:expr) => {{ @@ -379,7 +385,7 @@ macro_rules! spec_to_generic { }}; } -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] #[macro_export] macro_rules! spec_to_generic { ($spec_id:expr, $e:expr) => {{ @@ -478,7 +484,7 @@ macro_rules! spec_to_generic { }}; } -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] #[macro_export] macro_rules! spec_to_generic { ($spec_id:expr, $e:expr) => {{ @@ -575,53 +581,54 @@ mod tests { fn spec_to_generic() { use SpecId::*; - spec_to_generic!(FRONTIER, assert_eq!(SPEC::SPEC_ID, FRONTIER)); - spec_to_generic!(FRONTIER_THAWING, assert_eq!(SPEC::SPEC_ID, FRONTIER)); - spec_to_generic!(HOMESTEAD, assert_eq!(SPEC::SPEC_ID, HOMESTEAD)); - spec_to_generic!(DAO_FORK, assert_eq!(SPEC::SPEC_ID, HOMESTEAD)); - spec_to_generic!(TANGERINE, assert_eq!(SPEC::SPEC_ID, TANGERINE)); - spec_to_generic!(SPURIOUS_DRAGON, assert_eq!(SPEC::SPEC_ID, SPURIOUS_DRAGON)); - spec_to_generic!(BYZANTIUM, assert_eq!(SPEC::SPEC_ID, BYZANTIUM)); - spec_to_generic!(CONSTANTINOPLE, assert_eq!(SPEC::SPEC_ID, PETERSBURG)); - spec_to_generic!(PETERSBURG, assert_eq!(SPEC::SPEC_ID, PETERSBURG)); - spec_to_generic!(ISTANBUL, assert_eq!(SPEC::SPEC_ID, ISTANBUL)); - spec_to_generic!(MUIR_GLACIER, assert_eq!(SPEC::SPEC_ID, ISTANBUL)); - spec_to_generic!(BERLIN, assert_eq!(SPEC::SPEC_ID, BERLIN)); - spec_to_generic!(LONDON, assert_eq!(SPEC::SPEC_ID, LONDON)); - spec_to_generic!(ARROW_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); - spec_to_generic!(GRAY_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); - spec_to_generic!(MERGE, assert_eq!(SPEC::SPEC_ID, MERGE)); - #[cfg(feature = "optimism")] - spec_to_generic!(BEDROCK, assert_eq!(SPEC::SPEC_ID, BEDROCK)); - #[cfg(feature = "optimism")] - spec_to_generic!(REGOLITH, assert_eq!(SPEC::SPEC_ID, REGOLITH)); - spec_to_generic!(SHANGHAI, assert_eq!(SPEC::SPEC_ID, SHANGHAI)); - #[cfg(feature = "optimism")] - spec_to_generic!(CANYON, assert_eq!(SPEC::SPEC_ID, CANYON)); - #[cfg(feature = "scroll")] - spec_to_generic!(PRE_BERNOULLI, assert_eq!(SPEC::SPEC_ID, PRE_BERNOULLI)); - #[cfg(feature = "scroll")] - 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)); - #[cfg(feature = "optimism")] - spec_to_generic!(FJORD, assert_eq!(SPEC::SPEC_ID, FJORD)); - #[cfg(feature = "optimism")] - spec_to_generic!(GRANITE, assert_eq!(SPEC::SPEC_ID, GRANITE)); - #[cfg(feature = "optimism")] - spec_to_generic!(HOLOCENE, assert_eq!(SPEC::SPEC_ID, HOLOCENE)); - spec_to_generic!(PRAGUE, assert_eq!(SPEC::SPEC_ID, PRAGUE)); - spec_to_generic!(OSAKA, assert_eq!(SPEC::SPEC_ID, OSAKA)); - spec_to_generic!(LATEST, assert_eq!(SPEC::SPEC_ID, LATEST)); + #[cfg(any( + not(any(feature = "optimism", feature = "scroll")), + all(feature = "scroll", feature = "optimism") + ))] + { + spec_to_generic!(FRONTIER, assert_eq!(SPEC::SPEC_ID, FRONTIER)); + spec_to_generic!(FRONTIER_THAWING, assert_eq!(SPEC::SPEC_ID, FRONTIER)); + spec_to_generic!(HOMESTEAD, assert_eq!(SPEC::SPEC_ID, HOMESTEAD)); + spec_to_generic!(DAO_FORK, assert_eq!(SPEC::SPEC_ID, HOMESTEAD)); + spec_to_generic!(TANGERINE, assert_eq!(SPEC::SPEC_ID, TANGERINE)); + spec_to_generic!(SPURIOUS_DRAGON, assert_eq!(SPEC::SPEC_ID, SPURIOUS_DRAGON)); + spec_to_generic!(BYZANTIUM, assert_eq!(SPEC::SPEC_ID, BYZANTIUM)); + spec_to_generic!(CONSTANTINOPLE, assert_eq!(SPEC::SPEC_ID, PETERSBURG)); + spec_to_generic!(PETERSBURG, assert_eq!(SPEC::SPEC_ID, PETERSBURG)); + spec_to_generic!(ISTANBUL, assert_eq!(SPEC::SPEC_ID, ISTANBUL)); + spec_to_generic!(MUIR_GLACIER, assert_eq!(SPEC::SPEC_ID, ISTANBUL)); + spec_to_generic!(BERLIN, assert_eq!(SPEC::SPEC_ID, BERLIN)); + spec_to_generic!(LONDON, assert_eq!(SPEC::SPEC_ID, LONDON)); + spec_to_generic!(ARROW_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); + spec_to_generic!(GRAY_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); + spec_to_generic!(MERGE, assert_eq!(SPEC::SPEC_ID, MERGE)); + spec_to_generic!(SHANGHAI, assert_eq!(SPEC::SPEC_ID, SHANGHAI)); + spec_to_generic!(CANCUN, assert_eq!(SPEC::SPEC_ID, CANCUN)); + spec_to_generic!(PRAGUE, assert_eq!(SPEC::SPEC_ID, PRAGUE)); + spec_to_generic!(OSAKA, assert_eq!(SPEC::SPEC_ID, OSAKA)); + spec_to_generic!(LATEST, assert_eq!(SPEC::SPEC_ID, LATEST)); + } + #[cfg(all(feature = "optimism", not(feature = "scroll")))] + { + spec_to_generic!(BEDROCK, assert_eq!(SPEC::SPEC_ID, BEDROCK)); + spec_to_generic!(REGOLITH, assert_eq!(SPEC::SPEC_ID, REGOLITH)); + spec_to_generic!(CANYON, assert_eq!(SPEC::SPEC_ID, CANYON)); + spec_to_generic!(ECOTONE, assert_eq!(SPEC::SPEC_ID, ECOTONE)); + spec_to_generic!(FJORD, assert_eq!(SPEC::SPEC_ID, FJORD)); + spec_to_generic!(GRANITE, assert_eq!(SPEC::SPEC_ID, GRANITE)); + spec_to_generic!(HOLOCENE, assert_eq!(SPEC::SPEC_ID, HOLOCENE)); + } + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + { + spec_to_generic!(PRE_BERNOULLI, assert_eq!(SPEC::SPEC_ID, PRE_BERNOULLI)); + spec_to_generic!(BERNOULLI, assert_eq!(SPEC::SPEC_ID, BERNOULLI)); + spec_to_generic!(CURIE, assert_eq!(SPEC::SPEC_ID, CURIE)); + spec_to_generic!(EUCLID, assert_eq!(SPEC::SPEC_ID, EUCLID)); + } } } -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] #[cfg(test)] mod optimism_tests { use super::*; @@ -789,7 +796,7 @@ mod optimism_tests { } } -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "optimism")))] #[cfg(test)] mod scroll_tests { use super::*; diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 21438f47bb..b46e20d062 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -49,9 +49,9 @@ ethers-providers = { version = "2.0", optional = true } ethers-core = { version = "2.0", optional = true } # alloydb -alloy-provider = { version = "0.5.4", optional = true, default-features = false } -alloy-eips = { version = "0.5.4", optional = true, default-features = false } -alloy-transport = { version = "0.5.4", optional = true, default-features = false } +alloy-provider = { version = "0.5.3", optional = true, default-features = false } +alloy-eips = { version = "0.5.3", optional = true, default-features = false } +alloy-transport = { version = "0.5.3", optional = true, default-features = false } [dev-dependencies] alloy-sol-types = { version = "0.8.2", default-features = false, features = [ diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index 6f78f58aa4..c77fdff8c9 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -164,7 +164,7 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, SetGenericStage, EXT, DB> { /// Sets the Optimism handler with latest spec. /// /// If `optimism-default-handler` feature is enabled this is not needed. - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] pub fn optimism(mut self) -> EvmBuilder<'a, HandlerStage, EXT, DB> { self.handler = Handler::optimism_with_spec(self.handler.cfg.spec_id); EvmBuilder { @@ -177,7 +177,7 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, SetGenericStage, EXT, DB> { /// Sets the Scroll handler with latest spec. /// /// If `scroll-default-handler` feature is enabled this is not needed. - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] pub fn scroll(mut self) -> EvmBuilder<'a, HandlerStage, EXT, DB> { self.handler = Handler::scroll_with_spec(self.handler.cfg.spec_id); EvmBuilder { diff --git a/crates/revm/src/context/evm_context.rs b/crates/revm/src/context/evm_context.rs index 07bb58e908..ebfaccef0d 100644 --- a/crates/revm/src/context/evm_context.rs +++ b/crates/revm/src/context/evm_context.rs @@ -532,7 +532,9 @@ pub(crate) mod test_utils { journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::default()), db, error: Ok(()), - #[cfg(any(feature = "optimism", feature = "scroll"))] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + l1_block_info: None, + #[cfg(all(feature = "optimism", not(feature = "scroll")))] l1_block_info: None, }, precompiles: ContextPrecompiles::default(), @@ -547,7 +549,9 @@ pub(crate) mod test_utils { journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::default()), db, error: Ok(()), - #[cfg(any(feature = "optimism", feature = "scroll"))] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + l1_block_info: None, + #[cfg(all(feature = "optimism", not(feature = "scroll")))] l1_block_info: None, }, precompiles: ContextPrecompiles::default(), diff --git a/crates/revm/src/context/inner_evm_context.rs b/crates/revm/src/context/inner_evm_context.rs index 612f041cea..07b27df684 100644 --- a/crates/revm/src/context/inner_evm_context.rs +++ b/crates/revm/src/context/inner_evm_context.rs @@ -28,10 +28,10 @@ pub struct InnerEvmContext { /// Error that happened during execution. pub error: Result<(), EVMError>, /// Used as temporary value holder to store L1 block info. - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] pub l1_block_info: Option, /// Used as temporary value holder to store L1 block info. - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] pub l1_block_info: Option, } @@ -45,8 +45,10 @@ where journaled_state: self.journaled_state.clone(), db: self.db.clone(), error: self.error.clone(), - #[cfg(any(feature = "optimism", feature = "scroll"))] - l1_block_info: self.l1_block_info.clone(), + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + l1_block_info: None, + #[cfg(all(feature = "optimism", not(feature = "scroll")))] + l1_block_info: None, } } } @@ -58,7 +60,9 @@ impl InnerEvmContext { journaled_state: JournaledState::new(SpecId::LATEST, HashSet::default()), db, error: Ok(()), - #[cfg(any(feature = "optimism", feature = "scroll"))] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + l1_block_info: None, + #[cfg(all(feature = "optimism", not(feature = "scroll")))] l1_block_info: None, } } @@ -71,7 +75,9 @@ impl InnerEvmContext { journaled_state: JournaledState::new(SpecId::LATEST, HashSet::default()), db, error: Ok(()), - #[cfg(any(feature = "optimism", feature = "scroll"))] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + l1_block_info: None, + #[cfg(all(feature = "optimism", not(feature = "scroll")))] l1_block_info: None, } } @@ -86,8 +92,10 @@ impl InnerEvmContext { journaled_state: self.journaled_state, db, error: Ok(()), - #[cfg(any(feature = "optimism", feature = "scroll"))] - l1_block_info: self.l1_block_info, + #[cfg(all(feature = "scroll", not(feature = "optimism")))] + l1_block_info: None, + #[cfg(all(feature = "optimism", not(feature = "scroll")))] + l1_block_info: None, } } diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index a033823150..133db416ba 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -45,13 +45,15 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { /// Or `optimism_with_spec` if the optimism feature is enabled and `cfg.is_optimism` is set. pub fn new(cfg: HandlerCfg) -> Self { cfg_if::cfg_if! { - if #[cfg(feature = "optimism")] { + if #[cfg(all(feature = "optimism", not(feature = "scroll")))] + { if cfg.is_optimism { Handler::optimism_with_spec(cfg.spec_id) } else { Handler::mainnet_with_spec(cfg.spec_id) } - } else if #[cfg(feature = "scroll")] { + } else if #[cfg(all(feature = "scroll", not(feature = "optimism")))] + { if cfg.is_scroll { Handler::scroll_with_spec(cfg.spec_id) } else { @@ -82,7 +84,7 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { } /// Handler for optimism - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] pub fn optimism() -> Self { let mut handler = Self::mainnet::(); handler.cfg.is_optimism = true; @@ -93,7 +95,7 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { } /// Handler for scroll - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] pub fn scroll() -> Self { let mut handler = Self::mainnet::(); handler.cfg.is_scroll = true; @@ -104,13 +106,13 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { } /// Optimism with spec. Similar to [`Self::mainnet_with_spec`]. - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "scroll")))] pub fn optimism_with_spec(spec_id: SpecId) -> Self { spec_to_generic!(spec_id, Self::optimism::()) } /// Scroll with spec. Similar to [`Self::mainnet_with_spec`] - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "optimism")))] pub fn scroll_with_spec(spec_id: SpecId) -> Self { spec_to_generic!(spec_id, Self::scroll::()) } diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 18dbe72d3b..8dba94714c 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -43,7 +43,7 @@ pub use handler::Handler; pub use inspector::{inspector_handle_register, inspectors, GetInspector, Inspector}; pub use journaled_state::{JournalCheckpoint, JournalEntry, JournaledState}; // export Optimism types, helpers, and constants -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "scroll")))] pub use optimism::{L1BlockInfo, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT}; // Reexport libraries diff --git a/crates/revm/src/optimism.rs b/crates/revm/src/optimism.rs index 05256ca290..e49cfb0ba7 100644 --- a/crates/revm/src/optimism.rs +++ b/crates/revm/src/optimism.rs @@ -1,4 +1,5 @@ //! Optimism-specific constants, types, and helpers. +#![cfg(all(feature = "optimism", not(feature = "scroll")))] mod bn128; mod fast_lz; diff --git a/crates/revm/src/scroll.rs b/crates/revm/src/scroll.rs index d8b4959184..ac3c0dabbc 100644 --- a/crates/revm/src/scroll.rs +++ b/crates/revm/src/scroll.rs @@ -1,3 +1,5 @@ +#![cfg(all(feature = "scroll", not(feature = "optimism")))] + mod handler_register; mod l1block;