From a50faea60e7bbeb98b40cdfd33794a44e763ec45 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Tue, 13 Aug 2024 13:49:52 -0400 Subject: [PATCH 1/2] Fix precompile insertion in state trie --- trace_decoder/src/lib.rs | 1 + trace_decoder/src/processed_block_trace.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/trace_decoder/src/lib.rs b/trace_decoder/src/lib.rs index 42b83a69d..6ba419dc6 100644 --- a/trace_decoder/src/lib.rs +++ b/trace_decoder/src/lib.rs @@ -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, diff --git a/trace_decoder/src/processed_block_trace.rs b/trace_decoder/src/processed_block_trace.rs index bd6a23330..91eed3164 100644 --- a/trace_decoder/src/processed_block_trace.rs +++ b/trace_decoder/src/processed_block_trace.rs @@ -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; @@ -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, @@ -70,6 +74,7 @@ impl Vec> CodeHashResolving { impl TxnInfo { pub(crate) fn into_processed_txn_info Vec>( self, + tries: &PartialTriePreImages, all_accounts_in_pre_image: &[(H256, AccountRlp)], extra_state_accesses: &[H256], code_hash_resolver: &mut CodeHashResolving, @@ -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)); + + // Jerigon 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 { From 43f656b864b3295ebf6fd599659f94951244b7d9 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Tue, 13 Aug 2024 13:54:03 -0400 Subject: [PATCH 2/2] Reword --- trace_decoder/src/processed_block_trace.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trace_decoder/src/processed_block_trace.rs b/trace_decoder/src/processed_block_trace.rs index 91eed3164..eb0a07042 100644 --- a/trace_decoder/src/processed_block_trace.rs +++ b/trace_decoder/src/processed_block_trace.rs @@ -134,7 +134,7 @@ impl TxnInfo { let is_precompile = (FIRST_PRECOMPILE_ADDRESS..LAST_PRECOMPILE_ADDRESS) .contains(&U256::from_big_endian(&addr.0)); - // Jerigon witnesses will only include accessed precompile accounts as hash + // 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.