hardhat 2.10.2 → 2.11.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.
Files changed (428) hide show
  1. package/builtin-tasks/compile.js +6 -8
  2. package/builtin-tasks/compile.js.map +1 -1
  3. package/builtin-tasks/node.js +9 -12
  4. package/builtin-tasks/node.js.map +1 -1
  5. package/builtin-tasks/test.js +2 -3
  6. package/builtin-tasks/test.js.map +1 -1
  7. package/internal/artifacts.js +1 -1
  8. package/internal/artifacts.js.map +1 -1
  9. package/internal/cli/ArgumentsParser.js +5 -2
  10. package/internal/cli/ArgumentsParser.js.map +1 -1
  11. package/internal/cli/analytics.js +2 -2
  12. package/internal/cli/analytics.js.map +1 -1
  13. package/internal/cli/autocomplete.js +20 -32
  14. package/internal/cli/autocomplete.js.map +1 -1
  15. package/internal/cli/cli.js +1 -1
  16. package/internal/cli/cli.js.map +1 -1
  17. package/internal/cli/project-creation.js +14 -4
  18. package/internal/cli/project-creation.js.map +1 -1
  19. package/internal/constants.d.ts.map +1 -1
  20. package/internal/constants.js +2 -0
  21. package/internal/constants.js.map +1 -1
  22. package/internal/core/config/config-loading.js +2 -3
  23. package/internal/core/config/config-loading.js.map +1 -1
  24. package/internal/core/config/config-resolution.d.ts.map +1 -1
  25. package/internal/core/config/config-resolution.js +84 -35
  26. package/internal/core/config/config-resolution.js.map +1 -1
  27. package/internal/core/config/config-validation.js +38 -20
  28. package/internal/core/config/config-validation.js.map +1 -1
  29. package/internal/core/config/default-config.d.ts.map +1 -1
  30. package/internal/core/config/default-config.js +7 -4
  31. package/internal/core/config/default-config.js.map +1 -1
  32. package/internal/core/errors.js +4 -2
  33. package/internal/core/errors.js.map +1 -1
  34. package/internal/core/execution-mode.js +2 -2
  35. package/internal/core/execution-mode.js.map +1 -1
  36. package/internal/core/flamegraph.d.ts +10 -0
  37. package/internal/core/flamegraph.d.ts.map +1 -0
  38. package/internal/core/flamegraph.js +245 -0
  39. package/internal/core/flamegraph.js.map +1 -0
  40. package/internal/core/jsonrpc/types/base-types.d.ts +7 -8
  41. package/internal/core/jsonrpc/types/base-types.d.ts.map +1 -1
  42. package/internal/core/jsonrpc/types/base-types.js +24 -24
  43. package/internal/core/jsonrpc/types/base-types.js.map +1 -1
  44. package/internal/core/jsonrpc/types/input/blockTag.d.ts +15 -10
  45. package/internal/core/jsonrpc/types/input/blockTag.d.ts.map +1 -1
  46. package/internal/core/jsonrpc/types/input/blockTag.js +2 -0
  47. package/internal/core/jsonrpc/types/input/blockTag.js.map +1 -1
  48. package/internal/core/jsonrpc/types/input/callRequest.d.ts +5 -6
  49. package/internal/core/jsonrpc/types/input/callRequest.d.ts.map +1 -1
  50. package/internal/core/jsonrpc/types/input/callRequest.js.map +1 -1
  51. package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -7
  52. package/internal/core/jsonrpc/types/input/filterRequest.d.ts.map +1 -1
  53. package/internal/core/jsonrpc/types/input/filterRequest.js.map +1 -1
  54. package/internal/core/jsonrpc/types/input/transactionRequest.d.ts +7 -8
  55. package/internal/core/jsonrpc/types/input/transactionRequest.d.ts.map +1 -1
  56. package/internal/core/jsonrpc/types/input/transactionRequest.js.map +1 -1
  57. package/internal/core/jsonrpc/types/output/block.d.ts +29 -30
  58. package/internal/core/jsonrpc/types/output/block.d.ts.map +1 -1
  59. package/internal/core/jsonrpc/types/output/block.js +8 -2
  60. package/internal/core/jsonrpc/types/output/block.js.map +1 -1
  61. package/internal/core/jsonrpc/types/output/log.d.ts +3 -4
  62. package/internal/core/jsonrpc/types/output/log.d.ts.map +1 -1
  63. package/internal/core/jsonrpc/types/output/log.js.map +1 -1
  64. package/internal/core/jsonrpc/types/output/receipt.d.ts +10 -11
  65. package/internal/core/jsonrpc/types/output/receipt.d.ts.map +1 -1
  66. package/internal/core/jsonrpc/types/output/receipt.js.map +1 -1
  67. package/internal/core/jsonrpc/types/output/transaction.d.ts +13 -14
  68. package/internal/core/jsonrpc/types/output/transaction.d.ts.map +1 -1
  69. package/internal/core/jsonrpc/types/output/transaction.js.map +1 -1
  70. package/internal/core/providers/accounts.d.ts.map +1 -1
  71. package/internal/core/providers/accounts.js +30 -24
  72. package/internal/core/providers/accounts.js.map +1 -1
  73. package/internal/core/providers/chainId.js +1 -1
  74. package/internal/core/providers/chainId.js.map +1 -1
  75. package/internal/core/providers/construction.d.ts.map +1 -1
  76. package/internal/core/providers/construction.js +5 -5
  77. package/internal/core/providers/construction.js.map +1 -1
  78. package/internal/core/providers/gas-providers.d.ts +4 -4
  79. package/internal/core/providers/gas-providers.d.ts.map +1 -1
  80. package/internal/core/providers/gas-providers.js +16 -15
  81. package/internal/core/providers/gas-providers.js.map +1 -1
  82. package/internal/core/providers/http.js +7 -2
  83. package/internal/core/providers/http.js.map +1 -1
  84. package/internal/core/providers/util.js +5 -8
  85. package/internal/core/providers/util.js.map +1 -1
  86. package/internal/core/runtime-environment.js +1 -1
  87. package/internal/core/runtime-environment.js.map +1 -1
  88. package/internal/core/task-profiling.d.ts +18 -0
  89. package/internal/core/task-profiling.d.ts.map +1 -0
  90. package/internal/core/task-profiling.js +50 -0
  91. package/internal/core/task-profiling.js.map +1 -0
  92. package/internal/core/typescript-support.js +3 -3
  93. package/internal/core/typescript-support.js.map +1 -1
  94. package/internal/hardhat-network/jsonrpc/client.d.ts +39 -39
  95. package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
  96. package/internal/hardhat-network/jsonrpc/client.js +14 -14
  97. package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
  98. package/internal/hardhat-network/provider/BlockchainBase.d.ts +13 -10
  99. package/internal/hardhat-network/provider/BlockchainBase.d.ts.map +1 -1
  100. package/internal/hardhat-network/provider/BlockchainBase.js +38 -16
  101. package/internal/hardhat-network/provider/BlockchainBase.js.map +1 -1
  102. package/internal/hardhat-network/provider/BlockchainData.d.ts +15 -16
  103. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
  104. package/internal/hardhat-network/provider/BlockchainData.js +33 -29
  105. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
  106. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +7 -8
  107. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
  108. package/internal/hardhat-network/provider/HardhatBlockchain.js +13 -14
  109. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
  110. package/internal/hardhat-network/provider/PoolState.d.ts +1 -1
  111. package/internal/hardhat-network/provider/PoolState.d.ts.map +1 -1
  112. package/internal/hardhat-network/provider/PoolState.js +2 -3
  113. package/internal/hardhat-network/provider/PoolState.js.map +1 -1
  114. package/internal/hardhat-network/provider/TransactionQueue.d.ts +2 -3
  115. package/internal/hardhat-network/provider/TransactionQueue.d.ts.map +1 -1
  116. package/internal/hardhat-network/provider/TransactionQueue.js +3 -3
  117. package/internal/hardhat-network/provider/TransactionQueue.js.map +1 -1
  118. package/internal/hardhat-network/provider/TxPool.d.ts +8 -8
  119. package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
  120. package/internal/hardhat-network/provider/TxPool.js +66 -68
  121. package/internal/hardhat-network/provider/TxPool.js.map +1 -1
  122. package/internal/hardhat-network/provider/ethereumjs-workarounds.js +2 -2
  123. package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
  124. package/internal/hardhat-network/provider/filter.d.ts +5 -6
  125. package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
  126. package/internal/hardhat-network/provider/filter.js +7 -8
  127. package/internal/hardhat-network/provider/filter.js.map +1 -1
  128. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +10 -11
  129. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
  130. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +51 -47
  131. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
  132. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +8 -10
  133. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
  134. package/internal/hardhat-network/provider/fork/ForkStateManager.js +51 -69
  135. package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
  136. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts +1 -1
  137. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
  138. package/internal/hardhat-network/provider/fork/rpcToBlockData.js +2 -3
  139. package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
  140. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
  141. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
  142. package/internal/hardhat-network/provider/fork/rpcToTxData.js +7 -11
  143. package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
  144. package/internal/hardhat-network/provider/modules/eth.d.ts +2 -1
  145. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
  146. package/internal/hardhat-network/provider/modules/eth.js +92 -68
  147. package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
  148. package/internal/hardhat-network/provider/modules/evm.d.ts.map +1 -1
  149. package/internal/hardhat-network/provider/modules/evm.js +14 -14
  150. package/internal/hardhat-network/provider/modules/evm.js.map +1 -1
  151. package/internal/hardhat-network/provider/modules/hardhat.d.ts.map +1 -1
  152. package/internal/hardhat-network/provider/modules/hardhat.js +13 -13
  153. package/internal/hardhat-network/provider/modules/hardhat.js.map +1 -1
  154. package/internal/hardhat-network/provider/modules/logger.d.ts +7 -8
  155. package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
  156. package/internal/hardhat-network/provider/modules/logger.js +29 -32
  157. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  158. package/internal/hardhat-network/provider/modules/net.d.ts +1 -1
  159. package/internal/hardhat-network/provider/modules/net.d.ts.map +1 -1
  160. package/internal/hardhat-network/provider/modules/personal.d.ts.map +1 -1
  161. package/internal/hardhat-network/provider/modules/personal.js +3 -3
  162. package/internal/hardhat-network/provider/modules/personal.js.map +1 -1
  163. package/internal/hardhat-network/provider/modules/web3.d.ts.map +1 -1
  164. package/internal/hardhat-network/provider/modules/web3.js +5 -4
  165. package/internal/hardhat-network/provider/modules/web3.js.map +1 -1
  166. package/internal/hardhat-network/provider/node-types.d.ts +30 -29
  167. package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
  168. package/internal/hardhat-network/provider/node.d.ts +47 -42
  169. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  170. package/internal/hardhat-network/provider/node.js +262 -208
  171. package/internal/hardhat-network/provider/node.js.map +1 -1
  172. package/internal/hardhat-network/provider/output.d.ts +5 -6
  173. package/internal/hardhat-network/provider/output.d.ts.map +1 -1
  174. package/internal/hardhat-network/provider/output.js +39 -36
  175. package/internal/hardhat-network/provider/output.js.map +1 -1
  176. package/internal/hardhat-network/provider/provider.d.ts +1 -2
  177. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  178. package/internal/hardhat-network/provider/provider.js.map +1 -1
  179. package/internal/hardhat-network/provider/return-data.d.ts +1 -2
  180. package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
  181. package/internal/hardhat-network/provider/return-data.js +1 -1
  182. package/internal/hardhat-network/provider/return-data.js.map +1 -1
  183. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +5 -5
  184. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
  185. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +60 -17
  186. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
  187. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +4 -4
  188. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
  189. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +59 -16
  190. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
  191. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +3 -3
  192. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
  193. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +41 -9
  194. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
  195. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +4 -4
  196. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
  197. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +7 -23
  198. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
  199. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +3 -3
  200. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
  201. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +7 -22
  202. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
  203. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +3 -3
  204. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
  205. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +1 -1
  206. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
  207. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -6
  208. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
  209. package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js +2 -3
  210. package/internal/hardhat-network/provider/utils/fork-recomendations-banner.js.map +1 -1
  211. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +1 -0
  212. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
  213. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +5 -1
  214. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
  215. package/internal/hardhat-network/provider/utils/makeAccount.d.ts +1 -1
  216. package/internal/hardhat-network/provider/utils/makeAccount.d.ts.map +1 -1
  217. package/internal/hardhat-network/provider/utils/makeAccount.js +6 -6
  218. package/internal/hardhat-network/provider/utils/makeAccount.js.map +1 -1
  219. package/internal/hardhat-network/provider/utils/makeCommon.d.ts +2 -2
  220. package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
  221. package/internal/hardhat-network/provider/utils/makeCommon.js +7 -23
  222. package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
  223. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +1 -2
  224. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
  225. package/internal/hardhat-network/provider/utils/makeForkClient.js +7 -8
  226. package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
  227. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts +1 -1
  228. package/internal/hardhat-network/provider/utils/makeStateTrie.d.ts.map +1 -1
  229. package/internal/hardhat-network/provider/utils/makeStateTrie.js +4 -4
  230. package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
  231. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +6 -3
  232. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
  233. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +22 -4
  234. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
  235. package/internal/hardhat-network/provider/utils/random.d.ts +15 -0
  236. package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -0
  237. package/internal/hardhat-network/provider/utils/random.js +48 -0
  238. package/internal/hardhat-network/provider/utils/random.js.map +1 -0
  239. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts +1 -2
  240. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.d.ts.map +1 -1
  241. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js +5 -4
  242. package/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.js.map +1 -1
  243. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +2 -2
  244. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
  245. package/internal/hardhat-network/provider/utils/reorgs-protection.js +7 -7
  246. package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
  247. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts +1 -1
  248. package/internal/hardhat-network/provider/utils/txMapToArray.d.ts.map +1 -1
  249. package/internal/hardhat-network/stack-traces/compiler-to-model.js +6 -8
  250. package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
  251. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
  252. package/internal/hardhat-network/stack-traces/consoleLogger.js +45 -45
  253. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  254. package/internal/hardhat-network/stack-traces/constants.d.ts +3 -0
  255. package/internal/hardhat-network/stack-traces/constants.d.ts.map +1 -0
  256. package/internal/hardhat-network/stack-traces/constants.js +6 -0
  257. package/internal/hardhat-network/stack-traces/constants.js.map +1 -0
  258. package/internal/hardhat-network/stack-traces/contracts-identifier.js +2 -2
  259. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
  260. package/internal/hardhat-network/stack-traces/debug.js +29 -19
  261. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  262. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
  263. package/internal/hardhat-network/stack-traces/error-inferrer.js +44 -26
  264. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  265. package/internal/hardhat-network/stack-traces/message-trace.d.ts +6 -7
  266. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  267. package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
  268. package/internal/hardhat-network/stack-traces/model.js +6 -6
  269. package/internal/hardhat-network/stack-traces/model.js.map +1 -1
  270. package/internal/hardhat-network/stack-traces/panic-errors.d.ts +1 -2
  271. package/internal/hardhat-network/stack-traces/panic-errors.d.ts.map +1 -1
  272. package/internal/hardhat-network/stack-traces/panic-errors.js +1 -1
  273. package/internal/hardhat-network/stack-traces/panic-errors.js.map +1 -1
  274. package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
  275. package/internal/hardhat-network/stack-traces/solidity-errors.js +21 -12
  276. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  277. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +6 -5
  278. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
  279. package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
  280. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  281. package/internal/hardhat-network/stack-traces/solidityTracer.js +4 -0
  282. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  283. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts +2 -1
  284. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
  285. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +79 -78
  286. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
  287. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +5 -1
  288. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
  289. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +3 -2
  290. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  291. package/internal/hardhat-network/stack-traces/vm-tracer.js +15 -16
  292. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  293. package/internal/reset.js +1 -1
  294. package/internal/reset.js.map +1 -1
  295. package/internal/sentry/anonymizer.js +2 -3
  296. package/internal/sentry/anonymizer.js.map +1 -1
  297. package/internal/sentry/subprocess.js +1 -1
  298. package/internal/sentry/subprocess.js.map +1 -1
  299. package/internal/sentry/transport.js +3 -4
  300. package/internal/sentry/transport.js.map +1 -1
  301. package/internal/solidity/compilation-job.js +2 -4
  302. package/internal/solidity/compilation-job.js.map +1 -1
  303. package/internal/solidity/compiler/downloader.d.ts.map +1 -1
  304. package/internal/solidity/compiler/downloader.js +6 -6
  305. package/internal/solidity/compiler/downloader.js.map +1 -1
  306. package/internal/solidity/dependencyGraph.js +3 -5
  307. package/internal/solidity/dependencyGraph.js.map +1 -1
  308. package/internal/solidity/parse.js +1 -1
  309. package/internal/solidity/parse.js.map +1 -1
  310. package/internal/solidity/resolver.js +4 -1
  311. package/internal/solidity/resolver.js.map +1 -1
  312. package/internal/util/abi-helpers.js +1 -1
  313. package/internal/util/abi-helpers.js.map +1 -1
  314. package/internal/util/bigint.d.ts +25 -0
  315. package/internal/util/bigint.d.ts.map +1 -0
  316. package/internal/util/bigint.js +67 -0
  317. package/internal/util/bigint.js.map +1 -0
  318. package/internal/util/download.js +1 -1
  319. package/internal/util/download.js.map +1 -1
  320. package/internal/util/fs-utils.d.ts +32 -0
  321. package/internal/util/fs-utils.d.ts.map +1 -0
  322. package/internal/util/fs-utils.js +151 -0
  323. package/internal/util/fs-utils.js.map +1 -0
  324. package/internal/util/hardforks.d.ts +3 -3
  325. package/internal/util/hardforks.d.ts.map +1 -1
  326. package/internal/util/hardforks.js +5 -28
  327. package/internal/util/hardforks.js.map +1 -1
  328. package/internal/util/jsonrpc.js +1 -1
  329. package/internal/util/jsonrpc.js.map +1 -1
  330. package/internal/util/lazy.js +2 -2
  331. package/internal/util/lazy.js.map +1 -1
  332. package/internal/util/packageInfo.js +1 -1
  333. package/internal/util/packageInfo.js.map +1 -1
  334. package/internal/util/scripts-runner.js +5 -2
  335. package/internal/util/scripts-runner.js.map +1 -1
  336. package/internal/util/wei-values.d.ts +1 -2
  337. package/internal/util/wei-values.d.ts.map +1 -1
  338. package/internal/util/wei-values.js +9 -10
  339. package/internal/util/wei-values.js.map +1 -1
  340. package/internal/vendor/await-semaphore/index.d.ts +12 -0
  341. package/internal/vendor/await-semaphore/index.d.ts.map +1 -0
  342. package/internal/vendor/await-semaphore/index.js +64 -0
  343. package/internal/vendor/await-semaphore/index.js.map +1 -0
  344. package/package.json +13 -9
  345. package/profiling.d.ts +18 -0
  346. package/profiling.d.ts.map +1 -0
  347. package/profiling.js +32 -0
  348. package/profiling.js.map +1 -0
  349. package/src/builtin-tasks/node.ts +4 -6
  350. package/src/internal/constants.ts +3 -1
  351. package/src/internal/core/config/config-resolution.ts +30 -7
  352. package/src/internal/core/config/default-config.ts +2 -4
  353. package/src/internal/core/jsonrpc/types/base-types.ts +23 -24
  354. package/src/internal/core/jsonrpc/types/input/blockTag.ts +2 -4
  355. package/src/internal/core/jsonrpc/types/input/callRequest.ts +0 -4
  356. package/src/internal/core/jsonrpc/types/input/filterRequest.ts +0 -4
  357. package/src/internal/core/jsonrpc/types/input/transactionRequest.ts +0 -4
  358. package/src/internal/core/jsonrpc/types/output/block.ts +0 -4
  359. package/src/internal/core/jsonrpc/types/output/log.ts +0 -4
  360. package/src/internal/core/jsonrpc/types/output/receipt.ts +0 -4
  361. package/src/internal/core/jsonrpc/types/output/transaction.ts +0 -4
  362. package/src/internal/core/providers/accounts.ts +16 -26
  363. package/src/internal/core/providers/construction.ts +5 -3
  364. package/src/internal/core/providers/gas-providers.ts +25 -33
  365. package/src/internal/core/providers/util.ts +1 -1
  366. package/src/internal/hardhat-network/jsonrpc/client.ts +22 -22
  367. package/src/internal/hardhat-network/provider/BlockchainBase.ts +62 -25
  368. package/src/internal/hardhat-network/provider/BlockchainData.ts +39 -42
  369. package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +21 -21
  370. package/src/internal/hardhat-network/provider/PoolState.ts +3 -4
  371. package/src/internal/hardhat-network/provider/TransactionQueue.ts +11 -8
  372. package/src/internal/hardhat-network/provider/TxPool.ts +62 -64
  373. package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +3 -3
  374. package/src/internal/hardhat-network/provider/filter.ts +9 -12
  375. package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +52 -50
  376. package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +35 -60
  377. package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +2 -2
  378. package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +3 -3
  379. package/src/internal/hardhat-network/provider/modules/eth.ts +88 -63
  380. package/src/internal/hardhat-network/provider/modules/evm.ts +19 -22
  381. package/src/internal/hardhat-network/provider/modules/hardhat.ts +21 -19
  382. package/src/internal/hardhat-network/provider/modules/logger.ts +33 -40
  383. package/src/internal/hardhat-network/provider/modules/net.ts +1 -1
  384. package/src/internal/hardhat-network/provider/modules/personal.ts +2 -1
  385. package/src/internal/hardhat-network/provider/modules/web3.ts +5 -4
  386. package/src/internal/hardhat-network/provider/node-types.ts +32 -31
  387. package/src/internal/hardhat-network/provider/node.ts +379 -343
  388. package/src/internal/hardhat-network/provider/output.ts +32 -37
  389. package/src/internal/hardhat-network/provider/provider.ts +5 -6
  390. package/src/internal/hardhat-network/provider/return-data.ts +2 -3
  391. package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +51 -24
  392. package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +50 -23
  393. package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +29 -11
  394. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +12 -24
  395. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +11 -22
  396. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +3 -3
  397. package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +8 -9
  398. package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +4 -0
  399. package/src/internal/hardhat-network/provider/utils/makeAccount.ts +4 -10
  400. package/src/internal/hardhat-network/provider/utils/makeCommon.ts +8 -34
  401. package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +8 -9
  402. package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +3 -3
  403. package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +34 -6
  404. package/src/internal/hardhat-network/provider/utils/random.ts +54 -0
  405. package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +6 -7
  406. package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +8 -8
  407. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +7 -2
  408. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +1 -1
  409. package/src/internal/hardhat-network/stack-traces/debug.ts +1 -1
  410. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +6 -7
  411. package/src/internal/hardhat-network/stack-traces/message-trace.ts +6 -7
  412. package/src/internal/hardhat-network/stack-traces/model.ts +1 -1
  413. package/src/internal/hardhat-network/stack-traces/panic-errors.ts +3 -5
  414. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +16 -1
  415. package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +6 -6
  416. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +5 -0
  417. package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +106 -103
  418. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +23 -18
  419. package/src/internal/solidity/compiler/downloader.ts +5 -2
  420. package/src/internal/util/bigint.ts +84 -0
  421. package/src/internal/util/hardforks.ts +4 -29
  422. package/src/internal/util/wei-values.ts +11 -13
  423. package/src/types/config.ts +8 -10
  424. package/types/config.d.ts +8 -9
  425. package/types/config.d.ts.map +1 -1
  426. package/src/internal/hardhat-network/provider/fork/random.ts +0 -33
  427. package/src/internal/hardhat-network/provider/utils/bnToHex.ts +0 -5
  428. package/src/internal/hardhat-network/provider/utils/makeForkCommon.ts +0 -15
