EIP-3155: EVM trace specification

A JSON format for EVM traces


Metadata
Status: ReviewStandards Track: InterfaceCreated: 2020-12-07
Authors
Martin Holst Swende (@holiman), Marius van der Wijden (@MariusVanDerWijden)

Abstract


Introduce a new JSON standard for EVM traces during execution of state tests.

Motivation


The Ethereum Virtual Machine executes all smart contract code on ethereum. In order to debug smart contracts and state tests better, a common format was introduced to log every execution step of the EVM. This format was implemented by Go-Ethereum, Parity-Ethereum, Nethermind and Besu. Since the common format was not well-defined, the implementations differed slightly, making it hard to develop adequate tooling which reduces the usefulness of tracing significantly.

This EIP has multiple goals:

  • Move the specification to a more visible place to encourage new clients to implement it
  • Strictly define corner cases that were not addressed in the previous version
  • Allow for updates to the specification in case new fields are introduced during execution
  • Provide sample output

Implementing this EIP in all major clients allows us to create meaningful differential fuzzers that fuzz EVM implementations for the mainnet and all upcoming hardforks. It also helps to find differences in execution quickly in the case of a chain split.

This EIP will enable users to create better differential fuzzing infrastructure to compare the EVM implementations of all major Ethereum clients against each other. This could help to find bugs that are currently present in the client implementations.

Specification


Clients should be able to execute simple transactions as well as code and return traces. In the following, we will call this client CUT (client under test) and use go-ethereum's evm binary for code examples.

Datatypes

TypeExplanationExample
NumberPlain json number"pc":0
Hex-NumberHex-encoded number"gas":"0x2540be400"
StringPlain string"opName":"PUSH1"
Hex-StringHex-encoded string
Array of xArray of x encoded values
Key-ValueKey-Value structure with key and values encoded as hex strings
BooleanJson bool can either be true or false"pass": true

Output

The CUT MUST output a json object for EACH operation.

Required Fields

NameTypeExplanation
pcNumberProgram Counter
opNumberOpCode
gasHex-NumberGas left before executing this operation
gasCostHex-NumberGas cost of this operation
memSizeNumberSize of memory array
stackArray of Hex-NumbersArray of all values on the stack
depthNumberDepth of the call stack
returnDataHex-StringData returned by function call
refundHex-NumberAmount of global gas refunded

Optional Fields

NameTypeExplanation
opNameStringName of the operation
errorHex-StringDescription of an error (should contain revert reason if supported)
memoryArray of Hex-StringsArray of all allocated values
storageKey-ValueArray of all stored values

Example:


  • The stack, memory and memSize are the values before execution of the op.
  • All array attributes (stack, memory) MUST be initialized to empty arrays ("stack":[]) NOT to null.
  • If the CUT will not be outputting values for memory or storage then the memory and storage fields are omitted. This can happen either because the CUT does not support tracing these fields or it has been configured not to trace it.
  • The memSize field MUST be present regardless of memory support.
  • Clients SHOULD implement a way to disable recording the storage as the stateroot includes all storage updates.
  • Clients SHOULD output the fields in the same order as listed in this EIP.

The CUT MUST NOT output a line for the STOP operation if an error occurred:

Example:


Summary and Error Handling

At the end of execution, the CUT MUST print summary info; this info SHOULD have the following fields. The summary should be a single jsonl object.

Required Fields

NameTypeExplanation
stateRootHex-StringRoot of the state trie after executing the transaction
outputReturn values of the function
gasUsedHex-NumberAll gas used by the transaction
passBooleanBool whether transaction was executed successfully

Optional Fields

NameTypeExplanation
timeNumberTime in nanoseconds needed to execute the transaction
forkStringName of the fork rules used for execution

Example:


Rationale


This EIP is largely based on the previous non-official documentation for EVM tracing. It tries to cover as many corner cases as possible to enable true client compatibility. The datatypes and if a field is optional is chosen to be as compatible with current implementations as possible.

Backwards Compatibility


This EIP is fully backward compatible with ethereum as it only introduces a better tracing infrastructure that is optional for clients to implement.

Clients

This EIP is fully backward compatible with go-ethereum. OpenEthereum, Besu and Nethermind clients would have to change their JSON output of openethereum-evm evmtool and nethtest slightly do adhere to the new and stricter specs. New clients would need to implement this change if they want to be part of the differential fuzzing group.

Test Cases



Security Considerations


Tracing is expensive.

Exposing an endpoint for creating traces publicly could open up a denial of service vector.

Clients should consider putting trace endpoints behind a separate flag from other endpoints.

Copyright


Copyright and related rights waived via CC0.