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(tree): validate state root #9369

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all 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
18 changes: 13 additions & 5 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ use reth_evm::execute::{BlockExecutorProvider, Executor};
use reth_payload_primitives::PayloadTypes;
use reth_payload_validator::ExecutionPayloadValidator;
use reth_primitives::{
Address, Block, BlockNumber, Receipts, Requests, SealedBlock, SealedBlockWithSenders, B256,
U256,
Address, Block, BlockNumber, GotExpected, Receipts, Requests, SealedBlock,
SealedBlockWithSenders, B256, U256,
};
use reth_provider::{
BlockReader, ExecutionOutcome, StateProvider, StateProviderFactory, StateRootProvider,
};
use reth_provider::{BlockReader, ExecutionOutcome, StateProvider, StateProviderFactory};
use reth_revm::database::StateProviderDatabase;
use reth_rpc_types::{
engine::{
Expand Down Expand Up @@ -548,10 +550,16 @@ where
PostExecutionInput::new(&output.receipts, &output.requests),
)?;

// TODO: change StateRootProvider API to accept hashed post state
let hashed_state = HashedPostState::from_bundle_state(&output.state.state);

// TODO: compute and validate state root
let trie_output = TrieUpdates::default();
let (state_root, trie_output) = state_provider.state_root_with_updates(&output.state)?;
if state_root != block.state_root {
return Err(ConsensusError::BodyStateRootDiff(
GotExpected { got: state_root, expected: block.state_root }.into(),
)
.into())
}

let executed = ExecutedBlock {
block: Arc::new(block.block.seal(block_hash)),
Expand Down
Loading