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 0xaatif committed Aug 14, 2024
1 parent 4689cd8 commit 1b6a99f
Show file tree
Hide file tree
Showing 2 changed files with 20 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
20 changes: 19 additions & 1 deletion trace_decoder/src/processed_block_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 +73,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 +130,21 @@ 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
.get_by_path(TrieKey::from_hash(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 1b6a99f

Please sign in to comment.