rpc: struct logger differs from the execution-apis rules for failing steps, refund and opcode names

Open
#26,518 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
api, backend

Research direction

Start with execution/tracing/tracers/logger/json_stream.go and execution/vm/interpreter.go at the referenced commit; compare the logger hooks and opcode execution flow for the six listed mismatches. Use the supplied debug_traceCall requests on the specified forks to reproduce the output differences. Done means the default struct logger follows the stated rules for failing steps, refunds, and fork-specific opcode names.

Written by the indexing model from the issue text.

Description

ethereum/execution-apis#986 proposes rules for the default struct logger (debug_trace* with no tracer). The rules come from a comparison of geth, erigon, Nethermind, besu, reth and ethrex with EELS on the same cases. This issue lists where erigon differs. Each item says if the rule is already in the merged spec text, a proposal in ethereum/execution-apis#986, or part of ethereum/execution-apis#852 (open). ethereum/go-ethereum#36166 is one implementation of items 1, 2 and 3.

Tested: main 40db3c3, with debug_traceCall at Osaka and Amsterdam and debug_traceTransaction on mined transactions. Code lines are at 40db3c3. The requests are at the end. limit already counts steps. The root fields and stateGasReservoir already match ethereum/execution-apis#852 (open).

1. Every exceptional halt has a non-empty error on the step's own entry. Proposal in ethereum/execution-apis#986. The text stays client-defined.

  • Osaka, an invalid JUMP: erigon gives no error (gasCost 8). EELS, besu, reth, ethrex and geth with ethereum/go-ethereum#36166 give an error. erigon also has no error for INVALID (0xfe), an undefined opcode (0x0c), RETURNDATACOPY out of bounds, LOG0 in a static call and TSTORE in a static call. Halts in the gas step (out of gas, stack errors, SSTORE in a static call) already have one.
  • Code: when the opcode already has an entry, the interpreter's defer calls EmitFault only if the tracer has a fault hook (interpreter.go:603-606). JsonStreamLogger.Tracer() registers no OnFault (json_stream.go:74-83). Also, the logger writes and closes each entry in OnOpcodeV2 before the opcode executes (json_stream.go:208-268). So a fix needs an OnFault hook and one pending entry that the hook can complete. A completed REVERT must keep no error, so the fault of a REVERT needs a filter.

2. gasCost is 0 on a failing step. Proposal in ethereum/execution-apis#986. It replaces the merged text "assuming successful execution" for a step that halts exceptionally. The attempted cost depends on where each client detects the failure, so the clients do not agree on it.

case (Osaka, depth 2) erigon gasCost rule
memory expansion out of gas 137464152070 0
constant gas out of gas 1 0
stack underflow (ADD) 3 0
stack overflow (PUSH0) 2 0
invalid JUMP 8 0
CREATE in a static call 32000 0
SELFDESTRUCT in a static call 5000 0
  • The EELS t8n tracer gives the attempted cost on most of these steps. That tracer is EIP-3155 test tooling with a different output format, so the proposal in ethereum/execution-apis#986 decides.
  • Code: for a halt before execution, the defer emits the cost accumulated so far (interpreter.go:597-609). For a halt during execution, the entry already has the full cost (interpreter.go:716-719). The pending entry of item 1 also covers this case.

3. stateGasCost is omitted on a failing step. This is a change that I asked for in ethereum/execution-apis#852 (open, comment). Today ethereum/execution-apis#852 says the field "is zero at a step that fails before its gas is charged".

  • Amsterdam, an SSTORE that sets a new slot and runs out of gas on its state gas: erigon gives gasCost 12100 and stateGasCost 97920. The step fails, so the 97920 is never charged. The requested rule gives no stateGasCost, and ethereum/execution-apis#986 gives gasCost 0. geth, Nethermind, besu, reth and ethrex omit the field. The EELS t8n tracer gives 97920.
  • The same happens on a mined transaction (debug_traceTransaction): erigon gives gasCost 10100 and stateGasCost 97920.
  • Code: json_stream.go:217-220.

4. refund is the transaction's counter before the step. Merged text (ethereum/execution-apis#947): "The accumulated gas refund counter of the transaction before this opcode executes." ethereum/execution-apis#986 adds that a step that halts exceptionally also reports that counter, without the refund change it attempted.

  • Osaka, an SSTORE clears a slot and a second SSTORE restores it. On the clearing SSTORE, erigon gives refund: 4800. The counter before the step is 0, so the rule gives no refund there, and 4800 on the next entry. On the restoring SSTORE, erigon gives 2800 and the rule gives 4800. besu already reads the counter before the step.
  • Osaka, an SSTORE that runs out of gas after an earlier call cleared a slot (counter 4800): erigon gives 9600 and the rule gives 4800. At Amsterdam the values are 23232 and 11616. besu and ethrex already give the counter before the step.
  • The EELS t8n tracer gives the value after the charge, and the attempted value on the failing SSTORE. As in item 2, the spec text decides.
  • Code: OnOpcodeV2 reads GetRefund() (json_stream.go:227-231) after the gas function has changed the refund (interpreter.go:665-708). The interpreter captures oldGas at the loop top (interpreter.go:641-646). The refund needs a capture at the same point.

