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

fix: do not force precompile address access in case of txn reversion #488

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions trace_decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ pub fn entrypoint(
};

t.into_processed_txn_info(
&pre_images.tries,
&all_accounts_in_pre_images,
&extra_state_accesses,
&mut code_hash_resolver,
Expand Down
22 changes: 21 additions & 1 deletion trace_decoder/src/processed_block_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::iter::once;
use ethereum_types::{Address, H256, U256};
use evm_arithmetization::generation::mpt::{AccountRlp, LegacyReceiptRlp};
use mpt_trie::nibbles::Nibbles;
use mpt_trie::partial_trie::PartialTrie;

use crate::hash;
use crate::PartialTriePreImages;
Expand All @@ -22,6 +23,9 @@ pub const EMPTY_TRIE_HASH: H256 = H256([
108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33,
]);

const FIRST_PRECOMPILE_ADDRESS: U256 = U256([1, 0, 0, 0]);
const LAST_PRECOMPILE_ADDRESS: U256 = U256([10, 0, 0, 0]);

#[derive(Debug)]
pub(crate) struct ProcessedBlockTrace {
pub tries: PartialTriePreImages,
Expand Down Expand Up @@ -70,6 +74,7 @@ impl<F: Fn(&H256) -> Vec<u8>> CodeHashResolving<F> {
impl TxnInfo {
pub(crate) fn into_processed_txn_info<F: Fn(&H256) -> Vec<u8>>(
self,
tries: &PartialTriePreImages,
all_accounts_in_pre_image: &[(H256, AccountRlp)],
extra_state_accesses: &[H256],
code_hash_resolver: &mut CodeHashResolving<F>,
Expand Down Expand Up @@ -126,7 +131,22 @@ impl TxnInfo {
.storage_writes
.push((hashed_addr, storage_writes_vec));

nodes_used_by_txn.state_accesses.push(hashed_addr);
let is_precompile = (FIRST_PRECOMPILE_ADDRESS..LAST_PRECOMPILE_ADDRESS)
.contains(&U256::from_big_endian(&addr.0));

// Trie witnesses will only include accessed precompile accounts as hash
// nodes if the transaction calling them reverted. If this is the case, we
// shouldn't include them in this transaction's `state_accesses` to allow the
// decoder to build a minimal state trie without hitting any hash node.
if !is_precompile
|| tries
.state
.as_hashed_partial_trie()
.get(Nibbles::from_h256_be(hashed_addr))
.is_some()
{
nodes_used_by_txn.state_accesses.push(hashed_addr);
}

if let Some(c_usage) = trace.code_usage {
match c_usage {
Expand Down
Loading