diff --git a/crates/common/trie/db.rs b/crates/common/trie/db.rs index 185e81c235d..37e7eec369d 100644 --- a/crates/common/trie/db.rs +++ b/crates/common/trie/db.rs @@ -1,7 +1,7 @@ use ethereum_types::H256; -use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode, error::RLPDecodeError}; +use ethrex_rlp::encode::RLPEncode; -use crate::{Nibbles, Node, NodeRLP, Trie, error::TrieError}; +use crate::{Nibbles, Node, Trie, error::TrieError}; use std::{ collections::BTreeMap, sync::{Arc, Mutex}, @@ -62,13 +62,9 @@ impl InMemoryTrieDB { // Do not remove or make private as we use this in ethrex-replay pub fn from_nodes( root_hash: H256, - state_nodes: &BTreeMap, + state_nodes: &BTreeMap, ) -> Result { - let state_nodes: BTreeMap<_, _> = state_nodes - .iter() - .map(|(h, b)| Ok((*h, Node::decode(b)?))) - .collect::>()?; - let mut embedded_root = Trie::get_embedded_root(&state_nodes, root_hash)?; + let mut embedded_root = Trie::get_embedded_root(state_nodes, root_hash)?; let mut hashed_nodes = vec![]; embedded_root.commit(Nibbles::default(), &mut hashed_nodes); diff --git a/crates/networking/rpc/debug/execution_witness.rs b/crates/networking/rpc/debug/execution_witness.rs index 0f5c8048083..c8677a48564 100644 --- a/crates/networking/rpc/debug/execution_witness.rs +++ b/crates/networking/rpc/debug/execution_witness.rs @@ -4,7 +4,7 @@ use bytes::Bytes; use ethrex_common::{ Address, H256, serde_utils, types::{ - AccountState, ChainConfig, + AccountState, BlockHeader, ChainConfig, block_execution_witness::{ExecutionWitness, GuestProgramStateError}, }, utils::keccak, @@ -70,8 +70,24 @@ pub fn execution_witness_from_rpc_chain_config( rpc_witness: RpcExecutionWitness, chain_config: ChainConfig, first_block_number: u64, - initial_state_root: H256, ) -> Result { + let mut initial_state_root = None; + + for h in &rpc_witness.headers { + let header = BlockHeader::decode(h)?; + if header.number == first_block_number - 1 { + initial_state_root = Some(header.state_root); + break; + } + } + + let initial_state_root = initial_state_root.ok_or_else(|| { + GuestProgramStateError::Custom(format!( + "header for block {} not found", + first_block_number - 1 + )) + })?; + let nodes: BTreeMap = rpc_witness .state .into_iter()