Skip to content

Commit 1a9e584

Browse files
committed
WIP: build: upgrade to EDR v0.12.0-alpha.1
1 parent 664ec0e commit 1a9e584

File tree

2 files changed

+69
-36
lines changed

2 files changed

+69
-36
lines changed

packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import type {
1414
HttpHeader,
1515
TracingConfigWithBuffers,
1616
} from "@nomicfoundation/edr";
17+
import { privateToAddress } from "@ethereumjs/util";
18+
import { precompileP256Verify } from "@nomicfoundation/edr";
1719
import picocolors from "picocolors";
1820
import debug from "debug";
1921
import { EventEmitter } from "events";
@@ -192,6 +194,19 @@ export class EdrProviderWrapper
192194
l1HardforkFromString(ethereumsjsHardforkToEdrSpecId(hardforkName))
193195
);
194196

197+
for (const account of config.genesisAccounts) {
198+
const privateKey = Uint8Array.from(
199+
Buffer.from(account.privateKey.slice(2), "hex")
200+
);
201+
202+
genesisState.push({
203+
address: privateToAddress(privateKey),
204+
balance: BigInt(account.balance),
205+
nonce: 0n,
206+
storage: [],
207+
});
208+
}
209+
195210
const context = await getGlobalEdrContext();
196211
const provider = await context.createProvider(
197212
GENERIC_CHAIN_TYPE,
@@ -203,25 +218,31 @@ export class EdrProviderWrapper
203218
bailOnTransactionFailure: config.throwOnTransactionFailures,
204219
blockGasLimit: BigInt(config.blockGasLimit),
205220
chainId: BigInt(config.chainId),
206-
chains: Array.from(config.chains, ([chainId, hardforkConfig]) => {
207-
return {
208-
chainId: BigInt(chainId),
209-
hardforks: Array.from(
210-
hardforkConfig.hardforkHistory,
211-
([hardfork, blockNumber]) => {
212-
return {
213-
blockNumber: BigInt(blockNumber),
214-
specId: ethereumsjsHardforkToEdrSpecId(
215-
getHardforkName(hardfork)
216-
),
217-
};
218-
}
219-
),
220-
};
221-
}),
221+
chainOverrides: Array.from(
222+
config.chains,
223+
([chainId, hardforkConfig]) => {
224+
return {
225+
chainId: BigInt(chainId),
226+
name: "Unknown",
227+
hardforks: Array.from(
228+
hardforkConfig.hardforkHistory,
229+
([hardfork, blockNumber]) => {
230+
return {
231+
condition: { blockNumber: BigInt(blockNumber) },
232+
hardfork: ethereumsjsHardforkToEdrSpecId(
233+
getHardforkName(hardfork)
234+
),
235+
};
236+
}
237+
),
238+
};
239+
}
240+
),
222241
cacheDir: config.forkCachePath,
223242
coinbase: Buffer.from(coinbase.slice(2), "hex"),
224-
enableRip7212: config.enableRip7212,
243+
precompileOverrides: config.enableRip7212
244+
? [precompileP256Verify()]
245+
: [],
225246
fork,
226247
genesisState,
227248
hardfork: ethereumsjsHardforkToEdrSpecId(hardforkName),
@@ -239,16 +260,20 @@ export class EdrProviderWrapper
239260
},
240261
},
241262
networkId: BigInt(config.networkId),
263+
observability: {},
242264
ownedAccounts: config.genesisAccounts.map((account) => {
243-
return {
244-
secretKey: account.privateKey,
245-
balance: BigInt(account.balance),
246-
};
265+
return account.privateKey;
247266
}),
248267
},
249268
{
250269
enable: loggerConfig.enabled,
251-
decodeConsoleLogInputsCallback: ConsoleLogger.getDecodedLogs,
270+
decodeConsoleLogInputsCallback: (inputs: ArrayBuffer[]) => {
271+
return ConsoleLogger.getDecodedLogs(
272+
inputs.map((input) => {
273+
return Buffer.from(input);
274+
})
275+
);
276+
},
252277
printLineCallback: (message: string, replace: boolean) => {
253278
if (replace) {
254279
replaceLastLineFn(message);
@@ -318,7 +343,7 @@ export class EdrProviderWrapper
318343
const rawTraces = responseObject.traces;
319344
for (const rawTrace of rawTraces) {
320345
// For other consumers in JS we need to marshall the entire trace over FFI
321-
const trace = rawTrace.trace();
346+
const trace = rawTrace.trace;
322347

323348
// beforeTx event
324349
if (this._node._vm.events.listenerCount("beforeTx") > 0) {
@@ -421,8 +446,11 @@ export class EdrProviderWrapper
421446
this._callOverrideCallback = callback;
422447

423448
await this._provider.setCallOverrideCallback(
424-
async (address: Buffer, data: Buffer) => {
425-
return this._callOverrideCallback?.(address, data);
449+
async (address: ArrayBuffer, data: ArrayBuffer) => {
450+
return this._callOverrideCallback?.(
451+
Buffer.from(address),
452+
Buffer.from(data)
453+
);
426454
}
427455
);
428456
}

packages/hardhat-core/src/internal/hardhat-network/provider/utils/convertToEdr.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import type {
2+
SpecId,
3+
MineOrdering,
4+
IntervalRange,
5+
DebugTraceResult,
6+
TracingMessage,
7+
TracingMessageResult,
8+
TracingStep,
9+
} from "@nomicfoundation/edr";
110
import {
2-
type SpecId,
3-
type MineOrdering,
4-
type IntervalRange,
5-
type DebugTraceResult,
6-
type TracingMessage,
7-
type TracingMessageResult,
8-
type TracingStep,
911
FRONTIER,
1012
HOMESTEAD,
1113
DAO_FORK,
@@ -209,7 +211,10 @@ export function edrRpcDebugTraceToHardhat(
209211
structLogs.shift();
210212
}
211213

212-
let returnValue = rpcDebugTrace.output?.toString("hex") ?? "";
214+
let returnValue =
215+
rpcDebugTrace.output !== undefined
216+
? Buffer.from(rpcDebugTrace.output).toString("hex")
217+
: "";
213218
if (returnValue === "0x") {
214219
returnValue = "";
215220
}
@@ -262,10 +267,10 @@ export function edrTracingMessageResultToMinimalEVMResult(
262267
}
263268
if ("output" in result) {
264269
const { output } = result;
265-
if (Buffer.isBuffer(output)) {
266-
minimalEVMResult.execResult.output = output;
270+
if (output instanceof Uint8Array) {
271+
minimalEVMResult.execResult.output = Buffer.from(output);
267272
} else {
268-
minimalEVMResult.execResult.output = output.returnValue;
273+
minimalEVMResult.execResult.output = Buffer.from(output.returnValue);
269274
}
270275
}
271276

0 commit comments

Comments
 (0)