Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP - DO NOT MERGE] Prague support #6223

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion docs/src/content/hardhat-network/docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- merge
- shanghai
- cancun
- prague

## Config

Expand Down Expand Up @@ -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`

Expand Down
8 changes: 3 additions & 5 deletions packages/hardhat-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-core/src/builtin-tasks/node.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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("========");
Expand Down
1 change: 1 addition & 0 deletions packages/hardhat-core/src/internal/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const HARDHAT_NETWORK_SUPPORTED_HARDFORKS = [
"merge",
"shanghai",
"cancun",
"prague",
];

export const HARDHAT_MEMPOOL_SUPPORTED_ORDERS = ["fifo", "priority"] as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, -1], // TBD
]),
},
],
Expand Down Expand Up @@ -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, -1], // TBD
]),
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
22 changes: 8 additions & 14 deletions packages/hardhat-core/src/internal/core/providers/accounts.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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" ||
Expand Down Expand Up @@ -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)
Expand All @@ -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, {
Expand All @@ -232,9 +230,7 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId {
}

private async _getNonce(address: Buffer): Promise<bigint> {
const { bytesToHex: bufferToHex } = await import(
"@nomicfoundation/ethereumjs-util"
);
const { bytesToHex: bufferToHex } = await import("@ethereumjs/util");

const response = (await this._wrappedProvider.request({
method: "eth_getTransactionCount",
Expand All @@ -250,10 +246,10 @@ export class LocalAccountsProvider extends ProviderWrapperWithChainId {
privateKey: Buffer
): Promise<Uint8Array> {
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,
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-core/src/internal/core/providers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function normalizeHardhatNetworkAccountsConfig(
return accountsConfig;
}

const { bytesToHex } = require("@nomicfoundation/ethereumjs-util");
const { bytesToHex } = require("@ethereumjs/util");

return derivePrivateKeys(
accountsConfig.mnemonic,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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());
};

Expand All @@ -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());
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
bytesToHex as bufferToHex,
bytesToInt,
fromSigned,
} from "@nomicfoundation/ethereumjs-util";
} from "@ethereumjs/util";
import util from "util";

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class CompilerDownloader implements ICompilerDownloader {
downloadPath: string
): Promise<boolean> {
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;
Expand Down
2 changes: 2 additions & 0 deletions packages/hardhat-core/src/internal/util/hardforks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum HardforkName {
MERGE = "merge",
SHANGHAI = "shanghai",
CANCUN = "cancun",
PRAGUE = "prague",
}

const HARDFORKS_ORDER: HardforkName[] = [
Expand All @@ -43,6 +44,7 @@ const HARDFORKS_ORDER: HardforkName[] = [
HardforkName.MERGE,
HardforkName.SHANGHAI,
HardforkName.CANCUN,
HardforkName.PRAGUE,
];

export function getHardforkName(name: string): HardforkName {
Expand Down
Loading
Loading