Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v-next/hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"typescript": "~5.8.0"
},
"dependencies": {
"@nomicfoundation/edr": "0.12.0-next.24",
"@nomicfoundation/edr": "0.12.0-next.25",
"@nomicfoundation/hardhat-errors": "workspace:^3.0.6",
"@nomicfoundation/hardhat-utils": "workspace:^3.0.6",
"@nomicfoundation/hardhat-vendored": "workspace:^3.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SolidityStackTrace } from "./stack-traces/solidity-stack-trace.js";

Check failure on line 1 in v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/edr-provider.ts

View workflow job for this annotation

GitHub Actions / [hardhat] lint

'SolidityStackTrace' is defined but never used. Allowed unused vars must match /^_/u
import type { CoverageConfig } from "./types/coverage.js";
import type { LoggerConfig } from "./types/logger.js";
import type {
Expand Down Expand Up @@ -63,14 +63,10 @@

import { EdrProviderStackTraceGenerationError } from "./stack-traces/stack-trace-generation-errors.js";
import { createSolidityErrorWithStackTrace } from "./stack-traces/stack-trace-solidity-errors.js";
import {
isDebugTraceResult,
isEdrProviderErrorData,
} from "./type-validation.js";
import { isEdrProviderErrorData } from "./type-validation.js";
import { clientVersion } from "./utils/client-version.js";
import { ConsoleLogger } from "./utils/console-logger.js";
import {
edrRpcDebugTraceToHardhat,
hardhatMiningIntervalToEdrMiningInterval,
hardhatMempoolOrderToEdrMineOrdering,
hardhatHardforkToEdrSpecId,
Expand Down Expand Up @@ -289,15 +285,6 @@
"Invalid client version response",
);
return clientVersion(jsonRpcResponse.result);
} else if (
jsonRpcRequest.method === "debug_traceTransaction" ||
jsonRpcRequest.method === "debug_traceCall"
) {
assertHardhatInvariant(
isDebugTraceResult(jsonRpcResponse.result),
"Invalid debug trace response",
);
return edrRpcDebugTraceToHardhat(jsonRpcResponse.result);
} else {
return jsonRpcResponse.result;
}
Expand Down Expand Up @@ -339,18 +326,8 @@
const responseError = jsonRpcResponse.error;
let error;

let stackTrace: SolidityStackTrace | null = null;
try {
stackTrace = edrResponse.stackTrace();
} catch (e) {
if (e instanceof Error) {
await sendErrorTelemetry(new EdrProviderStackTraceGenerationError(e));
}

log("Failed to get stack trace: %O", e);
}

if (stackTrace !== null) {
const stackTrace = edrResponse.stackTrace();
if (stackTrace?.kind === "StackTrace") {
// If we have a stack trace, we know that the json rpc response data
// is an object with the data and transactionHash fields
assertHardhatInvariant(
Expand All @@ -360,11 +337,26 @@

error = createSolidityErrorWithStackTrace(
responseError.message,
stackTrace,
stackTrace.entries,
responseError.data.data,
responseError.data.transactionHash,
);
} else {
if (stackTrace !== null) {
switch (stackTrace.kind) {
case "UnexpectedError":
await sendErrorTelemetry(
new EdrProviderStackTraceGenerationError(
stackTrace.errorMessage,
),
);
log("Failed to get stack trace: %O", stackTrace.errorMessage);
break;
case "HeuristicFailed":
break;
}
}

error =
responseError.code === InvalidArgumentsError.CODE
? new InvalidArgumentsError(responseError.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { CustomError } from "@nomicfoundation/hardhat-utils/error";
abstract class StackTraceGenerationError extends CustomError {}

export class EdrProviderStackTraceGenerationError extends StackTraceGenerationError {
constructor(error: Error) {
super("Failed to generate stack trace for the EDR provider", error);
constructor(message: string) {
super(
"Failed to generate stack trace for the EDR provider",
new Error(message),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import type { DebugTraceResult } from "@nomicfoundation/edr";

import { isObject } from "@nomicfoundation/hardhat-utils/lang";

export function isDebugTraceResult(
result: unknown,
): result is DebugTraceResult {
return (
isObject(result) &&
"pass" in result &&
"gasUsed" in result &&
"structLogs" in result
);
}

interface EdrProviderErrorData {
data: string;
transactionHash?: string;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
} from "../../../../../types/config.js";
import type { ChainType } from "../../../../../types/network.js";
import type { GasMeasurement } from "../../../gas-analytics/types.js";
import type { RpcDebugTraceOutput, RpcStructLog } from "../types/output.js";
import type {
IntervalRange,
DebugTraceResult,
ChainOverride,
ForkConfig,
GasReport,
Expand Down Expand Up @@ -51,7 +49,7 @@
HOLOCENE,
ISTHMUS,
} from "@nomicfoundation/edr";
import { getUnprefixedHexString } from "@nomicfoundation/hardhat-utils/hex";

Check failure on line 52 in v-next/hardhat/src/internal/builtin-plugins/network-manager/edr/utils/convert-to-edr.ts

View workflow job for this annotation

GitHub Actions / [hardhat] lint

'getUnprefixedHexString' is defined but never used. Allowed unused vars must match /^_/u

import {
GENERIC_CHAIN_TYPE,
Expand Down Expand Up @@ -274,67 +272,6 @@
}
}

// TODO: EDR should handle this conversion. This is a temporary solution.
export function edrRpcDebugTraceToHardhat(
debugTraceResult: DebugTraceResult,
): RpcDebugTraceOutput {
const structLogs = debugTraceResult.structLogs.map((log) => {
const result: RpcStructLog = {
depth: Number(log.depth),
gas: Number(log.gas),
gasCost: Number(log.gasCost),
op: log.opName,
pc: Number(log.pc),
};

if (log.memory !== undefined) {
result.memory = log.memory;
}

if (log.stack !== undefined) {
// Remove 0x prefix which is required by EIP-3155, but not expected by Hardhat.
result.stack = log.stack.map(getUnprefixedHexString);
}

if (log.storage !== undefined) {
result.storage = Object.fromEntries(
Object.entries(log.storage).map(([key, value]) => [
getUnprefixedHexString(key),
getUnprefixedHexString(value),
]),
);
}

if (log.error !== undefined) {
result.error = {
message: log.error,
};
}

return result;
});

// REVM trace adds initial STOP that Hardhat doesn't expect
// TODO: double check with EDR team that this is still the case
if (structLogs.length > 0 && structLogs[0].op === "STOP") {
structLogs.shift();
}

/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
debugTraceResult.output is a string, but it's typed as Buffer in Edr */
let returnValue = (debugTraceResult.output as unknown as string) ?? "0x";
if (returnValue === "0x") {
returnValue = "";
}

return {
failed: !debugTraceResult.pass,
gas: Number(debugTraceResult.gasUsed),
returnValue,
structLogs,
};
}

export async function hardhatAccountsToEdrOwnedAccounts(
accounts: EdrNetworkAccountsConfig,
): Promise<Array<{ secretKey: string; balance: bigint }>> {
Expand Down
Loading