Skip to content
Draft
Changes from 5 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
39 changes: 29 additions & 10 deletions crates/common/types/block_execution_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ethrex_rlp::{decode::RLPDecode, encode::RLPEncode};
use ethrex_trie::{EMPTY_TRIE_HASH, Node, Trie, TrieError};
use rkyv::with::{Identity, MapKV};
use serde::{Deserialize, Serialize};
use tracing::debug;

/// State produced by the guest program execution inside the zkVM. It is
/// essentially built from the `ExecutionWitness`.
Expand Down Expand Up @@ -323,8 +324,19 @@ impl GuestProgramState {
.entry(address)
.or_insert_with(|| hash_address(&address));

let Ok(Some(encoded_state)) = self.state_trie.get(hashed_address) else {
return Ok(None);
let encoded_state = match self.state_trie.get(hashed_address) {
Ok(Some(encoded_state)) => encoded_state,
Ok(None) => return Ok(None),
Err(_) => {
// In the case of ethrex-replay this is normal when asking for the Witness of a block to a non-ethrex node.
// This log is mostly for L2 Prover, if witness is incomplete then this will help for debugging a state mismatch.
// Note that logs aren't printed inside zkVMs, so for debugging this it's best to use "execute" backend.
debug!(
"Getting node from state trie when getting info for {:#x} failed unexpectedly. Nodes might be missing. Defaulting to empty account.",
address
);
return Ok(None);
}
};
let state = AccountState::decode(&encoded_state).map_err(|_| {
GuestProgramStateError::Database("Failed to get decode account from trie".to_string())
Expand Down Expand Up @@ -356,17 +368,24 @@ impl GuestProgramState {
let Some(storage_trie) = self.get_valid_storage_trie(address)? else {
return Ok(None);
};
if let Some(encoded_key) = storage_trie
.get(&hashed_key)
.map_err(|e| GuestProgramStateError::Database(e.to_string()))?
{
U256::decode(&encoded_key)

match storage_trie.get(&hashed_key) {
Ok(Some(encoded_key)) => U256::decode(&encoded_key)
.map_err(|_| {
GuestProgramStateError::Database("failed to read storage from trie".to_string())
})
.map(Some)
} else {
Ok(None)
.map(Some),
Ok(None) => Ok(None),
Err(_) => {
// In the case of ethrex-replay this is normal when asking for the Witness of a block to a non-ethrex node.
// This log is mostly for L2 Prover, if witness is incomplete then this will help for debugging a state mismatch.
// Note that logs aren't printed inside zkVMs, so for debugging this it's best to use "execute" backend.
debug!(
"Getting node from state trie when getting storage key {:#x} for {:#x} failed unexpectedly. Nodes might be missing. Defaulting to empty storage.",
key, address
);
Ok(None)
}
}
}

Expand Down
Loading