Skip to content

Conversation

@mattevans
Copy link
Member

@mattevans mattevans commented Jan 14, 2026

Problem:

When you trace a transaction, you get a list of every opcode executed. But you can't easily answer: "Which contract was this opcode running inside?"

For example, if contract A calls contract B, and B calls C, you get a flat list like:

  PUSH1 (depth 1)  ← running in A
  CALL  (depth 1)  ← A calling B
  ADD   (depth 2)  ← running in B
  CALL  (depth 2)  ← B calling C
  MUL   (depth 3)  ← running in C
  STOP  (depth 3)  ← C returns
  STOP  (depth 2)  ← B returns
  STOP  (depth 1)  ← A returns

The problem: depth alone isn't enough. If A calls B, returns, then calls C - both B and C are at depth 2, but they're different call frames.

This PR:

  1. Call Frame Tracking (CallTracker)

Assigns a unique sequential ID to each call frame:

  • call_frame_id: Unique ID within the transaction (0, 1, 2, 3...)
  • call_frame_path: The path from root to current frame (e.g., [0, 1, 2] means root→frame1→frame2)

Now we can group opcodes by which contract execution they belong to, even when the same contract is called multiple times.

  1. gas_self Field

A new gas metric that doesn't double count child frame gas:

  • gas_used: Total gas consumed (includes child frames)
  • gas_self: Just this opcode's overhead (excludes child frames)

Example for a CALL:

  • gas_used = 23,858 (overhead 2,600 + child consumed 21,258)
  • gas_self = 2,600 (just the CALL overhead)

SUM(gas_self) across all opcodes = total transaction gas (no double counting).

  1. CREATE/CREATE2 Address Resolution

For contract creation opcodes, fetches the newly created contract address from the transaction receipt and populates call_to_address.

  1. EOA Call Handling

When a CALL targets an EOA (i.e., a wallet with no code), the depth doesn't increase. The PR emits a synthetic structlog to represent this EOA frame, keeping the call frame tracking consistent.

Introduce CallTracker to assign sequential frame IDs and maintain
call paths during opcode traversal. This enables accurate
identification of which contract call each opcode belongs to,
even when the same contract is called multiple times.

Extend Structlog with CallFrameID and CallFramePath fields to
persist the tracking information alongside each opcode record.

Update extractCallAddress to handle all CALL-type opcodes
(CALL, CALLCODE, DELEGATECALL, STATICCALL) for complete
call target extraction.
@mattevans mattevans requested a review from Savid as a code owner January 14, 2026 00:15
@mattevans mattevans self-assigned this Jan 14, 2026
@mattevans mattevans marked this pull request as draft January 14, 2026 00:18
feat: detect CREATE/CREATE2 opcodes and fetch contract address from receipt
refactor: replace extractCallAddress with extractCallAddressWithCreate to
handle contract creation addresses
… trace-based computation

- Remove fetchCreateAddress and hasCreateOpcode helpers
- Introduce ComputeCreateAddresses to extract addresses directly from trace
- Update extractCallAddressWithCreate signature to accept index and map
- Rename queue name from "transaction-structlog" to "transaction_structlog"
- Expand test coverage for nested and failed CREATE scenarios
The root frame now starts at depth 1 instead of 0 to match the
actual EVM structlog output, where execution begins at depth 1.
All tests updated to reflect the new depth semantics.
@mattevans mattevans marked this pull request as ready for review January 14, 2026 05:23
…om child gas

Introduce GasSelf to represent the gas consumed by an opcode *excluding*
any gas spent in child frames. For CALL/CREATE opcodes this yields the
pure call overhead (warm/cold access, memory expansion, value transfer);
for all other opcodes GasSelf equals GasUsed. This allows accurate
aggregation of total execution gas without double counting.

- Add ComputeGasSelf() helper that subtracts the sum of *direct* child
 GasUsed values from each CALL/CREATE opcode’s GasUsed.
- Extend Structlog struct and ClickHouse schema with new GasSelf column.
- Update both ProcessTransaction() and ExtractStructlogs() to populate
 the new field.
- Provide extensive unit tests covering nested, sibling and edge cases.
…odes

test(structlog): add comprehensive format_address tests for 20-byte padding
refactor(structlog): introduce formatAddress to normalize stack values to 42-char addresses
…ic frames

Replace heuristic precompile check with go-ethereum's canonical list to
avoid mis-classifying early EOAs/contracts as precompiles. Tighten the
EOA detection logic to only create synthetic frames when call depth
remains unchanged (depth == nextDepth) instead of the previous
nextDepth <= depth, eliminating phantom frames for failed calls and
out-of-gas scenarios.
* master:
  fix(ethereum): improve error message for unsupported chain IDs
  refactor(ethereum): change ChainID from int32 to int64 across services and processors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants