Skip to content

Commit ddd22df

Browse files
committed
build: restore Hardhat 2 debug traces in the patch
Hardhat 2 converts EDR's geth-format debug traces back to its legacy format in the open NomicFoundation/hardhat#7985. EDR's patched Hardhat 2.28.6 lacked that conversion, so EDR CI tested a format that Hardhat 2 no longer returns. Port the conversion from #7985. The port adds edrRpcDebugTraceToHardhat2 and its StorageTracker to convertToEdr.ts. It wires the memory default, the empty tracer handling and the result conversion into the provider's request method. RpcStructLog gains the returnData field. The debug trace code matches #7985. Outside it, the port keeps EDR's existing patch and its formatting. The compiled files come from TypeScript 5.0.4 with the package's own 2.28.6 tsconfig. That compiler reproduces the patched provider.js byte for byte. The source maps are now regenerated with the code they map. The revert commit restored the Hardhat 2 format fixtures and reversed the test hunks of #1251, so the debug tests are green again from here. assertEqualTraces loses the refund normalisation that only geth's format needed and the zeroing of call-opcode gas, which EDR now reports as the fixtures do. It compares returnValue without its prefix, except for a failed trace whose fixture recorded none. The unsupported tracer tests expect EDR's rejection of such a tracer as a JavaScript tracer, and debug_traceTransaction checks the hash first.
1 parent d37fdbe commit ddd22df

5 files changed

Lines changed: 841 additions & 84 deletions

File tree

‎hardhat-tests/test/internal/hardhat-network/provider/modules/debug/traceCall.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe("Debug module", function () {
6767
assertEqualTraces(trace, contractAGetMessageTrace);
6868
});
6969

70-
it("should get the correct trace when calling a function from contract A with a specific rpcDebugTracingConfig", async function () {
70+
it("should get the correct trace when calling a function from contract A with a specific rpcDebugTracingConfig", async function () {
7171
const trace = await this.provider.send("debug_traceCall", [
7272
{
7373
from: deployerAddress,
@@ -133,7 +133,8 @@ describe("Debug module", function () {
133133
tracer: "unsupportedTracer",
134134
},
135135
],
136-
"Hardhat currently only supports the default tracer, so no tracer parameter should be passed."
136+
// TODO: https://github.com/NomicFoundation/edr/issues/1250
137+
"JS Tracer is not enabled"
137138
);
138139
});
139140
});

‎hardhat-tests/test/internal/hardhat-network/provider/modules/debug/traceTransaction.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,21 @@ describe("Debug module", function () {
6868
});
6969

7070
it("Should throw an error when the value passed as tracer is not supported", async function () {
71+
const txHash = await sendDummyTransaction(this.provider, 0, {
72+
from: DEFAULT_ACCOUNTS_ADDRESSES[1],
73+
});
74+
7175
await assertInvalidArgumentsError(
7276
this.provider,
7377
"debug_traceTransaction",
7478
[
75-
"0x1234567876543234567876543456765434567aeaeaed67616732632762762373",
79+
txHash,
7680
{
7781
tracer: "unsupportedTracer",
7882
},
7983
],
80-
"Hardhat currently only supports the default tracer, so no tracer parameter should be passed."
84+
// TODO: https://github.com/NomicFoundation/edr/issues/1250
85+
"JS Tracer is not enabled"
8186
);
8287
});
8388

‎hardhat-tests/test/internal/hardhat-network/provider/utils/assertEqualTraces.ts‎

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { assert } from "chai";
22

3-
import {
4-
RpcDebugTraceOutput,
5-
RpcStructLog,
6-
} from "hardhat/internal/hardhat-network/provider/output";
3+
import { RpcDebugTraceOutput } from "hardhat/internal/hardhat-network/provider/output";
74

85
export function assertEqualTraces(
96
actual: RpcDebugTraceOutput,
@@ -16,8 +13,11 @@ export function assertEqualTraces(
1613
assert.equal(actual.failed, expected.failed);
1714
assert.equal(actual.gas, expected.gas);
1815

19-
// geth doesn't seem to include the returnValue
20-
// assert.equal(actual.returnValue, expected.returnValue);
16+
// The fixtures store returnValue without the 0x prefix that Hardhat 2 adds.
17+
// TurboGeth recorded no return value for the reverted mainnet transaction.
18+
if (!(expected.failed && expected.returnValue === "")) {
19+
assert.equal(actual.returnValue.replace(/^0x/, ""), expected.returnValue);
20+
}
2121

2222
// EthereumJS doesn't include STOP at the end when REVM does.
2323
if (actual.structLogs.length === expected.structLogs.length + 1) {
@@ -39,19 +39,6 @@ export function assertEqualTraces(
3939
expectedLog.gasCost = 0;
4040
}
4141

42-
// We don't support gas computation for these opcodes yet in EDR and always return 0.
43-
if (
44-
expectedLog.op === "CREATE" ||
45-
expectedLog.op === "CREATE2" ||
46-
expectedLog.op === "CALL" ||
47-
expectedLog.op === "CALLCODE" ||
48-
expectedLog.op === "DELEGATECALL" ||
49-
expectedLog.op === "STATICCALL"
50-
) {
51-
actualLog.gasCost = 0;
52-
expectedLog.gasCost = 0;
53-
}
54-
5542
// Fixture has deprecated name for KECCAK256
5643
if (actualLog.op === "KECCAK256") {
5744
actualLog.op = "SHA3";
@@ -75,24 +62,14 @@ export function assertEqualTraces(
7562
) {
7663
// Check for memory expansion
7764
if (
78-
expectedLog.memory!.length > expected.structLogs[i - 1].memory!.length
65+
expectedLog.memory.length > expected.structLogs[i - 1].memory!.length
7966
) {
80-
while (expectedLog.memory!.length > actualLog.memory!.length) {
81-
actualLog.memory!.push("0".repeat(64));
67+
while (expectedLog.memory.length > actualLog.memory.length) {
68+
actualLog.memory.push("0".repeat(64));
8269
}
8370
}
8471
}
8572

86-
// revm-inspectors emits `refund: 0` on every step, whereas Geth only emits
87-
// `refund` when non-zero. Normalize the expected log to match.
88-
const refund = (actualLog as RpcStructLog & { refund?: number }).refund;
89-
if (
90-
refund === 0 &&
91-
(expectedLog as RpcStructLog & { refund?: number }).refund === undefined
92-
) {
93-
(expectedLog as RpcStructLog & { refund?: number }).refund = 0;
94-
}
95-
9673
assert.deepEqual(
9774
actualLog,
9875
expectedLog,

0 commit comments

Comments
 (0)