Skip to content

Commit

Permalink
feat(tree): validate state root (#9369)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Jul 8, 2024
1 parent 2c2098c commit b14192f
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit b14192f

Please sign in to comment.