@@ -1,32 +1,32 @@
1
- import { Block, HeaderData } from "@ethereumjs/block";
2
- import Common from "@ethereumjs/common";
1
+ import { Block, HeaderData } from "@ignored/block";
2
+ import { Common } from "@ignored/common";
3
3
  import {
4
4
  AccessListEIP2930Transaction,
5
5
  FeeMarketEIP1559Transaction,
6
6
  Transaction,
7
7
  TypedTransaction,
8
- } from "@ethereumjs/tx";
9
- import VM from "@ethereumjs/vm";
10
- import Bloom from "@ethereumjs/vm/dist/bloom";
11
- import { EVMResult, ExecResult } from "@ethereumjs/vm/dist/evm/evm";
12
- import { ERROR } from "@ethereumjs/vm/dist/exceptions";
13
- import { RunBlockResult } from "@ethereumjs/vm/dist/runBlock";
14
- import { DefaultStateManager, StateManager } from "@ethereumjs/vm/dist/state";
15
- import { SignTypedDataVersion, signTypedData } from "@metamask/eth-sig-util";
16
- import chalk from "chalk";
17
- import debug from "debug";
8
+ } from "@ignored/tx";
18
9
  import {
19
10
  Address,
20
- BN,
21
- bufferToHex,
22
11
  ECDSASignature,
12
+ bigIntToBuffer,
13
+ bufferToHex,
23
14
  ecsign,
24
15
  hashPersonalMessage,
25
16
  privateToAddress,
17
+ setLengthLeft,
26
18
  toBuffer,
27
- } from "ethereumjs-util";
19
+ } from "@ignored/util";
20
+ import { Bloom, EEI, RunBlockResult, RunTxResult, VM } from "@ignored/vm";
21
+ import { EVM, EVMResult } from "@ignored/evm";
22
+ import { ERROR } from "@ignored/evm/dist/exceptions";
23
+ import { DefaultStateManager, StateManager } from "@ignored/statemanager";
24
+ import { SignTypedDataVersion, signTypedData } from "@metamask/eth-sig-util";
25
+ import chalk from "chalk";
26
+ import debug from "debug";
28
27
  import EventEmitter from "events";
