Skip to content

Commit

Permalink
feat: feature gate state root verification
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Edison <gregory.edison1993@gmail.com>
  • Loading branch information
greged93 committed Dec 24, 2024
1 parent d395494 commit 1d62191
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions crates/engine/tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ scroll = [
"reth-scroll-primitives",
"reth-scroll-storage/scroll"
]
scroll-mpt = [
"scroll",
"reth-stages/scroll-mpt"
]
12 changes: 9 additions & 3 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ use reth_payload_builder::PayloadBuilderHandle;
use reth_payload_builder_primitives::PayloadBuilder;
use reth_payload_primitives::PayloadBuilderAttributes;
use reth_primitives::{
EthPrimitives, GotExpected, NodePrimitives, SealedBlockFor, SealedBlockWithSenders,
SealedHeader,
EthPrimitives, NodePrimitives, SealedBlockFor, SealedBlockWithSenders, SealedHeader,
};
use reth_primitives_traits::Block;
use reth_provider::{
Expand Down Expand Up @@ -2287,6 +2286,9 @@ where
state_provider.state_root_from_state_with_updates(hashed_state.clone())?
};

#[cfg(feature = "scroll-mpt")]
let _ = state_root;
#[cfg(not(feature = "scroll-mpt"))]
if state_root != block.header().state_root() {
// call post-block hook
self.invalid_block_hook.on_invalid_block(
Expand All @@ -2296,7 +2298,11 @@ where
Some((&trie_output, state_root)),
);
return Err(ConsensusError::BodyStateRootDiff(
GotExpected { got: state_root, expected: block.header().state_root() }.into(),
reth_primitives::GotExpected {
got: state_root,
expected: block.header().state_root(),
}
.into(),
)
.into())
}
Expand Down
5 changes: 5 additions & 0 deletions crates/node/builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ scroll = [
"reth-engine-util/scroll",
"reth-invalid-block-hooks/scroll"
]
scroll-mpt = [
"scroll",
"reth-stages/scroll-mpt",
"reth-engine-tree/scroll-mpt"
]
5 changes: 3 additions & 2 deletions crates/scroll/bin/scroll-reth-mpt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ clap = { workspace = true, features = ["derive", "env"] }

[features]
scroll = [
"reth-node-builder/scroll",
"reth-node-builder/scroll-mpt",
"reth-provider/scroll",
"reth-scroll-cli/scroll"
"reth-scroll-cli/scroll",
"reth-scroll-node/scroll-mpt"
]
optimism = [
"reth-provider/optimism",
Expand Down
3 changes: 2 additions & 1 deletion crates/scroll/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ scroll = [
"reth-evm/scroll",
"reth-scroll-state-commitment/scroll",
"reth-scroll-evm/scroll",
]
]
scroll-mpt = ["scroll"]
1 change: 1 addition & 0 deletions crates/stages/stages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ scroll = [
"reth-scroll-storage/scroll",
"reth-scroll-primitives"
]
scroll-mpt = ["scroll"]

[[bench]]
name = "criterion"
Expand Down
3 changes: 3 additions & 0 deletions crates/stages/stages/src/stages/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ where
// Reset the checkpoint
self.save_execution_checkpoint(provider, None)?;

#[cfg(feature = "scroll-mpt")]
let _ = trie_root;
#[cfg(not(feature = "scroll-mpt"))]
validate_state_root(trie_root, SealedHeader::seal(target_block), to_block)?;

Ok(ExecOutput {
Expand Down

0 comments on commit 1d62191

Please sign in to comment.