Skip to content

Add native Geth flatCallTracer - #16483

Open
hudem1 wants to merge 1 commit into
masterfrom
fix/native-flat-call-tracer-20261126
Open

hudem1 wants to merge 1 commit into
masterfrom
fix/native-flat-call-tracer-20261126

Conversation

@hudem1

@hudem1 hudem1 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Tested commit d34d6f50c013a588a88209b6dd36466a5fdf75fe, based on master f296f39d245375d0273d77224380606e58e130c8, .NET 11.0.100, parent-only serial compilation/testing:

  • 8 causal selector/schema regressions fail on the master-only implementation, returning the missing-tracer error, then pass with native registration/output. Master production was temporarily restored, the regression-only test patch applied, and every candidate file restored byte-for-byte before rebuilding. No baseline compile failure is presented as runtime causality.
  • Focused native flat unit set 6 passed; flat-named RPC set 84 passed; combined flat/native stream/config/empty/deadline selection 206 passed; existing mux lifecycle 13 passed.
  • Exact clean committed-source full JsonRpc: 9,500 passed / 21 existing skips / 0 failures.
  • Exact clean committed-source full EVM: 21,001 passed / 27 existing skips / 0 failures.
  • Exact clean committed-source full Consensus: 1,343 passed / 0 failures.
  • Corresponding final-source Debug style builds for Blockchain, JsonRpc.Test, Evm.Test and Consensus.Test: 0 warnings/errors. Scoped verify-only whitespace and diff check pass. csharp-ls is unavailable; compiler/tests were used, no installation.
  • Controls cover default/nullable/duplicate/malformed configs, root and nested precompiles and canonical-vs-relocated filtering, CALL variants, CREATE/CREATE2, SELFDESTRUCT, revert/error conversion, metadata across real transactions/blocks vs synthetic/indexed calls, nested mux detachment, reused block tracers, stream equivalence, config/deadline precedence and empty/unmatched selections.
  • Initial consensus test-fixture failure is preserved: the fixture used flatCallTracer as an unregistered JavaScript expression and unconditionally cast its block tracer to IDisposable. Keep the original deferred-JavaScript guarantee using a genuinely unregistered selector; native selection is independently asserted. An unused-import analyzer warning and a parent import-cleanup compile mistake were also retained and corrected; assertions were not weakened.

Reproduce targeted gates:

dotnet test --project src/Nethermind/Nethermind.JsonRpc.Test/Nethermind.JsonRpc.Test.csproj -c release -- --filter 'FullyQualifiedName~flatCallTracer'
dotnet test --project src/Nethermind/Nethermind.Evm.Test/Nethermind.Evm.Test.csproj -c release -- --filter 'FullyQualifiedName~FlatCallTracer'

Master advanced after local validation to 14d42a1fef588929a50b6b359d531793006acf83 (41 commits, no direct overlap with these ten changed files). The local results above are not claimed for a merged tree with that newer master. Fresh CI/integration review remains required; no merge or auto-merge is requested.

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

Adds native Geth-style flatCallTracer selection through debug tracing, with includePrecompiles and convertParityErrors configuration. It returns flat call/create/selfdestruct entries rather than the nested callTracer tree.

Remarks

  • NAT-01: https://www.notion.so/40f360fc38d0814c8062f4d1798aebbe — owner Hugo; In progress / Done unchecked until an independently verified merge.
  • Source contract pinned to Geth bbafd66b66f5e37e877bf1efe3506ad74a6eda98/eth/tracers/native/call_flat.go, including generated JSON serializers and error mapping; audited 00821e33 baseline inspected too. Local reference fixtures were inspected, not executed. No full paired-client Geth run or performance improvement is claimed.
  • Focused integration scope is historical transaction/block, debug_traceCall, native streaming and mux. Simulation/traceCallMany-specific flat metadata is not advertised as validated Geth parity. Frame types absent from the pinned flat schema (e.g. newer TCREATE) are rejected rather than silently rendered as CALL.
  • Existing deadline/resource policies are reused, not broadened into fixing the separate legacy deadline/streaming PR family. Retain historical overrides and block txHash filtering per Hugo/Lukasz's explicit policy, permissive durations, and the one-space JS callback diagnostic policy.

Ready for review at the owner’s request. 🤖 AI agent (Pi / gpt-6.1-sol), implementing and validating on behalf of @hudem1.

