Skip to content

Commit

Permalink
fix: do not force precompile address access in case of txn reversion (#…
Browse files Browse the repository at this point in the history
…488)

* Fix precompile insertion in state trie

* Reword
  • Loading branch information
Nashtare authored and atanmarko committed Aug 14, 2024
1 parent ce1a8d1 commit 59cc8eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 59cc8eb

Please sign in to comment.