Skip to content

Commit da38ec6

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, and the debug fixtures in hardhat-tests had been switched to geth's format by f4bdc36. EDR CI therefore tested a format that Hardhat 2 no longer returns. Port the conversion from NomicFoundation/hardhat#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. Restore the fixtures, the modules/debug tests and assertEqualTraces from f4bdc36^ in the same commit, so every commit keeps the debug tests green. Requests drop enableMemory, since the package captures memory by default. assertEqualTraces loses the empty-memory and refund normalisations that only geth's format needed. It now compares returnValue without the 0x prefix that Hardhat 2 adds, because the fixtures store it unprefixed. The reverted mainnet fixture is exempt, since TurboGeth recorded no return value for it. The zeroed gasCost of call and create steps is dropped. The only such step left, a STATICCALL in the revert fixture, matches EDR's value. The skipped post-London fork case and its fixture are removed instead of restored. The case was skipped for https://github.com/NomicFoundation/hardhat/issues/3519, and the fixture served nothing else. The stale TODO about ethereumjs memory words goes with them. Some later changes still apply and are kept. The tests use ALCHEMY_URL without a non-null assertion, as in d2e5ae8. assertEqualTraces drops the assertions that the stricter eslint preset rejects. The unsupported tracer tests keep the expectations of f4bdc36, because EDR rejects such a tracer as a JavaScript tracer and debug_traceTransaction checks the hash first.
1 parent d2644ab commit da38ec6

15 files changed

Lines changed: 55201 additions & 298297 deletions
Lines changed: 18 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,9 @@
11
import { RpcDebugTraceOutput } from "hardhat/internal/hardhat-network/provider/output";
22

3-
// Trace generated using Geth 1.17.3
4-
//
5-
// Start the Geth dev node with debug API enabled:
6-
// ```bash
7-
// docker run -it --rm -p 8545:8545 -p 8546:8546 ethereum/client-go:stable --dev --http --http.addr 0.0.0.0 --http.api eth,net,debug --ws --ws.addr 0.0.0.0 --ws.api eth,net,debug
8-
// ```
9-
//
10-
// Add the following code to `scripts/simulate-geth.mts`:
11-
// ```ts
12-
// import * as viem from "viem";
13-
//
14-
// const url = "http://localhost:8546"; // For WSL: "http://10.0.0.43:8545";
15-
// const data = `0x3d61000480600b3d3981f35F5F525F`;
16-
//
17-
// const publicClient = viem
18-
// .createPublicClient({
19-
// transport: viem.http(url),
20-
// })
21-
// .extend((client) => ({
22-
// async traceTransaction(args: viem.Hash) {
23-
// return client.request({
24-
// method: "debug_traceTransaction",
25-
// params: [
26-
// args,
27-
// {
28-
// enableMemory: true,
29-
// } as any,
30-
// ],
31-
// });
32-
// },
33-
// }));
34-
// const walletClient = viem.createWalletClient({
35-
// transport: viem.http(url),
36-
// });
37-
//
38-
// const [gethAccount] = await walletClient.getAddresses();
39-
//
40-
// const gethClient = viem.createWalletClient({
41-
// transport: viem.http(url),
42-
// account: gethAccount,
43-
// });
44-
//
45-
// const deploymentTx = await gethClient.sendTransaction({
46-
// data,
47-
// chain: null,
48-
// });
49-
//
50-
// const receipt = await publicClient.waitForTransactionReceipt({
51-
// hash: deploymentTx,
52-
// });
53-
//
54-
// const contractAddress = receipt.contractAddress;
55-
// const txHash = await gethClient.sendTransaction({
56-
// to: contractAddress,
57-
// gas: 6_000_000n,
58-
// chain: null,
59-
// });
60-
//
61-
// const trace = await publicClient.traceTransaction(txHash);
62-
// console.log("Trace result:", JSON.stringify(trace, null, 2));
63-
// ```
64-
//
65-
// Run the script with:
66-
// ```bash
67-
// npx tsx scripts/simulate-geth.mts &> debug.txt
68-
// ```
69-
703
export const trace: RpcDebugTraceOutput = {
714
gas: 21012,
725
failed: false,
73-
returnValue: "0x",
6+
returnValue: "",
747
structLogs: [
758
{
769
pc: 0,
@@ -79,22 +12,35 @@ export const trace: RpcDebugTraceOutput = {
7912
gasCost: 2,
8013
depth: 1,
8114
stack: [],
15+
memory: [],
16+
storage: {},
8217
},
8318
{
8419
pc: 1,
8520
op: "PUSH0",
8621
gas: 5978998,
8722
gasCost: 2,
8823
depth: 1,
89-
stack: ["0x0"],
24+
stack: [
25+
"0000000000000000000000000000000000000000000000000000000000000000",
26+
],
27+
memory: [],
28+
storage: {},
9029
},
9130
{
9231
pc: 2,
9332
op: "MSTORE",
9433
gas: 5978996,
9534
gasCost: 6,
9635
depth: 1,
97-
stack: ["0x0", "0x0"],
36+
stack: [
37+
"0000000000000000000000000000000000000000000000000000000000000000",
38+
"0000000000000000000000000000000000000000000000000000000000000000",
39+
],
40+
memory: [
41+
"0000000000000000000000000000000000000000000000000000000000000000",
42+
],
43+
storage: {},
9844
},
9945
{
10046
pc: 3,
@@ -104,19 +50,9 @@ export const trace: RpcDebugTraceOutput = {
10450
depth: 1,
10551
stack: [],
10652
memory: [
107-
"0x0000000000000000000000000000000000000000000000000000000000000000",
108-
],
109-
},
110-
{
111-
pc: 4,
112-
op: "STOP",
113-
gas: 5978988,
114-
gasCost: 0,
115-
depth: 1,
116-
stack: ["0x0"],
117-
memory: [
118-
"0x0000000000000000000000000000000000000000000000000000000000000000",
53+
"0000000000000000000000000000000000000000000000000000000000000000",
11954
],
55+
storage: {},
12056
},
12157
],
12258
};

0 commit comments

Comments
 (0)