@claude

claude Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hudem1's task in 2m 3s —— View job


PR review: native flatCallTracer

  • Read the diff and the repo rules
  • Compared output against Geth call_flat.go: frame shapes, precompile filtering, error mapping, context fill
  • Checked integration: factory, config validation, deadline policy, mux propagation of IsTraceCall, traceCall vs. historical metadata
  • Posted inline comments

Summary

Overall this is a clean design. It wraps NativeCallTracer, so no VM tracing logic is duplicated, and it plugs into the factory, deadline and mux paths without much code. These parts match Geth:

  • the preorder traceAddress
  • precompile filtering applied only below the root, with siblings renumbered
  • dropping result on errors other than revert
  • the zero/null traceCall context (fillCallFrameFromContext with new(Context))
  • null-preserving bool config

IsTraceCall passes through mux children correctly, because they are built with options with {...}.

Findings

Medium

  1. STATICCALL frames emit "value":"0x0"; Geth leaves value out (NativeFlatCallTracer.cs:150). Geth passes a nil value for STATICCALL and flatCallAction.Value is omitempty. The inner NativeCallTracer already sets Value = null for STATICCALL to match Geth, and ?? UInt256.Zero undoes that. The new test Debug_traceCall_flatCallTracer_filters_and_renumbers_precompiles asserts the wrong value.

Low
2. ConvertError maps the "out of gas:" prefix, which is not in Geth's parityErrorMappingStartingWith. For example, the reentrancy-sentry error stays unconverted in Geth but becomes Out of gas here (:190).
3. Perf: each tx's result goes through write, then JsonDocument.Parse, then Clone() (:116). Array.IndexOf per tx makes block tracing O(n²) (:45).
4. Cosmetic: in result, Geth's field order is address, code, gasUsed, output. Here output is written before gasUsed (:162). Semantically JSON doesn't care, but byte-level diff tools comparing against Geth will flag it.

No security problems found. Comments added in the diff are fine: the <summary> and the Geth-referencing <remarks> give useful context.

Not mergeable yet: the Medium parity finding (1) needs a fix or a stated reason.

writer.WriteString("gas", Quantity(frame.Gas));
WriteBytes(writer, create ? "init" : "input", frame.Input);
if (!create && frame.To is { } to) writer.WriteString("to", to.ToString());
writer.WriteString("value", Quantity(frame.Value ?? UInt256.Zero));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Geth parity, STATICCALL value

Geth's StaticCall calls captureBegin(..., STATICCALL, ..., nil), so callFrame.Value is nil. flatCallAction.Value is *big.Int with json:"value,omitempty", so Geth leaves value out of staticcall actions. NativeCallTracer already copies this: it sets Value = null for STATICCALL (NativeCallTracer.cs:153/464). The ?? UInt256.Zero here puts back "value":"0x0". Debug_traceCall_flatCallTracer_filters_and_renumbers_precompiles asserts that wrong value (rows[2]["action"]["value"] == "0x0" for the staticcall row).

Suggested change
writer.WriteString("value", Quantity(frame.Value ?? UInt256.Zero));
if (frame.Value is { } value) writer.WriteString("value", Quantity(value));

Then update the test to expect no value on the staticcall row.

"return data out of bounds" => "Out of bounds",
"stack limit reached 1024 (1023)" => "Out of stack",
"precompiled failed" or "invalid input length" => "Built-in failed",
_ when error.StartsWith("out of gas:", StringComparison.Ordinal) => "Out of gas",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: this mapping isn't in Geth. Geth's parityErrorMappingStartingWith has only invalid opcode: and stack underflow. Nethermind's error text out of gas: not enough gas for reentrancy sentry matches Geth's not enough gas for reentrancy sentry, which Geth does not convert. With convertParityErrors, Geth returns the raw text and this code returns Out of gas. If this is on purpose, add a short comment saying why; if not, remove the line.

}
writer.WriteEndArray();
}
using JsonDocument document = JsonDocument.Parse(buffer.WrittenMemory);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: perf. Each tx's output is built three times: written into an ArrayBufferWriter, parsed into a JsonDocument, then Clone()d into another buffer. With large block traces (thousands of frames per tx), this is noticeable overhead. One option: snapshot into a small typed frame list (or a byte[] plus a raw-JSON value holder) before disposing _inner, and let the serializer write it once. Also, Array.IndexOf(block.Transactions, tx) (line 45) runs once per tx, so block tracing is O(n²). The block tracer already knows the index, though passing it through would mean changing the factory signature, so this is optional.

