EIP-7756: EOF/EVM Trace Specification

Updates EIP-3155 tracing to add EOF support


Metadata
Status: DraftStandards Track: InterfaceCreated: 2024-08-13
Authors
Martin Holst Swende (@holiman), Marius van der Wijden (@MariusVanDerWijden), Danno Ferrin (@shemnon)

Abstract


Updates the EIP-3155 JSON tracing specification to support EOF features.

Motivation


EIP-3155 defined a tracing standard for Legacy EVM operations. However, the EVM Object Format (EIP-7692) adds a number of features that need to be reflected in debugging traces.

The use of these traces has also moved out from state testing, including live block tracing and differential fuzzing, increasing the need to keep tracing up to date.

This EIP has multiple goals:

  • Add members to the trace object to support new EOF features.
  • Support tracing contracts contained in an EOF container as well as uncontained "legacy" contracts in the same trace.
  • Clarify any previous ambiguities in the EIP-3155 specification.

Specification


To promote clarity and provide a cohesive specification, the entire tracing specification will be presented with alterations in-line rather than as a set of diffs on top of EIP-3155. Differences will be highlighted in the Backwards Compatibility section.

Datatypes

TypeExplanationJSON member example
NumberJSON number"pc":0
Hex-NumberHex-encoded number"gas":"0x2540be400"
StringPlain string"opName":"PUSH1"
Hex-StringHex-encoded string"returnData":"0x60616203"
ArrayArray of Hex-Strings"stack":["0x0", "0x0"]
Key-ValueKey-Value structure with key and values encoded as hex strings"storage":{"0x0":"0x1", "0x1":"0x1"}
BooleanJson bool can either be true or false"pass": true

Output

  • The client outputs one JSON object per EVM operation executed.
  • The client MUST NOT output multiple lines for the same operation execution.
  • The client MUST NOT output a line for the STOP operation if an error occurred, or if the contract runs out of instructions.

Each object contains the following members.

NameTypeRequiredExplanation
pcNumberYesProgram Counter
sectionNumberYes if EOFEOF Code Section
opNumberYesOpcode
immediateHex-Stringsee belowImmediate argument of the Opcode
gasHex-NumberYesGas left before executing this operation
gasCostHex-NumberYesGas cost of this operation
memoryArrayNoArray of all allocated values
memSizeNumberYesSize of memory array
stackArrayYesArray of all values on the stack
depthNumberYesDepth of the contract call stack (non-CALLF)
functionDepthNumberYes if not zeroDepth of the EIP-4750 CALLF return stack
returnDataHex-StringNoData returned by contract calls
refundHex-NumberYesAmount of global gas refunded
opNameStringNoName of the operation
errorHex-StringNoDescription of an error or revert data
storageMapNoArray of all stored values
  • The pc value is zero indexed either from the beginning of the contract when the contract is not in an EOF container, or from the beginning of the code section when it is a contract contained in an EOF container.
  • The section member must only be present when tracing a contract that is contained in an EOF container. In cases where legacy and EOF contracts are in the same call trace the presence and absence of the section member indicates if the contract at that step is EOF or legacy.
  • The immediate member is optional for PUSH series instructions, and mandatory for all other operations that have immediate arguments.
    • For RJUMPV this would include the table length and the entire table. Clients MAY instead store just the table length.
  • The gas, stack, memory and memSize, depth, and functionDepth members are the values before execution of the op.
  • The gasCost is the sum of all gas costs, including dynamic costs such as memory expansion, call stipend, and account warming costs.
  • All array attributes (stack, memory) MUST be initialized to empty arrays ("stack":[]NOT"stack":null`).
  • The memory or storage members may be omitted if they are empty or the client does not produce them.
  • The memSize member MUST be present regardless of memory support. Even when memSize is zero.
  • The functionDepth member may be omitted when zero. It must be omitted if the contract is legacy EVM.
  • The error and returnData members can be omitted if they are empty.
  • If the prior operation failed with an exceptional halt, error should identify the halt. Otherwise, if the prior operation was a REVERT operation error should contain the hex-encoded revert data.
  • The storage member should only include items read or written via SSTORE or SLOAD, and not the account's entire storage.
  • Clients SHOULD implement a way to disable recording the storage as the stateroot includes all storage updates.
  • Clients SHOULD output the members in the same order as listed in this EIP.

Example:


Summary Line

At the end of execution, the client should print summary info. This summary MUST be a single JSON object.

This info SHOULD have the following members.

NameTypeRequiredExplanation
stateRootHex-StringYesRoot of the state trie after executing the transaction
outputHex-StringYesReturn values of the function
gasUsedHex-NumberYesAll gas used by the transaction
passBooleanYesIf the tx was successful, or if the test passed
timeNumberNoTime in nanoseconds needed to execute the transaction
forkStringNoName of the fork rules used for execution

Example:


Rationale


This EIP is an extension of the EIP-3155 tracing features that has been in use for years. Rather than dramatically re-boot the feature, the information was added to the existing traces.

A "mini" trace was contemplated to allow for tracing to be included in tools such as t8n and to allow for more efficient RPC tracing calls, but that seemed sufficiently different that it would be a stand-alone EIP rather than an EIP that adds features to the existing tracing capabilities.

The idea of moving to a JSON Schema was rejected to ensure maximum compatibility with existing clients.

Backwards Compatibility


Clients emitting tracing JSON for uncontained "legacy" contracts will produce a compatible trace, except as outlined below

Changes from EIP-3155

  • The term Client Under Test or CUT has been replaced simply with "client."

Additions to EIP-3155

  • The immediate member was added to support the large number of instructions that contain immediate operations. Without this change, users would need bytes of the contracts being executed to rationalize the traces.
  • The section and functionDepth members were added to support EIP-4750 EOF Functions.
  • Added clarification around where pc indexes when run in an EOF container.

Clients

Besu, evmone, EthereumJS, Geth, Nethermind, and Reth already produce these standard traces in various tools. Adding the new fields will align with work needed to support the EOF EIPs enumerated in EIP-7692.

Test Cases


This is the trace output from the Ethereum Execution Specification Test from one of the parameterized executions of test_eof_functions_contract_call_succeed. Memory and return data is disabled.


Security Considerations


Clients should be aware that tracing can be expensive both in terms of CPU overhead and network bandwidth. Tracing endpoints should not be enabled by default, and when they are enabled should have access restrictions on the network level. Failure to do so could result in a client being overwhelmed with requests and, if operating as a validator, cause the client to fail to provide execution attestations in a timely manner.

Differential fuzzing is also a double-edged sword.
While it allows client teams the ability to identify consensus splits, the client teams need to be prompt in fixing any issues that are discovered.

Copyright


Copyright and related rights waived via CC0.