diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 1c0d9e1b267b..0a6452984c42 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,7 +28,7 @@ jobs: features: "scroll asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs" - type: scroll-mpt args: --bin scroll-reth-mpt --workspace --lib --examples --tests --benches --locked - features: "scroll asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs" + features: "scroll skip-state-root-validation mpt asm-keccak jemalloc jemalloc-prof min-error-logs min-warn-logs min-info-logs min-debug-logs min-trace-logs" - type: book args: --manifest-path book/sources/Cargo.toml --workspace --bins features: "" diff --git a/Cargo.lock b/Cargo.lock index a266d744fad7..7df9ba7a5861 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9392,6 +9392,7 @@ dependencies = [ "reth-primitives-traits", "reth-scroll-forks", "reth-scroll-state-commitment", + "reth-trie-common", "serde", "serde_json", ] diff --git a/crates/scroll/bin/scroll-reth-mpt/Cargo.toml b/crates/scroll/bin/scroll-reth-mpt/Cargo.toml index d52394afee6d..f9ad96f5cb13 100644 --- a/crates/scroll/bin/scroll-reth-mpt/Cargo.toml +++ b/crates/scroll/bin/scroll-reth-mpt/Cargo.toml @@ -29,6 +29,10 @@ scroll = [ "reth-provider/scroll", "reth-scroll-cli/scroll", ] +mpt = [ + "reth-scroll-cli/mpt", + "reth-scroll-node/mpt", +] skip-state-root-validation = [ "reth-node-builder/skip-state-root-validation", "reth-scroll-node/skip-state-root-validation" @@ -42,3 +46,4 @@ optimism = [ [[bin]] name = "scroll-reth-mpt" path = "src/main.rs" +required-features = ["mpt", "skip-state-root-validation", "scroll"] diff --git a/crates/scroll/chainspec/Cargo.toml b/crates/scroll/chainspec/Cargo.toml index 4b28834a3c38..1c2a67ad5c1c 100644 --- a/crates/scroll/chainspec/Cargo.toml +++ b/crates/scroll/chainspec/Cargo.toml @@ -15,8 +15,9 @@ workspace = true # reth reth-chainspec.workspace = true reth-ethereum-forks.workspace = true -reth-primitives-traits.workspace = true reth-network-peers.workspace = true +reth-primitives-traits.workspace = true +reth-trie-common = { workspace = true, optional = true } # scroll reth-scroll-forks.workspace = true @@ -60,3 +61,4 @@ std = [ "derive_more/std", "reth-network-peers/std" ] +mpt = ["reth-trie-common"] diff --git a/crates/scroll/chainspec/src/lib.rs b/crates/scroll/chainspec/src/lib.rs index a4b523431ba8..6510b6aa9201 100644 --- a/crates/scroll/chainspec/src/lib.rs +++ b/crates/scroll/chainspec/src/lib.rs @@ -29,6 +29,8 @@ use std::sync::LazyLock; extern crate alloc; +use reth_scroll_state_commitment as _; + mod constants; pub use constants::{ SCROLL_DEV_L1_CONFIG, SCROLL_DEV_L1_MESSAGE_QUEUE_ADDRESS, SCROLL_DEV_L1_PROXY_ADDRESS, @@ -233,7 +235,10 @@ impl ScrollChainSpec { difficulty: self.genesis.difficulty, nonce: self.genesis.nonce.into(), extra_data: self.genesis.extra_data.clone(), + #[cfg(not(feature = "mpt"))] state_root: reth_scroll_state_commitment::state_root_ref_unhashed(&self.genesis.alloc), + #[cfg(feature = "mpt")] + state_root: reth_trie_common::root::state_root_ref_unhashed(&self.genesis.alloc), timestamp: self.genesis.timestamp, mix_hash: self.genesis.mix_hash, beneficiary: self.genesis.coinbase, diff --git a/crates/scroll/cli/Cargo.toml b/crates/scroll/cli/Cargo.toml index 4270e15af03a..13cdb87ad9bd 100644 --- a/crates/scroll/cli/Cargo.toml +++ b/crates/scroll/cli/Cargo.toml @@ -46,4 +46,5 @@ scroll = [ "reth-node-core/scroll", "reth-scroll-evm/scroll", "reth-scroll-node/scroll" -] \ No newline at end of file +] +mpt = ["reth-scroll-chainspec/mpt"] \ No newline at end of file diff --git a/crates/scroll/execution/Cargo.toml b/crates/scroll/execution/Cargo.toml index ad6a369a9c05..1b1ccee40ce2 100644 --- a/crates/scroll/execution/Cargo.toml +++ b/crates/scroll/execution/Cargo.toml @@ -24,3 +24,4 @@ scroll = [ "reth-revm/scroll" ] test-utils = ["reth-revm/test-utils"] +mpt = [] diff --git a/crates/scroll/execution/src/finalize.rs b/crates/scroll/execution/src/finalize.rs index 4c558caaaac7..cfaf7a6eaf3f 100644 --- a/crates/scroll/execution/src/finalize.rs +++ b/crates/scroll/execution/src/finalize.rs @@ -2,10 +2,12 @@ use reth_revm::{cached::CachedReadsDbMut, database::EvmStateProvider, revm::State}; +#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +use reth_revm::database::StateProviderDatabase; #[cfg(feature = "test-utils")] use reth_revm::EmptyDBTyped; -#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] -use reth_revm::{database::StateProviderDatabase, revm::CacheDB, DatabaseRef}; +#[cfg(any(not(feature = "scroll"), feature = "mpt", feature = "test-utils"))] +use reth_revm::{revm::CacheDB, DatabaseRef}; #[cfg(feature = "scroll")] use reth_scroll_storage::ScrollStateProviderDatabase; @@ -76,7 +78,7 @@ impl FinalizeExecution for State<&mut StateProviderDatabas } } -#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +#[cfg(any(not(feature = "scroll"), feature = "mpt", feature = "test-utils"))] impl FinalizeExecution for State> { type Output = reth_revm::db::BundleState; diff --git a/crates/scroll/node/Cargo.toml b/crates/scroll/node/Cargo.toml index 7df01c10185b..1708d95f4b8a 100644 --- a/crates/scroll/node/Cargo.toml +++ b/crates/scroll/node/Cargo.toml @@ -64,4 +64,8 @@ scroll = [ "reth-scroll-evm/scroll", "reth-scroll-engine/scroll" ] +mpt = [ + "reth-scroll-chainspec/mpt", + "reth-scroll-state-commitment/mpt" +] skip-state-root-validation = [] \ No newline at end of file diff --git a/crates/scroll/revm/Cargo.toml b/crates/scroll/revm/Cargo.toml index f5fbd1ad1c0e..8ca8dbe33b64 100644 --- a/crates/scroll/revm/Cargo.toml +++ b/crates/scroll/revm/Cargo.toml @@ -42,6 +42,7 @@ std = [ "revm/std", "serde?/std" ] +mpt = [] blst = ["revm/blst"] optional_block_gas_limit = ["revm/optional_block_gas_limit"] diff --git a/crates/scroll/revm/src/states/bundle.rs b/crates/scroll/revm/src/states/bundle.rs index 5972a351e32f..c1b758fe4315 100644 --- a/crates/scroll/revm/src/states/bundle.rs +++ b/crates/scroll/revm/src/states/bundle.rs @@ -72,21 +72,13 @@ impl From<(BundleState, &ScrollPostExecutionContext)> for ScrollBundleState { } // This conversion can cause a loss of information since performed without additional context. -#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] +#[cfg(any(feature = "mpt", feature = "test-utils"))] impl From for ScrollBundleState { fn from(bundle: BundleState) -> Self { (bundle, &ScrollPostExecutionContext::default()).into() } } -// This conversion can cause a loss of information since performed without additional context. -#[cfg(any(not(feature = "scroll"), feature = "test-utils"))] -impl From<(BundleState, &())> for ScrollBundleState { - fn from((bundle, _): (BundleState, &())) -> Self { - bundle.into() - } -} - impl ScrollBundleState { /// Return builder instance for further manipulation pub fn builder(revert_range: RangeInclusive) -> ScrollBundleBuilder { diff --git a/crates/scroll/revm/src/test_utils.rs b/crates/scroll/revm/src/test_utils.rs index 278b16ab0ef6..2322002593da 100644 --- a/crates/scroll/revm/src/test_utils.rs +++ b/crates/scroll/revm/src/test_utils.rs @@ -1,14 +1,14 @@ use crate::{ shared::AccountInfo, states::{ - ScrollAccountInfo, ScrollAccountInfoRevert, ScrollAccountRevert, ScrollPlainStateReverts, - ScrollStateChangeset, + ScrollAccountInfo, ScrollAccountInfoRevert, ScrollAccountRevert, ScrollBundleState, + ScrollPlainStateReverts, ScrollStateChangeset, }, }; use reth_scroll_primitives::poseidon::{hash_code, POSEIDON_EMPTY}; use revm::db::{ states::{reverts::AccountInfoRevert, PlainStateReverts, StateChangeset}, - AccountRevert, + AccountRevert, BundleState, }; // This conversion can cause a loss of information since performed without additional context. @@ -99,3 +99,10 @@ impl From for AccountInfo { } } } + +// This conversion can cause a loss of information since performed without additional context. +impl From<(BundleState, &())> for ScrollBundleState { + fn from((bundle, _): (BundleState, &())) -> Self { + bundle.into() + } +} diff --git a/crates/scroll/state-commitment/Cargo.toml b/crates/scroll/state-commitment/Cargo.toml index 3c08dea4962e..e34605608179 100644 --- a/crates/scroll/state-commitment/Cargo.toml +++ b/crates/scroll/state-commitment/Cargo.toml @@ -70,6 +70,7 @@ scroll = [ "reth-provider/scroll", "reth-trie/scroll" ] +mpt = ["reth-trie/mpt", "reth-scroll-execution/mpt"] test-utils = [ "dep:zktrie_rust", "dep:zktrie", diff --git a/crates/scroll/trie/Cargo.toml b/crates/scroll/trie/Cargo.toml index d61447dae6d1..886b5f6d75b4 100644 --- a/crates/scroll/trie/Cargo.toml +++ b/crates/scroll/trie/Cargo.toml @@ -23,4 +23,5 @@ hex-literal = "0.4" proptest-arbitrary-interop.workspace = true [features] -scroll = ["reth-trie/scroll"] \ No newline at end of file +scroll = ["reth-trie/scroll"] +mpt = ["reth-trie/mpt"] \ No newline at end of file diff --git a/crates/stages/stages/src/stages/merkle.rs b/crates/stages/stages/src/stages/merkle.rs index fa6b50c081a4..d9db943af3e9 100644 --- a/crates/stages/stages/src/stages/merkle.rs +++ b/crates/stages/stages/src/stages/merkle.rs @@ -276,7 +276,9 @@ where self.save_execution_checkpoint(provider, None)?; #[cfg(feature = "skip-state-root-validation")] - let _ = trie_root; + { + debug!(target: "sync::stages::merkle::exec", ?trie_root, block_number = target_block.number()); + } #[cfg(not(feature = "skip-state-root-validation"))] validate_state_root(trie_root, SealedHeader::seal(target_block), to_block)?; diff --git a/crates/trie/common/Cargo.toml b/crates/trie/common/Cargo.toml index 2e6c6fe95a1a..5a30cad28991 100644 --- a/crates/trie/common/Cargo.toml +++ b/crates/trie/common/Cargo.toml @@ -116,6 +116,7 @@ scroll = [ "reth-primitives-traits/scroll", "dep:reth-scroll-primitives", ] +mpt = ["scroll"] [[bench]] name = "prefix_set" diff --git a/crates/trie/common/src/key.rs b/crates/trie/common/src/key.rs index c439c7eaf94e..ebc443801b28 100644 --- a/crates/trie/common/src/key.rs +++ b/crates/trie/common/src/key.rs @@ -108,9 +108,9 @@ impl BitsCompatibility for Nibbles { /// there is a byte for each bit in the input. The representation is big-endian with respect to the /// input. When the `scroll` feature is not enabled, this method will unpack the bytes into nibbles. pub fn unpack_nibbles>(data: T) -> Nibbles { - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "mpt")))] let nibbles = Nibbles::unpack_bits(data); - #[cfg(not(feature = "scroll"))] + #[cfg(any(not(feature = "scroll"), feature = "mpt"))] let nibbles = Nibbles::unpack(data); nibbles } @@ -120,9 +120,9 @@ pub fn unpack_nibbles>(data: T) -> Nibbles { /// For the `scroll` feature, this method will pack the bits into a byte representation. When the /// `scroll` feature is not enabled, this method will pack the nibbles into bytes. pub fn pack_nibbles(nibbles: &Nibbles) -> SmallVec<[u8; 32]> { - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "mpt")))] let packed = nibbles.pack_bits(); - #[cfg(not(feature = "scroll"))] + #[cfg(any(not(feature = "scroll"), feature = "mpt"))] let packed = nibbles.pack(); packed } diff --git a/crates/trie/trie/Cargo.toml b/crates/trie/trie/Cargo.toml index e393339d5d86..6bda7acc7563 100644 --- a/crates/trie/trie/Cargo.toml +++ b/crates/trie/trie/Cargo.toml @@ -84,6 +84,11 @@ scroll = [ "reth-primitives-traits/scroll", "reth-trie-common/scroll" ] +mpt = [ + "revm/scroll", + "reth-primitives-traits/scroll", + "reth-trie-common/mpt" +] [[bench]] name = "hash_post_state" diff --git a/crates/trie/trie/src/walker.rs b/crates/trie/trie/src/walker.rs index 233e3c1a467e..ed73f833ddb4 100644 --- a/crates/trie/trie/src/walker.rs +++ b/crates/trie/trie/src/walker.rs @@ -10,7 +10,7 @@ use reth_trie_common::pack_nibbles; #[cfg(feature = "metrics")] use crate::metrics::WalkerMetrics; -#[cfg(feature = "scroll")] +#[cfg(all(feature = "scroll", not(feature = "mpt")))] use crate::BitsCompatibility; /// `TrieWalker` is a structure that enables traversal of a Merkle trie. @@ -105,9 +105,9 @@ impl TrieWalker { .and_then(|key| { if self.can_skip_current_node { // TODO(scroll): replace this with key abstraction. - #[cfg(not(feature = "scroll"))] + #[cfg(any(not(feature = "scroll"), feature = "mpt"))] let key = key.increment().map(|inc| inc.pack()); - #[cfg(feature = "scroll")] + #[cfg(all(feature = "scroll", not(feature = "mpt")))] let key = key.increment_bit().map(|inc| inc.pack_bits()); key } else { diff --git a/testing/testing-utils/Cargo.toml b/testing/testing-utils/Cargo.toml index 654c526be895..d12e447e4413 100644 --- a/testing/testing-utils/Cargo.toml +++ b/testing/testing-utils/Cargo.toml @@ -24,7 +24,7 @@ secp256k1 = { workspace = true, features = ["rand"] } [dev-dependencies] alloy-eips.workspace = true -reth-primitives-traits .workspace = true +reth-primitives-traits.workspace = true [features] scroll = ["reth-primitives/scroll"]