29
28
 
29
+ import { BigIntUtils } from "../../util/bigint";
30
30
  import { CompilerInput, CompilerOutput } from "../../../types";
31
31
  import { HardforkHistoryConfig } from "../../../types/config";
32
32
  import { HARDHAT_NETWORK_SUPPORTED_HARDFORKS } from "../../constants";
@@ -71,7 +71,7 @@ import { VmTraceDecoder } from "../stack-traces/vm-trace-decoder";
71
71
  import { VMTracer } from "../stack-traces/vm-tracer";
72
72
 
73
73
  import "./ethereumjs-workarounds";
74
- import { rpcQuantityToBN } from "../../core/jsonrpc/types/base-types";
74
+ import { rpcQuantityToBigInt } from "../../core/jsonrpc/types/base-types";
75
75
  import { JsonRpcClient } from "../jsonrpc/client";
76
76
  import { bloomFilter, Filter, filterLogs, LATEST_BLOCK, Type } from "./filter";
77
77
  import { ForkBlockchain } from "./fork/ForkBlockchain";
@@ -112,9 +112,11 @@ import { getCurrentTimestamp } from "./utils/getCurrentTimestamp";
112
112
  import { makeCommon } from "./utils/makeCommon";
113
113
  import { makeForkClient } from "./utils/makeForkClient";
114
114
  import { makeStateTrie } from "./utils/makeStateTrie";
115
- import { makeForkCommon } from "./utils/makeForkCommon";
116
115
  import { putGenesisBlock } from "./utils/putGenesisBlock";
117
116
  import { txMapToArray } from "./utils/txMapToArray";
117
+ import { RandomBufferGenerator } from "./utils/random";
118
+
119
+ type ExecResult = EVMResult["execResult"];
118
120
 
119
121
  const log = debug("hardhat:core:hardhat-network:node");
120
122
 
@@ -136,23 +138,25 @@ export class HardhatNode extends EventEmitter {
136
138
  chainId,
137
139
  } = config;
138
140
 
139
- let common: Common;
140
141
  let stateManager: StateManager;
141
142
  let blockchain: HardhatBlockchainInterface;
142
- let initialBlockTimeOffset: BN | undefined;
143
- let nextBlockBaseFeePerGas: BN | undefined;
143
+ let initialBlockTimeOffset: bigint | undefined;
144
+ let nextBlockBaseFeePerGas: bigint | undefined;
144
145
  let forkNetworkId: number | undefined;
145
- let forkBlockNum: number | undefined;
146
+ let forkBlockNum: bigint | undefined;
146
147
  let hardforkActivations: HardforkHistoryConfig = new Map();
147
148
 
148
149
  const initialBaseFeePerGasConfig =
149
150
  config.initialBaseFeePerGas !== undefined
150
- ? new BN(config.initialBaseFeePerGas)
151
+ ? BigInt(config.initialBaseFeePerGas)
151
152
  : undefined;
152
153
 
153
154
  const hardfork = getHardforkName(config.hardfork);
155
+ const mixHashGenerator = RandomBufferGenerator.create("randomMixHashSeed");
154
156
  let forkClient: JsonRpcClient | undefined;
155
157
 
