Skip to content

HH2: Port hardhat-network provider to the current EDR API and restore trace events - #8422

Draft
nebasuke wants to merge 2 commits into
v2from
bas/v2-edr-napi-v3-traces
Draft

HH2: Port hardhat-network provider to the current EDR API and restore trace events#8422
nebasuke wants to merge 2 commits into
v2from
bas/v2-edr-napi-v3-traces

Conversation

@nebasuke

@nebasuke nebasuke commented Jul 4, 2026

Copy link
Copy Markdown
Member

Draft in preparation of N-API v3 and re-enabling traces for HH2.

Claude summary

What

Ports the hardhat-network provider glue to the current EDR API and restores the vm trace-event bridge that HH2 plugins (e.g. solidity-coverage, smock) rely on:

  • Provider glue port: the fork/initialDate/top-level blockGasLimit provider config is replaced by the network union and mining.blockGasLimit/defaultTransactionGasLimit; local-network genesis block gas limit and time are threaded through hardhat_reset; convertToEdr drops the converters for removed EDR surface.
  • Trace-event bridge restored: EDR re-adds raw traces as Response.traces() (a method returning napi-v3-shaped items). The previously commented-out bridge is re-enabled: iterate traces() and emit step/beforeMessage/afterMessage on the minimal vm, with marshalling updated to the new shapes (step.opcode.name, step.memory, tracingMessageResult.execResult).
  • Call traces enabled: EDR's includeCallTraces defaults to None, in which case traces() returns no arenas and the bridge silently emits nothing (the solidity-coverage 0%-coverage failure mode). The provider now requests IncludeTraces.All at creation.

Status / blocked on

Draft until an EDR release ships the Response.traces() work (NomicFoundation/edr#1301); the @nomicfoundation/edr version bump is intentionally not part of this branch yet.

Testing

  • Validated against a local build of the EDR branch: full hardhat-core test run for the glue port, and the bridge verified end-to-end (step/beforeMessage/afterMessage counts) by a dedicated spec in EDR's hardhat-tests suite.
  • The provider source here is kept byte-identical to the patches/hardhat@2.28.6.patch EDR applies in its hardhat-tests CI, so this branch is exercised continuously on the EDR side.

nebasuke added 2 commits June 10, 2026 14:48
Adapts hardhat-core from @NomicFoundation/edr 0.12.0-next.23 to the
current EDR API. The provider/convertToEdr changes are taken from the
EDR repo's own hardhat@2.28.4 patch (patches/hardhat@2.28.4.patch),
which the EDR CI has been maintaining against its vendored hardhat
test suite:

- ProviderConfig: `fork` is replaced by the `network` union (local
  config or fork config) and `defaultTransactionGasLimit` is required.
- Response no longer exposes `traces`.
- `stackTrace()` returns a kind-tagged result (StackTrace |
  UnexpectedError | HeuristicFailed | UnsafeToReplay) instead of an
  entry array.
- `getLatestSupportedSolcVersion` is renamed to
  `latestSupportedSolidityVersion` (test-only usage).

One addition over the EDR-side patch: `stackTrace.entries` is now cast
to Hardhat's local `SolidityStackTrace` union. EDR's typings export
`SolidityStackTraceEntry` (previously a dangling reference that
typechecked as `any`), and EDR's union includes
`CheatcodeErrorStackTraceEntry`, which only fires in solidity-test
runs, never on the network-provider path.

Validated against a local napi-rs v3 EDR build: hardhat-core builds
clean and the full test suite passes (1149 passing, 0 failing).
The glue port left the vm trace-event bridge commented out because EDR
no longer exposed Response.traces. EDR now re-adds it as a method
(Response.traces()), returning napi-v3-shaped trace items. Re-enable the
bridge: iterate traces() -> emit step/beforeMessage/afterMessage on the
minimal vm, and update convertToEdr marshalling to the new shapes
(step.opcode.name, step.memory, tracingMessageResult.execResult).
Copilot AI review requested due to automatic review settings July 4, 2026 21:15
@changeset-bot

changeset-bot Bot commented Jul 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 570acb8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI 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.

Pull request overview

Ports Hardhat Network’s EDR-backed provider integration to the current EDR API, and re-enables the VM trace-event bridge that HH2 plugins rely on.

Changes:

  • Updated tests to use EDR’s renamed “latest supported Solidity version” helper.
  • Updated provider config plumbing from fork/initialDate/top-level blockGasLimit to EDR’s network union and mining.blockGasLimit/defaultTransactionGasLimit, including hardhat_reset handling.
  • Restored the trace-event bridge by iterating Response.traces() and emitting step/beforeMessage/afterMessage with updated trace-item shapes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/hardhat-core/test/helpers/compilation.ts Updates EDR API usage for “latest supported Solidity version” in compilation helpers.
packages/hardhat-core/test/builtin-tasks/compile.ts Updates EDR API usage for “latest supported Solidity version” in compile-task tests.
packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts Updates trace marshalling to match new EDR trace shapes.
packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts Ports provider config to the new EDR API and re-enables trace-event bridging + reset behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +184 to 188
name: step.opcode.name,
},
stack: step.stack,
memory: step.memory,
};
Comment on lines 269 to 280
mining: {
autoMine: config.automine,
blockGasLimit: BigInt(config.blockGasLimit),
interval: ethereumjsIntervalMiningConfigToEdr(config.intervalMining),
memPool: {
order: ethereumjsMempoolOrderToEdrMineOrdering(config.mempoolOrder),
},
},
network,
networkId: BigInt(config.networkId),
observability: {},
ownedAccounts,
@nebasuke nebasuke changed the title Port hardhat-network provider to the current EDR API and restore trace events HH2: Port hardhat-network provider to the current EDR API and restore trace events Jul 5, 2026
@Wodann

Wodann commented Jul 8, 2026

Copy link
Copy Markdown
Member

Duplicate of #7985

@Wodann Wodann marked this as a duplicate of #7985 Jul 8, 2026
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