Skip to content
Draft
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
37 changes: 14 additions & 23 deletions crates/common/types/block_execution_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,9 @@ 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)? {
Some(encoded_state) => encoded_state,
None => 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 +357,14 @@ 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)? {
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),
None => Ok(None),
}
}

Expand All @@ -381,19 +379,12 @@ impl GuestProgramState {
if code_hash == *EMPTY_KECCACK_HASH {
return Ok(Code::default());
}
match self.codes_hashed.get(&code_hash) {
Some(code) => Ok(code.clone()),
None => {
// We do this because what usually happens is that the Witness doesn't have the code we asked for but it is because it isn't relevant for that particular case.
// In client implementations there are differences and it's natural for some clients to access more/less information in some edge cases.
// Sidenote: logger doesn't work inside SP1, that's why we use println!
println!(
"Missing bytecode for hash {} in witness. Defaulting to empty code.", // If there's a state root mismatch and this prints we have to see if it's the cause or not.
hex::encode(code_hash)
);
Ok(Code::default())
}
}
self.codes_hashed.get(&code_hash).cloned().ok_or_else(|| {
GuestProgramStateError::Custom(format!(
"Missing bytecode for hash {} in witness",
hex::encode(code_hash)
))
})
}

/// When executing multiple blocks in the L2 it happens that the headers in block_headers correspond to the same block headers that we have in the blocks array. The main goal is to hash these only once and set them in both places.
Expand Down