@github-actions

Copy link
Copy Markdown
Contributor

Stateless guest cost

block steps Δ steps prover cost Δ cost
11957686 251,692,232 +0.000% 26,847,903,666 +0.000%
11962410 149,158,028 +0.000% 15,829,079,953 +0.000%
11962415 180,209,258 +0.000% 19,290,240,344 +0.000%
11962427 153,151,902 +0.000% 16,139,237,373 +0.000%
11962485 157,259,412 +0.000% 16,790,020,831 +0.000%
25526356 85,493,795 +0.000% 14,363,185,798 +0.000%
25532382 91,363,842 +0.000% 16,317,769,483 +0.000%
25532442 102,121,429 +0.000% 16,609,465,716 +0.000%
25532454 109,141,515 +0.000% 18,243,070,994 +0.000%
25532553 96,008,991 +0.000% 15,889,355,987 +0.000%
25532642 99,756,703 +0.000% 16,614,851,468 +0.000%
all 11 blocks 1,475,357,107 +0.000% 192,934,181,613 +0.000%
Variable cost by bucket, summed over shared blocks (excludes BASE)
bucket before after Δ
MAIN 91,472,140,634 91,472,140,634 +0.000%
OPCODES 19,320,551,101 19,320,551,101 +0.000%
PRECOMPILES 58,259,256,787 58,259,256,787 +0.000%
MEMORY 20,744,893,699 20,744,893,699 +0.000%

b7120a7bcaaa (merge commit) · 11 pinned blocks · ziskemu is deterministic, so these figures are exact and any non-zero delta is real.

Compared against 14d42a1fef58.

@hudem1
hudem1 marked this pull request as ready for review November 29, 2026 12:42
@claude

claude Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @hudem1's task in 33s —— View job


PR review: native flatCallTracer (re-run on ready_for_review)

  • Checked for new commits since the earlier review (none: head is still d34d6f5)
  • Re-checked the integration diff: factory, config validation, deadline allowlist, IsTraceCall passing, tests
  • Posted summary (comment)

I found no new issues. The earlier inline findings are still open, and I did not post them again:

  • Medium: staticcall actions output "value":"0x0", but Geth leaves value out (NativeFlatCallTracer.cs:150).
  • Low: the extra "out of gas:" parity-error mapping (:190).
  • Low: the triple JSON pass per tx and O(n²) Array.IndexOf (:116, :45).
  • Low: result field order (:162).

Not mergeable yet: the Medium finding needs a fix or a stated reason.

@claude

claude Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Re-review: native flatCallTracer (marked ready for review)

There are no new commits since the earlier review; the head is still d34d6f5. I re-checked the integration diff: factory registration, ValidateConfig, deadline-policy allowlist, the IsTraceCall flag in both GethStyleTracer.Trace overloads, the source-gen config type, and the extended RPC test matrices. I found nothing new. The open items from the earlier review are still unaddressed, and none has a reply:

Severity Finding Location
Medium staticcall actions output "value":"0x0". Geth leaves value out, because it is nil with omitempty. ?? UInt256.Zero undoes the Value = null that NativeCallTracer already sets, and the precompile test asserts the wrong value. NativeFlatCallTracer.cs:150 (thread)
Low The "out of gas:" prefix mapping is not in Geth's parityErrorMappingStartingWith, so the reentrancy-sentry error is converted here but not in Geth. :190
Low Perf: each tx's output goes through write, then JsonDocument.Parse, then Clone(). Array.IndexOf per tx makes block tracing O(n²). :116, :45
Low result field order is output, gasUsed; Geth's is gasUsed, output. This only matters for byte-level diffs. :162

No Critical/High or security issues found. The added XML docs are fine.

Not mergeable yet: the Medium Geth-parity finding needs a fix or an explicit reason it is intentional.

🤖 AI agent (Claude Code / Opus 5.5) review bot

View job run

@svlachakis svlachakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pinned reference supplies zero for nested STATICCALL values and maps the out of gas: prefix. The current output matches both. Low - GethStyleTracer.std.cs:77: setting IsTraceCall here adds a record allocation to every debug_traceCall. Set it in the options copies already made for indexed and non-indexed calls.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants