Repository navigation
feat: add backwards compatibility for Response::traces - #1301
Conversation
🦋 Changeset detectedLatest commit: f88951c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This PR reintroduces backwards compatibility for the Response::traces getter to support Hardhat 2's EthereumJS VM interface. The implementation converts the new CallTraceArena format back to the flat trace format that Hardhat 2 expects.
Changes:
- Adds
Response::traces()method that convertsCallTraceArenato flat trace format compatible with Hardhat 2 - Removes
edr_tracingdependency from multiple crates - Deletes
nested_tracer.rsand related code that are no longer needed - Re-enables verbose tracing tests for Hardhat 2 compatibility
Reviewed changes
Copilot reviewed 22 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
crates/edr_napi/src/trace.rs |
Implements conversion from CallTraceArena to flat trace format with Hardhat 2 compatibility quirks |
crates/edr_napi/src/provider/response.rs |
Adds traces() method to Response |
crates/edr_provider/src/observability.rs |
Updates tracing configuration to capture full stack snapshots |
patches/hardhat@2.28.4.patch |
Updates Hardhat 2 integration to use new trace format |
crates/edr_napi/test/provider.ts |
Re-enables verbose tracing tests |
| Multiple Cargo.toml files | Removes edr_tracing dependency |
crates/edr_solidity/src/nested_tracer.rs |
Deleted - no longer needed |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let tracing_config = if config.verbose_raw_tracing { | ||
| TracingInspectorConfig::all() | ||
| } else { | ||
| TracingInspectorConfig::default_parity().set_steps(true) | ||
| TracingInspectorConfig::default_parity() | ||
| .set_steps(true) | ||
| .set_stack_snapshots(StackSnapshotType::Full) |
There was a problem hiding this comment.
The StackSnapshotType::Full configuration is set regardless of verbose mode. This means that the full stack will always be captured in the tracing inspector, even when verbose tracing is disabled.
However, the actual filtering to return only the top of the stack happens in the conversion function raw_trace_from_call_trace_arena based on the verbose parameter. This creates an inconsistency where:
- The inspector always captures full stack (performance cost)
- The conversion then throws away most of the data when
verbose=false
Consider setting StackSnapshotType based on verbose_raw_tracing to avoid unnecessary data collection and improve performance.
There was a problem hiding this comment.
It's fixed in the stacked PRs rather than here: #1536 drops StackSnapshotType::Full from the non-verbose config and captures only the top of the stack per step.
87edb00 to
041399f
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1301 +/- ##
==========================================
+ Coverage 81.02% 81.47% +0.45%
==========================================
Files 474 473 -1
Lines 84016 83919 -97
Branches 84016 83919 -97
==========================================
+ Hits 68072 68373 +301
+ Misses 13661 13253 -408
- Partials 2283 2293 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
popescuoctavian
left a comment
There was a problem hiding this comment.
There is significant performance regression seen in the benchmarks -- up to 2.45x.
I believe this is caused by the inclusion of the full stack snapshot. However, I don't see an immediate solution here, with the existing revm-inspectors tracing code.
d203b12 to
369dc66
Compare
|
/bench |
|
⏳ EDR CI for this commit hasn't passed yet, so the regression benchmark was not started. Comment |
|
/bench |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench |
|
🚀 Starting regression benchmark for |
|
❌ Regression benchmark failed for |
|
/bench |
|
🚀 Starting regression benchmark for |
|
/bench |
|
🚀 Starting regression benchmark for |
|
✅ Regression benchmark passed for |
popescuoctavian
left a comment
There was a problem hiding this comment.
I did a full re-review, looks good overall, thanks! Left a couple of questions and one suggestion, up to you if they should be addressed. Feel free to merge without requesting another review.
Hardhat 2 consumes raw traces to emit its VM step and message events. `Response::traces()` converts each recorded call trace arena into the flat message, step and result sequence the removed `edr_tracing` collector produced. The `edr_tracing` dependency and `nested_tracer` are removed from `edr_napi`, `edr_provider` and `edr_solidity`.
`ObservabilityConfig` gains `recordStack`. Hardhat 2 needs the top of the stack for its VM step events. Recording the full stack for every step retains several times as much memory. `StackSnapshotType::Top` comes from a fork of revm-inspectors 0.41.4 with paradigmxyz/revm-inspectors#468 applied. Verbose tracing records the full stack and memory while enabled. Disabling it restores the configured `recordStack`.
The patch for 2.28.6 carries over the 2.28.4 patch and re-enables the VM event bridge, which reads `Response.traces()`. Hardhat 2 creates its provider with `includeCallTraces: All`, so responses carry the traces the bridge reads. The provider also records the top of the stack for Hardhat 2's VM step events. Its message events expect precompile calls, which call traces always include. A hardhat-tests spec asserts that the bridge emits step and message events, including for a precompile call.
The Hardhat 2 patch no longer computes `defaultTransactionGasLimit`. Since the provider made the field optional, EDR derives the same value per block. On forks it also uses the executing block's hardfork, so the derived value is better there. `transactionGasCap` stays, so solidity-coverage keeps lifting the EIP-7825 transaction gas limit.
The legacy collector dropped any call frame that reverted before its first step, including the top-level frame. The raw trace conversion now also applies this rule to a non-create root node and returns no messages for it. The legacy collector skipped a leading STOP step only in call frames, because creation frames carried no code. The conversion now keeps the leading STOP in creation frames.
The field was added earlier on this branch and nothing ever set it to anything but its default. Memory snapshots follow setVerboseTracing as before.
Neither status reaches an arena today. A fatal database error makes revm return an error, and observe_execution drops the observer on an error before a response exists. Suspend always sets a new-frame action first, so it never ends a frame. A panic would abort the published binary, which is built with panic set to abort. Both statuses now map to no reason while success stays false. A test pins that a failed storage read in a nested call fails the request without collecting a trace. The internal status rests on revm's interpreter convention and cannot be produced from EDR, so it has no test.
geth's call tracer and reth report no address for a failed create. The removed edr_tracing collector reported the address the frame ran at. The raw trace follows geth and reth. The tests pin that choice.

Resolves #1288. Stacked on #1831, which sits on #1848; the review diff is the five commits of this branch.
#1278 unified tracing on
CallTraceArenaand droppedResponse.traces. Hardhat 2 reads that getter to emit the VMstep,beforeMessageandafterMessageevents that solidity-coverage, hardhat-gas-reporter and hardhat-tracer consume, so no EDR release since then can ship to Hardhat 2.This PR reinstates the raw trace format as
Response.traces()on top of the arena and makes what a trace records configurable. It restores the old behaviour and fixes what the first version got wrong. The work that goes beyond the old behaviour is in the follow-up PR stacked on this one.What changes
Response.traces()converts each recorded arena into the flat message, step and result sequence the removededr_tracingcollector produced, quirks included: the firstSTOPstep is skipped, a call that reverts before its first step emits no message,DELEGATECALLreports the original caller, and halts only an inspector observes report as a revert instead of panicking (crates/edr_napi/src/trace.rs,result.rs).ObservabilityConfiggainsrecordStack: StackSnapshotType(None,Top,Full; defaultNone).setVerboseTracing(true)records the full stack and memory, and disabling it restores the configured value.includeCallTraces: AllandrecordStack: Top, and its bridge readstraces(). It no longer passesdefaultTransactionGasLimit, which the provider derives per block since feat: derive the default transaction gas limit from the executing block #1831.transactionGasCapstays for solidity-coverage.StackSnapshotType::Topcomes from a fork of revm-inspectors 0.42.2 with feat: add top-of-stack snapshot type paradigmxyz/revm-inspectors#468 applied (Wodann/revm-inspectors, branchfeat/top-of-stack-snapshot-0.42).crates/edr_solidity/src/nested_tracer.rsand theedr_tracingdependency ofedr_napi,edr_providerandedr_solidity.Compatibility
traces()is a method, not a getter, so a consumer converts once per response. build: upgrade Hardhat 2 to @nomicfoundation/edr v0.25.1 hardhat#7985 is the Hardhat 2 side.setVerboseTracing(true)records the full stack and memory. Onmainit usedTracingInspectorConfig::all(), which also recorded state diffs, return data and immediates that nothing read.Behaviour changes
contractAddress. The removed collector forwarded revm'sCreateOutcome.address, which is set for every create whose frame ran, reverted or halted. geth'scallTracerclearstofor a CREATE or CREATE2 frame that failed, incallFrame.processOutputofeth/tracers/native/call.go, and reth's call tracer sets it toNonefor any create withsuccessfalse, in revm-inspectors'geth_empty_call_frame. The raw trace follows them and a test pins it. Hardhat 2 core only forwards the field toafterMessagelisteners, and the validated plugin suites passed with it absent.Benchmark Results
Provider benchmark on
edr-benchmark-runner.preis@nomicfoundation/edr@0.12.0-next.23, the EDR Hardhat 2.29.1 ships, dispatched on the same runner (run 37049477125). This PR is headc6d484cc4(run 37368017467) against the storedmainbaseline of that day. Later heads of the same code measured the same 1.18× against theirmain. Likepre, this PR traces every transaction, whilemaintraces none, which is the whole gap againstmain.premainThe CI alert against
mainis expected. With the follow-up PR on top, the series reaches 1.00×main(run 37088120381).With a VM
steplistener attached, measured locally againstpreon an idle machine, medians of 5 runs:preSeaport is the one case slower than
pre; the follow-up PR brings it to 0.82×. The Solidity-test benchmark and the Hardhat 3 regression benchmark (99 entries, 11 scenarios) show no alert on this code (run 37539250895).Validation
58316dda8published as Hardhat 2.29.4 with this EDR at47f7abfb8, against shipped Hardhat 2.29.1 with EDR 0.12.0-next.23. OpenZeppelin v5.7.0, Uniswap v3-core, Seaport, Rocket Pool, Safe and NexusMutual, plus the solidity-coverage, hardhat-tracer and hardhat-gas-reporter suites, about 25,000 cases per side. Every suite gives the same pass/fail set on both builds except one Safe test that parsesdebug_traceTransactionoutput, whose format changed independently of this PR. Listening consumers: Rocket Pool coverage 0.97× the old wall time at 0.63× its peak RSS, the NexusMutual suite with hardhat-tracer loaded 0.88× at 0.58×, OpenZeppelin coverage 0.96× at 1.00×. NexusMutual's old-build coverage run did not fit in memory on the test machine; the first run measured it at 1.01× and 0.79×.steplistener attached surfaced an abort in the publish build, anunreachable!onStateChangeDuringStaticCallinconvert_status. The first commit fixes it and a napi test pins it.hardhat-testsspectrace-event-bridge.tscovers step and message events for a plain call and a precompile call.Notes for review
recordStack: Topcopies one stack element per step on every transaction while traces are statically on; the follow-up PR removes that cost by collecting only while a listener exists.traces()that releases the Rust arenas after the first call was measured and dropped: a persistent reference to the JS array made seaport 9% slower and 58% larger in RSS, and a hidden-property variant was within noise.pcandopfrom steps, sorecordStackdoes not affect it.preand this PR alike (1617–1675 against the snapshot's 1649); a harness issue, not introduced here.crates/tracing, which has no dependents after this PR; build: upgrade Hardhat 2 to @nomicfoundation/edr v0.25.1 hardhat#7985 type-checks once a release contains this PR and should drop its copy of the default gas limit resolver too. A console-address bug in the same conversion is fixed separately in fix: recognise console calls by the Hardhat console address #1821.