From 913d96bb5e1e46d251f19cbae8071fb51c812ee9 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Tue, 4 Feb 2025 16:25:12 +0000 Subject: [PATCH 1/9] feat: replace forked ethereumjs packages with originals --- packages/hardhat-core/package.json | 8 +- .../hardhat-core/src/builtin-tasks/node.ts | 4 +- .../internal/core/jsonrpc/types/base-types.ts | 2 +- .../src/internal/core/providers/accounts.ts | 22 ++-- .../src/internal/core/providers/util.ts | 2 +- .../hardhat-network/jsonrpc/client.ts | 5 +- .../hardhat-network/provider/node-types.ts | 2 +- .../hardhat-network/provider/provider.ts | 2 +- .../provider/utils/convertToEdr.ts | 2 +- .../provider/utils/makeAccount.ts | 7 +- .../provider/utils/makeCommon.ts | 2 +- .../hardhat-network/provider/utils/random.ts | 9 +- .../hardhat-network/provider/vm/minimal-vm.ts | 4 +- .../hardhat-network/provider/vm/types.ts | 2 +- .../stack-traces/consoleLogger.ts | 2 +- .../stack-traces/solidity-errors.ts | 2 +- .../internal/solidity/compiler/downloader.ts | 2 +- .../core/jsonrpc/types/input/validation.ts | 2 +- .../test/internal/core/providers/accounts.ts | 6 +- .../hardhat-network/helpers/assertions.ts | 2 +- .../hardhat-network/helpers/blockchain.ts | 4 +- .../hardhat-network/helpers/constants.ts | 2 +- .../hardhat-network/helpers/leftPad32.ts | 2 +- .../hardhat-network/helpers/providers.ts | 2 +- .../hardhat-network/helpers/retrieveCommon.ts | 2 +- .../hardhat-network/helpers/transactions.ts | 4 +- .../hardhat-network/jsonrpc/client.ts | 5 +- .../test/internal/util/hardforks.ts | 2 +- .../test/internal/util/keys-derivation.ts | 2 +- pnpm-lock.yaml | 122 ++++++------------ 30 files changed, 85 insertions(+), 151 deletions(-) diff --git a/packages/hardhat-core/package.json b/packages/hardhat-core/package.json index 3ab6506f6bd..ecaf1cc4687 100644 --- a/packages/hardhat-core/package.json +++ b/packages/hardhat-core/package.json @@ -59,7 +59,6 @@ "devDependencies": { "@nomicfoundation/eslint-plugin-hardhat-internal-rules": "workspace:^", "@nomicfoundation/eslint-plugin-slow-imports": "workspace:^", - "@nomicfoundation/ethereumjs-block": "5.0.4", "@types/async-eventemitter": "^0.2.1", "@types/bn.js": "^5.1.0", "@types/chai": "^4.2.0", @@ -98,12 +97,12 @@ "typescript": "~5.0.0" }, "dependencies": { + "@ethereumjs/common": "^4.4.0", + "@ethereumjs/tx": "^5.4.0", + "@ethereumjs/util": "^9.1.0", "@ethersproject/abi": "^5.1.2", "@metamask/eth-sig-util": "^4.0.0", "@nomicfoundation/edr": "^0.8.0", - "@nomicfoundation/ethereumjs-common": "4.0.4", - "@nomicfoundation/ethereumjs-tx": "5.0.4", - "@nomicfoundation/ethereumjs-util": "9.0.4", "@nomicfoundation/solidity-analyzer": "^0.1.0", "@sentry/node": "^5.18.1", "@types/bn.js": "^5.1.0", @@ -118,7 +117,6 @@ "enquirer": "^2.3.0", "env-paths": "^2.2.0", "ethereum-cryptography": "^1.0.3", - "ethereumjs-abi": "^0.6.8", "find-up": "^5.0.0", "fp-ts": "1.19.3", "fs-extra": "^7.0.1", diff --git a/packages/hardhat-core/src/builtin-tasks/node.ts b/packages/hardhat-core/src/builtin-tasks/node.ts index 7c268df5b2f..cd2421d60e5 100644 --- a/packages/hardhat-core/src/builtin-tasks/node.ts +++ b/packages/hardhat-core/src/builtin-tasks/node.ts @@ -1,4 +1,4 @@ -import type EthereumjsUtilT from "@nomicfoundation/ethereumjs-util"; +import type EthereumjsUtilT from "@ethereumjs/util"; import picocolors from "picocolors"; import debug from "debug"; @@ -56,7 +56,7 @@ function logHardhatNetworkAccounts(networkConfig: HardhatNetworkConfig) { privateToAddress, toBytes, toChecksumAddress, - } = require("@nomicfoundation/ethereumjs-util") as typeof EthereumjsUtilT; + } = require("@ethereumjs/util") as typeof EthereumjsUtilT; console.log("Accounts"); console.log("========"); diff --git a/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts b/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts index c3cedecea30..510ff4b8d66 100644 --- a/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts +++ b/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts @@ -2,7 +2,7 @@ import { bytesToHex as bufferToHex, isValidAddress, toBytes, -} from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/util"; import * as t from "io-ts"; import * as BigIntUtils from "../../../util/bigint"; diff --git a/packages/hardhat-core/src/internal/core/providers/accounts.ts b/packages/hardhat-core/src/internal/core/providers/accounts.ts index d60d7ec757c..bdf8075c9be 100644 --- a/packages/hardhat-core/src/internal/core/providers/accounts.ts +++ b/packages/hardhat-core/src/internal/core/providers/accounts.ts @@ -1,7 +1,7 @@ import * as t from "io-ts"; import { signTypedData, SignTypedDataVersion } from "@metamask/eth-sig-util"; -import { FeeMarketEIP1559Transaction } from "@nomicfoundation/ethereumjs-tx"; +import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; import { EIP1193Provider, RequestArguments } from "../../../types"; import { HardhatError } from "../errors"; import { ERRORS } from "../errors-list"; @@ -49,7 +49,7 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { toRpcSig, toBytes, bytesToHex: bufferToHex, - } = await import("@nomicfoundation/ethereumjs-util"); + } = await import("@ethereumjs/util"); if ( args.method === "eth_accounts" || @@ -197,7 +197,7 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { bytesToHex: bufferToHex, toBytes, privateToAddress, - } = require("@nomicfoundation/ethereumjs-util"); + } = require("@ethereumjs/util"); const privateKeys: Buffer[] = localAccountsHexPrivateKeys.map((h) => toBytes(h) @@ -210,9 +210,7 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { } private _getPrivateKeyForAddress(address: Buffer): Buffer { - const { - bytesToHex: bufferToHex, - } = require("@nomicfoundation/ethereumjs-util"); + const { bytesToHex: bufferToHex } = require("@ethereumjs/util"); const pk = this._addressToPrivateKey.get(bufferToHex(address)); if (pk === undefined) { throw new HardhatError(ERRORS.NETWORK.NOT_LOCAL_ACCOUNT, { @@ -232,9 +230,7 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { } private async _getNonce(address: Buffer): Promise { - const { bytesToHex: bufferToHex } = await import( - "@nomicfoundation/ethereumjs-util" - ); + const { bytesToHex: bufferToHex } = await import("@ethereumjs/util"); const response = (await this._wrappedProvider.request({ method: "eth_getTransactionCount", @@ -250,10 +246,10 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { privateKey: Buffer ): Promise { const { AccessListEIP2930Transaction, LegacyTransaction } = await import( - "@nomicfoundation/ethereumjs-tx" + "@ethereumjs/tx" ); - const { Common } = await import("@nomicfoundation/ethereumjs-common"); + const { Common } = await import("@ethereumjs/common"); const txData = { ...transactionRequest, @@ -320,9 +316,7 @@ export class HDWalletProvider extends LocalAccountsProvider { passphrase ); - const { - bytesToHex: bufferToHex, - } = require("@nomicfoundation/ethereumjs-util"); + const { bytesToHex: bufferToHex } = require("@ethereumjs/util"); const privateKeysAsHex = privateKeys.map((pk) => bufferToHex(pk)); super(provider, privateKeysAsHex); } diff --git a/packages/hardhat-core/src/internal/core/providers/util.ts b/packages/hardhat-core/src/internal/core/providers/util.ts index 9d734155361..775712cc372 100644 --- a/packages/hardhat-core/src/internal/core/providers/util.ts +++ b/packages/hardhat-core/src/internal/core/providers/util.ts @@ -53,7 +53,7 @@ export function normalizeHardhatNetworkAccountsConfig( return accountsConfig; } - const { bytesToHex } = require("@nomicfoundation/ethereumjs-util"); + const { bytesToHex } = require("@ethereumjs/util"); return derivePrivateKeys( accountsConfig.mnemonic, diff --git a/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts b/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts index 82bd9e6c98a..30ea7ab9dd3 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/jsonrpc/client.ts @@ -1,7 +1,4 @@ -import { - Address, - bytesToHex as bufferToHex, -} from "@nomicfoundation/ethereumjs-util"; +import { Address, bytesToHex as bufferToHex } from "@ethereumjs/util"; import fsExtra from "fs-extra"; import * as t from "io-ts"; import path from "path"; diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/node-types.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/node-types.ts index 8049b4e019c..dc93e59a3d2 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/node-types.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/node-types.ts @@ -72,7 +72,7 @@ export interface LegacyTransactionParams extends BaseTransactionParams { export interface AccessListTransactionParams extends BaseTransactionParams { gasPrice: bigint; - // We use this access list format because @nomicfoundation/ethereumjs-tx access list data + // We use this access list format because @ethereumjs/tx access list data // forces us to use it or stringify them accessList: AccessListBufferItem[]; // We don't include chainId as it's not necessary, the node diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts index ea642699975..79e6a7f9d9d 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts @@ -14,7 +14,7 @@ import type { HttpHeader, TracingConfigWithBuffers, } from "@nomicfoundation/edr"; -import { Common } from "@nomicfoundation/ethereumjs-common"; +import { Common } from "@ethereumjs/common"; import picocolors from "picocolors"; import debug from "debug"; import { EventEmitter } from "events"; diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts index a955ef12258..848357f5d4b 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts @@ -7,7 +7,7 @@ import type { TracingMessageResult, TracingStep, } from "@nomicfoundation/edr"; -import { Address } from "@nomicfoundation/ethereumjs-util"; +import { Address } from "@ethereumjs/util"; import { requireNapiRsModule } from "../../../../common/napi-rs"; import { HardforkName } from "../../../util/hardforks"; diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeAccount.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeAccount.ts index 2a17985c3d0..0896c437fff 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeAccount.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeAccount.ts @@ -1,9 +1,4 @@ -import { - Account, - Address, - privateToAddress, - toBytes, -} from "@nomicfoundation/ethereumjs-util"; +import { Account, Address, privateToAddress, toBytes } from "@ethereumjs/util"; import { GenesisAccount } from "../node-types"; diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeCommon.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeCommon.ts index 55c000e7cab..20631cfd9ea 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeCommon.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/makeCommon.ts @@ -1,4 +1,4 @@ -import { Common } from "@nomicfoundation/ethereumjs-common"; +import { Common } from "@ethereumjs/common"; import { LocalNodeConfig } from "../node-types"; import { HardforkName } from "../../../util/hardforks"; diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/random.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/random.ts index 8267290a1b7..a2af6186c6d 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/random.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/random.ts @@ -1,4 +1,4 @@ -import type EthereumjsUtilT from "@nomicfoundation/ethereumjs-util"; +import type EthereumjsUtilT from "@ethereumjs/util"; import type * as UtilKeccakT from "../../../util/keccak"; export class RandomBufferGenerator { @@ -37,7 +37,7 @@ export class RandomBufferGenerator { export const randomHash = () => { const { bytesToHex: bufferToHex } = - require("@nomicfoundation/ethereumjs-util") as typeof EthereumjsUtilT; + require("@ethereumjs/util") as typeof EthereumjsUtilT; return bufferToHex(randomHashBuffer()); }; @@ -47,14 +47,13 @@ export const randomHashBuffer = (): Uint8Array => { }; export const randomAddress = () => { - const { Address } = - require("@nomicfoundation/ethereumjs-util") as typeof EthereumjsUtilT; + const { Address } = require("@ethereumjs/util") as typeof EthereumjsUtilT; return new Address(randomAddressBuffer()); }; export const randomAddressString = () => { const { bytesToHex: bufferToHex } = - require("@nomicfoundation/ethereumjs-util") as typeof EthereumjsUtilT; + require("@ethereumjs/util") as typeof EthereumjsUtilT; return bufferToHex(randomAddressBuffer()); }; diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/vm/minimal-vm.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/vm/minimal-vm.ts index f80fa55d614..84246a8f3c1 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/vm/minimal-vm.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/vm/minimal-vm.ts @@ -1,12 +1,12 @@ import type { Provider as EdrProviderT } from "@nomicfoundation/edr"; -import type { Address } from "@nomicfoundation/ethereumjs-util"; +import type { Address } from "@ethereumjs/util"; import type { MinimalEVMResult, MinimalInterpreterStep, MinimalMessage, } from "./types"; -import { AsyncEventEmitter } from "@nomicfoundation/ethereumjs-util"; +import { AsyncEventEmitter } from "@ethereumjs/util"; /** * Used by the provider to keep the `_vm` variable used by some plugins. This diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/vm/types.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/vm/types.ts index ba4332ec5de..5fa485635f3 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/vm/types.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/vm/types.ts @@ -1,5 +1,5 @@ import type { ExceptionalHalt, SuccessReason } from "@nomicfoundation/edr"; -import type { Address } from "@nomicfoundation/ethereumjs-util"; +import type { Address } from "@ethereumjs/util"; /** * These types are minimal versions of the values returned by ethereumjs diff --git a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts index 5e2ef4a1d75..a26a63e0dde 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts @@ -3,7 +3,7 @@ import { bytesToHex as bufferToHex, bytesToInt, fromSigned, -} from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/util"; import util from "util"; import { diff --git a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/solidity-errors.ts b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/solidity-errors.ts index cce9bfe9e33..3246c0cbe18 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/solidity-errors.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/solidity-errors.ts @@ -1,4 +1,4 @@ -import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util"; +import { bytesToHex as bufferToHex } from "@ethereumjs/util"; import { ReturnData } from "../provider/return-data"; import { panicErrorCodeToMessage } from "./panic-errors"; diff --git a/packages/hardhat-core/src/internal/solidity/compiler/downloader.ts b/packages/hardhat-core/src/internal/solidity/compiler/downloader.ts index 6d96ec8456e..a77c836b326 100644 --- a/packages/hardhat-core/src/internal/solidity/compiler/downloader.ts +++ b/packages/hardhat-core/src/internal/solidity/compiler/downloader.ts @@ -317,7 +317,7 @@ export class CompilerDownloader implements ICompilerDownloader { downloadPath: string ): Promise { const { bytesToHex } = - require("@nomicfoundation/ethereumjs-util") as typeof import("@nomicfoundation/ethereumjs-util"); + require("@ethereumjs/util") as typeof import("@ethereumjs/util"); const { keccak256 } = await import("../../util/keccak"); const expectedKeccak256 = build.keccak256; diff --git a/packages/hardhat-core/test/internal/core/jsonrpc/types/input/validation.ts b/packages/hardhat-core/test/internal/core/jsonrpc/types/input/validation.ts index 67cf2af2e9b..a77b0270e31 100644 --- a/packages/hardhat-core/test/internal/core/jsonrpc/types/input/validation.ts +++ b/packages/hardhat-core/test/internal/core/jsonrpc/types/input/validation.ts @@ -1,4 +1,4 @@ -import { toBytes } from "@nomicfoundation/ethereumjs-util"; +import { toBytes } from "@ethereumjs/util"; import { assert } from "chai"; import * as t from "io-ts"; diff --git a/packages/hardhat-core/test/internal/core/providers/accounts.ts b/packages/hardhat-core/test/internal/core/providers/accounts.ts index 3d1661e02f1..aceb5973810 100644 --- a/packages/hardhat-core/test/internal/core/providers/accounts.ts +++ b/packages/hardhat-core/test/internal/core/providers/accounts.ts @@ -1,11 +1,11 @@ -import { Common } from "@nomicfoundation/ethereumjs-common"; -import { AccessListEIP2930Transaction } from "@nomicfoundation/ethereumjs-tx"; +import { Common } from "@ethereumjs/common"; +import { AccessListEIP2930Transaction } from "@ethereumjs/tx"; import { assert } from "chai"; import { bytesToHex as bufferToHex, privateToAddress, toBytes, -} from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/util"; import { ERRORS } from "../../../../src/internal/core/errors-list"; import { numberToRpcQuantity } from "../../../../src/internal/core/jsonrpc/types/base-types"; diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/assertions.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/assertions.ts index 438da46a4f2..31f3c3d5483 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/assertions.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/assertions.ts @@ -1,5 +1,5 @@ import { assert } from "chai"; -import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util"; +import { bytesToHex as bufferToHex } from "@ethereumjs/util"; import { numberToRpcQuantity, diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/blockchain.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/blockchain.ts index 8fb199ba71e..c18ec6fc214 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/blockchain.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/blockchain.ts @@ -1,8 +1,8 @@ import { LegacyTransaction as Transaction, LegacyTxData as TxData, -} from "@nomicfoundation/ethereumjs-tx"; -import { bytesToHex, toBytes } from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/tx"; +import { bytesToHex, toBytes } from "@ethereumjs/util"; import { numberToRpcQuantity } from "../../../../src/internal/core/jsonrpc/types/base-types"; import { randomAddress } from "../../../../src/internal/hardhat-network/provider/utils/random"; diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/constants.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/constants.ts index 362d3f46e88..09b4d1314d1 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/constants.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/constants.ts @@ -1,5 +1,5 @@ // reused from ethers.js -import { Address, toBytes } from "@nomicfoundation/ethereumjs-util"; +import { Address, toBytes } from "@ethereumjs/util"; import path from "path"; function toBuffer(x: Parameters[0]) { diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/leftPad32.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/leftPad32.ts index 591098b8b22..696d5e42272 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/leftPad32.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/leftPad32.ts @@ -1,4 +1,4 @@ -import { setLengthLeft, toBytes } from "@nomicfoundation/ethereumjs-util"; +import { setLengthLeft, toBytes } from "@ethereumjs/util"; import { assert } from "chai"; function toBuffer(x: Parameters[0]) { diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/providers.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/providers.ts index ffda52c93f7..5e48460278c 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/providers.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/providers.ts @@ -2,7 +2,7 @@ import { bytesToHex as bufferToHex, privateToAddress, toBytes, -} from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/util"; import { HardhatNetworkMempoolConfig, diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/retrieveCommon.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/retrieveCommon.ts index f2c1c52cda8..f2922999930 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/retrieveCommon.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/retrieveCommon.ts @@ -1,5 +1,5 @@ /* eslint-disable dot-notation,@typescript-eslint/dot-notation */ -import { Common } from "@nomicfoundation/ethereumjs-common"; +import { Common } from "@ethereumjs/common"; export async function retrieveCommon(provider: any): Promise { return provider["_common"]; diff --git a/packages/hardhat-core/test/internal/hardhat-network/helpers/transactions.ts b/packages/hardhat-core/test/internal/hardhat-network/helpers/transactions.ts index ace06af9a9c..c81f4ed3a6f 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/helpers/transactions.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/helpers/transactions.ts @@ -1,9 +1,9 @@ -import { LegacyTransaction } from "@nomicfoundation/ethereumjs-tx"; +import { LegacyTransaction } from "@ethereumjs/tx"; import { bytesToHex as bufferToHex, toBytes, zeroAddress, -} from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/util"; import { numberToRpcQuantity } from "../../../../src/internal/core/jsonrpc/types/base-types"; import { RpcTransactionRequestInput } from "../../../../src/internal/core/jsonrpc/types/input/transactionRequest"; diff --git a/packages/hardhat-core/test/internal/hardhat-network/jsonrpc/client.ts b/packages/hardhat-core/test/internal/hardhat-network/jsonrpc/client.ts index b6da59df999..26e69d0a6a9 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/jsonrpc/client.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/jsonrpc/client.ts @@ -1,7 +1,4 @@ -import { - bytesToBigInt as bufferToBigInt, - toBytes, -} from "@nomicfoundation/ethereumjs-util"; +import { bytesToBigInt as bufferToBigInt, toBytes } from "@ethereumjs/util"; import { assert } from "chai"; import fsExtra from "fs-extra"; import sinon from "sinon"; diff --git a/packages/hardhat-core/test/internal/util/hardforks.ts b/packages/hardhat-core/test/internal/util/hardforks.ts index 0d33b8bc560..679fbc0bfa4 100644 --- a/packages/hardhat-core/test/internal/util/hardforks.ts +++ b/packages/hardhat-core/test/internal/util/hardforks.ts @@ -1,4 +1,4 @@ -import { Common } from "@nomicfoundation/ethereumjs-common"; +import { Common } from "@ethereumjs/common"; import { assert } from "chai"; import { getHardforkName, diff --git a/packages/hardhat-core/test/internal/util/keys-derivation.ts b/packages/hardhat-core/test/internal/util/keys-derivation.ts index e91301301af..28eb41299f7 100644 --- a/packages/hardhat-core/test/internal/util/keys-derivation.ts +++ b/packages/hardhat-core/test/internal/util/keys-derivation.ts @@ -2,7 +2,7 @@ import { bytesToHex as bufferToHex, privateToAddress, toChecksumAddress, -} from "@nomicfoundation/ethereumjs-util"; +} from "@ethereumjs/util"; import { assert } from "chai"; import { deriveKeyFromMnemonicAndPath } from "../../../src/internal/util/keys-derivation"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 03218c1790d..627ebcfbb06 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,6 +194,15 @@ importers: packages/hardhat-core: dependencies: + '@ethereumjs/common': + specifier: ^4.4.0 + version: 4.4.0 + '@ethereumjs/tx': + specifier: ^5.4.0 + version: 5.4.0 + '@ethereumjs/util': + specifier: ^9.1.0 + version: 9.1.0 '@ethersproject/abi': specifier: ^5.1.2 version: 5.7.0 @@ -203,15 +212,6 @@ importers: '@nomicfoundation/edr': specifier: ^0.8.0 version: 0.8.0 - '@nomicfoundation/ethereumjs-common': - specifier: 4.0.4 - version: 4.0.4 - '@nomicfoundation/ethereumjs-tx': - specifier: 5.0.4 - version: 5.0.4 - '@nomicfoundation/ethereumjs-util': - specifier: 9.0.4 - version: 9.0.4 '@nomicfoundation/solidity-analyzer': specifier: ^0.1.0 version: 0.1.2 @@ -254,9 +254,6 @@ importers: ethereum-cryptography: specifier: ^1.0.3 version: 1.2.0 - ethereumjs-abi: - specifier: ^0.6.8 - version: 0.6.8 find-up: specifier: ^5.0.0 version: 5.0.0 @@ -333,9 +330,6 @@ importers: '@nomicfoundation/eslint-plugin-slow-imports': specifier: workspace:^ version: link:../eslint-plugin-slow-imports - '@nomicfoundation/ethereumjs-block': - specifier: 5.0.4 - version: 5.0.4 '@types/async-eventemitter': specifier: ^0.2.1 version: 0.2.4 @@ -2777,6 +2771,9 @@ packages: '@ethereumjs/common@2.6.5': resolution: {integrity: sha512-lRyVQOeCDaIVtgfbowla32pzeDv2Obr8oR8Put5RdUBNRGr1VGPGQNGP6elWIpgK3YdpzqTOh4GyUGOureVeeA==} + '@ethereumjs/common@4.4.0': + resolution: {integrity: sha512-Fy5hMqF6GsE6DpYTyqdDIJPJgUtDn4dL120zKw+Pswuo+iLyBsEYuSyzMw6NVzD2vDzcBG9fE4+qX4X2bPc97w==} + '@ethereumjs/rlp@4.0.1': resolution: {integrity: sha512-tqsQiBQDQdmPWE1xkkBq4rlSW5QZpLOUJ5RJh2/9fug+q9tnUhuZoVLk7s0scUIKTOzEtR72DFBXI4WiZcMpvw==} engines: {node: '>=14'} @@ -2793,10 +2790,18 @@ packages: '@ethereumjs/tx@3.5.2': resolution: {integrity: sha512-gQDNJWKrSDGu2w7w0PzVXVBNMzb7wwdDOmOqczmhNjqFxFuIbhVJDwiGEnxFNC2/b8ifcZzY7MLcluizohRzNw==} + '@ethereumjs/tx@5.4.0': + resolution: {integrity: sha512-SCHnK7m/AouZ7nyoR0MEXw1OO/tQojSbp88t8oxhwes5iZkZCtfFdUrJaiIb72qIpH2FVw6s1k1uP7LXuH7PsA==} + engines: {node: '>=18'} + '@ethereumjs/util@8.1.0': resolution: {integrity: sha512-zQ0IqbdX8FZ9aw11vP+dZkKDkS+kgIvQPHnSAXzP9pLu+Rfu3D3XEeLbicvoXJTYnhZiPmsZUxgdzXwNKxRPbA==} engines: {node: '>=14'} + '@ethereumjs/util@9.1.0': + resolution: {integrity: sha512-XBEKsYqLGXLah9PNJbgdkigthkG7TAGvlD/sH12beMXEyHDyigfcbdvHhmLyDWgDyOJn4QwiQUaF7yeuhnjdog==} + engines: {node: '>=18'} + '@ethersproject/abi@5.7.0': resolution: {integrity: sha512-351ktp42TiRcYB3H1OP8yajPeAQstMW/yCFokj/AthP9bLHzQFPlOrxOcwYEDkUAICmOHljvN4K39OMTMUa9RA==} @@ -3118,31 +3123,11 @@ packages: resolution: {integrity: sha512-dwWRrghSVBQDpt0wP+6RXD8BMz2i/9TI34TcmZqeEAZuCLei3U9KZRgGTKVAM1rMRvrpf5ROfPqrWNetKVUTag==} engines: {node: '>= 18'} - '@nomicfoundation/ethereumjs-block@5.0.4': - resolution: {integrity: sha512-AcyacJ9eX/uPEvqsPiB+WO1ymE+kyH48qGGiGV+YTojdtas8itUTW5dehDSOXEEItWGbbzEJ4PRqnQZlWaPvDw==} - engines: {node: '>=18'} - - '@nomicfoundation/ethereumjs-common@4.0.4': - resolution: {integrity: sha512-9Rgb658lcWsjiicr5GzNCjI1llow/7r0k50dLL95OJ+6iZJcVbi15r3Y0xh2cIO+zgX0WIHcbzIu6FeQf9KPrg==} - '@nomicfoundation/ethereumjs-rlp@5.0.4': resolution: {integrity: sha512-8H1S3s8F6QueOc/X92SdrA4RDenpiAEqMg5vJH99kcQaCy/a3Q6fgseo75mgWlbanGJXSlAPtnCeG9jvfTYXlw==} engines: {node: '>=18'} hasBin: true - '@nomicfoundation/ethereumjs-trie@6.0.4': - resolution: {integrity: sha512-3nSwQiFMvr2VFe/aZUyinuohYvtytUqZCUCvIWcPJ/BwJH6oQdZRB42aNFBJ/8nAh2s3OcroWpBLskzW01mFKA==} - engines: {node: '>=18'} - - '@nomicfoundation/ethereumjs-tx@5.0.4': - resolution: {integrity: sha512-Xjv8wAKJGMrP1f0n2PeyfFCCojHd7iS3s/Ab7qzF1S64kxZ8Z22LCMynArYsVqiFx6rzYy548HNVEyI+AYN/kw==} - engines: {node: '>=18'} - peerDependencies: - c-kzg: ^2.1.2 - peerDependenciesMeta: - c-kzg: - optional: true - '@nomicfoundation/ethereumjs-util@9.0.4': resolution: {integrity: sha512-sLOzjnSrlx9Bb9EFNtHzK/FJFsfg2re6bsGqinFinH1gCqVfz9YYlXiMWwDM4C/L4ywuHFCYwfKTVr/QHQcU0Q==} engines: {node: '>=18'} @@ -3661,9 +3646,6 @@ packages: '@types/react@18.3.18': resolution: {integrity: sha512-t4yC+vtgnkYjNSKlFx1jkAhH8LgTo2N/7Qvi83kdEaUtMDiwpbLAktKDaAMlRcJ5eSxZkH74eEGt1ky31d7kfQ==} - '@types/readable-stream@2.3.15': - resolution: {integrity: sha512-oM5JSKQCcICF1wvGgmecmHldZ48OZamtMxcGGVICOJA8o8cahXC1zEVAif8iwoc5j8etxFaRFnf095+CDsuoFQ==} - '@types/resolve@1.20.6': resolution: {integrity: sha512-A4STmOXPhMUtHH+S6ymgE2GiBSMqf4oTvcQZMcHzokuTLVYzXTB8ttjcgxOVaAp2lGwEdzZ0J+cRbbeevQj1UQ==} @@ -6368,6 +6350,7 @@ packages: lodash.get@4.4.2: resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==} + deprecated: This package is deprecated. Use the optional chaining (?.) operator instead. lodash.isequal@4.5.0: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} @@ -6421,9 +6404,6 @@ packages: resolution: {integrity: sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - lru-cache@10.4.3: - resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} - lru-cache@4.1.5: resolution: {integrity: sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==} @@ -9268,13 +9248,17 @@ snapshots: crc-32: 1.2.2 ethereumjs-util: 7.1.5 + '@ethereumjs/common@4.4.0': + dependencies: + '@ethereumjs/util': 9.1.0 + '@ethereumjs/rlp@4.0.1': {} '@ethereumjs/rlp@5.0.2': {} '@ethereumjs/tx@3.3.2': dependencies: - '@ethereumjs/common': 2.5.0 + '@ethereumjs/common': 2.6.5 ethereumjs-util: 7.1.5 '@ethereumjs/tx@3.5.2': @@ -9282,12 +9266,24 @@ snapshots: '@ethereumjs/common': 2.6.5 ethereumjs-util: 7.1.5 + '@ethereumjs/tx@5.4.0': + dependencies: + '@ethereumjs/common': 4.4.0 + '@ethereumjs/rlp': 5.0.2 + '@ethereumjs/util': 9.1.0 + ethereum-cryptography: 2.2.1 + '@ethereumjs/util@8.1.0': dependencies: '@ethereumjs/rlp': 4.0.1 ethereum-cryptography: 2.2.1 micro-ftch: 0.3.1 + '@ethereumjs/util@9.1.0': + dependencies: + '@ethereumjs/rlp': 5.0.2 + ethereum-cryptography: 2.2.1 + '@ethersproject/abi@5.7.0': dependencies: '@ethersproject/address': 5.7.0 @@ -9866,43 +9862,8 @@ snapshots: '@nomicfoundation/edr-linux-x64-musl': 0.8.0 '@nomicfoundation/edr-win32-x64-msvc': 0.8.0 - '@nomicfoundation/ethereumjs-block@5.0.4': - dependencies: - '@nomicfoundation/ethereumjs-common': 4.0.4 - '@nomicfoundation/ethereumjs-rlp': 5.0.4 - '@nomicfoundation/ethereumjs-trie': 6.0.4 - '@nomicfoundation/ethereumjs-tx': 5.0.4 - '@nomicfoundation/ethereumjs-util': 9.0.4 - ethereum-cryptography: 0.1.3 - transitivePeerDependencies: - - c-kzg - - '@nomicfoundation/ethereumjs-common@4.0.4': - dependencies: - '@nomicfoundation/ethereumjs-util': 9.0.4 - transitivePeerDependencies: - - c-kzg - '@nomicfoundation/ethereumjs-rlp@5.0.4': {} - '@nomicfoundation/ethereumjs-trie@6.0.4': - dependencies: - '@nomicfoundation/ethereumjs-rlp': 5.0.4 - '@nomicfoundation/ethereumjs-util': 9.0.4 - '@types/readable-stream': 2.3.15 - ethereum-cryptography: 0.1.3 - lru-cache: 10.4.3 - readable-stream: 3.6.2 - transitivePeerDependencies: - - c-kzg - - '@nomicfoundation/ethereumjs-tx@5.0.4': - dependencies: - '@nomicfoundation/ethereumjs-common': 4.0.4 - '@nomicfoundation/ethereumjs-rlp': 5.0.4 - '@nomicfoundation/ethereumjs-util': 9.0.4 - ethereum-cryptography: 0.1.3 - '@nomicfoundation/ethereumjs-util@9.0.4': dependencies: '@nomicfoundation/ethereumjs-rlp': 5.0.4 @@ -10499,11 +10460,6 @@ snapshots: '@types/prop-types': 15.7.14 csstype: 3.1.3 - '@types/readable-stream@2.3.15': - dependencies: - '@types/node': 18.19.59 - safe-buffer: 5.1.2 - '@types/resolve@1.20.6': {} '@types/responselike@1.0.3': @@ -13762,8 +13718,6 @@ snapshots: lowercase-keys@3.0.0: {} - lru-cache@10.4.3: {} - lru-cache@4.1.5: dependencies: pseudomap: 1.0.2 From 7bdff8ff5169b639f7c10a25939c97a8716f0fc5 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Tue, 4 Feb 2025 16:42:04 +0000 Subject: [PATCH 2/9] feat: replace forked ethereumjs packages with originals in hardhat-ledger --- packages/hardhat-ledger/package.json | 2 +- packages/hardhat-ledger/src/provider.ts | 8 +++----- pnpm-lock.yaml | 27 +++---------------------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/packages/hardhat-ledger/package.json b/packages/hardhat-ledger/package.json index 8ecd840d223..e5a3349e3e6 100644 --- a/packages/hardhat-ledger/package.json +++ b/packages/hardhat-ledger/package.json @@ -35,11 +35,11 @@ "README.md" ], "dependencies": { + "@ethereumjs/util": "^9.1.0", "@ledgerhq/errors": "^6.12.6", "@ledgerhq/hw-app-eth": "6.33.6", "@ledgerhq/hw-transport": "^6.28.4", "@ledgerhq/hw-transport-node-hid": "^6.27.13", - "@nomicfoundation/ethereumjs-util": "9.0.4", "chalk": "^2.4.2", "debug": "^4.1.1", "env-paths": "^2.2.0", diff --git a/packages/hardhat-ledger/src/provider.ts b/packages/hardhat-ledger/src/provider.ts index 3313cdc5e17..a315612910d 100644 --- a/packages/hardhat-ledger/src/provider.ts +++ b/packages/hardhat-ledger/src/provider.ts @@ -1,7 +1,7 @@ import { ethers } from "ethers"; import * as t from "io-ts"; -import { isValidAddress } from "@nomicfoundation/ethereumjs-util"; +import { isValidAddress } from "@ethereumjs/util"; import { isEIP712Message, ledgerService } from "@ledgerhq/hw-app-eth"; import TransportNodeHid from "@ledgerhq/hw-transport-node-hid"; @@ -407,9 +407,7 @@ export class LedgerProvider extends ProviderWrapperWithChainId { } private async _toRpcSig(signature: Signature): Promise { - const { toRpcSig, toBytes } = await import( - "@nomicfoundation/ethereumjs-util" - ); + const { toRpcSig, toBytes } = await import("@ethereumjs/util"); return toRpcSig( BigInt(signature.v - 27), @@ -419,7 +417,7 @@ export class LedgerProvider extends ProviderWrapperWithChainId { } private async _getNonce(address: Buffer): Promise { - const { bytesToHex } = await import("@nomicfoundation/ethereumjs-util"); + const { bytesToHex } = await import("@ethereumjs/util"); const response = (await this._wrappedProvider.request({ method: "eth_getTransactionCount", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 627ebcfbb06..097faee45d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1111,6 +1111,9 @@ importers: packages/hardhat-ledger: dependencies: + '@ethereumjs/util': + specifier: ^9.1.0 + version: 9.1.0 '@ledgerhq/errors': specifier: ^6.12.6 version: 6.19.1 @@ -1123,9 +1126,6 @@ importers: '@ledgerhq/hw-transport-node-hid': specifier: ^6.27.13 version: 6.29.5 - '@nomicfoundation/ethereumjs-util': - specifier: 9.0.4 - version: 9.0.4 chalk: specifier: ^2.4.2 version: 2.4.2 @@ -3123,20 +3123,6 @@ packages: resolution: {integrity: sha512-dwWRrghSVBQDpt0wP+6RXD8BMz2i/9TI34TcmZqeEAZuCLei3U9KZRgGTKVAM1rMRvrpf5ROfPqrWNetKVUTag==} engines: {node: '>= 18'} - '@nomicfoundation/ethereumjs-rlp@5.0.4': - resolution: {integrity: sha512-8H1S3s8F6QueOc/X92SdrA4RDenpiAEqMg5vJH99kcQaCy/a3Q6fgseo75mgWlbanGJXSlAPtnCeG9jvfTYXlw==} - engines: {node: '>=18'} - hasBin: true - - '@nomicfoundation/ethereumjs-util@9.0.4': - resolution: {integrity: sha512-sLOzjnSrlx9Bb9EFNtHzK/FJFsfg2re6bsGqinFinH1gCqVfz9YYlXiMWwDM4C/L4ywuHFCYwfKTVr/QHQcU0Q==} - engines: {node: '>=18'} - peerDependencies: - c-kzg: ^2.1.2 - peerDependenciesMeta: - c-kzg: - optional: true - '@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.2': resolution: {integrity: sha512-JaqcWPDZENCvm++lFFGjrDd8mxtf+CtLd2MiXvMNTBD33dContTZ9TWETwNFwg7JTJT5Q9HEecH7FA+HTSsIUw==} engines: {node: '>= 12'} @@ -9862,13 +9848,6 @@ snapshots: '@nomicfoundation/edr-linux-x64-musl': 0.8.0 '@nomicfoundation/edr-win32-x64-msvc': 0.8.0 - '@nomicfoundation/ethereumjs-rlp@5.0.4': {} - - '@nomicfoundation/ethereumjs-util@9.0.4': - dependencies: - '@nomicfoundation/ethereumjs-rlp': 5.0.4 - ethereum-cryptography: 0.1.3 - '@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.2': optional: true From f84ee43c289914576bb046c3cac57eea3bb88dbe Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 6 Feb 2025 16:53:14 +0000 Subject: [PATCH 3/9] feat: add prague to supported hardforks --- docs/src/content/hardhat-network/docs/reference/index.md | 3 ++- packages/hardhat-core/src/internal/constants.ts | 1 + packages/hardhat-core/src/internal/util/hardforks.ts | 2 ++ packages/hardhat-core/test/internal/util/hardforks.ts | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/src/content/hardhat-network/docs/reference/index.md b/docs/src/content/hardhat-network/docs/reference/index.md index 2078eef9c21..af3aefa8a7f 100644 --- a/docs/src/content/hardhat-network/docs/reference/index.md +++ b/docs/src/content/hardhat-network/docs/reference/index.md @@ -14,6 +14,7 @@ - merge - shanghai - cancun +- prague ## Config @@ -66,7 +67,7 @@ The block gas limit to use in Hardhat Network's blockchain. Default value: `30_0 #### `hardfork` -This setting changes how Hardhat Network works, to mimic Ethereum's mainnet at a given hardfork. It must be one of `"byzantium"`, `"constantinople"`, `"petersburg"`, `"istanbul"`, `"muirGlacier"`, `"berlin"`, `"london"`, `"arrowGlacier"`, `"grayGlacier"`, `"merge"`, `"shanghai"` and `"cancun"`. Default value: `"cancun"` +This setting changes how Hardhat Network works, to mimic Ethereum's mainnet at a given hardfork. It must be one of `"byzantium"`, `"constantinople"`, `"petersburg"`, `"istanbul"`, `"muirGlacier"`, `"berlin"`, `"london"`, `"arrowGlacier"`, `"grayGlacier"`, `"merge"`, `"shanghai"`, `"cancun"` and `"prague"`. Default value: `"cancun"` #### `throwOnTransactionFailures` diff --git a/packages/hardhat-core/src/internal/constants.ts b/packages/hardhat-core/src/internal/constants.ts index f6c39bd9971..47b0f1dd812 100644 --- a/packages/hardhat-core/src/internal/constants.ts +++ b/packages/hardhat-core/src/internal/constants.ts @@ -23,6 +23,7 @@ export const HARDHAT_NETWORK_SUPPORTED_HARDFORKS = [ "merge", "shanghai", "cancun", + "prague", ]; export const HARDHAT_MEMPOOL_SUPPORTED_ORDERS = ["fifo", "priority"] as const; diff --git a/packages/hardhat-core/src/internal/util/hardforks.ts b/packages/hardhat-core/src/internal/util/hardforks.ts index a5fb8c932f8..14ff4128d39 100644 --- a/packages/hardhat-core/src/internal/util/hardforks.ts +++ b/packages/hardhat-core/src/internal/util/hardforks.ts @@ -23,6 +23,7 @@ export enum HardforkName { MERGE = "merge", SHANGHAI = "shanghai", CANCUN = "cancun", + PRAGUE = "prague", } const HARDFORKS_ORDER: HardforkName[] = [ @@ -43,6 +44,7 @@ const HARDFORKS_ORDER: HardforkName[] = [ HardforkName.MERGE, HardforkName.SHANGHAI, HardforkName.CANCUN, + HardforkName.PRAGUE, ]; export function getHardforkName(name: string): HardforkName { diff --git a/packages/hardhat-core/test/internal/util/hardforks.ts b/packages/hardhat-core/test/internal/util/hardforks.ts index 679fbc0bfa4..bf30f7b7c1c 100644 --- a/packages/hardhat-core/test/internal/util/hardforks.ts +++ b/packages/hardhat-core/test/internal/util/hardforks.ts @@ -45,6 +45,7 @@ describe("Hardfork utils", function () { assert.equal("merge", HardforkName.MERGE); assert.equal("shanghai", HardforkName.SHANGHAI); assert.equal("cancun", HardforkName.CANCUN); + assert.equal("prague", HardforkName.PRAGUE); }); }); From 0f28475f64f8ddf72da7c0de2dfbc75b2b5cd955 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 6 Feb 2025 17:31:16 +0000 Subject: [PATCH 4/9] feat: add prague to chains map --- .../hardhat-core/src/internal/core/config/default-config.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/hardhat-core/src/internal/core/config/default-config.ts b/packages/hardhat-core/src/internal/core/config/default-config.ts index 986b360821a..bed6cd2dd80 100644 --- a/packages/hardhat-core/src/internal/core/config/default-config.ts +++ b/packages/hardhat-core/src/internal/core/config/default-config.ts @@ -56,7 +56,7 @@ export const defaultHardhatNetworkParams: Omit< minGasPrice: 0n, chains: new Map([ [ - // block numbers below were taken from https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/common/src/chains + // block numbers below were taken from https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/common/src/chains.ts 1, // mainnet { hardforkHistory: new Map([ @@ -77,6 +77,7 @@ export const defaultHardhatNetworkParams: Omit< [HardforkName.MERGE, 15_537_394], [HardforkName.SHANGHAI, 17_034_870], [HardforkName.CANCUN, 19_426_589], + [HardforkName.PRAGUE, 30_000_000], // TODO: replace with actual block number ]), }, ], @@ -138,6 +139,7 @@ export const defaultHardhatNetworkParams: Omit< [HardforkName.MERGE, 1_450_409], [HardforkName.SHANGHAI, 2_990_908], [HardforkName.CANCUN, 5_187_023], + [HardforkName.PRAGUE, 30_000_000], // TODO: replace with actual block number ]), }, ], From 3e40b71935ac7ae48ed70cfbdcf0bdf0a757fcff Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 6 Feb 2025 17:32:06 +0000 Subject: [PATCH 5/9] feat: add prague to edr mappings --- .../hardhat-network/provider/utils/convertToEdr.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts index 848357f5d4b..586c8669681 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts @@ -61,6 +61,9 @@ export function ethereumsjsHardforkToEdrSpecId(hardfork: HardforkName): SpecId { return SpecId.Shanghai; case HardforkName.CANCUN: return SpecId.Cancun; + case HardforkName.PRAGUE: + // TODO: update the value when Prague is added to EDR + return SpecId.Cancun; default: const _exhaustiveCheck: never = hardfork; throw new Error( @@ -107,9 +110,11 @@ export function edrSpecIdToEthereumHardfork(specId: SpecId): HardforkName { return HardforkName.MERGE; case SpecId.Shanghai: return HardforkName.SHANGHAI; - // HACK: EthereumJS doesn't support Cancun, so report Shanghai case SpecId.Cancun: - return HardforkName.SHANGHAI; + return HardforkName.CANCUN; + // TODO: uncomment when Prague is added to EDR + /* case SpecId.Prague: + return HardforkName.PRAGUE; */ default: throw new Error(`Unknown spec id '${specId}', this shouldn't happen`); From 32c54e4e44dd2524474d8f6458d3cb66056f8cef Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Mon, 10 Feb 2025 17:05:20 +0000 Subject: [PATCH 6/9] feat: add authorization list and sign type 4 tx --- .../core/jsonrpc/types/authorization-list.ts | 20 +++++++++ .../internal/core/jsonrpc/types/base-types.ts | 12 ++++++ .../jsonrpc/types/input/transactionRequest.ts | 10 +++++ .../src/internal/core/providers/accounts.ts | 42 +++++++++++++++++-- .../hardhat-network/provider/output.ts | 17 +++++++- .../test/internal/core/providers/accounts.ts | 35 ++++++++++++++++ 6 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 packages/hardhat-core/src/internal/core/jsonrpc/types/authorization-list.ts diff --git a/packages/hardhat-core/src/internal/core/jsonrpc/types/authorization-list.ts b/packages/hardhat-core/src/internal/core/jsonrpc/types/authorization-list.ts new file mode 100644 index 00000000000..194a6e5b80d --- /dev/null +++ b/packages/hardhat-core/src/internal/core/jsonrpc/types/authorization-list.ts @@ -0,0 +1,20 @@ +import * as t from "io-ts"; + +import { rpcAddress, rpcQuantity, rpcHash, rpcParity } from "./base-types"; + +const rpcAuthorizationListTuple = t.type({ + chainId: rpcQuantity, + address: rpcAddress, + nonce: rpcQuantity, + yParity: rpcParity, + r: rpcHash, + s: rpcHash, +}); + +export const rpcAuthorizationList = t.array(rpcAuthorizationListTuple); + +export type RpcAuthorizationListTuple = t.TypeOf< + typeof rpcAuthorizationListTuple +>; + +export type RpcAuthorizationList = t.TypeOf; diff --git a/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts b/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts index 510ff4b8d66..2baaf55c4c7 100644 --- a/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts +++ b/packages/hardhat-core/src/internal/core/jsonrpc/types/base-types.ts @@ -27,6 +27,14 @@ export const rpcData = new t.Type( t.identity ); +export const rpcParity = new t.Type( + "PARITY", + Buffer.isBuffer, + (u, c) => + isRpcParityString(u) ? t.success(Buffer.from(toBytes(u))) : t.failure(u, c), + t.identity +); + export const rpcHash = new t.Type( "HASH", (v): v is Buffer => Buffer.isBuffer(v) && v.length === HASH_LENGTH_BYTES, @@ -216,6 +224,10 @@ function isRpcDataString(u: unknown): u is string { return typeof u === "string" && u.match(/^0x(?:[0-9a-fA-F]{2})*$/) !== null; } +function isRpcParityString(u: unknown): u is string { + return typeof u === "string" && u.match(/^0x[0-9a-fA-F]{1,2}$/) !== null; +} + function isRpcHashString(u: unknown): u is string { return typeof u === "string" && u.length === 66 && isRpcDataString(u); } diff --git a/packages/hardhat-core/src/internal/core/jsonrpc/types/input/transactionRequest.ts b/packages/hardhat-core/src/internal/core/jsonrpc/types/input/transactionRequest.ts index 1f13b8a8b12..ebca6600599 100644 --- a/packages/hardhat-core/src/internal/core/jsonrpc/types/input/transactionRequest.ts +++ b/packages/hardhat-core/src/internal/core/jsonrpc/types/input/transactionRequest.ts @@ -3,6 +3,7 @@ import * as t from "io-ts"; import { optionalOrNullable } from "../../../../util/io-ts"; import { rpcAccessList } from "../access-list"; import { rpcAddress, rpcData, rpcHash, rpcQuantity } from "../base-types"; +import { rpcAuthorizationList } from "../authorization-list"; // Type used by eth_sendTransaction export const rpcTransactionRequest = t.type( @@ -20,6 +21,7 @@ export const rpcTransactionRequest = t.type( maxPriorityFeePerGas: optionalOrNullable(rpcQuantity), blobs: optionalOrNullable(t.array(rpcData)), blobVersionedHashes: optionalOrNullable(t.array(rpcHash)), + authorizationList: optionalOrNullable(rpcAuthorizationList), }, "RpcTransactionRequest" ); @@ -42,6 +44,14 @@ export interface RpcTransactionRequestInput { maxPriorityFeePerGas?: string; blobs?: string[]; blobVersionedHashes?: string[]; + authorizationList?: Array<{ + chainId: string; + address: string; + nonce: string; + yParity: string; + r: string; + s: string; + }>; } export type RpcTransactionRequest = t.TypeOf; diff --git a/packages/hardhat-core/src/internal/core/providers/accounts.ts b/packages/hardhat-core/src/internal/core/providers/accounts.ts index bdf8075c9be..cd58d69bbfe 100644 --- a/packages/hardhat-core/src/internal/core/providers/accounts.ts +++ b/packages/hardhat-core/src/internal/core/providers/accounts.ts @@ -245,12 +245,16 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { chainId: number, privateKey: Buffer ): Promise { - const { AccessListEIP2930Transaction, LegacyTransaction } = await import( - "@ethereumjs/tx" - ); + const { + AccessListEIP2930Transaction, + LegacyTransaction, + EOACodeEIP7702Transaction, + } = await import("@ethereumjs/tx"); const { Common } = await import("@ethereumjs/common"); + const { toBytes } = await import("@ethereumjs/util"); + const txData = { ...transactionRequest, gasLimit: transactionRequest.gas, @@ -268,8 +272,38 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId { ({ address, storageKeys }) => [address, storageKeys] as [Buffer, Buffer[]] ); + // we convert the authorization list to the type + // that EOACodeEIP7702Transaction expects + const authorizationList = txData.authorizationList?.map( + ({ chainId: authChainId, address, nonce, yParity, r, s }) => + // TODO: There is an error in the type definition of rpcAuthorizationList + // in the @ethereumjs/common@4.4.0 package where nonce is defined as an + // array but it should be a string. This is fixed in the alpha version + // of the package but is not yet released. To work around this, we wrap + // nonce in an array here. However, this will not be accepted by the + // node and will throw an error. + [ + Buffer.from(toBytes(authChainId)), + address, + [Buffer.from(toBytes(nonce))], + yParity, + r, + s, + ] as [Buffer, Buffer, Buffer[], Buffer, Buffer, Buffer] + ); + let transaction; - if (txData.maxFeePerGas !== undefined) { + if (authorizationList !== undefined) { + transaction = EOACodeEIP7702Transaction.fromTxData( + { + ...txData, + accessList, + authorizationList, + gasPrice: undefined, + }, + { common } + ); + } else if (txData.maxFeePerGas !== undefined) { transaction = FeeMarketEIP1559Transaction.fromTxData( { ...txData, diff --git a/packages/hardhat-core/src/internal/hardhat-network/provider/output.ts b/packages/hardhat-core/src/internal/hardhat-network/provider/output.ts index 66e35744f4e..3680d436d47 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/provider/output.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/provider/output.ts @@ -31,7 +31,8 @@ export interface RpcBlockOutput { export type RpcTransactionOutput = | LegacyRpcTransactionOutput | AccessListEIP2930RpcTransactionOutput - | EIP1559RpcTransactionOutput; + | EIP1559RpcTransactionOutput + | EOACodeEIP7702TransactionOutput; interface BaseRpcTransactionOutput { blockHash: string | null; @@ -60,6 +61,15 @@ export type RpcAccessListOutput = Array<{ storageKeys: string[]; }>; +export type RpcAuthorizationListOutput = Array<{ + chainId: string; + address: string; + nonce: string; + yParity: string; + r: string; + s: string; +}>; + export interface AccessListEIP2930RpcTransactionOutput extends BaseRpcTransactionOutput { gasPrice: string; @@ -75,6 +85,11 @@ export interface EIP1559RpcTransactionOutput extends BaseRpcTransactionOutput { chainId: string; } +export interface EOACodeEIP7702TransactionOutput + extends EIP1559RpcTransactionOutput { + authorizationList?: RpcAuthorizationListOutput; +} + export interface RpcReceiptOutput { blockHash: string; blockNumber: string; diff --git a/packages/hardhat-core/test/internal/core/providers/accounts.ts b/packages/hardhat-core/test/internal/core/providers/accounts.ts index aceb5973810..89a8880ecb5 100644 --- a/packages/hardhat-core/test/internal/core/providers/accounts.ts +++ b/packages/hardhat-core/test/internal/core/providers/accounts.ts @@ -42,6 +42,7 @@ describe("Local accounts provider", () => { "0x6d7229c1db5892730b84b4bc10543733b72cabf4cd3130d910faa8e459bb8eca", "0x6d4ec871d9b5469119bbfc891e958b6220d076a6849006098c370c8af5fc7776", "0xec02c2b7019e75378a05018adc30a0252ba705670acb383a1d332e57b0b792d2", + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", ]; beforeEach(() => { @@ -307,6 +308,40 @@ describe("Local accounts provider", () => { validateRawEIP2930Transaction(expectedRaw, tx); }); + // TODO: enable this test once prague is supported + it.skip("should send EIP-7702 transactions", async () => { + const tx = { + from: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + to: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + gas: numberToRpcQuantity(100000), + maxFeePerGas: numberToRpcQuantity(10n * 10n ** 9n), + maxPriorityFeePerGas: numberToRpcQuantity(10n ** 9n), + chainId: numberToRpcQuantity(MOCK_PROVIDER_CHAIN_ID), + nonce: numberToRpcQuantity(0), + authorizationList: [ + { + chainId: numberToRpcQuantity(MOCK_PROVIDER_CHAIN_ID), + nonce: numberToRpcQuantity(1), + address: "0x1234567890123456789012345678901234567890", + yParity: "0x1", + r: "0xd4c36a32c935f7abf3950062024b08ee85a707cd725274a5b017865ea6e989ad", + s: "0x6218f33b32f2f26783db21cde75e6b72bcacfedbac4c1a1af438e3e5c755918a", + }, + ], + }; + await wrapper.request({ + method: "eth_sendTransaction", + params: [tx], + }); + + const rawTransaction = mock.getLatestParams("eth_sendRawTransaction")[0]; + + const expectedRaw = + "0x04f8ca7b80843b9aca008502540be400830186a094f39fd6e51aad88f6f4ce6ab8827279cfffb922668080c0f85cf85a7b9412345678901234567890123456789012345678900101a0d4c36a32c935f7abf3950062024b08ee85a707cd725274a5b017865ea6e989ada06218f33b32f2f26783db21cde75e6b72bcacfedbac4c1a1af438e3e5c755918a80a09ae0f9ac575ff45f38805f7101455b397d248166a2a5771122a66e6c279c279ba0234d80d08a6f369a134b0058b74076e608db10da97ec3660ad829c8d4246098f"; + + assert.equal(rawTransaction, expectedRaw); + }); + it("should add the chainId value if it's missing", async () => { const tx = { from: "0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead", From 99dd06e156da440b307f0aa1e0b004b3ef0d3493 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 6 Feb 2025 19:42:17 +0000 Subject: [PATCH 7/9] feat: remove hardfork default based on enableTransientStorage --- .../internal/core/config/config-resolution.ts | 13 ---------- .../internal/core/config/config-resolution.ts | 24 ------------------- 2 files changed, 37 deletions(-) diff --git a/packages/hardhat-core/src/internal/core/config/config-resolution.ts b/packages/hardhat-core/src/internal/core/config/config-resolution.ts index 1c8ce6c085c..ee8f589eacb 100644 --- a/packages/hardhat-core/src/internal/core/config/config-resolution.ts +++ b/packages/hardhat-core/src/internal/core/config/config-resolution.ts @@ -238,19 +238,6 @@ function resolveHardhatNetworkConfig( delete config.initialBaseFeePerGas; } - if ( - hardhatNetworkConfig.enableTransientStorage === true && - hardhatNetworkConfig.hardfork === undefined - ) { - config.hardfork = "cancun"; - } - if ( - hardhatNetworkConfig.enableTransientStorage === false && - hardhatNetworkConfig.hardfork === undefined - ) { - config.hardfork = "shanghai"; - } - return config; } diff --git a/packages/hardhat-core/test/internal/core/config/config-resolution.ts b/packages/hardhat-core/test/internal/core/config/config-resolution.ts index 3476cd408c5..49e6192ebdc 100644 --- a/packages/hardhat-core/test/internal/core/config/config-resolution.ts +++ b/packages/hardhat-core/test/internal/core/config/config-resolution.ts @@ -761,30 +761,6 @@ describe("Config resolution", () => { }); }); }); - - it("should use cancun as the hardfork when enableTransientStorage is set", async function () { - const config = resolveConfig(__filename, { - networks: { - hardhat: { - enableTransientStorage: true, - }, - }, - }); - - assert.equal(config.networks.hardhat.hardfork, "cancun"); - }); - - it("should use shanghai as the hardfork when enableTransientStorage is disabled", async function () { - const config = resolveConfig(__filename, { - networks: { - hardhat: { - enableTransientStorage: false, - }, - }, - }); - - assert.equal(config.networks.hardhat.hardfork, "shanghai"); - }); }); describe("HTTP networks resolution", function () { From 49c95707187fb42140aba8267d0eb649645e86cb Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Thu, 6 Feb 2025 17:28:48 +0000 Subject: [PATCH 8/9] feat: make prague the default hardfork --- docs/src/content/hardhat-network/docs/reference/index.md | 2 +- .../hardhat-core/src/internal/core/config/default-config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/content/hardhat-network/docs/reference/index.md b/docs/src/content/hardhat-network/docs/reference/index.md index af3aefa8a7f..ec4efb25331 100644 --- a/docs/src/content/hardhat-network/docs/reference/index.md +++ b/docs/src/content/hardhat-network/docs/reference/index.md @@ -67,7 +67,7 @@ The block gas limit to use in Hardhat Network's blockchain. Default value: `30_0 #### `hardfork` -This setting changes how Hardhat Network works, to mimic Ethereum's mainnet at a given hardfork. It must be one of `"byzantium"`, `"constantinople"`, `"petersburg"`, `"istanbul"`, `"muirGlacier"`, `"berlin"`, `"london"`, `"arrowGlacier"`, `"grayGlacier"`, `"merge"`, `"shanghai"`, `"cancun"` and `"prague"`. Default value: `"cancun"` +This setting changes how Hardhat Network works, to mimic Ethereum's mainnet at a given hardfork. It must be one of `"byzantium"`, `"constantinople"`, `"petersburg"`, `"istanbul"`, `"muirGlacier"`, `"berlin"`, `"london"`, `"arrowGlacier"`, `"grayGlacier"`, `"merge"`, `"shanghai"`, `"cancun"` and `"prague"`. Default value: `"prague"` #### `throwOnTransactionFailures` diff --git a/packages/hardhat-core/src/internal/core/config/default-config.ts b/packages/hardhat-core/src/internal/core/config/default-config.ts index bed6cd2dd80..2669680440b 100644 --- a/packages/hardhat-core/src/internal/core/config/default-config.ts +++ b/packages/hardhat-core/src/internal/core/config/default-config.ts @@ -36,7 +36,7 @@ export const defaultHardhatNetworkParams: Omit< HardhatNetworkConfig, "gas" | "initialDate" > = { - hardfork: HardforkName.CANCUN, + hardfork: HardforkName.PRAGUE, blockGasLimit: 30_000_000, gasPrice: HARDHAT_NETWORK_DEFAULT_GAS_PRICE, chainId: 31337, From d19f7d29d0bd75fdd67d2d5127f03b8c874b34eb Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Mon, 10 Feb 2025 17:13:55 +0000 Subject: [PATCH 9/9] feat: re-enable signing test --- packages/hardhat-core/test/internal/core/providers/accounts.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/hardhat-core/test/internal/core/providers/accounts.ts b/packages/hardhat-core/test/internal/core/providers/accounts.ts index 89a8880ecb5..5af6b0b0803 100644 --- a/packages/hardhat-core/test/internal/core/providers/accounts.ts +++ b/packages/hardhat-core/test/internal/core/providers/accounts.ts @@ -308,8 +308,7 @@ describe("Local accounts provider", () => { validateRawEIP2930Transaction(expectedRaw, tx); }); - // TODO: enable this test once prague is supported - it.skip("should send EIP-7702 transactions", async () => { + it("should send EIP-7702 transactions", async () => { const tx = { from: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", to: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",