Skip to main content

forest/rpc/methods/eth/trace/
mod.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4//! Ethereum trace construction and state diff logic.
5//!
6//! Submodules:
7//! - [`parity`] — builds Parity-compatible [`types::EthTrace`] entries from
8//!   FVM execution traces.
9//! - [`geth`] - builds Geth-compatible entries from the FVM execution traces.
10//! - [`state_diff`] — computes account-level state diffs between pre/post
11//!   execution.
12//! - [`types`] — shared type definitions for all `trace_*` RPC responses.
13
14mod geth;
15mod parity;
16mod state_diff;
17#[cfg(test)]
18mod test_helpers;
19pub(crate) mod types;
20mod utils;
21
22pub(super) use geth::*;
23pub(super) use parity::*;
24pub(crate) use state_diff::build_state_diff;
25
26use super::lookup_eth_address;
27use super::types::EthAddress;
28use anyhow::Context;
29use fvm_ipld_blockstore::Blockstore;
30use types::EthTrace;
31
32use crate::shim::{address::Address, state_tree::StateTree};
33
34/// Shared mutable context threaded through recursive trace building.
35///
36/// Used by both Parity-style and Geth-style trace constructors to track
37/// the current caller, collected traces, and subtrace count.
38#[derive(Default)]
39pub(super) struct Environment {
40    pub(super) caller: EthAddress,
41    pub(super) is_evm: bool,
42    pub(super) subtrace_count: i64,
43    pub(super) traces: Vec<EthTrace>,
44    pub(super) last_byte_code: Option<EthAddress>,
45}
46
47pub(super) fn base_environment<BS: Blockstore + Send + Sync>(
48    state: &StateTree<BS>,
49    from: &Address,
50) -> anyhow::Result<Environment> {
51    let sender = lookup_eth_address(from, state)?
52        .with_context(|| format!("top-level message sender {from} could not be found"))?;
53    Ok(Environment {
54        caller: sender,
55        ..Environment::default()
56    })
57}