5. Opcode 0x44 is PREVRANDAO from the Paris fork. Proposal in ethereum/execution-apis#986, from EIP-4399 (Final).

  • PREVRANDAO POP STOP at Osaka: erigon gives DIFFICULTY, also at Paris. EELS and besu give PREVRANDAO at Paris and at Osaka, and ethrex at Osaka (ethrex was not probed before Shanghai).
  • Code: opcodes.go:302.

6. The op name comes from the opcode set of the block's fork. Proposal in ethereum/execution-apis#986. A byte that is not defined at that fork reads opcode 0x<hex> not defined, the form erigon already uses for 0x0c.

  • PUSH0 at a Paris block: erigon gives PUSH0, the rule gives opcode 0x5f not defined. The same applies to CLZ at a Prague block and to 0x4b, 0xe6, 0xe7 and 0xe8 at an Osaka block (erigon: SLOTNUM, DUPN, SWAPN, EXCHANGE). besu gives INVALID, and the EELS t8n tracer gives InvalidOpcode, its name for every undefined byte.
  • Code: OpCode.String() uses one table for all forks (opcodes.go:429-436), called at json_stream.go:212.

Root fields and state-gas fields. ethereum/execution-apis#986 closes the struct log entry and the result object to fields that the spec does not define. erigon's root fields regularGasUsed, stateGasUsed and gasRefund, and the entry fields stateGasCost and stateGasReservoir, follow ethereum/execution-apis#852 (open). The planned merge order is ethereum/execution-apis#855, then ethereum/execution-apis#986, then ethereum/execution-apis#852 rebased with these fields added to the closed schemas. So erigon does not need to remove them.

Item 4 follows merged text, and ethereum/execution-apis#986 states its failing-step part. Item 3 depends on ethereum/execution-apis#852. The other items are proposals, and comments on them are welcome in ethereum/execution-apis#986.

Requests

debug_traceCall with the default struct logger. 0xc1 calls 0xc2. The overrides set all code and storage that a case needs; neither address has code or storage on mainnet. The sender needs no balance. Run the Osaka requests on an Osaka chain, for example mainnet at "latest", and the Amsterdam request on an Amsterdam devnet.

Item 1 (Osaka):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"latest",{"stateOverrides":{"0x00000000000000000000000000000000000000c1":{"code":"0x5f5f5f5f5f60c262000064f15000"},"0x00000000000000000000000000000000000000c2":{"code":"0x600556"}}}]}

Item 2, memory expansion (Osaka):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"latest",{"stateOverrides":{"0x00000000000000000000000000000000000000c1":{"code":"0x5f5f5f5f5f60c262000064f15000"},"0x00000000000000000000000000000000000000c2":{"code":"0x6001630fffffff52"}}}]}

Item 3 (Amsterdam):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"latest",{"stateOverrides":{"0x00000000000000000000000000000000000000c2":{"code":"0x60015f5500"},"0x00000000000000000000000000000000000000c1":{"code":"0x5f5f5f5f5f60c26200c350f15000"}}}]}

Item 4, clear and restore (Osaka; slot 0 of 0xc2 starts at 1):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"latest",{"stateOverrides":{"0x00000000000000000000000000000000000000c2":{"code":"0x5f5f5560015f555f5000","stateDiff":{"0x0000000000000000000000000000000000000000000000000000000000000000":"0x0000000000000000000000000000000000000000000000000000000000000001"}},"0x00000000000000000000000000000000000000c1":{"code":"0x5f5f5f5f5f60c2620186a0f15000"}}}]}

Item 4, failing SSTORE (Osaka; slots 1 and 2 of 0xc2 start at 1 and 2; the failing SSTORE is entry 43):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"latest",{"stateOverrides":{"0x00000000000000000000000000000000000000c2":{"code":"0x5f356020355560015060025000","stateDiff":{"0x0000000000000000000000000000000000000000000000000000000000000001":"0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000000000000000000000000000002"}},"0x00000000000000000000000000000000000000c1":{"code":"0x60005f5260016020525f5f60405f5f7300000000000000000000000000000000000000c2620186a0f15060005f5260026020525f5f60405f5f7300000000000000000000000000000000000000c262000fabf15060015000"}}}]}

Item 5 (Osaka):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"latest",{"stateOverrides":{"0x00000000000000000000000000000000000000c2":{"code":"0x445000"},"0x00000000000000000000000000000000000000c1":{"code":"0x6000600060006000600060c262000064f15000"}}}]}

Item 6 (mainnet block 16000000, Paris; needs an archive node):

{"jsonrpc":"2.0","id":1,"method":"debug_traceCall","params":[{"from":"0x0c2c51a0990aee1d73c1228de158688341557508","to":"0x00000000000000000000000000000000000000c1","gas":"0x100000"},"0xf42400",{"stateOverrides":{"0x00000000000000000000000000000000000000c2":{"code":"0x5f00"},"0x00000000000000000000000000000000000000c1":{"code":"0x6000600060006000600060c262000064f15000"}}}]}
Dominant language
Go
Stars
3.6k
Forks
1.6k
Avg merge
1d 17h
Merged PRs (30d)
820

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from erigontech/erigon

All issues in erigontech/erigon

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.