158
+ const common = makeCommon(config);
159
+
156
160
  if (isForkedNodeConfig(config)) {
157
161
  const {
158
162
  forkClient: _forkClient,
@@ -160,13 +164,12 @@ export class HardhatNode extends EventEmitter {
160
164
  forkBlockTimestamp,
161
165
  } = await makeForkClient(config.forkConfig, config.forkCachePath);
162
166
  forkClient = _forkClient;
163
- common = await makeForkCommon(config);
164
167
 
165
168
  forkNetworkId = forkClient.getNetworkId();
166
- forkBlockNum = forkBlockNumber.toNumber();
169
+ forkBlockNum = forkBlockNumber;
167
170
 
168
171
  this._validateHardforks(
169
- config.forkConfig.blockNumber,
172
+ BigIntUtils.mapNumberToBigInt(config.forkConfig.blockNumber),
170
173
  common,
171
174
  forkNetworkId
172
175
  );
@@ -180,7 +183,7 @@ export class HardhatNode extends EventEmitter {
180
183
 
181
184
  blockchain = new ForkBlockchain(forkClient, forkBlockNumber, common);
182
185
 
183
- initialBlockTimeOffset = new BN(
186
+ initialBlockTimeOffset = BigInt(
184
187
  getDifferenceInSeconds(new Date(forkBlockTimestamp), new Date())
185
188
  );
186
189
 
@@ -195,7 +198,7 @@ export class HardhatNode extends EventEmitter {
195
198
  } else {
196
199
  const latestBlock = await blockchain.getLatestBlock();
197
200
  if (latestBlock.header.baseFeePerGas === undefined) {
198
- nextBlockBaseFeePerGas = new BN(
201
+ nextBlockBaseFeePerGas = BigInt(
199
202
  HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS
200
203
  );
201
204
  }
@@ -207,10 +210,8 @@ export class HardhatNode extends EventEmitter {
207
210
  }
208
211
  } else {
209
212
  const stateTrie = await makeStateTrie(genesisAccounts);
210
- common = makeCommon(config, stateTrie);
211
213
 
212
214
  stateManager = new DefaultStateManager({
213
- common,
214
215
  trie: stateTrie,
215
216
  });
216
217
 
@@ -221,17 +222,21 @@ export class HardhatNode extends EventEmitter {
221
222
  HardforkName.LONDON
222
223
  )
223
224
  ? initialBaseFeePerGasConfig ??
224
- new BN(HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS)
225
+ BigInt(HARDHAT_NETWORK_DEFAULT_INITIAL_BASE_FEE_PER_GAS)
225
226
  : undefined;
226
227
 
227
228
  await putGenesisBlock(
228
229
  hardhatBlockchain,
229
230
  common,
231
+ config,
232
+ stateTrie,
233
+ hardfork,
234
+ mixHashGenerator.next(),
230
235
  genesisBlockBaseFeePerGas
231
236
  );
232
237
 
233
238
  if (config.initialDate !== undefined) {
234
- initialBlockTimeOffset = new BN(
239
+ initialBlockTimeOffset = BigInt(
235
240
  getDifferenceInSeconds(config.initialDate, new Date())
236
241
  );
237
242
  }
@@ -239,14 +244,21 @@ export class HardhatNode extends EventEmitter {
239
244
  blockchain = hardhatBlockchain;
240
245
  }
241
246
 
242
- const txPool = new TxPool(stateManager, new BN(blockGasLimit), common);
247
+ const txPool = new TxPool(stateManager, BigInt(blockGasLimit), common);
243
248
 
244
- const vm = new VM({
249
+ const eei = new EEI(stateManager, common, blockchain);
250
+ const evm = await EVM.create({
251
+ eei,
252
+ allowUnlimitedContractSize,
245
253
  common,
254
+ });
255
+
256
+ const vm = await VM.create({
257
+ evm,
246
258
  activatePrecompiles: true,
259
+ common,
247
260
  stateManager,
248
- blockchain: blockchain as any,
249
- allowUnlimitedContractSize,
261
+ blockchain,
250
262
  });
251
263
 
252
264
  const node = new HardhatNode(
@@ -262,7 +274,9 @@ export class HardhatNode extends EventEmitter {
262
274
  genesisAccounts,
263
275
  networkId,
264
276
  chainId,
277
+ hardfork,
265
278
  hardforkActivations,
279
+ mixHashGenerator,
266
280
  tracingConfig,
267
281
  forkNetworkId,
268
282
  forkBlockNum,
@@ -274,7 +288,7 @@ export class HardhatNode extends EventEmitter {
274
288
  }
275
289
 
276
290
  private static _validateHardforks(
277
- forkBlockNumber: number | undefined,
291
+ forkBlockNumber: bigint | undefined,
278
292
  common: Common,
279
293
  remoteChainId: number
280
294
  ): void {
@@ -312,10 +326,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
312
326
  private readonly _localAccounts: Map<string, Buffer> = new Map(); // address => private key
313
327
  private readonly _impersonatedAccounts: Set<string> = new Set(); // address
314
328
 
315
- private _nextBlockTimestamp: BN = new BN(0);
316
- private _userProvidedNextBlockBaseFeePerGas?: BN;
329
+ private _nextBlockTimestamp: bigint = 0n;
330
+ private _userProvidedNextBlockBaseFeePerGas?: bigint;
317
331
 
318
- private _lastFilterId = new BN(0);
332
+ private _lastFilterId: bigint = 0n;
319
333
  private _filters: Map<string, Filter> = new Map();
320
334
 
321
335
  private _nextSnapshotId = 1; // We start in 1 to mimic Ganache
@@ -327,7 +341,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
327
341
  private readonly _consoleLogger: ConsoleLogger = new ConsoleLogger();
328
342
  private _failedStackTraces = 0;
329
343
 
330
- private _irregularStatesByBlockNumber: Map<string, Buffer> = new Map(); // blockNumber as BN.toString() => state root
344
+ // blockNumber => state root
345
+ private _irregularStatesByBlockNumber: Map<bigint, Buffer> = new Map();
331
346
 
332
347
  private constructor(
333
348
  private readonly _vm: VM,
@@ -335,18 +350,20 @@ Hardhat Network's forking functionality only works with blocks from at least spu
335
350
  private readonly _blockchain: HardhatBlockchainInterface,
336
351
  private readonly _txPool: TxPool,
337
352
  private _automine: boolean,
338
- private _minGasPrice: BN,
339
- private _blockTimeOffsetSeconds: BN = new BN(0),
353
+ private _minGasPrice: bigint,
354
+ private _blockTimeOffsetSeconds: bigint = 0n,
340
355
  private _mempoolOrder: MempoolOrder,
341
356
  private _coinbase: string,
342
357
  genesisAccounts: GenesisAccount[],
343
358
  private readonly _configNetworkId: number,
344
359
  private readonly _configChainId: number,
360
+ public readonly hardfork: HardforkName,
345
361
  private readonly _hardforkActivations: HardforkHistoryConfig,
362
+ private _mixHashGenerator: RandomBufferGenerator,
346
363
  tracingConfig?: TracingConfig,
347
364
  private _forkNetworkId?: number,
348
- private _forkBlockNumber?: number,
349
- nextBlockBaseFee?: BN,
365
+ private _forkBlockNumber?: bigint,
366
+ nextBlockBaseFee?: bigint,
350
367
  private _forkClient?: JsonRpcClient
351
368
  ) {
352
369
  super();
@@ -452,13 +469,15 @@ Hardhat Network's forking functionality only works with blocks from at least spu
452
469
  return this._mineTransaction(tx);
453
470
  }
454
471
 
455
- public async mineBlock(timestamp?: BN): Promise<MineBlockResult> {
456
- const [blockTimestamp, offsetShouldChange, newOffset] =
457
- this._calculateTimestampAndOffset(timestamp);
472
+ public async mineBlock(timestamp?: bigint): Promise<MineBlockResult> {
473
+ const timestampAndOffset = this._calculateTimestampAndOffset(timestamp);
474
+ let [blockTimestamp] = timestampAndOffset;
475
+ const [, offsetShouldChange, newOffset] = timestampAndOffset;
476
+
458
477
  const needsTimestampIncrease =
459
478
  await this._timestampClashesWithPreviousBlockOne(blockTimestamp);
460
479
  if (needsTimestampIncrease) {
461
- blockTimestamp.iaddn(1);
480
+ blockTimestamp += 1n;
462
481
  }
463
482
 
464
483
  let result: MineBlockResult;
@@ -485,7 +504,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
485
504
  await this._saveBlockAsSuccessfullyRun(result.block, result.blockResult);
486
505
 
487
506
  if (needsTimestampIncrease) {
488
- this.increaseTime(new BN(1));
507
+ this.increaseTime(1n);
489
508
  }
490
509
 
491
510
  if (offsetShouldChange) {
@@ -506,10 +525,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
506
525
  * ones that were reserved are not included).
507
526
  */
508
527
  public async mineBlocks(
509
- count: BN = new BN(1),
510
- interval: BN = new BN(1)
528
+ count: bigint = 1n,
529
+ interval: bigint = 1n
511
530
  ): Promise<MineBlockResult[]> {
512
- if (count.eqn(0)) {
531
+ if (count === 0n) {
513
532
  // nothing to do
514
533
  return [];
515
534
  }
@@ -522,15 +541,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
522
541
  // helper function to mine a block with a timstamp that respects the
523
542
  // interval
524
543
  const mineBlock = async () => {
525
- const nextTimestamp = (await this.getLatestBlock()).header.timestamp.add(
526
- interval
527
- );
544
+ const nextTimestamp =
545
+ (await this.getLatestBlock()).header.timestamp + interval;
528
546
  mineBlockResults.push(await this.mineBlock(nextTimestamp));
529
547
  };
530
548
 
531
549
  // then we mine any pending transactions
532
550
  while (
533
- count.gtn(mineBlockResults.length) &&
551
+ count > mineBlockResults.length &&
534
552
  this._txPool.hasPendingTransactions()
535
553
  ) {
536
554
  await mineBlock();
@@ -539,18 +557,18 @@ Hardhat Network's forking functionality only works with blocks from at least spu
539
557
  // If there is at least one remaining block, we mine one. This way, we
540
558
  // guarantee that there's an empty block immediately before and after the
541
559
  // reservation. This makes the logging easier to get right.
542
- if (count.gtn(mineBlockResults.length)) {
560
+ if (count > mineBlockResults.length) {
543
561
  await mineBlock();
544
562
  }
545
563
 
546
- const remainingBlockCount = count.subn(mineBlockResults.length);
564
+ const remainingBlockCount = count - BigInt(mineBlockResults.length);
547
565
 
548
566
  // There should be at least 2 blocks left for the reservation to work,
549
567
  // because we always mine a block after it. But here we use a bigger
550
568
  // number to err on the safer side.
551
- if (remainingBlockCount.lten(5)) {
569
+ if (remainingBlockCount <= 5) {
552
570
  // if there are few blocks left to mine, we just mine them
553
- while (count.gtn(mineBlockResults.length)) {
571
+ while (count > mineBlockResults.length) {
554
572
  await mineBlock();
555
573
  }
556
574
 
@@ -560,7 +578,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
560
578
  // otherwise, we reserve a range and mine the last one
561
579
  const latestBlock = await this.getLatestBlock();
562
580
  this._blockchain.reserveBlocks(
563
- remainingBlockCount.subn(1),
581
+ remainingBlockCount - 1n,
564
582
  interval,
565
583
  await this._stateManager.getStateRoot(),
566
584
  await this.getBlockTotalDifficulty(latestBlock),
@@ -574,7 +592,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
574
592
 
575
593
  public async runCall(
576
594
  call: CallParams,
577
- blockNumberOrPending: BN | "pending"
595
+ blockNumberOrPending: bigint | "pending"
578
596
  ): Promise<RunCallResult> {
579
597
  let txParams: TransactionParams;
580
598
 
@@ -588,14 +606,13 @@ Hardhat Network's forking functionality only works with blocks from at least spu
588
606
  !this.isEip1559Active(blockNumberOrPending)
589
607
  ) {
590
608
  txParams = {
591
- gasPrice: new BN(0),
609
+ gasPrice: 0n,
592
610
  nonce,
593
611
  ...call,
594
612
  };
595
613
  } else {
596
- const maxFeePerGas =
597
- call.maxFeePerGas ?? call.maxPriorityFeePerGas ?? new BN(0);
598
- const maxPriorityFeePerGas = call.maxPriorityFeePerGas ?? new BN(0);
614
+ const maxFeePerGas = call.maxFeePerGas ?? call.maxPriorityFeePerGas ?? 0n;
615
+ const maxPriorityFeePerGas = call.maxPriorityFeePerGas ?? 0n;
599
616
 
600
617
  txParams = {
601
618
  ...call,
@@ -623,8 +640,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
623
640
 
624
641
  public async getAccountBalance(
625
642
  address: Address,
626
- blockNumberOrPending?: BN | "pending"
627
- ): Promise<BN> {
643
+ blockNumberOrPending?: bigint | "pending"
644
+ ): Promise<bigint> {
628
645
  if (blockNumberOrPending === undefined) {
629
646
  blockNumberOrPending = this.getLatestBlockNumber();
630
647
  }
@@ -633,27 +650,27 @@ Hardhat Network's forking functionality only works with blocks from at least spu
633
650
  this._stateManager.getAccount(address)
634
651
  );
635
652
 
636
- return new BN(account.balance);
653
+ return account.balance;
637
654
  }
638
655
 
639
656
  public async getNextConfirmedNonce(
640
657
  address: Address,
641
- blockNumberOrPending: BN | "pending"
642
- ): Promise<BN> {
658
+ blockNumberOrPending: bigint | "pending"
659
+ ): Promise<bigint> {
643
660
  const account = await this._runInBlockContext(blockNumberOrPending, () =>
644
661
  this._stateManager.getAccount(address)
645
662
  );
646
663
 
647
- return new BN(account.nonce);
664
+ return account.nonce;
648
665
  }
649
666
 
650
- public async getAccountNextPendingNonce(address: Address): Promise<BN> {
667
+ public async getAccountNextPendingNonce(address: Address): Promise<bigint> {
651
668
  return this._txPool.getNextPendingNonce(address);
652
669
  }
653
670
 
654
671
  public async getCodeFromTrace(
655
672
  trace: MessageTrace | undefined,
656
- blockNumberOrPending: BN | "pending"
673
+ blockNumberOrPending: bigint | "pending"
657
674
  ): Promise<Buffer> {
658
675
  if (
659
676
  trace === undefined ||
@@ -670,11 +687,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
670
687
  return this._blockchain.getLatestBlock();
671
688
  }
672
689
 
673
- public getLatestBlockNumber(): BN {
690
+ public getLatestBlockNumber(): bigint {
674
691
  return this._blockchain.getLatestBlockNumber();
675
692
  }
676
693
 
677
- public async getPendingBlockAndTotalDifficulty(): Promise<[Block, BN]> {
694
+ public async getPendingBlockAndTotalDifficulty(): Promise<[Block, bigint]> {
678
695
  return this._runInPendingBlockContext(async () => {
679
696
  const block = await this._blockchain.getLatestBlock();
680
697
  const totalDifficulty = await this._blockchain.getTotalDifficulty(
@@ -689,13 +706,13 @@ Hardhat Network's forking functionality only works with blocks from at least spu
689
706
  return [...this._localAccounts.keys()];
690
707
  }
691
708
 
692
- public getBlockGasLimit(): BN {
709
+ public getBlockGasLimit(): bigint {
693
710
  return this._txPool.getBlockGasLimit();
694
711
  }
695
712
 
696
713
  public async estimateGas(
697
714
  callParams: CallParams,
698
- blockNumberOrPending: BN | "pending"
715
+ blockNumberOrPending: bigint | "pending"
699
716
  ): Promise<EstimateGasResult> {
700
717
  // We get the CallParams and transform it into a TransactionParams to be
701
718
  // able to run it.
@@ -780,7 +797,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
780
797
  };
781
798
  }
782
799
 
783
- const initialEstimation = result.gasUsed;
800
+ const initialEstimation = result.totalGasSpent;
784
801
 
785
802
  return {
786
803
  estimation: await this._correctInitialEstimation(
@@ -793,20 +810,20 @@ Hardhat Network's forking functionality only works with blocks from at least spu
793
810
  };
794
811
  }
795
812
 
796
- public async getGasPrice(): Promise<BN> {
813
+ public async getGasPrice(): Promise<bigint> {
797
814
  const nextBlockBaseFeePerGas = await this.getNextBlockBaseFeePerGas();
798
815
 
799
816
  if (nextBlockBaseFeePerGas === undefined) {
800
817
  // We return a hardcoded value for networks without EIP-1559
801
- return new BN(8e9);
818
+ return 8n * 10n ** 9n;
802
819
  }
803
820
 
804
- const suggestedPriorityFeePerGas = new BN(1e9);
805
- return nextBlockBaseFeePerGas.add(suggestedPriorityFeePerGas);
821
+ const suggestedPriorityFeePerGas = 10n ** 9n;
822
+ return nextBlockBaseFeePerGas + suggestedPriorityFeePerGas;
806
823
  }
807
824
 
808
- public async getMaxPriorityFeePerGas(): Promise<BN> {
809
- return new BN(HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS);
825
+ public async getMaxPriorityFeePerGas(): Promise<bigint> {
826
+ return BigInt(HARDHAT_NETWORK_DEFAULT_MAX_PRIORITY_FEE_PER_GAS);
810
827
  }
811
828
 
812
829
  public getCoinbaseAddress(): Address {
@@ -815,10 +832,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
815
832
 
816
833
  public async getStorageAt(
817
834
  address: Address,
818
- positionIndex: BN,
819
- blockNumberOrPending: BN | "pending"
835
+ positionIndex: bigint,
836
+ blockNumberOrPending: bigint | "pending"
820
837
  ): Promise<Buffer> {
821
- const key = positionIndex.toArrayLike(Buffer, "be", 32);
838
+ const key = setLengthLeft(bigIntToBuffer(positionIndex), 32);
822
839
 
823
840
  const data = await this._runInBlockContext(blockNumberOrPending, () =>
824
841
  this._stateManager.getContractStorage(address, key)
@@ -837,11 +854,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
837
854
 
838
855
  public async getBlockByNumber(pending: "pending"): Promise<Block>;
839
856
  public async getBlockByNumber(
840
- blockNumberOrPending: BN | "pending"
857
+ blockNumberOrPending: bigint | "pending"
841
858
  ): Promise<Block | undefined>;
842
859
 
843
860
  public async getBlockByNumber(
844
- blockNumberOrPending: BN | "pending"
861
+ blockNumberOrPending: bigint | "pending"
845
862
  ): Promise<Block | undefined> {
846
863
  if (blockNumberOrPending === "pending") {
847
864
  return this._runInPendingBlockContext(() =>
@@ -865,44 +882,44 @@ Hardhat Network's forking functionality only works with blocks from at least spu
865
882
  return block ?? undefined;
866
883
  }
867
884
 
868
- public async getBlockTotalDifficulty(block: Block): Promise<BN> {
885
+ public async getBlockTotalDifficulty(block: Block): Promise<bigint> {
869
886
  return this._blockchain.getTotalDifficulty(block.hash());
870
887
  }
871
888
 
872
889
  public async getCode(
873
890
  address: Address,
874
- blockNumberOrPending: BN | "pending"
891
+ blockNumberOrPending: bigint | "pending"
875
892
  ): Promise<Buffer> {
876
893
  return this._runInBlockContext(blockNumberOrPending, () =>
877
894
  this._stateManager.getContractCode(address)
878
895
  );
879
896
  }
880
897
 
881
- public getNextBlockTimestamp(): BN {
882
- return this._nextBlockTimestamp.clone();
898
+ public getNextBlockTimestamp(): bigint {
899
+ return this._nextBlockTimestamp;
883
900
  }
884
901
 
885
- public setNextBlockTimestamp(timestamp: BN) {
886
- this._nextBlockTimestamp = new BN(timestamp);
902
+ public setNextBlockTimestamp(timestamp: bigint) {
903
+ this._nextBlockTimestamp = timestamp;
887
904
  }
888
905
 
889
- public getTimeIncrement(): BN {
890
- return this._blockTimeOffsetSeconds.clone();
906
+ public getTimeIncrement(): bigint {
907
+ return this._blockTimeOffsetSeconds;
891
908
  }
892
909
 
893
- public setTimeIncrement(timeIncrement: BN) {
910
+ public setTimeIncrement(timeIncrement: bigint) {
894
911
  this._blockTimeOffsetSeconds = timeIncrement;
895
912
  }
896
913
 
897
- public increaseTime(increment: BN) {
898
- this._blockTimeOffsetSeconds = this._blockTimeOffsetSeconds.add(increment);
914
+ public increaseTime(increment: bigint) {
915
+ this._blockTimeOffsetSeconds += increment;
899
916
  }
900
917
 
901
- public setUserProvidedNextBlockBaseFeePerGas(baseFeePerGas: BN) {
918
+ public setUserProvidedNextBlockBaseFeePerGas(baseFeePerGas: bigint) {
902
919
  this._userProvidedNextBlockBaseFeePerGas = baseFeePerGas;
903
920
  }
904
921
 
905
- public getUserProvidedNextBlockBaseFeePerGas(): BN | undefined {
922
+ public getUserProvidedNextBlockBaseFeePerGas(): bigint | undefined {
906
923
  return this._userProvidedNextBlockBaseFeePerGas;
907
924
  }
908
925
 
@@ -910,7 +927,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
910
927
  this._userProvidedNextBlockBaseFeePerGas = undefined;
911
928
  }
912
929
 
913
- public async getNextBlockBaseFeePerGas(): Promise<BN | undefined> {
930
+ public async getNextBlockBaseFeePerGas(): Promise<bigint | undefined> {
914
931
  if (!this.isEip1559Active()) {
915
932
  return undefined;
916
933
  }
@@ -986,6 +1003,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
986
1003
  userProvidedNextBlockBaseFeePerGas:
987
1004
  this.getUserProvidedNextBlockBaseFeePerGas(),
988
1005
  coinbase: this.getCoinbaseAddress().toString(),
1006
+ mixHashGenerator: this._mixHashGenerator.clone(),
989
1007
  };
990
1008
 
991
1009
  this._irregularStatesByBlockNumber = new Map(
@@ -1011,9 +1029,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1011
1029
  const now = new Date();
1012
1030
  const offsetToSnapshotInMillis = snapshot.date.valueOf() - now.valueOf();
1013
1031
  const offsetToSnapshotInSecs = Math.ceil(offsetToSnapshotInMillis / 1000);
1014
- const newOffset = snapshot.blockTimeOffsetSeconds.addn(
1015
- offsetToSnapshotInSecs
1016
- );
1032
+ const newOffset =
1033
+ snapshot.blockTimeOffsetSeconds + BigInt(offsetToSnapshotInSecs);
1017
1034
 
1018
1035
  // We delete all following blocks, changes the state root, and all the
1019
1036
  // relevant Node fields.
@@ -1023,7 +1040,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1023
1040
  this._blockchain.deleteLaterBlocks(snapshot.latestBlock);
1024
1041
  this._irregularStatesByBlockNumber = snapshot.irregularStatesByBlockNumber;
1025
1042
  const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(
1026
- (await this.getLatestBlock()).header.number.toString()
1043
+ (await this.getLatestBlock()).header.number
1027
1044
  );
1028
1045
  await this._stateManager.setStateRoot(
1029
1046
  irregularStateOrUndefined ?? snapshot.stateRoot
@@ -1042,6 +1059,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1042
1059
 
1043
1060
  this._coinbase = snapshot.coinbase;
1044
1061
 
1062
+ this._mixHashGenerator = snapshot.mixHashGenerator;
1063
+
1045
1064
  // We delete this and the following snapshots, as they can only be used
1046
1065
  // once in Ganache
1047
1066
  this._snapshots.splice(snapshotIndex);
@@ -1052,7 +1071,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1052
1071
  public async newFilter(
1053
1072
  filterParams: FilterParams,
1054
1073
  isSubscription: boolean
1055
- ): Promise<BN> {
1074
+ ): Promise<bigint> {
1056
1075
  filterParams = await this._computeFilterParams(filterParams, true);
1057
1076
 
1058
1077
  const filterId = this._getNextFilterId();
@@ -1074,7 +1093,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1074
1093
  return filterId;
1075
1094
  }
1076
1095
 
1077
- public async newBlockFilter(isSubscription: boolean): Promise<BN> {
1096
+ public async newBlockFilter(isSubscription: boolean): Promise<bigint> {
1078
1097
  const block = await this.getLatestBlock();
1079
1098
 
1080
1099
  const filterId = this._getNextFilterId();
@@ -1092,7 +1111,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1092
1111
 
1093
1112
  public async newPendingTransactionFilter(
1094
1113
  isSubscription: boolean
1095
- ): Promise<BN> {
1114
+ ): Promise<bigint> {
1096
1115
  const filterId = this._getNextFilterId();
1097
1116
 
1098
1117
  this._filters.set(this._filterIdToFiltersKey(filterId), {
@@ -1108,7 +1127,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1108
1127
  }
1109
1128
 
1110
1129
  public async uninstallFilter(
1111
- filterId: BN,
1130
+ filterId: bigint,
1112
1131
  subscription: boolean
1113
1132
  ): Promise<boolean> {
1114
1133
  const key = this._filterIdToFiltersKey(filterId);
@@ -1130,7 +1149,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1130
1149
  }
1131
1150
 
1132
1151
  public async getFilterChanges(
1133
- filterId: BN
1152
+ filterId: bigint
1134
1153
  ): Promise<string[] | RpcLogOutput[] | undefined> {
1135
1154
  const key = this._filterIdToFiltersKey(filterId);
1136
1155
  const filter = this._filters.get(key);
@@ -1155,7 +1174,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1155
1174
  }
1156
1175
 
1157
1176
  public async getFilterLogs(
1158
- filterId: BN
1177
+ filterId: bigint
1159
1178
  ): Promise<RpcLogOutput[] | undefined> {
1160
1179
  const key = this._filterIdToFiltersKey(filterId);
1161
1180
  const filter = this._filters.get(key);
@@ -1225,12 +1244,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1225
1244
  return this._automine;
1226
1245
  }
1227
1246
 
1228
- public async setBlockGasLimit(gasLimit: BN | number) {
1247
+ public async setBlockGasLimit(gasLimit: bigint | number) {
1229
1248
  this._txPool.setBlockGasLimit(gasLimit);
1230
1249
  await this._txPool.updatePendingAndQueued();
1231
1250
  }
1232
1251
 
1233
- public async setMinGasPrice(minGasPrice: BN) {
1252
+ public async setMinGasPrice(minGasPrice: bigint) {
1234
1253
  this._minGasPrice = minGasPrice;
1235
1254
  }
1236
1255
 
@@ -1255,7 +1274,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1255
1274
 
1256
1275
  public async setAccountBalance(
1257
1276
  address: Address,
1258
- newBalance: BN
1277
+ newBalance: bigint
1259
1278
  ): Promise<void> {
1260
1279
  const account = await this._stateManager.getAccount(address);
1261
1280
  account.balance = newBalance;
@@ -1273,7 +1292,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1273
1292
 
1274
1293
  public async setNextConfirmedNonce(
1275
1294
  address: Address,
1276
- newNonce: BN
1295
+ newNonce: bigint
1277
1296
  ): Promise<void> {
1278
1297
  if (!this._txPool.isEmpty()) {
1279
1298
  throw new InternalError(
@@ -1281,7 +1300,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1281
1300
  );
1282
1301
  }
1283
1302
  const account = await this._stateManager.getAccount(address);
1284
- if (newNonce.lt(account.nonce)) {
1303
+ if (newNonce < account.nonce) {
1285
1304
  throw new InvalidInputError(
1286
1305
  `New nonce (${newNonce.toString()}) must not be smaller than the existing nonce (${account.nonce.toString()})`
1287
1306
  );
@@ -1293,12 +1312,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1293
1312
 
1294
1313
  public async setStorageAt(
1295
1314
  address: Address,
1296
- positionIndex: BN,
1315
+ positionIndex: bigint,
1297
1316
  value: Buffer
1298
1317
  ) {
1299
1318
  await this._stateManager.putContractStorage(
1300
1319
  address,
1301
- positionIndex.toArrayLike(Buffer, "be", 32),
1320
+ setLengthLeft(bigIntToBuffer(positionIndex), 32),
1302
1321
  value
1303
1322
  );
1304
1323
  await this._persistIrregularWorldState();
@@ -1312,126 +1331,123 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1312
1331
  );
1313
1332
  }
1314
1333
 
1315
- return this._runInBlockContext(
1316
- new BN(block.header.number).subn(1),
1317
- async () => {
1318
- const blockNumber = block.header.number.toNumber();
1319
- const blockchain = this._blockchain;
1320
- let vm = this._vm;
1321
- if (
1322
- blockchain instanceof ForkBlockchain &&
1323
- blockNumber <= blockchain.getForkBlockNumber().toNumber()
1324
- ) {
1325
- assertHardhatInvariant(
1326
- this._forkNetworkId !== undefined,
1327
- "this._forkNetworkId should exist if the blockchain is an instance of ForkBlockchain"
1328
- );
1334
+ return this._runInBlockContext(block.header.number - 1n, async () => {
1335
+ const blockNumber = block.header.number;
1336
+ const blockchain = this._blockchain;
1337
+ let vm = this._vm;
1338
+ if (
1339
+ blockchain instanceof ForkBlockchain &&
1340
+ blockNumber <= blockchain.getForkBlockNumber()
1341
+ ) {
1342
+ assertHardhatInvariant(
1343
+ this._forkNetworkId !== undefined,
1344
+ "this._forkNetworkId should exist if the blockchain is an instance of ForkBlockchain"
1345
+ );
1329
1346
 
1330
- const common = this._getCommonForTracing(
1331
- this._forkNetworkId,
1332
- blockNumber
1333
- );
1347
+ const common = this._getCommonForTracing(
1348
+ this._forkNetworkId,
1349
+ blockNumber
1350
+ );
1334
1351
 
1335
- vm = new VM({
1336
- common,
1337
- activatePrecompiles: true,
1338
- stateManager: this._vm.stateManager,
1339
- blockchain: this._vm.blockchain,
1340
- });
1341
- }
1352
+ vm = await VM.create({
1353
+ common,
1354
+ activatePrecompiles: true,
1355
+ stateManager: this._vm.stateManager,
1356
+ blockchain: this._vm.blockchain,
1357
+ });
1358
+ }
1342
1359
 
1343
- // We don't support tracing transactions before the spuriousDragon fork
1344
- // to avoid having to distinguish between empty and non-existing accounts.
1345
- // We *could* do it during the non-forked mode, but for simplicity we just
1346
- // don't support it at all.
1347
- const isPreSpuriousDragon = !vm._common.gteHardfork("spuriousDragon");
1348
- if (isPreSpuriousDragon) {
1349
- throw new InvalidInputError(
1350
- "Tracing is not supported for transactions using hardforks older than Spurious Dragon. "
1351
- );
1352
- }
1360
+ // We don't support tracing transactions before the spuriousDragon fork
1361
+ // to avoid having to distinguish between empty and non-existing accounts.
1362
+ // We *could* do it during the non-forked mode, but for simplicity we just
1363
+ // don't support it at all.
1364
+ const isPreSpuriousDragon = !vm._common.gteHardfork("spuriousDragon");
1365
+ if (isPreSpuriousDragon) {
1366
+ throw new InvalidInputError(
1367
+ "Tracing is not supported for transactions using hardforks older than Spurious Dragon. "
1368
+ );
1369
+ }
1353
1370
 
1354
- for (const tx of block.transactions) {
1355
- let txWithCommon: TypedTransaction;
1356
- const sender = tx.getSenderAddress();
1357
- if (tx.type === 0) {
1358
- txWithCommon = new FakeSenderTransaction(sender, tx, {
1371
+ for (const tx of block.transactions) {
1372
+ let txWithCommon: TypedTransaction;
1373
+ const sender = tx.getSenderAddress();
1374
+ if (tx.type === 0) {
1375
+ txWithCommon = new FakeSenderTransaction(sender, tx, {
1376
+ common: vm._common,
1377
+ });
1378
+ } else if (tx.type === 1) {
1379
+ txWithCommon = new FakeSenderAccessListEIP2930Transaction(
1380
+ sender,
1381
+ tx,
1382
+ {
1359
1383
  common: vm._common,
1360
- });
1361
- } else if (tx.type === 1) {
1362
- txWithCommon = new FakeSenderAccessListEIP2930Transaction(
1363
- sender,
1364
- tx,
1365
- {
1366
- common: vm._common,
1367
- }
1368
- );
1369
- } else if (tx.type === 2) {
1370
- txWithCommon = new FakeSenderEIP1559Transaction(
1371
- sender,
1372
- { ...tx, gasPrice: undefined },
1373
- {
1374
- common: vm._common,
1375
- }
1376
- );
1377
- } else {
1378
- throw new InternalError(
1379
- "Only legacy, EIP2930, and EIP1559 txs are supported"
1380
- );
1381
- }
1384
+ }
1385
+ );
1386
+ } else if (tx.type === 2) {
1387
+ txWithCommon = new FakeSenderEIP1559Transaction(
1388
+ sender,
1389
+ { ...tx, gasPrice: undefined },
1390
+ {
1391
+ common: vm._common,
1392
+ }
1393
+ );
1394
+ } else {
1395
+ throw new InternalError(
1396
+ "Only legacy, EIP2930, and EIP1559 txs are supported"
1397
+ );
1398
+ }
1382
1399
 
1383
- const txHash = txWithCommon.hash();
1384
- if (txHash.equals(hash)) {
1385
- const vmDebugTracer = new VMDebugTracer(vm);
1386
- return vmDebugTracer.trace(async () => {
1387
- await vm.runTx({ tx: txWithCommon, block });
1388
- }, config);
1389
- }
1390
- await vm.runTx({ tx: txWithCommon, block });
1400
+ const txHash = txWithCommon.hash();
1401
+ if (txHash.equals(hash)) {
1402
+ const vmDebugTracer = new VMDebugTracer(vm);
1403
+ return vmDebugTracer.trace(async () => {
1404
+ await vm.runTx({ tx: txWithCommon, block });
1405
+ }, config);
1391
1406
  }
1392
- throw new TransactionExecutionError(
1393
- `Unable to find a transaction in a block that contains that transaction, this should never happen`
1394
- );
1407
+ await vm.runTx({ tx: txWithCommon, block });
1395
1408
  }
1396
- );
1409
+ throw new TransactionExecutionError(
1410
+ `Unable to find a transaction in a block that contains that transaction, this should never happen`
1411
+ );
1412
+ });
1397
1413
  }
1398
1414
 
1399
1415
  public async getFeeHistory(
1400
- blockCount: BN,
1401
- newestBlock: BN | "pending",
1416
+ blockCount: bigint,
1417
+ newestBlock: bigint | "pending",
1402
1418
  rewardPercentiles: number[]
1403
1419
  ): Promise<FeeHistory> {
1404
1420
  const latestBlock = this.getLatestBlockNumber();
1405
- const pendingBlockNumber = latestBlock.addn(1);
1421
+ const pendingBlockNumber = latestBlock + 1n;
1406
1422
 
1407
1423
  const resolvedNewestBlock =
1408
1424
  newestBlock === "pending" ? pendingBlockNumber : newestBlock;
1409
1425
 
1410
- const oldestBlock = BN.max(
1411
- resolvedNewestBlock.sub(blockCount).addn(1),
1412
- new BN(0)
1426
+ const oldestBlock = BigIntUtils.max(
1427
+ resolvedNewestBlock - blockCount + 1n,
1428
+ 0n
1413
1429
  );
1414
1430
 
1415
1431
  // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
1416
1432
  const rangeIncludesRemoteBlocks =
1417
1433
  this._forkBlockNumber !== undefined &&
1418
- oldestBlock.lten(this._forkBlockNumber);
1434
+ oldestBlock <= this._forkBlockNumber;
1419
1435
 
1420
- const baseFeePerGas: BN[] = [];
1436
+ const baseFeePerGas: bigint[] = [];
1421
1437
  const gasUsedRatio: number[] = [];
1422
- const reward: BN[][] = [];
1438
+ const reward: bigint[][] = [];
1423
1439
 
1424
- const lastBlock = resolvedNewestBlock.addn(1);
1440
+ const lastBlock = resolvedNewestBlock + 1n;
1425
1441
 
1426
1442
  // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
1427
1443
  if (rangeIncludesRemoteBlocks) {
1428
1444
  try {
1429
- const lastRemoteBlock = BN.min(
1430
- new BN(this._forkBlockNumber!),
1445
+ const lastRemoteBlock = BigIntUtils.min(
1446
+ BigInt(this._forkBlockNumber!),
1431
1447
  lastBlock
1432
1448
  );
1433
1449
 
1434
- const remoteBlockCount = lastRemoteBlock.sub(oldestBlock).addn(1);
1450
+ const remoteBlockCount = lastRemoteBlock - oldestBlock + 1n;
1435
1451
 
1436
1452
  const remoteValues = await this._forkClient!.getFeeHistory(
1437
1453
  remoteBlockCount,
@@ -1456,46 +1472,46 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1456
1472
  // We get the pending block here, and only if necessary, as it's something
1457
1473
  // costly to do.
1458
1474
  let pendingBlock: Block | undefined;
1459
- if (lastBlock.gte(pendingBlockNumber)) {
1475
+ if (lastBlock >= pendingBlockNumber) {
1460
1476
  pendingBlock = await this.getBlockByNumber("pending");
1461
1477
  }
1462
1478
 
1463
1479
  // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
1464
1480
  const firstLocalBlock = !rangeIncludesRemoteBlocks
1465
1481
  ? oldestBlock
1466
- : BN.min(new BN(this._forkBlockNumber!), lastBlock).addn(1);
1482
+ : BigIntUtils.min(BigInt(this._forkBlockNumber!), lastBlock) + 1n;
1467
1483
 
1468
1484
  for (
1469
1485
  let blockNumber = firstLocalBlock; // This is part of a temporary fix to https://github.com/NomicFoundation/hardhat/issues/2380
1470
- blockNumber.lte(lastBlock);
1471
- blockNumber = blockNumber.addn(1)
1486
+ blockNumber <= lastBlock;
1487
+ blockNumber++
1472
1488
  ) {
1473
- if (blockNumber.lt(pendingBlockNumber)) {
1489
+ if (blockNumber < pendingBlockNumber) {
1474
1490
  // We know the block exists
1475
1491
  const block = (await this.getBlockByNumber(blockNumber))!;
1476
- baseFeePerGas.push(block.header.baseFeePerGas ?? new BN(0));
1492
+ baseFeePerGas.push(block.header.baseFeePerGas ?? 0n);
1477
1493
 
1478
- if (blockNumber.lt(lastBlock)) {
1494
+ if (blockNumber < lastBlock) {
1479
1495
  gasUsedRatio.push(this._getGasUsedRatio(block));
1480
1496
 
1481
1497
  if (rewardPercentiles.length > 0) {
1482
1498
  reward.push(await this._getRewards(block, rewardPercentiles));
1483
1499
  }
1484
1500
  }
1485
- } else if (blockNumber.eq(pendingBlockNumber)) {
1501
+ } else if (blockNumber === pendingBlockNumber) {
1486
1502
  // This can only be run with EIP-1559, so this exists
1487
1503
  baseFeePerGas.push((await this.getNextBlockBaseFeePerGas())!);
1488
1504
 
1489
- if (blockNumber.lt(lastBlock)) {
1505
+ if (blockNumber < lastBlock) {
1490
1506
  gasUsedRatio.push(this._getGasUsedRatio(pendingBlock!));
1491
1507
 
1492
1508
  if (rewardPercentiles.length > 0) {
1493
1509
  // We don't compute this for the pending block, as there's no
1494
1510
  // effective miner fee yet.
1495
- reward.push(rewardPercentiles.map((_) => new BN(0)));
1511
+ reward.push(rewardPercentiles.map((_) => 0n));
1496
1512
  }
1497
1513
  }
1498
- } else if (blockNumber.eq(pendingBlockNumber.addn(1))) {
1514
+ } else if (blockNumber === pendingBlockNumber + 1n) {
1499
1515
  baseFeePerGas.push(pendingBlock!.header.calcNextBaseFee());
1500
1516
  } else {
1501
1517
  assertHardhatInvariant(false, "This should never happen");
@@ -1518,21 +1534,21 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1518
1534
  const FLOATS_PRECISION = 100_000;
1519
1535
 
1520
1536
  return (
1521
- block.header.gasUsed
1522
- .muln(FLOATS_PRECISION)
1523
- .div(block.header.gasLimit)
1524
- .toNumber() / FLOATS_PRECISION
1537
+ Number(
1538
+ (block.header.gasUsed * BigInt(FLOATS_PRECISION)) /
1539
+ block.header.gasLimit
1540
+ ) / FLOATS_PRECISION
1525
1541
  );
1526
1542
  }
1527
1543
 
1528
1544
  private async _getRewards(
1529
1545
  block: Block,
1530
1546
  rewardPercentiles: number[]
1531
- ): Promise<BN[]> {
1547
+ ): Promise<bigint[]> {
1532
1548
  const FLOATS_PRECISION = 100_000;
1533
1549
 
1534
1550
  if (block.transactions.length === 0) {
1535
- return rewardPercentiles.map((_) => new BN(0));
1551
+ return rewardPercentiles.map((_) => 0n);
1536
1552
  }
1537
1553
 
1538
1554
  const receipts = await Promise.all(
@@ -1544,36 +1560,38 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1544
1560
  const effectiveGasRewardAndGas = receipts
1545
1561
  .map((r, i) => {
1546
1562
  const tx = block.transactions[i];
1547
- const baseFeePerGas = block.header.baseFeePerGas ?? new BN(0);
1563
+ const baseFeePerGas = block.header.baseFeePerGas ?? 0n;
1548
1564
 
1549
1565
  // reward = min(maxPriorityFeePerGas, maxFeePerGas - baseFeePerGas)
1550
- let effectiveGasReward: BN;
1566
+ let effectiveGasReward: bigint;
1551
1567
  if ("maxPriorityFeePerGas" in tx) {
1552
- effectiveGasReward = tx.maxFeePerGas.sub(baseFeePerGas);
1553
- if (tx.maxPriorityFeePerGas.lt(effectiveGasReward)) {
1568
+ effectiveGasReward = tx.maxFeePerGas - baseFeePerGas;
1569
+ if (tx.maxPriorityFeePerGas < effectiveGasReward) {
1554
1570
  effectiveGasReward = tx.maxPriorityFeePerGas;
1555
1571
  }
1556
1572
  } else {
1557
- effectiveGasReward = tx.gasPrice.sub(baseFeePerGas);
1573
+ effectiveGasReward = tx.gasPrice - baseFeePerGas;
1558
1574
  }
1559
1575
 
1560
1576
  return {
1561
1577
  effectiveGasReward,
1562
- gasUsed: rpcQuantityToBN(r?.gasUsed!),
1578
+ gasUsed: rpcQuantityToBigInt(r?.gasUsed!),
1563
1579
  };
1564
1580
  })
1565
- .sort((a, b) => a.effectiveGasReward.cmp(b.effectiveGasReward));
1581
+ .sort((a, b) =>
1582
+ BigIntUtils.cmp(a.effectiveGasReward, b.effectiveGasReward)
1583
+ );
1566
1584
 
1567
1585
  return rewardPercentiles.map((p) => {
1568
- let gasUsed = new BN(0);
1569
- const targetGas = block.header.gasLimit
1570
- .muln(Math.ceil(p * FLOATS_PRECISION))
1571
- .divn(100 * FLOATS_PRECISION);
1586
+ let gasUsed = 0n;
1587
+ const targetGas =
1588
+ (block.header.gasLimit * BigInt(Math.ceil(p * FLOATS_PRECISION))) /
1589
+ BigInt(100 * FLOATS_PRECISION);
1572
1590
 
1573
1591
  for (const values of effectiveGasRewardAndGas) {
1574
- gasUsed = gasUsed.add(values.gasUsed);
1592
+ gasUsed += values.gasUsed;
1575
1593
 
1576
- if (targetGas.lte(gasUsed)) {
1594
+ if (targetGas <= gasUsed) {
1577
1595
  return values.effectiveGasReward;
1578
1596
  }
1579
1597
  }
@@ -1674,23 +1692,22 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1674
1692
 
1675
1693
  // validate nonce
1676
1694
  const nextPendingNonce = await this._txPool.getNextPendingNonce(sender);
1677
- const txNonce = new BN(tx.nonce);
1695
+ const txNonce = tx.nonce;
1678
1696
 
1679
1697
  const expectedNonceMsg = `Expected nonce to be ${nextPendingNonce.toString()} but got ${txNonce.toString()}.`;
1680
- if (txNonce.gt(nextPendingNonce)) {
1698
+ if (txNonce > nextPendingNonce) {
1681
1699
  throw new InvalidInputError(
1682
1700
  `Nonce too high. ${expectedNonceMsg} Note that transactions can't be queued when automining.`
1683
1701
  );
1684
1702
  }
1685
- if (txNonce.lt(nextPendingNonce)) {
1703
+ if (txNonce < nextPendingNonce) {
1686
1704
  throw new InvalidInputError(`Nonce too low. ${expectedNonceMsg}`);
1687
1705
  }
1688
1706
 
1689
1707
  // validate gas price
1690
- const txPriorityFee = new BN(
1691
- "gasPrice" in tx ? tx.gasPrice : tx.maxPriorityFeePerGas
1692
- );
1693
- if (txPriorityFee.lt(this._minGasPrice)) {
1708
+ const txPriorityFee =
1709
+ "gasPrice" in tx ? tx.gasPrice : tx.maxPriorityFeePerGas;
1710
+ if (txPriorityFee < this._minGasPrice) {
1694
1711
  throw new InvalidInputError(
1695
1712
  `Transaction gas price is ${txPriorityFee.toString()}, which is below the minimum of ${this._minGasPrice.toString()}`
1696
1713
  );
@@ -1700,13 +1717,13 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1700
1717
  const nextBlockGasFee = await this.getNextBlockBaseFeePerGas();
1701
1718
  if (nextBlockGasFee !== undefined) {
1702
1719
  if ("maxFeePerGas" in tx) {
1703
- if (nextBlockGasFee.gt(tx.maxFeePerGas)) {
1720
+ if (nextBlockGasFee > tx.maxFeePerGas) {
1704
1721
  throw new InvalidInputError(
1705
1722
  `Transaction maxFeePerGas (${tx.maxFeePerGas.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`
1706
1723
  );
1707
1724
  }
1708
1725
  } else {
1709
- if (nextBlockGasFee.gt(tx.gasPrice)) {
1726
+ if (nextBlockGasFee > tx.gasPrice) {
1710
1727
  throw new InvalidInputError(
1711
1728
  `Transaction gasPrice (${tx.gasPrice.toString()}) is too low for the next block, which has a baseFeePerGas of ${nextBlockGasFee.toString()}`
1712
1729
  );
@@ -1722,17 +1739,23 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1722
1739
  * This method reverts any modification to the state manager if it throws.
1723
1740
  */
1724
1741
  private async _mineBlockWithPendingTxs(
1725
- blockTimestamp: BN
1742
+ blockTimestamp: bigint
1726
1743
  ): Promise<MineBlockResult> {
1727
1744
  const parentBlock = await this.getLatestBlock();
1728
1745
 
1729
1746
  const headerData: HeaderData = {
1730
1747
  gasLimit: this.getBlockGasLimit(),
1731
1748
  coinbase: this.getCoinbaseAddress(),
1732
- nonce: "0x0000000000000042",
1749
+ nonce: this.isPostMergeHardfork()
1750
+ ? "0x0000000000000000"
1751
+ : "0x0000000000000042",
1733
1752
  timestamp: blockTimestamp,
1734
1753
  };
1735
1754
 
1755
+ if (this.isPostMergeHardfork()) {
1756
+ headerData.mixHash = this._getNextMixHash();
1757
+ }
1758
+
1736
1759
  headerData.baseFeePerGas = await this.getNextBlockBaseFeePerGas();
1737
1760
 
1738
1761
  const blockBuilder = await this._vm.buildBlock({
@@ -1759,12 +1782,12 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1759
1782
  const receipts = [];
1760
1783
 
1761
1784
  while (
1762
- blockGasLimit.sub(blockBuilder.gasUsed).gte(minTxFee) &&
1785
+ blockGasLimit - blockBuilder.gasUsed >= minTxFee &&
1763
1786
  tx !== undefined
1764
1787
  ) {
1765
1788
  if (
1766
1789
  !this._isTxMinable(tx, headerData.baseFeePerGas) ||
1767
- tx.gasLimit.gt(blockGasLimit.sub(blockBuilder.gasUsed))
1790
+ tx.gasLimit > blockGasLimit - blockBuilder.gasUsed
1768
1791
  ) {
1769
1792
  transactionQueue.removeLastSenderTransactions();
1770
1793
  } else {
@@ -1788,7 +1811,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1788
1811
  results,
1789
1812
  receipts,
1790
1813
  stateRoot: block.header.stateRoot,
1791
- logsBloom: block.header.bloom,
1814
+ logsBloom: block.header.logsBloom,
1792
1815
  receiptRoot: block.header.receiptTrie,
1793
1816
  gasUsed: block.header.gasUsed,
1794
1817
  },
@@ -1800,9 +1823,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1800
1823
  }
1801
1824
  }
1802
1825
 
1803
- private _getMinimalTransactionFee(): BN {
1826
+ private _getMinimalTransactionFee(): bigint {
1804
1827
  // Typically 21_000 gas
1805
- return new BN(this._vm._common.param("gasPrices", "tx"));
1828
+ return this._vm._common.param("gasPrices", "tx");
1806
1829
  }
1807
1830
 
1808
1831
  private async _getFakeTransaction(
@@ -1937,7 +1960,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1937
1960
  } else if (returnData.isErrorReturnData()) {
1938
1961
  returnDataExplanation = `with reason "${returnData.decodeError()}"`;
1939
1962
  } else if (returnData.isPanicReturnData()) {
1940
- const panicCode = returnData.decodePanic().toString("hex");
1963
+ const panicCode = returnData.decodePanic().toString(16);
1941
1964
  returnDataExplanation = `with panic code "0x${panicCode}"`;
1942
1965
  } else {
1943
1966
  returnDataExplanation = "with unrecognized return data or custom error";
@@ -1973,18 +1996,20 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1973
1996
  );
1974
1997
  }
1975
1998
 
1976
- private _calculateTimestampAndOffset(timestamp?: BN): [BN, boolean, BN] {
1977
- let blockTimestamp: BN;
1999
+ private _calculateTimestampAndOffset(
2000
+ timestamp?: bigint
2001
+ ): [bigint, boolean, bigint] {
2002
+ let blockTimestamp: bigint;
1978
2003
  let offsetShouldChange: boolean;
1979
- let newOffset: BN = new BN(0);
1980
- const currentTimestamp = new BN(getCurrentTimestamp());
2004
+ let newOffset: bigint = 0n;
2005
+ const currentTimestamp = BigInt(getCurrentTimestamp());
1981
2006
 
1982
2007
  // if timestamp is not provided, we check nextBlockTimestamp, if it is
1983
2008
  // set, we use it as the timestamp instead. If it is not set, we use
1984
2009
  // time offset + real time as the timestamp.
1985
- if (timestamp === undefined || timestamp.eqn(0)) {
1986
- if (this.getNextBlockTimestamp().eqn(0)) {
1987
- blockTimestamp = currentTimestamp.add(this.getTimeIncrement());
2010
+ if (timestamp === undefined || timestamp === 0n) {
2011
+ if (this.getNextBlockTimestamp() === 0n) {
2012
+ blockTimestamp = currentTimestamp + this.getTimeIncrement();
1988
2013
  offsetShouldChange = false;
1989
2014
  } else {
1990
2015
  blockTimestamp = this.getNextBlockTimestamp();
@@ -1996,14 +2021,14 @@ Hardhat Network's forking functionality only works with blocks from at least spu
1996
2021
  }
1997
2022
 
1998
2023
  if (offsetShouldChange) {
1999
- newOffset = blockTimestamp.sub(currentTimestamp);
2024
+ newOffset = blockTimestamp - currentTimestamp;
2000
2025
  }
2001
2026
 
2002
2027
  return [blockTimestamp, offsetShouldChange, newOffset];
2003
2028
  }
2004
2029
 
2005
2030
  private _resetNextBlockTimestamp() {
2006
- this.setNextBlockTimestamp(new BN(0));
2031
+ this.setNextBlockTimestamp(0n);
2007
2032
  }
2008
2033
 
2009
2034
  private async _notifyPendingTransaction(tx: TypedTransaction) {
@@ -2077,7 +2102,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2077
2102
  case Type.LOGS_SUBSCRIPTION:
2078
2103
  if (
2079
2104
  bloomFilter(
2080
- new Bloom(block.header.bloom),
2105
+ new Bloom(block.header.logsBloom),
2081
2106
  filter.criteria!.addresses,
2082
2107
  filter.criteria!.normalizedTopics
2083
2108
  )
@@ -2102,23 +2127,23 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2102
2127
  }
2103
2128
 
2104
2129
  private async _timestampClashesWithPreviousBlockOne(
2105
- blockTimestamp: BN
2130
+ blockTimestamp: bigint
2106
2131
  ): Promise<boolean> {
2107
2132
  const latestBlock = await this.getLatestBlock();
2108
- const latestBlockTimestamp = new BN(latestBlock.header.timestamp);
2133
+ const latestBlockTimestamp = latestBlock.header.timestamp;
2109
2134
 
2110
- return latestBlockTimestamp.eq(blockTimestamp);
2135
+ return latestBlockTimestamp === blockTimestamp;
2111
2136
  }
2112
2137
 
2113
2138
  private async _runInBlockContext<T>(
2114
- blockNumberOrPending: BN | "pending",
2139
+ blockNumberOrPending: bigint | "pending",
2115
2140
  action: () => Promise<T>
2116
2141
  ): Promise<T> {
2117
2142
  if (blockNumberOrPending === "pending") {
2118
2143
  return this._runInPendingBlockContext(action);
2119
2144
  }
2120
2145
 
2121
- if (blockNumberOrPending.eq(this.getLatestBlockNumber())) {
2146
+ if (blockNumberOrPending === this.getLatestBlockNumber()) {
2122
2147
  return action();
2123
2148
  }
2124
2149
 
@@ -2151,7 +2176,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2151
2176
 
2152
2177
  private async _setBlockContext(block: Block): Promise<void> {
2153
2178
  const irregularStateOrUndefined = this._irregularStatesByBlockNumber.get(
2154
- block.header.number.toString()
2179
+ block.header.number
2155
2180
  );
2156
2181
 
2157
2182
  if (this._stateManager instanceof ForkStateManager) {
@@ -2175,17 +2200,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2175
2200
  }
2176
2201
 
2177
2202
  private async _correctInitialEstimation(
2178
- blockNumberOrPending: BN | "pending",
2203
+ blockNumberOrPending: bigint | "pending",
2179
2204
  txParams: TransactionParams,
2180
- initialEstimation: BN
2181
- ): Promise<BN> {
2205
+ initialEstimation: bigint
2206
+ ): Promise<bigint> {
2182
2207
  let tx = await this._getFakeTransaction({
2183
2208
  ...txParams,
2184
2209
  gasLimit: initialEstimation,
2185
2210
  });
2186
2211
 
2187
- if (tx.getBaseFee().gte(initialEstimation)) {
2188
- initialEstimation = tx.getBaseFee().addn(1);
2212
+ if (tx.getBaseFee() >= initialEstimation) {
2213
+ initialEstimation = tx.getBaseFee() + 1n;
2189
2214
 
2190
2215
  tx = await this._getFakeTransaction({
2191
2216
  ...txParams,
@@ -2210,13 +2235,13 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2210
2235
  }
2211
2236
 
2212
2237
  private async _binarySearchEstimation(
2213
- blockNumberOrPending: BN | "pending",
2238
+ blockNumberOrPending: bigint | "pending",
2214
2239
  txParams: TransactionParams,
2215
- highestFailingEstimation: BN,
2216
- lowestSuccessfulEstimation: BN,
2240
+ highestFailingEstimation: bigint,
2241
+ lowestSuccessfulEstimation: bigint,
2217
2242
  roundNumber = 0
2218
- ): Promise<BN> {
2219
- if (lowestSuccessfulEstimation.lte(highestFailingEstimation)) {
2243
+ ): Promise<bigint> {
2244
+ if (lowestSuccessfulEstimation <= highestFailingEstimation) {
2220
2245
  // This shouldn't happen, but we don't want to go into an infinite loop
2221
2246
  // if it ever happens
2222
2247
  return lowestSuccessfulEstimation;
@@ -2224,21 +2249,22 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2224
2249
 
2225
2250
  const MAX_GAS_ESTIMATION_IMPROVEMENT_ROUNDS = 20;
2226
2251
 
2227
- const diff = lowestSuccessfulEstimation.sub(highestFailingEstimation);
2228
-
2229
- const minDiff = highestFailingEstimation.gten(4_000_000)
2230
- ? 50_000
2231
- : highestFailingEstimation.gten(1_000_000)
2232
- ? 10_000
2233
- : highestFailingEstimation.gten(100_000)
2234
- ? 1_000
2235
- : highestFailingEstimation.gten(50_000)
2236
- ? 500
2237
- : highestFailingEstimation.gten(30_000)
2238
- ? 300
2239
- : 200;
2240
-
2241
- if (diff.lten(minDiff)) {
2252
+ const diff = lowestSuccessfulEstimation - highestFailingEstimation;
2253
+
2254
+ const minDiff =
2255
+ highestFailingEstimation >= 4_000_000n
2256
+ ? 50_000
2257
+ : highestFailingEstimation >= 1_000_000n
2258
+ ? 10_000
2259
+ : highestFailingEstimation >= 100_000n
2260
+ ? 1_000
2261
+ : highestFailingEstimation >= 50_000n
2262
+ ? 500
2263
+ : highestFailingEstimation >= 30_000n
2264
+ ? 300
2265
+ : 200;
2266
+
2267
+ if (diff <= minDiff) {
2242
2268
  return lowestSuccessfulEstimation;
2243
2269
  }
2244
2270
 
@@ -2246,16 +2272,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2246
2272
  return lowestSuccessfulEstimation;
2247
2273
  }
2248
2274
 
2249
- const binSearchNewEstimation = highestFailingEstimation.add(diff.divn(2));
2275
+ const binSearchNewEstimation = highestFailingEstimation + diff / 2n;
2250
2276
 
2251
2277
  const optimizedEstimation =
2252
2278
  roundNumber === 0
2253
- ? highestFailingEstimation.muln(3)
2279
+ ? 3n * highestFailingEstimation
2254
2280
  : binSearchNewEstimation;
2255
2281
 
2256
- const newEstimation = optimizedEstimation.gt(binSearchNewEstimation)
2257
- ? binSearchNewEstimation
2258
- : optimizedEstimation;
2282
+ const newEstimation =
2283
+ optimizedEstimation > binSearchNewEstimation
2284
+ ? binSearchNewEstimation
2285
+ : optimizedEstimation;
2259
2286
 
2260
2287
  // Let other things execute
2261
2288
  await new Promise((resolve) => setImmediate(resolve));
@@ -2294,9 +2321,9 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2294
2321
  */
2295
2322
  private async _runTxAndRevertMutations(
2296
2323
  tx: TypedTransaction,
2297
- blockNumberOrPending: BN | "pending",
2324
+ blockNumberOrPending: bigint | "pending",
2298
2325
  forceBaseFeeZero = false
2299
- ): Promise<EVMResult> {
2326
+ ): Promise<RunTxResult> {
2300
2327
  const initialStateRoot = await this._stateManager.getStateRoot();
2301
2328
 
2302
2329
  let blockContext: Block | undefined;
@@ -2321,7 +2348,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2321
2348
  // know anything about the txs in the current block
2322
2349
  }
2323
2350
 
2324
- // NOTE: This is a workaround of both an @ethereumjs/vm limitation, and
2351
+ // NOTE: This is a workaround of both an @ignored/vm limitation, and
2325
2352
  // a bug in Hardhat Network.
2326
2353
  //
2327
2354
  // See: https://github.com/nomiclabs/hardhat/issues/1666
@@ -2343,23 +2370,24 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2343
2370
  common: this._vm._common,
2344
2371
  });
2345
2372
 
2346
- (blockContext.header as any).baseFeePerGas = new BN(0);
2373
+ (blockContext.header as any).baseFeePerGas = 0n;
2347
2374
  }
2348
2375
 
2349
2376
  originalCommon = (this._vm as any)._common;
2350
- (this._vm as any)._common = new Common({
2351
- chain: {
2352
- // eslint-disable-next-line @typescript-eslint/dot-notation
2353
- ...this._vm._common["_chainParams"],
2377
+
2378
+ (this._vm as any)._common = Common.custom(
2379
+ {
2354
2380
  chainId:
2355
2381
  this._forkBlockNumber === undefined ||
2356
- blockContext.header.number.gte(new BN(this._forkBlockNumber))
2382
+ blockContext.header.number >= this._forkBlockNumber
2357
2383
  ? this._configChainId
2358
2384
  : this._forkNetworkId,
2359
2385
  networkId: this._forkNetworkId ?? this._configNetworkId,
2360
2386
  },
2361
- hardfork: this._selectHardfork(blockContext.header.number),
2362
- });
2387
+ {
2388
+ hardfork: this._selectHardfork(blockContext.header.number),
2389
+ }
2390
+ );
2363
2391
 
2364
2392
  return await this._vm.runTx({
2365
2393
  block: blockContext,
@@ -2391,10 +2419,10 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2391
2419
  newFilterParams.toBlock = latestBlockNumber;
2392
2420
  }
2393
2421
 
2394
- if (newFilterParams.toBlock.gt(latestBlockNumber)) {
2422
+ if (newFilterParams.toBlock > latestBlockNumber) {
2395
2423
  newFilterParams.toBlock = latestBlockNumber;
2396
2424
  }
2397
- if (newFilterParams.fromBlock.gt(latestBlockNumber)) {
2425
+ if (newFilterParams.fromBlock > latestBlockNumber) {
2398
2426
  newFilterParams.fromBlock = latestBlockNumber;
2399
2427
  }
2400
2428
 
@@ -2407,17 +2435,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2407
2435
  return dt;
2408
2436
  }
2409
2437
 
2410
- private _getNextFilterId(): BN {
2411
- this._lastFilterId = this._lastFilterId.addn(1);
2438
+ private _getNextFilterId(): bigint {
2439
+ this._lastFilterId++;
2412
2440
 
2413
2441
  return this._lastFilterId;
2414
2442
  }
2415
2443
 
2416
- private _filterIdToFiltersKey(filterId: BN): string {
2444
+ private _filterIdToFiltersKey(filterId: bigint): string {
2417
2445
  return filterId.toString();
2418
2446
  }
2419
2447
 
2420
- private _emitEthEvent(filterId: BN, result: any) {
2448
+ private _emitEthEvent(filterId: bigint, result: any) {
2421
2449
  this.emit("ethEvent", {
2422
2450
  result,
2423
2451
  filterId,
@@ -2426,8 +2454,8 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2426
2454
 
2427
2455
  private async _getNonce(
2428
2456
  address: Address,
2429
- blockNumberOrPending: BN | "pending"
2430
- ): Promise<BN> {
2457
+ blockNumberOrPending: bigint | "pending"
2458
+ ): Promise<bigint> {
2431
2459
  if (blockNumberOrPending === "pending") {
2432
2460
  return this.getAccountNextPendingNonce(address);
2433
2461
  }
@@ -2446,28 +2474,28 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2446
2474
 
2447
2475
  private _isTxMinable(
2448
2476
  tx: TypedTransaction,
2449
- nextBlockBaseFeePerGas?: BN
2477
+ nextBlockBaseFeePerGas?: bigint
2450
2478
  ): boolean {
2451
2479
  const txMaxFee = "gasPrice" in tx ? tx.gasPrice : tx.maxFeePerGas;
2452
2480
 
2453
2481
  const canPayBaseFee =
2454
2482
  nextBlockBaseFeePerGas !== undefined
2455
- ? txMaxFee.gte(nextBlockBaseFeePerGas)
2483
+ ? txMaxFee >= nextBlockBaseFeePerGas
2456
2484
  : true;
2457
2485
 
2458
- const atLeastMinGasPrice = txMaxFee.gte(this._minGasPrice);
2486
+ const atLeastMinGasPrice = txMaxFee >= this._minGasPrice;
2459
2487
 
2460
2488
  return canPayBaseFee && atLeastMinGasPrice;
2461
2489
  }
2462
2490
 
2463
2491
  private async _persistIrregularWorldState(): Promise<void> {
2464
2492
  this._irregularStatesByBlockNumber.set(
2465
- this.getLatestBlockNumber().toString(),
2493
+ this.getLatestBlockNumber(),
2466
2494
  await this._stateManager.getStateRoot()
2467
2495
  );
2468
2496
  }
2469
2497
 
2470
- public isEip1559Active(blockNumberOrPending?: BN | "pending"): boolean {
2498
+ public isEip1559Active(blockNumberOrPending?: bigint | "pending"): boolean {
2471
2499
  if (
2472
2500
  blockNumberOrPending !== undefined &&
2473
2501
  blockNumberOrPending !== "pending"
@@ -2480,11 +2508,20 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2480
2508
  return this._vm._common.gteHardfork("london");
2481
2509
  }
2482
2510
 
2511
+ public isPostMergeHardfork(): boolean {
2512
+ return hardforkGte(this.hardfork, HardforkName.MERGE);
2513
+ }
2514
+
2515
+ private _getNextMixHash(): Buffer {
2516
+ return this._mixHashGenerator.next();
2517
+ }
2518
+
2483
2519
  private async _getEstimateGasFeePriceFields(
2484
2520
  callParams: CallParams,
2485
- blockNumberOrPending: BN | "pending"
2521
+ blockNumberOrPending: bigint | "pending"
2486
2522
  ): Promise<
2487
- { gasPrice: BN } | { maxFeePerGas: BN; maxPriorityFeePerGas: BN }
2523
+ | { gasPrice: bigint }
2524
+ | { maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }
2488
2525
  > {
2489
2526
  if (
2490
2527
  !this.isEip1559Active(blockNumberOrPending) ||
@@ -2499,7 +2536,7 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2499
2536
  if (maxPriorityFeePerGas === undefined) {
2500
2537
  maxPriorityFeePerGas = await this.getMaxPriorityFeePerGas();
2501
2538
 
2502
- if (maxFeePerGas !== undefined && maxFeePerGas.lt(maxPriorityFeePerGas)) {
2539
+ if (maxFeePerGas !== undefined && maxFeePerGas < maxPriorityFeePerGas) {
2503
2540
  maxPriorityFeePerGas = maxFeePerGas;
2504
2541
  }
2505
2542
  }
@@ -2507,23 +2544,22 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2507
2544
  if (maxFeePerGas === undefined) {
2508
2545
  if (blockNumberOrPending === "pending") {
2509
2546
  const baseFeePerGas = await this.getNextBlockBaseFeePerGas();
2510
- maxFeePerGas = baseFeePerGas!.muln(2).add(maxPriorityFeePerGas);
2547
+ maxFeePerGas = 2n * baseFeePerGas! + maxPriorityFeePerGas;
2511
2548
  } else {
2512
2549
  const block = await this.getBlockByNumber(blockNumberOrPending);
2513
2550
 
2514
- maxFeePerGas = maxPriorityFeePerGas.add(
2515
- block!.header.baseFeePerGas ?? new BN(0)
2516
- );
2551
+ maxFeePerGas =
2552
+ maxPriorityFeePerGas + (block!.header.baseFeePerGas ?? 0n);
2517
2553
  }
2518
2554
  }
2519
2555
 
2520
2556
  return { maxFeePerGas, maxPriorityFeePerGas };
2521
2557
  }
2522
2558
 
2523
- private _selectHardfork(blockNumber: BN): string {
2559
+ private _selectHardfork(blockNumber: bigint): string {
2524
2560
  if (
2525
2561
  this._forkBlockNumber === undefined ||
2526
- blockNumber.gte(new BN(this._forkBlockNumber))
2562
+ blockNumber >= this._forkBlockNumber
2527
2563
  ) {
2528
2564
  return this._vm._common.hardfork() as HardforkName;
2529
2565
  }
@@ -2544,11 +2580,11 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2544
2580
  );
2545
2581
  const [hardfork, activationBlock] = hardforkHistory.reduce(
2546
2582
  ([highestHardfork, highestBlock], [thisHardfork, thisBlock]) =>
2547
- thisBlock > highestBlock && new BN(thisBlock).lte(blockNumber)
2583
+ thisBlock > highestBlock && thisBlock <= blockNumber
2548
2584
  ? [thisHardfork, thisBlock]
2549
2585
  : [highestHardfork, highestBlock]
2550
2586
  );
2551
- if (hardfork === undefined || blockNumber.ltn(activationBlock)) {
2587
+ if (hardfork === undefined || blockNumber < activationBlock) {
2552
2588
  throw new InternalError(
2553
2589
  `Could not find a hardfork to run for block ${blockNumber.toString()}, after having looked for one in the HardhatNode's hardfork activation history, which was: ${JSON.stringify(
2554
2590
  hardforkHistory
@@ -2567,17 +2603,17 @@ Hardhat Network's forking functionality only works with blocks from at least spu
2567
2603
  return hardfork;
2568
2604
  }
2569
2605
 
2570
- private _getCommonForTracing(networkId: number, blockNumber: number): Common {
2606
+ private _getCommonForTracing(networkId: number, blockNumber: bigint): Common {
2571
2607
  try {
2572
- const common = new Common({
2573
- chain: {
2574
- // eslint-disable-next-line @typescript-eslint/dot-notation
2575
- ...Common["_getChainParams"]("mainnet"),
2608
+ const common = Common.custom(
2609
+ {
2576
2610
  chainId: networkId,
2577
2611
  networkId,
2578
2612
  },
2579
- hardfork: this._selectHardfork(new BN(blockNumber)),
2580
- });
2613
+ {
2614
+ hardfork: this._selectHardfork(BigInt(blockNumber)),
2615
+ }
2616
+ );
2581
2617
 
2582
2618
  return common;
2583
2619
  } catch {