hardhat 2.20.0 → 2.21.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
- package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -6
- package/internal/core/providers/construction.d.ts.map +1 -1
- package/internal/core/providers/construction.js +28 -4
- package/internal/core/providers/construction.js.map +1 -1
- package/internal/core/providers/http.d.ts +2 -0
- package/internal/core/providers/http.d.ts.map +1 -1
- package/internal/core/providers/http.js +2 -1
- package/internal/core/providers/http.js.map +1 -1
- package/internal/core/runtime-environment.d.ts.map +1 -1
- package/internal/core/runtime-environment.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.d.ts +0 -2
- package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/client.js +0 -16
- package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.js +9 -1
- package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.d.ts +5 -5
- package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/BlockchainData.js +10 -10
- package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +0 -7
- package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/HardhatBlockchain.js +2 -14
- package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/TxPool.d.ts +3 -2
- package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
- package/internal/hardhat-network/provider/TxPool.js +16 -16
- package/internal/hardhat-network/provider/TxPool.js.map +1 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js +1 -1
- package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
- package/internal/hardhat-network/provider/filter.d.ts +6 -5
- package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
- package/internal/hardhat-network/provider/filter.js +2 -2
- package/internal/hardhat-network/provider/filter.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +0 -7
- package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js +4 -21
- package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +13 -19
- package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/ForkStateManager.js +61 -59
- package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js +0 -3
- package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
- package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.js +1 -1
- package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
- package/internal/hardhat-network/provider/modules/base.js +4 -4
- package/internal/hardhat-network/provider/modules/base.js.map +1 -1
- package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/eth.js +9 -16
- package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.d.ts +6 -84
- package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
- package/internal/hardhat-network/provider/modules/logger.js +3 -530
- package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
- package/internal/hardhat-network/provider/node-types.d.ts +2 -65
- package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node-types.js +0 -5
- package/internal/hardhat-network/provider/node-types.js.map +1 -1
- package/internal/hardhat-network/provider/node.d.ts +2 -6
- package/internal/hardhat-network/provider/node.d.ts.map +1 -1
- package/internal/hardhat-network/provider/node.js +79 -148
- package/internal/hardhat-network/provider/node.js.map +1 -1
- package/internal/hardhat-network/provider/output.d.ts +0 -14
- package/internal/hardhat-network/provider/output.d.ts.map +1 -1
- package/internal/hardhat-network/provider/output.js +0 -264
- package/internal/hardhat-network/provider/output.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +26 -25
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +342 -186
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +10 -8
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +9 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +10 -8
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +9 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +10 -9
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +7 -6
- package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +6 -5
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +5 -4
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +8 -7
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +2 -2
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +8 -7
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -1
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +2 -2
- package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -1
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -4
- package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts +14 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.js +191 -0
- package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -0
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +0 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +1 -5
- package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeCommon.js +1 -3
- package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +2 -2
- package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js +1 -15
- package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +10 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/makeForkClient.js +38 -18
- package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
- package/internal/hardhat-network/provider/utils/makeStateTrie.js +2 -2
- package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +3 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -6
- package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
- package/internal/hardhat-network/provider/utils/random.d.ts +1 -0
- package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/random.js +7 -1
- package/internal/hardhat-network/provider/utils/random.js.map +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
- package/internal/hardhat-network/provider/utils/reorgs-protection.js +5 -5
- package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.d.ts +22 -0
- package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/exit.js +93 -0
- package/internal/hardhat-network/provider/vm/exit.js.map +1 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.d.ts +29 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.js +46 -0
- package/internal/hardhat-network/provider/vm/minimal-vm.js.map +1 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.d.ts +36 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.js +73 -0
- package/internal/hardhat-network/provider/vm/proxy-vm.js.map +1 -0
- package/internal/hardhat-network/provider/vm/types.d.ts +27 -0
- package/internal/hardhat-network/provider/vm/types.d.ts.map +1 -0
- package/internal/hardhat-network/provider/vm/types.js +3 -0
- package/internal/hardhat-network/provider/vm/types.js.map +1 -0
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts +6 -0
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js +33 -16
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +1 -2
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.js +6 -7
- package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
- package/internal/hardhat-network/stack-traces/debug.js +6 -6
- package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +13 -7
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.d.ts +8 -3
- package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.js +22 -1
- package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
- package/internal/hardhat-network/stack-traces/model.d.ts +8 -0
- package/internal/hardhat-network/stack-traces/model.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/model.js +52 -0
- package/internal/hardhat-network/stack-traces/model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/opcodes.d.ts +1 -0
- package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/opcodes.js +5 -1
- package/internal/hardhat-network/stack-traces/opcodes.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +2 -2
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +5 -5
- package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +28 -34
- package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +7 -0
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +69 -2
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +7 -12
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.js +46 -65
- package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
- package/internal/util/date.d.ts +1 -0
- package/internal/util/date.d.ts.map +1 -1
- package/internal/util/date.js +5 -1
- package/internal/util/date.js.map +1 -1
- package/internal/util/hardforks.d.ts +2 -0
- package/internal/util/hardforks.d.ts.map +1 -1
- package/internal/util/hardforks.js +27 -1
- package/internal/util/hardforks.js.map +1 -1
- package/package.json +18 -16
- package/src/internal/core/providers/construction.ts +7 -9
- package/src/internal/core/providers/http.ts +3 -1
- package/src/internal/core/runtime-environment.ts +2 -1
- package/src/internal/hardhat-network/jsonrpc/client.ts +1 -28
- package/src/internal/hardhat-network/jsonrpc/handler.ts +9 -1
- package/src/internal/hardhat-network/provider/modules/logger.ts +6 -801
- package/src/internal/hardhat-network/provider/node-types.ts +2 -89
- package/src/internal/hardhat-network/provider/output.ts +0 -352
- package/src/internal/hardhat-network/provider/provider.ts +482 -263
- package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +228 -0
- package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +0 -4
- package/src/internal/hardhat-network/provider/utils/makeCommon.ts +1 -12
- package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +63 -24
- package/src/internal/hardhat-network/provider/utils/random.ts +8 -1
- package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +5 -5
- package/src/internal/hardhat-network/provider/vm/exit.ts +101 -0
- package/src/internal/hardhat-network/provider/vm/minimal-vm.ts +101 -0
- package/src/internal/hardhat-network/provider/vm/types.ts +31 -0
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +40 -21
- package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +10 -12
- package/src/internal/hardhat-network/stack-traces/debug.ts +6 -6
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +15 -8
- package/src/internal/hardhat-network/stack-traces/message-trace.ts +40 -4
- package/src/internal/hardhat-network/stack-traces/model.ts +61 -0
- package/src/internal/hardhat-network/stack-traces/opcodes.ts +4 -0
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +2 -2
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +6 -5
- package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +113 -4
- package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +67 -95
- package/src/internal/util/date.ts +4 -0
- package/src/internal/util/hardforks.ts +52 -0
- package/src/internal/hardhat-network/provider/BlockchainBase.ts +0 -185
- package/src/internal/hardhat-network/provider/BlockchainData.ts +0 -261
- package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +0 -140
- package/src/internal/hardhat-network/provider/PoolState.ts +0 -48
- package/src/internal/hardhat-network/provider/TransactionQueue.ts +0 -158
- package/src/internal/hardhat-network/provider/TxPool.ts +0 -715
- package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +0 -21
- package/src/internal/hardhat-network/provider/filter.ts +0 -142
- package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +0 -433
- package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +0 -480
- package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +0 -35
- package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +0 -44
- package/src/internal/hardhat-network/provider/modules/base.ts +0 -156
- package/src/internal/hardhat-network/provider/modules/debug.ts +0 -104
- package/src/internal/hardhat-network/provider/modules/eth.ts +0 -1781
- package/src/internal/hardhat-network/provider/modules/evm.ts +0 -249
- package/src/internal/hardhat-network/provider/modules/hardhat.ts +0 -481
- package/src/internal/hardhat-network/provider/modules/net.ts +0 -60
- package/src/internal/hardhat-network/provider/modules/personal.ts +0 -40
- package/src/internal/hardhat-network/provider/modules/web3.ts +0 -49
- package/src/internal/hardhat-network/provider/node.ts +0 -2993
- package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +0 -226
- package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +0 -224
- package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +0 -216
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +0 -143
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +0 -144
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +0 -171
- package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.ts +0 -169
- package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +0 -25
- package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +0 -60
- package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +0 -29
- package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +0 -61
- package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +0 -45
- package/src/internal/hardhat-network/provider/utils/txMapToArray.ts +0 -7
- package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +0 -630
|
@@ -1,91 +1,44 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@nomicfoundation/
|
|
7
|
-
|
|
8
|
-
import {
|
|
2
|
+
CreateOutput,
|
|
3
|
+
ExecutionResult,
|
|
4
|
+
TracingMessage,
|
|
5
|
+
TracingStep,
|
|
6
|
+
} from "@nomicfoundation/edr";
|
|
7
|
+
|
|
8
|
+
import { bytesToBigInt } from "@nomicfoundation/ethereumjs-util";
|
|
9
|
+
|
|
9
10
|
import { assertHardhatInvariant } from "../../core/errors";
|
|
11
|
+
import { Exit, ExitCode } from "../provider/vm/exit";
|
|
10
12
|
|
|
11
13
|
import {
|
|
12
14
|
CallMessageTrace,
|
|
13
15
|
CreateMessageTrace,
|
|
14
16
|
isCreateTrace,
|
|
17
|
+
isHaltResult,
|
|
15
18
|
isPrecompileTrace,
|
|
19
|
+
isSuccessResult,
|
|
16
20
|
MessageTrace,
|
|
17
21
|
PrecompileMessageTrace,
|
|
18
22
|
} from "./message-trace";
|
|
19
23
|
|
|
20
24
|
/* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
|
|
21
25
|
|
|
22
|
-
const DUMMY_RETURN_DATA =
|
|
26
|
+
const DUMMY_RETURN_DATA = Buffer.from([]);
|
|
23
27
|
const DUMMY_GAS_USED = 0n;
|
|
24
28
|
|
|
25
29
|
export class VMTracer {
|
|
30
|
+
public tracingSteps: TracingStep[] = [];
|
|
31
|
+
|
|
26
32
|
private _messageTraces: MessageTrace[] = [];
|
|
27
|
-
private _enabled = false;
|
|
28
33
|
private _lastError: Error | undefined;
|
|
29
|
-
private _maxPrecompileNumber
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
private readonly _vm: VM,
|
|
33
|
-
private readonly _getContractCode: (
|
|
34
|
-
address: Address
|
|
35
|
-
) => Promise<Uint8Array>,
|
|
36
|
-
private readonly _throwErrors = true
|
|
37
|
-
) {
|
|
38
|
-
this._beforeMessageHandler = this._beforeMessageHandler.bind(this);
|
|
39
|
-
this._stepHandler = this._stepHandler.bind(this);
|
|
40
|
-
this._afterMessageHandler = this._afterMessageHandler.bind(this);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public enableTracing() {
|
|
44
|
-
if (this._enabled) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
assertHardhatInvariant(
|
|
48
|
-
this._vm.evm.events !== undefined,
|
|
49
|
-
"EVM should have an 'events' property"
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
this._vm.evm.events.on("beforeMessage", this._beforeMessageHandler);
|
|
53
|
-
this._vm.evm.events.on("step", this._stepHandler);
|
|
54
|
-
this._vm.evm.events.on("afterMessage", this._afterMessageHandler);
|
|
55
|
-
this._enabled = true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public disableTracing() {
|
|
59
|
-
if (!this._enabled) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
34
|
+
private _maxPrecompileNumber;
|
|
62
35
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
this._vm.evm.events.removeListener(
|
|
69
|
-
"beforeMessage",
|
|
70
|
-
this._beforeMessageHandler
|
|
71
|
-
);
|
|
72
|
-
this._vm.evm.events.removeListener("step", this._stepHandler);
|
|
73
|
-
this._vm.evm.events.removeListener(
|
|
74
|
-
"afterMessage",
|
|
75
|
-
this._afterMessageHandler
|
|
76
|
-
);
|
|
77
|
-
this._enabled = false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public get enabled(): boolean {
|
|
81
|
-
return this._enabled;
|
|
36
|
+
constructor(private readonly _throwErrors = true) {
|
|
37
|
+
// TODO: temporarily hardcoded to remove the need of using ethereumjs' common and evm here
|
|
38
|
+
this._maxPrecompileNumber = 10;
|
|
82
39
|
}
|
|
83
40
|
|
|
84
41
|
public getLastTopLevelMessageTrace(): MessageTrace | undefined {
|
|
85
|
-
if (!this._enabled) {
|
|
86
|
-
throw new Error("You can't get a vm trace if the VMTracer is disabled");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
42
|
return this._messageTraces[0];
|
|
90
43
|
}
|
|
91
44
|
|
|
@@ -101,9 +54,8 @@ export class VMTracer {
|
|
|
101
54
|
return this._throwErrors || this._lastError === undefined;
|
|
102
55
|
}
|
|
103
56
|
|
|
104
|
-
|
|
57
|
+
public async addBeforeMessage(message: TracingMessage) {
|
|
105
58
|
if (!this._shouldKeepTracing()) {
|
|
106
|
-
next();
|
|
107
59
|
return;
|
|
108
60
|
}
|
|
109
61
|
|
|
@@ -112,13 +64,15 @@ export class VMTracer {
|
|
|
112
64
|
|
|
113
65
|
if (message.depth === 0) {
|
|
114
66
|
this._messageTraces = [];
|
|
67
|
+
this.tracingSteps = [];
|
|
115
68
|
}
|
|
116
69
|
|
|
117
70
|
if (message.to === undefined) {
|
|
118
71
|
const createTrace: CreateMessageTrace = {
|
|
119
|
-
code:
|
|
72
|
+
code: message.data,
|
|
120
73
|
steps: [],
|
|
121
74
|
value: message.value,
|
|
75
|
+
exit: new Exit(ExitCode.SUCCESS),
|
|
122
76
|
returnData: DUMMY_RETURN_DATA,
|
|
123
77
|
numberOfSubtraces: 0,
|
|
124
78
|
depth: message.depth,
|
|
@@ -128,13 +82,14 @@ export class VMTracer {
|
|
|
128
82
|
|
|
129
83
|
trace = createTrace;
|
|
130
84
|
} else {
|
|
131
|
-
const toAsBigInt = bytesToBigInt(message.to
|
|
85
|
+
const toAsBigInt = bytesToBigInt(message.to);
|
|
132
86
|
|
|
133
87
|
if (toAsBigInt > 0 && toAsBigInt <= this._maxPrecompileNumber) {
|
|
134
88
|
const precompileTrace: PrecompileMessageTrace = {
|
|
135
89
|
precompile: Number(toAsBigInt),
|
|
136
|
-
calldata:
|
|
90
|
+
calldata: message.data,
|
|
137
91
|
value: message.value,
|
|
92
|
+
exit: new Exit(ExitCode.SUCCESS),
|
|
138
93
|
returnData: DUMMY_RETURN_DATA,
|
|
139
94
|
depth: message.depth,
|
|
140
95
|
gasUsed: DUMMY_GAS_USED,
|
|
@@ -144,19 +99,29 @@ export class VMTracer {
|
|
|
144
99
|
} else {
|
|
145
100
|
const codeAddress = message.codeAddress;
|
|
146
101
|
|
|
147
|
-
|
|
102
|
+
// if we enter here, then `to` is not undefined, therefore
|
|
103
|
+
// `codeAddress` and `code` should be defined
|
|
104
|
+
assertHardhatInvariant(
|
|
105
|
+
codeAddress !== undefined,
|
|
106
|
+
"codeAddress should be defined"
|
|
107
|
+
);
|
|
108
|
+
assertHardhatInvariant(
|
|
109
|
+
message.code !== undefined,
|
|
110
|
+
"code should be defined"
|
|
111
|
+
);
|
|
148
112
|
|
|
149
113
|
const callTrace: CallMessageTrace = {
|
|
150
|
-
code,
|
|
151
|
-
calldata:
|
|
114
|
+
code: message.code,
|
|
115
|
+
calldata: message.data,
|
|
152
116
|
steps: [],
|
|
153
117
|
value: message.value,
|
|
118
|
+
exit: new Exit(ExitCode.SUCCESS),
|
|
154
119
|
returnData: DUMMY_RETURN_DATA,
|
|
155
|
-
address: message.to
|
|
120
|
+
address: message.to,
|
|
156
121
|
numberOfSubtraces: 0,
|
|
157
122
|
depth: message.depth,
|
|
158
123
|
gasUsed: DUMMY_GAS_USED,
|
|
159
|
-
codeAddress
|
|
124
|
+
codeAddress,
|
|
160
125
|
};
|
|
161
126
|
|
|
162
127
|
trace = callTrace;
|
|
@@ -177,23 +142,22 @@ export class VMTracer {
|
|
|
177
142
|
}
|
|
178
143
|
|
|
179
144
|
this._messageTraces.push(trace);
|
|
180
|
-
next();
|
|
181
145
|
} catch (error) {
|
|
182
146
|
if (this._throwErrors) {
|
|
183
|
-
|
|
147
|
+
throw error;
|
|
184
148
|
} else {
|
|
185
149
|
this._lastError = error as Error;
|
|
186
|
-
next();
|
|
187
150
|
}
|
|
188
151
|
}
|
|
189
152
|
}
|
|
190
153
|
|
|
191
|
-
|
|
154
|
+
public async addStep(step: TracingStep) {
|
|
192
155
|
if (!this._shouldKeepTracing()) {
|
|
193
|
-
next();
|
|
194
156
|
return;
|
|
195
157
|
}
|
|
196
158
|
|
|
159
|
+
this.tracingSteps.push(step);
|
|
160
|
+
|
|
197
161
|
try {
|
|
198
162
|
const trace = this._messageTraces[this._messageTraces.length - 1];
|
|
199
163
|
|
|
@@ -203,46 +167,54 @@ export class VMTracer {
|
|
|
203
167
|
);
|
|
204
168
|
}
|
|
205
169
|
|
|
206
|
-
trace.steps.push({ pc: step.pc });
|
|
207
|
-
next();
|
|
170
|
+
trace.steps.push({ pc: Number(step.pc) });
|
|
208
171
|
} catch (error) {
|
|
209
172
|
if (this._throwErrors) {
|
|
210
|
-
|
|
173
|
+
throw error;
|
|
211
174
|
} else {
|
|
212
175
|
this._lastError = error as Error;
|
|
213
|
-
next();
|
|
214
176
|
}
|
|
215
177
|
}
|
|
216
178
|
}
|
|
217
179
|
|
|
218
|
-
|
|
180
|
+
public async addAfterMessage(result: ExecutionResult, haltOverride?: Exit) {
|
|
219
181
|
if (!this._shouldKeepTracing()) {
|
|
220
|
-
next();
|
|
221
182
|
return;
|
|
222
183
|
}
|
|
223
184
|
|
|
224
185
|
try {
|
|
225
186
|
const trace = this._messageTraces[this._messageTraces.length - 1];
|
|
187
|
+
trace.gasUsed = result.result.gasUsed;
|
|
226
188
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
189
|
+
const executionResult = result.result;
|
|
190
|
+
if (isSuccessResult(executionResult)) {
|
|
191
|
+
trace.exit = Exit.fromEdrSuccessReason(executionResult.reason);
|
|
192
|
+
trace.returnData = executionResult.output.returnValue;
|
|
230
193
|
|
|
231
|
-
|
|
232
|
-
|
|
194
|
+
if (isCreateTrace(trace)) {
|
|
195
|
+
trace.deployedContract = (
|
|
196
|
+
executionResult.output as CreateOutput
|
|
197
|
+
).address;
|
|
198
|
+
}
|
|
199
|
+
} else if (isHaltResult(executionResult)) {
|
|
200
|
+
trace.exit =
|
|
201
|
+
haltOverride ?? Exit.fromEdrExceptionalHalt(executionResult.reason);
|
|
202
|
+
|
|
203
|
+
trace.returnData = Buffer.from([]);
|
|
204
|
+
} else {
|
|
205
|
+
trace.exit = new Exit(ExitCode.REVERT);
|
|
206
|
+
|
|
207
|
+
trace.returnData = executionResult.output;
|
|
233
208
|
}
|
|
234
209
|
|
|
235
210
|
if (this._messageTraces.length > 1) {
|
|
236
211
|
this._messageTraces.pop();
|
|
237
212
|
}
|
|
238
|
-
|
|
239
|
-
next();
|
|
240
213
|
} catch (error) {
|
|
241
214
|
if (this._throwErrors) {
|
|
242
|
-
|
|
215
|
+
throw error;
|
|
243
216
|
} else {
|
|
244
217
|
this._lastError = error as Error;
|
|
245
|
-
next();
|
|
246
218
|
}
|
|
247
219
|
}
|
|
248
220
|
}
|
|
@@ -6,6 +6,10 @@ export function dateToTimestampSeconds(date: Date): number {
|
|
|
6
6
|
return Math.floor(date.valueOf() / 1000);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export function timestampSecondsToDate(timestamp: number): Date {
|
|
10
|
+
return new Date(timestamp * 1000);
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
export function getDifferenceInSeconds(a: Date, b: Date): number {
|
|
10
14
|
return Math.floor((a.valueOf() - b.valueOf()) / 1000);
|
|
11
15
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { HardforkHistoryConfig } from "../../types/config";
|
|
2
|
+
import { HARDHAT_NETWORK_SUPPORTED_HARDFORKS } from "../constants";
|
|
1
3
|
import { assertHardhatInvariant } from "../core/errors";
|
|
4
|
+
import { InternalError } from "../core/providers/errors";
|
|
5
|
+
|
|
6
|
+
/* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
|
|
2
7
|
|
|
3
8
|
export enum HardforkName {
|
|
4
9
|
FRONTIER = "chainstart",
|
|
@@ -69,3 +74,50 @@ export function hardforkGte(
|
|
|
69
74
|
|
|
70
75
|
return indexA >= indexB;
|
|
71
76
|
}
|
|
77
|
+
|
|
78
|
+
export function selectHardfork(
|
|
79
|
+
forkBlockNumber: bigint | undefined,
|
|
80
|
+
currentHardfork: string,
|
|
81
|
+
hardforkActivations: HardforkHistoryConfig | undefined,
|
|
82
|
+
blockNumber: bigint
|
|
83
|
+
): string {
|
|
84
|
+
if (forkBlockNumber === undefined || blockNumber > forkBlockNumber) {
|
|
85
|
+
return currentHardfork;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (hardforkActivations === undefined || hardforkActivations.size === 0) {
|
|
89
|
+
throw new InternalError(
|
|
90
|
+
`No known hardfork for execution on historical block ${blockNumber.toString()} (relative to fork block number ${forkBlockNumber}). The node was not configured with a hardfork activation history. See http://hardhat.org/custom-hardfork-history`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** search this._hardforkActivations for the highest block number that
|
|
95
|
+
* isn't higher than blockNumber, and then return that found block number's
|
|
96
|
+
* associated hardfork name. */
|
|
97
|
+
const hardforkHistory: Array<[name: string, block: number]> = Array.from(
|
|
98
|
+
hardforkActivations.entries()
|
|
99
|
+
);
|
|
100
|
+
const [hardfork, activationBlock] = hardforkHistory.reduce(
|
|
101
|
+
([highestHardfork, highestBlock], [thisHardfork, thisBlock]) =>
|
|
102
|
+
thisBlock > highestBlock && thisBlock <= blockNumber
|
|
103
|
+
? [thisHardfork, thisBlock]
|
|
104
|
+
: [highestHardfork, highestBlock]
|
|
105
|
+
);
|
|
106
|
+
if (hardfork === undefined || blockNumber < activationBlock) {
|
|
107
|
+
throw new InternalError(
|
|
108
|
+
`Could not find a hardfork to run for block ${blockNumber.toString()}, after having looked for one in the hardfork activation history, which was: ${JSON.stringify(
|
|
109
|
+
hardforkHistory
|
|
110
|
+
)}. For more information, see https://hardhat.org/hardhat-network/reference/#config`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!HARDHAT_NETWORK_SUPPORTED_HARDFORKS.includes(hardfork)) {
|
|
115
|
+
throw new InternalError(
|
|
116
|
+
`Tried to run a call or transaction in the context of a block whose hardfork is "${hardfork}", but Hardhat Network only supports the following hardforks: ${HARDHAT_NETWORK_SUPPORTED_HARDFORKS.join(
|
|
117
|
+
", "
|
|
118
|
+
)}`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return hardfork;
|
|
123
|
+
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { Block, BlockHeader } from "@nomicfoundation/ethereumjs-block";
|
|
2
|
-
import {
|
|
3
|
-
BlockchainInterface,
|
|
4
|
-
CasperConsensus,
|
|
5
|
-
CliqueConsensus,
|
|
6
|
-
Consensus,
|
|
7
|
-
EthashConsensus,
|
|
8
|
-
} from "@nomicfoundation/ethereumjs-blockchain";
|
|
9
|
-
import { Common, ConsensusAlgorithm } from "@nomicfoundation/ethereumjs-common";
|
|
10
|
-
import { TypedTransaction } from "@nomicfoundation/ethereumjs-tx";
|
|
11
|
-
|
|
12
|
-
import { assertHardhatInvariant } from "../../core/errors";
|
|
13
|
-
import * as BigIntUtils from "../../util/bigint";
|
|
14
|
-
import { BlockchainData } from "./BlockchainData";
|
|
15
|
-
import { RpcReceiptOutput } from "./output";
|
|
16
|
-
|
|
17
|
-
/* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
|
|
18
|
-
|
|
19
|
-
export abstract class BlockchainBase {
|
|
20
|
-
public consensus: Consensus;
|
|
21
|
-
protected readonly _data: BlockchainData;
|
|
22
|
-
|
|
23
|
-
constructor(protected _common: Common) {
|
|
24
|
-
this._data = new BlockchainData(_common);
|
|
25
|
-
|
|
26
|
-
// copied from blockchain.ts in @nomicfoundation/ethereumjs-blockchain
|
|
27
|
-
switch (this._common.consensusAlgorithm()) {
|
|
28
|
-
case ConsensusAlgorithm.Casper:
|
|
29
|
-
this.consensus = new CasperConsensus();
|
|
30
|
-
break;
|
|
31
|
-
case ConsensusAlgorithm.Clique:
|
|
32
|
-
this.consensus = new CliqueConsensus();
|
|
33
|
-
break;
|
|
34
|
-
case ConsensusAlgorithm.Ethash:
|
|
35
|
-
this.consensus = new EthashConsensus();
|
|
36
|
-
break;
|
|
37
|
-
default:
|
|
38
|
-
throw new Error(
|
|
39
|
-
`consensus algorithm ${this._common.consensusAlgorithm()} not supported`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public abstract addBlock(block: Block): Promise<Block>;
|
|
45
|
-
|
|
46
|
-
public addTransactionReceipts(receipts: RpcReceiptOutput[]) {
|
|
47
|
-
for (const receipt of receipts) {
|
|
48
|
-
this._data.addTransactionReceipt(receipt);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public async delBlock(blockHash: Buffer) {
|
|
53
|
-
this.deleteBlock(blockHash);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public deleteBlock(blockHash: Buffer) {
|
|
57
|
-
const block = this._data.getBlockByHash(blockHash);
|
|
58
|
-
if (block === undefined) {
|
|
59
|
-
throw new Error("Block not found");
|
|
60
|
-
}
|
|
61
|
-
this._delBlock(block.header.number);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public async getBlock(
|
|
65
|
-
blockHashOrNumber: Buffer | bigint | number
|
|
66
|
-
): Promise<Block> {
|
|
67
|
-
if (
|
|
68
|
-
(typeof blockHashOrNumber === "number" ||
|
|
69
|
-
BigIntUtils.isBigInt(blockHashOrNumber)) &&
|
|
70
|
-
this._data.isReservedBlock(BigInt(blockHashOrNumber))
|
|
71
|
-
) {
|
|
72
|
-
this._data.fulfillBlockReservation(BigInt(blockHashOrNumber));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (typeof blockHashOrNumber === "number") {
|
|
76
|
-
const blockByNumber = this._data.getBlockByNumber(
|
|
77
|
-
BigInt(blockHashOrNumber)
|
|
78
|
-
);
|
|
79
|
-
if (blockByNumber === undefined) {
|
|
80
|
-
throw new Error("Block not found");
|
|
81
|
-
}
|
|
82
|
-
return blockByNumber;
|
|
83
|
-
}
|
|
84
|
-
if (BigIntUtils.isBigInt(blockHashOrNumber)) {
|
|
85
|
-
const blockByNumber = this._data.getBlockByNumber(blockHashOrNumber);
|
|
86
|
-
if (blockByNumber === undefined) {
|
|
87
|
-
throw new Error("Block not found");
|
|
88
|
-
}
|
|
89
|
-
return blockByNumber;
|
|
90
|
-
}
|
|
91
|
-
const blockByHash = this._data.getBlockByHash(blockHashOrNumber);
|
|
92
|
-
if (blockByHash === undefined) {
|
|
93
|
-
throw new Error("Block not found");
|
|
94
|
-
}
|
|
95
|
-
return blockByHash;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public abstract getLatestBlockNumber(): bigint;
|
|
99
|
-
|
|
100
|
-
public async getLatestBlock(): Promise<Block> {
|
|
101
|
-
return this.getBlock(this.getLatestBlockNumber());
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public getLocalTransaction(
|
|
105
|
-
transactionHash: Buffer
|
|
106
|
-
): TypedTransaction | undefined {
|
|
107
|
-
return this._data.getTransaction(transactionHash);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public iterator(
|
|
111
|
-
_name: string,
|
|
112
|
-
_onBlock: (block: Block, reorg: boolean) => void | Promise<void>
|
|
113
|
-
): Promise<number> {
|
|
114
|
-
throw new Error("Method not implemented.");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public async putBlock(block: Block): Promise<void> {
|
|
118
|
-
await this.addBlock(block);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
public reserveBlocks(
|
|
122
|
-
count: bigint,
|
|
123
|
-
interval: bigint,
|
|
124
|
-
previousBlockStateRoot: Buffer,
|
|
125
|
-
previousBlockTotalDifficulty: bigint,
|
|
126
|
-
previousBlockBaseFeePerGas: bigint | undefined
|
|
127
|
-
) {
|
|
128
|
-
this._data.reserveBlocks(
|
|
129
|
-
this.getLatestBlockNumber() + 1n,
|
|
130
|
-
count,
|
|
131
|
-
interval,
|
|
132
|
-
previousBlockStateRoot,
|
|
133
|
-
previousBlockTotalDifficulty,
|
|
134
|
-
previousBlockBaseFeePerGas
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public copy(): BlockchainInterface {
|
|
139
|
-
throw new Error("Method not implemented.");
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public validateHeader(
|
|
143
|
-
_header: BlockHeader,
|
|
144
|
-
_height?: bigint | undefined
|
|
145
|
-
): Promise<void> {
|
|
146
|
-
throw new Error("Method not implemented.");
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
protected _delBlock(blockNumber: bigint): void {
|
|
150
|
-
let i = blockNumber;
|
|
151
|
-
|
|
152
|
-
while (i <= this.getLatestBlockNumber()) {
|
|
153
|
-
if (this._data.isReservedBlock(i)) {
|
|
154
|
-
const reservation = this._data.cancelReservationWithBlock(i);
|
|
155
|
-
i = reservation.last + 1n;
|
|
156
|
-
} else {
|
|
157
|
-
const current = this._data.getBlockByNumber(i);
|
|
158
|
-
if (current !== undefined) {
|
|
159
|
-
this._data.removeBlock(current);
|
|
160
|
-
}
|
|
161
|
-
i++;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
protected async _computeTotalDifficulty(block: Block): Promise<bigint> {
|
|
167
|
-
const difficulty = block.header.difficulty;
|
|
168
|
-
const blockNumber = block.header.number;
|
|
169
|
-
|
|
170
|
-
if (blockNumber === 0n) {
|
|
171
|
-
return difficulty;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const parentBlock = await this.getBlock(blockNumber - 1n);
|
|
175
|
-
|
|
176
|
-
const parentHash = parentBlock.hash();
|
|
177
|
-
const parentTD = this._data.getTotalDifficulty(parentHash);
|
|
178
|
-
assertHardhatInvariant(
|
|
179
|
-
parentTD !== undefined,
|
|
180
|
-
"Parent block should have total difficulty"
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
return parentTD + difficulty;
|
|
184
|
-
}
|
|
185
|
-
}
|