Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mpt feature #122

Merged
merged 8 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/scroll/bin/scroll-reth-mpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -42,3 +46,4 @@ optimism = [
[[bin]]
name = "scroll-reth-mpt"
path = "src/main.rs"
required-features = ["mpt", "skip-state-root-validation", "scroll"]
4 changes: 3 additions & 1 deletion crates/scroll/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,3 +61,4 @@ std = [
"derive_more/std",
"reth-network-peers/std"
]
mpt = ["reth-trie-common"]
5 changes: 5 additions & 0 deletions crates/scroll/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/scroll/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ scroll = [
"reth-node-core/scroll",
"reth-scroll-evm/scroll",
"reth-scroll-node/scroll"
]
]
mpt = ["reth-scroll-chainspec/mpt"]
1 change: 1 addition & 0 deletions crates/scroll/execution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ scroll = [
"reth-revm/scroll"
]
test-utils = ["reth-revm/test-utils"]
mpt = []
2 changes: 1 addition & 1 deletion crates/scroll/execution/src/finalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<DB: EvmStateProvider> FinalizeExecution for State<&mut StateProviderDatabas
}
}

#[cfg(any(not(feature = "scroll"), feature = "test-utils"))]
#[cfg(any(not(feature = "scroll"), feature = "mpt", feature = "test-utils"))]
greged93 marked this conversation as resolved.
Show resolved Hide resolved
impl<DB: DatabaseRef> FinalizeExecution for State<CacheDB<DB>> {
type Output = reth_revm::db::BundleState;

Expand Down
4 changes: 4 additions & 0 deletions crates/scroll/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
1 change: 1 addition & 0 deletions crates/scroll/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ std = [
"revm/std",
"serde?/std"
]
mpt = []

blst = ["revm/blst"]
optional_block_gas_limit = ["revm/optional_block_gas_limit"]
Expand Down
10 changes: 1 addition & 9 deletions crates/scroll/revm/src/states/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
greged93 marked this conversation as resolved.
Show resolved Hide resolved
impl From<BundleState> 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<u64>) -> ScrollBundleBuilder {
Expand Down
13 changes: 10 additions & 3 deletions crates/scroll/revm/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -99,3 +99,10 @@ impl From<ScrollAccountInfo> 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()
}
}
1 change: 1 addition & 0 deletions crates/scroll/state-commitment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion crates/scroll/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ hex-literal = "0.4"
proptest-arbitrary-interop.workspace = true

[features]
scroll = ["reth-trie/scroll"]
scroll = ["reth-trie/scroll"]
mpt = ["reth-trie/mpt"]
4 changes: 3 additions & 1 deletion crates/stages/stages/src/stages/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
greged93 marked this conversation as resolved.
Show resolved Hide resolved
}
#[cfg(not(feature = "skip-state-root-validation"))]
validate_state_root(trie_root, SealedHeader::seal(target_block), to_block)?;

Expand Down
1 change: 1 addition & 0 deletions crates/trie/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ scroll = [
"reth-primitives-traits/scroll",
"dep:reth-scroll-primitives",
]
mpt = ["scroll"]

[[bench]]
name = "prefix_set"
Expand Down
8 changes: 4 additions & 4 deletions crates/trie/common/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsRef<[u8]>>(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
}
Expand All @@ -120,9 +120,9 @@ pub fn unpack_nibbles<T: AsRef<[u8]>>(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
}
5 changes: 5 additions & 0 deletions crates/trie/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions crates/trie/trie/src/walker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -105,9 +105,9 @@ impl<C> TrieWalker<C> {
.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 {
Expand Down
2 changes: 1 addition & 1 deletion testing/testing-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Loading