Ethereum data — EVM Traces simplified

Kirubakumaresh Rajendran
Coinmonks
Published in
3 min readJul 7, 2022

--

The Ethereum Virtual Machine (EVM) traces provide detailed run time data for each step of the transaction, including information such as gas used, result, error values, and so on. EVM traces, unlike state and transactions, are not part of the blockchain and do not have to be persisted on nodes.

💁‍♂️ Etherscan runs an instrumented EVM, allowing us to view traces from various clients (parity, geth)

How do traces help?

Debugging Errors

When a transaction reverts in EVM, the status is recorded in the transaction receipt. However, there is no additional information that describes the reason for the failure. The only option is to examine the traces to determine the cause.

Parity VM trace — out of gas — Etherscan

Internals Calls/Transfers

Any smart contract execution begins with a transaction initiated by an external account. In turn, the smart contract can interact with other contracts or make transfers. These activities are not recorded in the blockchain. A smart contract, for example, can airdrop tokens (i.e. send free tokens) to a group of users, but this activity is not recorded in the blockchain as a transaction. For such activities, the contract can choose to emit events, which can then be viewed in the logs. Otherwise, the only way to observe them is to monitor the traces.

New to trading? Try crypto trading bots or copy trading

Some of the common operations that requires monitoring are :

CALL trace type indicates when a smart contract transfers ether to another account or invokes the method of another contract.

CALL — contract calling another contract
Parity VM trace — CALL — Etherscan

CREATE trace type indicates when a smart contract is deployed to the Ethereum network. Smart contracts can be deployed by an EOA account or another smart contract.

Parity VM Trace — CREATE — Smart contract deploys another contract — Etherscan

Other trace types that may be of interest are SELFDESTRUCT (contract removed from blockchain) and REWARD (rewards to miners). By inspecting the trace data, one can gain a better understanding of what is happening within a transaction.

Why Traces are not stored in most of the nodes?

Tracing is a time-consuming and resource-intensive process. The node must be capable of storing and retrieving large amounts of trace data. It also reduces a node’s ability to sync the entire blockchain history. Because storing traces is not required for block validation or mining, most nodes run without tracing enabled.

How to retrieve EVM traces?

There are several ways to retrieve EVM traces of a transaction.

a) Replaying the transaction in a full/archive node: Ethereum clients expose methods that attempt to rerun the transaction in the same way it was previously executed and collect the traces. While retrieving the result takes time, nodes are not required to store the traces as long as sufficient information to run the transaction is available.

b) Running an archive node with traces enabled: Ethereum clients support running nodes with traces enabled. This would allow nodes to store traces so that they could be retrieved quickly without having to re-execute the transaction. However, this comes at the expense of higher costs and slower node performance.

c) Using APIs: Third party services such as Infura or Alchemy manage trace enabled nodes and offers API endpoints to collect transaction trace. Although it is by far the simplest, the downside is that you have to rely on a centralised entity.

I hope this article has given you a better understanding of EVM traces. Feel free to reach out if you have any questions or comments. Twitter | LinkedIn

--

--

Kirubakumaresh Rajendran
Coinmonks

Building twigblock.com to empower anyone to unlock web3 data. I write about web3 data analytics/science. kikura.eth | linktr.ee/kirubakumaresh