hardhat 2.20.1 → 2.21.0-dev.1

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 (271) hide show
  1. package/internal/core/jsonrpc/types/input/blockTag.d.ts +3 -3
  2. package/internal/core/jsonrpc/types/input/filterRequest.d.ts +6 -6
  3. package/internal/core/providers/construction.d.ts.map +1 -1
  4. package/internal/core/providers/construction.js +28 -4
  5. package/internal/core/providers/construction.js.map +1 -1
  6. package/internal/core/providers/http.d.ts +2 -0
  7. package/internal/core/providers/http.d.ts.map +1 -1
  8. package/internal/core/providers/http.js +2 -1
  9. package/internal/core/providers/http.js.map +1 -1
  10. package/internal/core/runtime-environment.d.ts.map +1 -1
  11. package/internal/core/runtime-environment.js.map +1 -1
  12. package/internal/hardhat-network/jsonrpc/client.d.ts +0 -2
  13. package/internal/hardhat-network/jsonrpc/client.d.ts.map +1 -1
  14. package/internal/hardhat-network/jsonrpc/client.js +0 -16
  15. package/internal/hardhat-network/jsonrpc/client.js.map +1 -1
  16. package/internal/hardhat-network/jsonrpc/handler.js +9 -1
  17. package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
  18. package/internal/hardhat-network/provider/BlockchainData.d.ts +5 -5
  19. package/internal/hardhat-network/provider/BlockchainData.d.ts.map +1 -1
  20. package/internal/hardhat-network/provider/BlockchainData.js +10 -10
  21. package/internal/hardhat-network/provider/BlockchainData.js.map +1 -1
  22. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts +0 -7
  23. package/internal/hardhat-network/provider/HardhatBlockchain.d.ts.map +1 -1
  24. package/internal/hardhat-network/provider/HardhatBlockchain.js +2 -14
  25. package/internal/hardhat-network/provider/HardhatBlockchain.js.map +1 -1
  26. package/internal/hardhat-network/provider/TxPool.d.ts +3 -2
  27. package/internal/hardhat-network/provider/TxPool.d.ts.map +1 -1
  28. package/internal/hardhat-network/provider/TxPool.js +16 -16
  29. package/internal/hardhat-network/provider/TxPool.js.map +1 -1
  30. package/internal/hardhat-network/provider/ethereumjs-workarounds.js +1 -1
  31. package/internal/hardhat-network/provider/ethereumjs-workarounds.js.map +1 -1
  32. package/internal/hardhat-network/provider/filter.d.ts +6 -5
  33. package/internal/hardhat-network/provider/filter.d.ts.map +1 -1
  34. package/internal/hardhat-network/provider/filter.js +2 -2
  35. package/internal/hardhat-network/provider/filter.js.map +1 -1
  36. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts +0 -7
  37. package/internal/hardhat-network/provider/fork/ForkBlockchain.d.ts.map +1 -1
  38. package/internal/hardhat-network/provider/fork/ForkBlockchain.js +4 -21
  39. package/internal/hardhat-network/provider/fork/ForkBlockchain.js.map +1 -1
  40. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts +13 -19
  41. package/internal/hardhat-network/provider/fork/ForkStateManager.d.ts.map +1 -1
  42. package/internal/hardhat-network/provider/fork/ForkStateManager.js +61 -59
  43. package/internal/hardhat-network/provider/fork/ForkStateManager.js.map +1 -1
  44. package/internal/hardhat-network/provider/fork/rpcToBlockData.d.ts.map +1 -1
  45. package/internal/hardhat-network/provider/fork/rpcToBlockData.js +0 -3
  46. package/internal/hardhat-network/provider/fork/rpcToBlockData.js.map +1 -1
  47. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts +2 -2
  48. package/internal/hardhat-network/provider/fork/rpcToTxData.d.ts.map +1 -1
  49. package/internal/hardhat-network/provider/fork/rpcToTxData.js +1 -1
  50. package/internal/hardhat-network/provider/fork/rpcToTxData.js.map +1 -1
  51. package/internal/hardhat-network/provider/modules/base.js +4 -4
  52. package/internal/hardhat-network/provider/modules/base.js.map +1 -1
  53. package/internal/hardhat-network/provider/modules/eth.d.ts.map +1 -1
  54. package/internal/hardhat-network/provider/modules/eth.js +9 -16
  55. package/internal/hardhat-network/provider/modules/eth.js.map +1 -1
  56. package/internal/hardhat-network/provider/modules/logger.d.ts +6 -84
  57. package/internal/hardhat-network/provider/modules/logger.d.ts.map +1 -1
  58. package/internal/hardhat-network/provider/modules/logger.js +3 -530
  59. package/internal/hardhat-network/provider/modules/logger.js.map +1 -1
  60. package/internal/hardhat-network/provider/node-types.d.ts +2 -65
  61. package/internal/hardhat-network/provider/node-types.d.ts.map +1 -1
  62. package/internal/hardhat-network/provider/node-types.js +0 -5
  63. package/internal/hardhat-network/provider/node-types.js.map +1 -1
  64. package/internal/hardhat-network/provider/node.d.ts +2 -6
  65. package/internal/hardhat-network/provider/node.d.ts.map +1 -1
  66. package/internal/hardhat-network/provider/node.js +79 -153
  67. package/internal/hardhat-network/provider/node.js.map +1 -1
  68. package/internal/hardhat-network/provider/output.d.ts +0 -14
  69. package/internal/hardhat-network/provider/output.d.ts.map +1 -1
  70. package/internal/hardhat-network/provider/output.js +0 -264
  71. package/internal/hardhat-network/provider/output.js.map +1 -1
  72. package/internal/hardhat-network/provider/provider.d.ts +28 -25
  73. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  74. package/internal/hardhat-network/provider/provider.js +349 -185
  75. package/internal/hardhat-network/provider/provider.js.map +1 -1
  76. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts +10 -8
  77. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.d.ts.map +1 -1
  78. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js +9 -9
  79. package/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.js.map +1 -1
  80. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts +10 -8
  81. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.d.ts.map +1 -1
  82. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js +9 -9
  83. package/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.js.map +1 -1
  84. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts +10 -9
  85. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.d.ts.map +1 -1
  86. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js +7 -6
  87. package/internal/hardhat-network/provider/transactions/FakeSenderTransaction.js.map +1 -1
  88. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts +6 -5
  89. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.d.ts.map +1 -1
  90. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js +1 -1
  91. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.js.map +1 -1
  92. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts +5 -4
  93. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.d.ts.map +1 -1
  94. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js +1 -1
  95. package/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.js.map +1 -1
  96. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts +8 -7
  97. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.d.ts.map +1 -1
  98. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js +2 -2
  99. package/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.js.map +1 -1
  100. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts +8 -7
  101. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.d.ts.map +1 -1
  102. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js +2 -2
  103. package/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.js.map +1 -1
  104. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts +5 -4
  105. package/internal/hardhat-network/provider/types/HardhatBlockchainInterface.d.ts.map +1 -1
  106. package/internal/hardhat-network/provider/utils/convertToEdr.d.ts +14 -0
  107. package/internal/hardhat-network/provider/utils/convertToEdr.d.ts.map +1 -0
  108. package/internal/hardhat-network/provider/utils/convertToEdr.js +194 -0
  109. package/internal/hardhat-network/provider/utils/convertToEdr.js.map +1 -0
  110. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts +0 -1
  111. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.d.ts.map +1 -1
  112. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js +1 -5
  113. package/internal/hardhat-network/provider/utils/getCurrentTimestamp.js.map +1 -1
  114. package/internal/hardhat-network/provider/utils/makeCommon.d.ts +1 -1
  115. package/internal/hardhat-network/provider/utils/makeCommon.d.ts.map +1 -1
  116. package/internal/hardhat-network/provider/utils/makeCommon.js +1 -3
  117. package/internal/hardhat-network/provider/utils/makeCommon.js.map +1 -1
  118. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts +2 -2
  119. package/internal/hardhat-network/provider/utils/makeFakeSignature.d.ts.map +1 -1
  120. package/internal/hardhat-network/provider/utils/makeFakeSignature.js +1 -15
  121. package/internal/hardhat-network/provider/utils/makeFakeSignature.js.map +1 -1
  122. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts +10 -1
  123. package/internal/hardhat-network/provider/utils/makeForkClient.d.ts.map +1 -1
  124. package/internal/hardhat-network/provider/utils/makeForkClient.js +38 -18
  125. package/internal/hardhat-network/provider/utils/makeForkClient.js.map +1 -1
  126. package/internal/hardhat-network/provider/utils/makeStateTrie.js +2 -2
  127. package/internal/hardhat-network/provider/utils/makeStateTrie.js.map +1 -1
  128. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts +3 -1
  129. package/internal/hardhat-network/provider/utils/putGenesisBlock.d.ts.map +1 -1
  130. package/internal/hardhat-network/provider/utils/putGenesisBlock.js +2 -6
  131. package/internal/hardhat-network/provider/utils/putGenesisBlock.js.map +1 -1
  132. package/internal/hardhat-network/provider/utils/random.d.ts +1 -0
  133. package/internal/hardhat-network/provider/utils/random.d.ts.map +1 -1
  134. package/internal/hardhat-network/provider/utils/random.js +7 -1
  135. package/internal/hardhat-network/provider/utils/random.js.map +1 -1
  136. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts +1 -1
  137. package/internal/hardhat-network/provider/utils/reorgs-protection.d.ts.map +1 -1
  138. package/internal/hardhat-network/provider/utils/reorgs-protection.js +5 -5
  139. package/internal/hardhat-network/provider/utils/reorgs-protection.js.map +1 -1
  140. package/internal/hardhat-network/provider/vm/exit.d.ts +22 -0
  141. package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -0
  142. package/internal/hardhat-network/provider/vm/exit.js +93 -0
  143. package/internal/hardhat-network/provider/vm/exit.js.map +1 -0
  144. package/internal/hardhat-network/provider/vm/minimal-vm.d.ts +29 -0
  145. package/internal/hardhat-network/provider/vm/minimal-vm.d.ts.map +1 -0
  146. package/internal/hardhat-network/provider/vm/minimal-vm.js +43 -0
  147. package/internal/hardhat-network/provider/vm/minimal-vm.js.map +1 -0
  148. package/internal/hardhat-network/provider/vm/proxy-vm.d.ts +36 -0
  149. package/internal/hardhat-network/provider/vm/proxy-vm.d.ts.map +1 -0
  150. package/internal/hardhat-network/provider/vm/proxy-vm.js +73 -0
  151. package/internal/hardhat-network/provider/vm/proxy-vm.js.map +1 -0
  152. package/internal/hardhat-network/provider/vm/types.d.ts +28 -0
  153. package/internal/hardhat-network/provider/vm/types.d.ts.map +1 -0
  154. package/internal/hardhat-network/provider/vm/types.js +3 -0
  155. package/internal/hardhat-network/provider/vm/types.js.map +1 -0
  156. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts +6 -0
  157. package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
  158. package/internal/hardhat-network/stack-traces/consoleLogger.js +33 -16
  159. package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
  160. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +1 -2
  161. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +1 -1
  162. package/internal/hardhat-network/stack-traces/contracts-identifier.js +6 -7
  163. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +1 -1
  164. package/internal/hardhat-network/stack-traces/debug.js +6 -6
  165. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  166. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +1 -1
  167. package/internal/hardhat-network/stack-traces/error-inferrer.js +13 -7
  168. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +1 -1
  169. package/internal/hardhat-network/stack-traces/message-trace.d.ts +8 -3
  170. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  171. package/internal/hardhat-network/stack-traces/message-trace.js +22 -1
  172. package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
  173. package/internal/hardhat-network/stack-traces/model.d.ts +8 -0
  174. package/internal/hardhat-network/stack-traces/model.d.ts.map +1 -1
  175. package/internal/hardhat-network/stack-traces/model.js +52 -0
  176. package/internal/hardhat-network/stack-traces/model.js.map +1 -1
  177. package/internal/hardhat-network/stack-traces/opcodes.d.ts +1 -0
  178. package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +1 -1
  179. package/internal/hardhat-network/stack-traces/opcodes.js +5 -1
  180. package/internal/hardhat-network/stack-traces/opcodes.js.map +1 -1
  181. package/internal/hardhat-network/stack-traces/solidity-errors.js +2 -2
  182. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  183. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  184. package/internal/hardhat-network/stack-traces/solidityTracer.js +5 -5
  185. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  186. package/internal/hardhat-network/stack-traces/vm-debug-tracer.d.ts.map +1 -1
  187. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js +28 -34
  188. package/internal/hardhat-network/stack-traces/vm-debug-tracer.js.map +1 -1
  189. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +7 -0
  190. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
  191. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +69 -2
  192. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
  193. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +7 -12
  194. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  195. package/internal/hardhat-network/stack-traces/vm-tracer.js +46 -65
  196. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  197. package/internal/util/date.d.ts +1 -0
  198. package/internal/util/date.d.ts.map +1 -1
  199. package/internal/util/date.js +5 -1
  200. package/internal/util/date.js.map +1 -1
  201. package/internal/util/hardforks.d.ts +2 -0
  202. package/internal/util/hardforks.d.ts.map +1 -1
  203. package/internal/util/hardforks.js +27 -1
  204. package/internal/util/hardforks.js.map +1 -1
  205. package/package.json +16 -14
  206. package/src/internal/core/providers/construction.ts +7 -9
  207. package/src/internal/core/providers/http.ts +3 -1
  208. package/src/internal/core/runtime-environment.ts +2 -1
  209. package/src/internal/hardhat-network/jsonrpc/client.ts +1 -28
  210. package/src/internal/hardhat-network/jsonrpc/handler.ts +9 -1
  211. package/src/internal/hardhat-network/provider/modules/logger.ts +6 -801
  212. package/src/internal/hardhat-network/provider/node-types.ts +2 -89
  213. package/src/internal/hardhat-network/provider/output.ts +0 -352
  214. package/src/internal/hardhat-network/provider/provider.ts +501 -261
  215. package/src/internal/hardhat-network/provider/utils/convertToEdr.ts +232 -0
  216. package/src/internal/hardhat-network/provider/utils/getCurrentTimestamp.ts +0 -4
  217. package/src/internal/hardhat-network/provider/utils/makeCommon.ts +1 -12
  218. package/src/internal/hardhat-network/provider/utils/makeForkClient.ts +63 -24
  219. package/src/internal/hardhat-network/provider/utils/random.ts +8 -1
  220. package/src/internal/hardhat-network/provider/utils/reorgs-protection.ts +5 -5
  221. package/src/internal/hardhat-network/provider/vm/exit.ts +101 -0
  222. package/src/internal/hardhat-network/provider/vm/minimal-vm.ts +98 -0
  223. package/src/internal/hardhat-network/provider/vm/types.ts +32 -0
  224. package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +40 -21
  225. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +10 -12
  226. package/src/internal/hardhat-network/stack-traces/debug.ts +6 -6
  227. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +15 -8
  228. package/src/internal/hardhat-network/stack-traces/message-trace.ts +40 -4
  229. package/src/internal/hardhat-network/stack-traces/model.ts +61 -0
  230. package/src/internal/hardhat-network/stack-traces/opcodes.ts +4 -0
  231. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +2 -2
  232. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +6 -5
  233. package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +113 -4
  234. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +67 -95
  235. package/src/internal/util/date.ts +4 -0
  236. package/src/internal/util/hardforks.ts +52 -0
  237. package/src/internal/hardhat-network/provider/BlockchainBase.ts +0 -185
  238. package/src/internal/hardhat-network/provider/BlockchainData.ts +0 -261
  239. package/src/internal/hardhat-network/provider/HardhatBlockchain.ts +0 -140
  240. package/src/internal/hardhat-network/provider/PoolState.ts +0 -48
  241. package/src/internal/hardhat-network/provider/TransactionQueue.ts +0 -158
  242. package/src/internal/hardhat-network/provider/TxPool.ts +0 -715
  243. package/src/internal/hardhat-network/provider/ethereumjs-workarounds.ts +0 -21
  244. package/src/internal/hardhat-network/provider/filter.ts +0 -142
  245. package/src/internal/hardhat-network/provider/fork/ForkBlockchain.ts +0 -433
  246. package/src/internal/hardhat-network/provider/fork/ForkStateManager.ts +0 -480
  247. package/src/internal/hardhat-network/provider/fork/rpcToBlockData.ts +0 -35
  248. package/src/internal/hardhat-network/provider/fork/rpcToTxData.ts +0 -44
  249. package/src/internal/hardhat-network/provider/modules/base.ts +0 -156
  250. package/src/internal/hardhat-network/provider/modules/debug.ts +0 -104
  251. package/src/internal/hardhat-network/provider/modules/eth.ts +0 -1781
  252. package/src/internal/hardhat-network/provider/modules/evm.ts +0 -249
  253. package/src/internal/hardhat-network/provider/modules/hardhat.ts +0 -481
  254. package/src/internal/hardhat-network/provider/modules/net.ts +0 -60
  255. package/src/internal/hardhat-network/provider/modules/personal.ts +0 -40
  256. package/src/internal/hardhat-network/provider/modules/web3.ts +0 -49
  257. package/src/internal/hardhat-network/provider/node.ts +0 -2999
  258. package/src/internal/hardhat-network/provider/transactions/FakeSenderAccessListEIP2930Transaction.ts +0 -226
  259. package/src/internal/hardhat-network/provider/transactions/FakeSenderEIP1559Transaction.ts +0 -224
  260. package/src/internal/hardhat-network/provider/transactions/FakeSenderTransaction.ts +0 -216
  261. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP1559Transaction.ts +0 -143
  262. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidEIP2930Transaction.ts +0 -144
  263. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidTransaction.ts +0 -171
  264. package/src/internal/hardhat-network/provider/transactions/ReadOnlyValidUnknownTypeTransaction.ts +0 -169
  265. package/src/internal/hardhat-network/provider/types/HardhatBlockchainInterface.ts +0 -25
  266. package/src/internal/hardhat-network/provider/utils/makeFakeSignature.ts +0 -60
  267. package/src/internal/hardhat-network/provider/utils/makeStateTrie.ts +0 -29
  268. package/src/internal/hardhat-network/provider/utils/putGenesisBlock.ts +0 -61
  269. package/src/internal/hardhat-network/provider/utils/reorganizeTransactionsLists.ts +0 -45
  270. package/src/internal/hardhat-network/provider/utils/txMapToArray.ts +0 -7
  271. package/src/internal/hardhat-network/stack-traces/vm-debug-tracer.ts +0 -630
@@ -1,17 +1,30 @@
1
1
  import type {
2
2
  Artifacts,
3
3
  BoundExperimentalHardhatNetworkMessageTraceHook,
4
+ CompilerInput,
5
+ CompilerOutput,
4
6
  EIP1193Provider,
5
7
  EthSubscription,
6
8
  HardhatNetworkChainsConfig,
7
9
  RequestArguments,
8
10
  } from "../../../types";
9
11
 
12
+ import {
13
+ EdrContext,
14
+ Provider as EdrProviderT,
15
+ ExecutionResult,
16
+ RawTrace,
17
+ Response,
18
+ SubscriptionEvent,
19
+ TracingMessage,
20
+ TracingStep,
21
+ } from "@nomicfoundation/edr";
10
22
  import { Common } from "@nomicfoundation/ethereumjs-common";
11
23
  import chalk from "chalk";
12
24
  import debug from "debug";
13
25
  import { EventEmitter } from "events";
14
26
  import fsExtra from "fs-extra";
27
+ import * as t from "io-ts";
15
28
  import semver from "semver";
16
29
 
17
30
  import {
@@ -19,24 +32,31 @@ import {
19
32
  HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT,
20
33
  } from "../../constants";
21
34
  import {
35
+ rpcCompilerInput,
36
+ rpcCompilerOutput,
37
+ } from "../../core/jsonrpc/types/input/solc";
38
+ import { validateParams } from "../../core/jsonrpc/types/input/validation";
39
+ import {
40
+ InvalidArgumentsError,
22
41
  InvalidInputError,
23
- MethodNotFoundError,
24
- MethodNotSupportedError,
25
42
  ProviderError,
26
43
  } from "../../core/providers/errors";
27
- import { Mutex } from "../../vendor/await-semaphore";
28
-
44
+ import { isErrorResponse } from "../../core/providers/http";
45
+ import { getHardforkName } from "../../util/hardforks";
46
+ import { createModelsAndDecodeBytecodes } from "../stack-traces/compiler-to-model";
47
+ import { ConsoleLogger } from "../stack-traces/consoleLogger";
48
+ import { ContractsIdentifier } from "../stack-traces/contracts-identifier";
49
+ import {
50
+ VmTraceDecoder,
51
+ initializeVmTraceDecoder,
52
+ } from "../stack-traces/vm-trace-decoder";
29
53
  import { FIRST_SOLC_VERSION_SUPPORTED } from "../stack-traces/constants";
30
- import { MiningTimer } from "./MiningTimer";
31
- import { DebugModule } from "./modules/debug";
32
- import { EthModule } from "./modules/eth";
33
- import { EvmModule } from "./modules/evm";
34
- import { HardhatModule } from "./modules/hardhat";
35
- import { ModulesLogger } from "./modules/logger";
36
- import { PersonalModule } from "./modules/personal";
37
- import { NetModule } from "./modules/net";
38
- import { Web3Module } from "./modules/web3";
39
- import { HardhatNode } from "./node";
54
+ import { encodeSolidityStackTrace } from "../stack-traces/solidity-errors";
55
+ import { SolidityStackTrace } from "../stack-traces/solidity-stack-trace";
56
+ import { SolidityTracer } from "../stack-traces/solidityTracer";
57
+ import { VMTracer } from "../stack-traces/vm-tracer";
58
+
59
+ import { getPackageJson } from "../../util/packageInfo";
40
60
  import {
41
61
  ForkConfig,
42
62
  GenesisAccount,
@@ -45,18 +65,35 @@ import {
45
65
  NodeConfig,
46
66
  TracingConfig,
47
67
  } from "./node-types";
68
+ import {
69
+ edrRpcDebugTraceToHardhat,
70
+ edrTracingMessageResultToMinimalEVMResult,
71
+ edrTracingMessageToMinimalMessage,
72
+ edrTracingStepToMinimalInterpreterStep,
73
+ ethereumjsIntervalMiningConfigToEdr,
74
+ ethereumjsMempoolOrderToEdrMineOrdering,
75
+ ethereumsjsHardforkToEdrSpecId,
76
+ } from "./utils/convertToEdr";
77
+ import { makeCommon } from "./utils/makeCommon";
78
+ import { LoggerConfig, printLine, replaceLastLine } from "./modules/logger";
79
+ import { MinimalEthereumJsVm, getMinimalEthereumJsVm } from "./vm/minimal-vm";
48
80
 
49
81
  const log = debug("hardhat:core:hardhat-network:provider");
50
82
 
51
- // Set of methods that are never logged
52
- const PRIVATE_RPC_METHODS = new Set([
53
- "hardhat_getStackTraceFailuresCount",
54
- "hardhat_setLoggingEnabled",
55
- ]);
56
-
57
83
  /* eslint-disable @nomicfoundation/hardhat-internal-rules/only-hardhat-error */
58
84
 
59
85
  export const DEFAULT_COINBASE = "0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e";
86
+ let _globalEdrContext: EdrContext | undefined;
87
+
88
+ // Lazy initialize the global EDR context.
89
+ export function getGlobalEdrContext(): EdrContext {
90
+ if (_globalEdrContext === undefined) {
91
+ // Only one is allowed to exist
92
+ _globalEdrContext = new EdrContext();
93
+ }
94
+
95
+ return _globalEdrContext;
96
+ }
60
97
 
61
98
  interface HardhatNetworkProviderConfig {
62
99
  hardfork: string;
@@ -83,312 +120,515 @@ interface HardhatNetworkProviderConfig {
83
120
  enableTransientStorage: boolean;
84
121
  }
85
122
 
86
- export class HardhatNetworkProvider
123
+ export function getNodeConfig(
124
+ config: HardhatNetworkProviderConfig,
125
+ tracingConfig?: TracingConfig
126
+ ): NodeConfig {
127
+ return {
128
+ automine: config.automine,
129
+ blockGasLimit: config.blockGasLimit,
130
+ minGasPrice: config.minGasPrice,
131
+ genesisAccounts: config.genesisAccounts,
132
+ allowUnlimitedContractSize: config.allowUnlimitedContractSize,
133
+ tracingConfig,
134
+ initialBaseFeePerGas: config.initialBaseFeePerGas,
135
+ mempoolOrder: config.mempoolOrder,
136
+ hardfork: config.hardfork,
137
+ chainId: config.chainId,
138
+ networkId: config.networkId,
139
+ initialDate: config.initialDate,
140
+ forkConfig: config.forkConfig,
141
+ forkCachePath:
142
+ config.forkConfig !== undefined ? config.forkCachePath : undefined,
143
+ coinbase: config.coinbase ?? DEFAULT_COINBASE,
144
+ chains: config.chains,
145
+ allowBlocksWithSameTimestamp: config.allowBlocksWithSameTimestamp,
146
+ enableTransientStorage: config.enableTransientStorage,
147
+ };
148
+ }
149
+
150
+ export interface RawTraceCallbacks {
151
+ onStep?: (messageTrace: TracingStep) => Promise<void>;
152
+ onBeforeMessage?: (messageTrace: TracingMessage) => Promise<void>;
153
+ onAfterMessage?: (messageTrace: ExecutionResult) => Promise<void>;
154
+ }
155
+
156
+ class EdrProviderEventAdapter extends EventEmitter {}
157
+
158
+ type CallOverrideCallback = (
159
+ address: Buffer,
160
+ data: Buffer
161
+ ) => Promise<
162
+ { result: Buffer; shouldRevert: boolean; gas: bigint } | undefined
163
+ >;
164
+
165
+ export class EdrProviderWrapper
87
166
  extends EventEmitter
88
167
  implements EIP1193Provider
89
168
  {
90
- private _node?: HardhatNode;
91
- private _ethModule?: EthModule;
92
- private _netModule?: NetModule;
93
- private _web3Module?: Web3Module;
94
- private _evmModule?: EvmModule;
95
- private _hardhatModule?: HardhatModule;
96
- private _debugModule?: DebugModule;
97
- private _personalModule?: PersonalModule;
98
- private readonly _mutex = new Mutex();
99
- // this field is not used here but it's used in the tests
100
- private _common?: Common;
101
-
102
- constructor(
103
- private readonly _config: HardhatNetworkProviderConfig,
104
- private readonly _logger: ModulesLogger,
105
- private readonly _artifacts?: Artifacts
169
+ private _failedStackTraces = 0;
170
+
171
+ // temporarily added to make smock work with HH+EDR
172
+ private _callOverrideCallback?: CallOverrideCallback;
173
+
174
+ private constructor(
175
+ private readonly _provider: EdrProviderT,
176
+ // we add this for backwards-compatibility with plugins like solidity-coverage
177
+ private readonly _node: {
178
+ _vm: MinimalEthereumJsVm;
179
+ },
180
+ private readonly _eventAdapter: EdrProviderEventAdapter,
181
+ private readonly _vmTraceDecoder: VmTraceDecoder,
182
+ private readonly _rawTraceCallbacks: RawTraceCallbacks,
183
+ // The common configuration for EthereumJS VM is not used by EDR, but tests expect it as part of the provider.
184
+ private readonly _common: Common,
185
+ tracingConfig?: TracingConfig
106
186
  ) {
107
187
  super();
188
+
189
+ if (tracingConfig !== undefined) {
190
+ initializeVmTraceDecoder(this._vmTraceDecoder, tracingConfig);
191
+ }
108
192
  }
109
193
 
110
- public async request(args: RequestArguments): Promise<unknown> {
111
- const release = await this._mutex.acquire();
194
+ public static async create(
195
+ config: HardhatNetworkProviderConfig,
196
+ loggerConfig: LoggerConfig,
197
+ rawTraceCallbacks: RawTraceCallbacks,
198
+ tracingConfig?: TracingConfig
199
+ ): Promise<EdrProviderWrapper> {
200
+ const { Provider } =
201
+ require("@nomicfoundation/edr") as typeof import("@nomicfoundation/edr");
202
+
203
+ const coinbase = config.coinbase ?? DEFAULT_COINBASE;
204
+
205
+ let fork;
206
+ if (config.forkConfig !== undefined) {
207
+ fork = {
208
+ jsonRpcUrl: config.forkConfig.jsonRpcUrl,
209
+ blockNumber:
210
+ config.forkConfig.blockNumber !== undefined
211
+ ? BigInt(config.forkConfig.blockNumber)
212
+ : undefined,
213
+ };
214
+ }
215
+
216
+ const initialDate =
217
+ config.initialDate !== undefined
218
+ ? BigInt(Math.floor(config.initialDate.getTime() / 1000))
219
+ : undefined;
220
+
221
+ // To accomodate construction ordering, we need an adapter to forward events
222
+ // from the EdrProvider callback to the wrapper's listener
223
+ const eventAdapter = new EdrProviderEventAdapter();
224
+
225
+ const printLineFn = loggerConfig.printLineFn ?? printLine;
226
+ const replaceLastLineFn = loggerConfig.replaceLastLineFn ?? replaceLastLine;
227
+
228
+ const contractsIdentifier = new ContractsIdentifier();
229
+ const vmTraceDecoder = new VmTraceDecoder(contractsIdentifier);
230
+
231
+ const hardforkName = getHardforkName(config.hardfork);
232
+
233
+ const provider = await Provider.withConfig(
234
+ getGlobalEdrContext(),
235
+ {
236
+ allowBlocksWithSameTimestamp:
237
+ config.allowBlocksWithSameTimestamp ?? false,
238
+ allowUnlimitedContractSize: config.allowUnlimitedContractSize,
239
+ bailOnCallFailure: config.throwOnCallFailures,
240
+ bailOnTransactionFailure: config.throwOnTransactionFailures,
241
+ blockGasLimit: BigInt(config.blockGasLimit),
242
+ chainId: BigInt(config.chainId),
243
+ chains: Array.from(config.chains, ([chainId, hardforkConfig]) => {
244
+ return {
245
+ chainId: BigInt(chainId),
246
+ hardforks: Array.from(
247
+ hardforkConfig.hardforkHistory,
248
+ ([hardfork, blockNumber]) => {
249
+ return {
250
+ blockNumber: BigInt(blockNumber),
251
+ specId: ethereumsjsHardforkToEdrSpecId(
252
+ getHardforkName(hardfork)
253
+ ),
254
+ };
255
+ }
256
+ ),
257
+ };
258
+ }),
259
+ cacheDir: config.forkCachePath,
260
+ coinbase: Buffer.from(coinbase.slice(2), "hex"),
261
+ fork,
262
+ hardfork: ethereumsjsHardforkToEdrSpecId(hardforkName),
263
+ genesisAccounts: config.genesisAccounts.map((account) => {
264
+ return {
265
+ secretKey: account.privateKey,
266
+ balance: BigInt(account.balance),
267
+ };
268
+ }),
269
+ initialDate,
270
+ initialBaseFeePerGas:
271
+ config.initialBaseFeePerGas !== undefined
272
+ ? BigInt(config.initialBaseFeePerGas!)
273
+ : undefined,
274
+ minGasPrice: config.minGasPrice,
275
+ mining: {
276
+ autoMine: config.automine,
277
+ interval: ethereumjsIntervalMiningConfigToEdr(config.intervalMining),
278
+ memPool: {
279
+ order: ethereumjsMempoolOrderToEdrMineOrdering(config.mempoolOrder),
280
+ },
281
+ },
282
+ networkId: BigInt(config.networkId),
283
+ },
284
+ {
285
+ enable: loggerConfig.enabled,
286
+ decodeConsoleLogInputsCallback: (inputs: Buffer[]) => {
287
+ const consoleLogger = new ConsoleLogger();
288
+ return consoleLogger.getDecodedLogs(inputs);
289
+ },
290
+ getContractAndFunctionNameCallback: (
291
+ code: Buffer,
292
+ calldata?: Buffer
293
+ ) => {
294
+ return vmTraceDecoder.getContractAndFunctionNamesForCall(
295
+ code,
296
+ calldata
297
+ );
298
+ },
299
+ printLineCallback: (message: string, replace: boolean) => {
300
+ if (replace) {
301
+ replaceLastLineFn(message);
302
+ } else {
303
+ printLineFn(message);
304
+ }
305
+ },
306
+ },
307
+ (event: SubscriptionEvent) => {
308
+ eventAdapter.emit("ethEvent", event);
309
+ }
310
+ );
112
311
 
312
+ const minimalEthereumJsNode = {
313
+ _vm: getMinimalEthereumJsVm(provider),
314
+ };
315
+
316
+ const common = makeCommon(getNodeConfig(config));
317
+ const wrapper = new EdrProviderWrapper(
318
+ provider,
319
+ minimalEthereumJsNode,
320
+ eventAdapter,
321
+ vmTraceDecoder,
322
+ rawTraceCallbacks,
323
+ common,
324
+ tracingConfig
325
+ );
326
+
327
+ // Pass through all events from the provider
328
+ eventAdapter.addListener(
329
+ "ethEvent",
330
+ wrapper._ethEventListener.bind(wrapper)
331
+ );
332
+
333
+ return wrapper;
334
+ }
335
+
336
+ public async request(args: RequestArguments): Promise<unknown> {
113
337
  if (args.params !== undefined && !Array.isArray(args.params)) {
114
338
  throw new InvalidInputError(
115
339
  "Hardhat Network doesn't support JSON-RPC params sent as an object"
116
340
  );
117
341
  }
118
342
 
119
- try {
120
- let result;
121
- if (this._logger.isEnabled() && !PRIVATE_RPC_METHODS.has(args.method)) {
122
- result = await this._sendWithLogging(args.method, args.params);
123
- } else {
124
- result = await this._send(args.method, args.params);
125
- }
126
-
127
- if (args.method === "hardhat_reset") {
128
- this.emit(HARDHAT_NETWORK_RESET_EVENT);
129
- }
130
- if (args.method === "evm_revert") {
131
- this.emit(HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT);
132
- }
343
+ const params = args.params ?? [];
133
344
 
134
- return result;
135
- } finally {
136
- release();
345
+ if (args.method === "hardhat_addCompilationResult") {
346
+ return this._addCompilationResultAction(
347
+ ...this._addCompilationResultParams(params)
348
+ );
349
+ } else if (args.method === "hardhat_getStackTraceFailuresCount") {
350
+ return this._getStackTraceFailuresCountAction(
351
+ ...this._getStackTraceFailuresCountParams(params)
352
+ );
137
353
  }
138
- }
139
354
 
140
- private async _sendWithLogging(
141
- method: string,
142
- params: any[] = []
143
- ): Promise<any> {
144
- try {
145
- const result = await this._send(method, params);
146
- // We log after running the method, because we want to use different
147
- // colors depending on whether it failed or not
148
-
149
- // TODO: If an eth_call, eth_sendTransaction, or eth_sendRawTransaction
150
- // fails without throwing, this will be displayed in green. It's unclear
151
- // if this is correct. See Eth module's TODOs for more info.
152
-
153
- if (method !== "hardhat_intervalMine") {
154
- this._logger.printMethod(method);
355
+ const stringifiedArgs = JSON.stringify({
356
+ method: args.method,
357
+ params,
358
+ });
155
359
 
156
- const printedSomething = this._logger.printLogs();
157
- if (printedSomething) {
158
- this._logger.printEmptyLine();
360
+ const responseObject: Response = await this._provider.handleRequest(
361
+ stringifiedArgs
362
+ );
363
+ const response = JSON.parse(responseObject.json);
364
+
365
+ const rawTraces = responseObject.traces;
366
+ for (const rawTrace of rawTraces) {
367
+ const trace = rawTrace.trace();
368
+ for (const traceItem of trace) {
369
+ if ("pc" in traceItem) {
370
+ this._node._vm.evm.events.emit(
371
+ "step",
372
+ edrTracingStepToMinimalInterpreterStep(traceItem)
373
+ );
374
+ if (this._rawTraceCallbacks.onStep !== undefined) {
375
+ await this._rawTraceCallbacks.onStep(traceItem);
376
+ }
377
+ } else if ("executionResult" in traceItem) {
378
+ this._node._vm.evm.events.emit(
379
+ "afterMessage",
380
+ edrTracingMessageResultToMinimalEVMResult(traceItem)
381
+ );
382
+ if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
383
+ await this._rawTraceCallbacks.onAfterMessage(
384
+ traceItem.executionResult
385
+ );
386
+ }
387
+ } else {
388
+ this._node._vm.evm.events.emit(
389
+ "beforeMessage",
390
+ edrTracingMessageToMinimalMessage(traceItem)
391
+ );
392
+ if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
393
+ await this._rawTraceCallbacks.onBeforeMessage(traceItem);
394
+ }
159
395
  }
160
396
  }
397
+ }
161
398
 
162
- return result;
163
- } catch (err) {
164
- if (
165
- err instanceof MethodNotFoundError ||
166
- err instanceof MethodNotSupportedError
167
- ) {
168
- this._logger.printMethodNotSupported(method);
399
+ if (isErrorResponse(response)) {
400
+ let error;
169
401
 
170
- throw err;
402
+ const solidityTrace = responseObject.solidityTrace;
403
+ let stackTrace: SolidityStackTrace | undefined;
404
+ if (solidityTrace !== null) {
405
+ stackTrace = await this._rawTraceToSolidityStackTrace(solidityTrace);
171
406
  }
172
407
 
173
- this._logger.printFailedMethod(method);
174
- this._logger.printLogs();
175
-
176
- if (err instanceof Error && !this._logger.isLoggedError(err)) {
177
- if (ProviderError.isProviderError(err)) {
178
- this._logger.printEmptyLine();
179
- this._logger.printErrorMessage(err.message);
180
-
181
- const isEIP155Error =
182
- err instanceof InvalidInputError && err.message.includes("EIP155");
183
- if (isEIP155Error) {
184
- this._logger.printMetaMaskWarning();
185
- }
408
+ if (stackTrace !== undefined) {
409
+ error = encodeSolidityStackTrace(response.error.message, stackTrace);
410
+ // Pass data and transaction hash from the original error
411
+ (error as any).data = {
412
+ data: response.error.data?.data ?? undefined,
413
+ transactionHash: response.error.data?.transactionHash ?? undefined,
414
+ };
415
+ } else {
416
+ if (response.error.code === InvalidArgumentsError.CODE) {
417
+ error = new InvalidArgumentsError(response.error.message);
186
418
  } else {
187
- this._logger.printUnknownError(err);
419
+ error = new ProviderError(
420
+ response.error.message,
421
+ response.error.code
422
+ );
188
423
  }
424
+ error.data = response.error.data;
189
425
  }
190
426
 
191
- this._logger.printEmptyLine();
192
-
193
- throw err;
427
+ // eslint-disable-next-line @nomicfoundation/hardhat-internal-rules/only-hardhat-error
428
+ throw error;
194
429
  }
195
- }
196
430
 
197
- private async _send(method: string, params: any[] = []): Promise<any> {
198
- await this._init();
199
-
200
- if (method.startsWith("eth_")) {
201
- return this._ethModule!.processRequest(method, params);
431
+ if (args.method === "hardhat_reset") {
432
+ this.emit(HARDHAT_NETWORK_RESET_EVENT);
433
+ } else if (args.method === "evm_revert") {
434
+ this.emit(HARDHAT_NETWORK_REVERT_SNAPSHOT_EVENT);
202
435
  }
203
436
 
204
- if (method.startsWith("net_")) {
205
- return this._netModule!.processRequest(method, params);
206
- }
207
-
208
- if (method.startsWith("web3_")) {
209
- return this._web3Module!.processRequest(method, params);
210
- }
211
-
212
- if (method.startsWith("evm_")) {
213
- return this._evmModule!.processRequest(method, params);
437
+ // Override EDR version string with Hardhat version string with EDR backend,
438
+ // e.g. `HardhatNetwork/2.19.0/@nomicfoundation/edr/0.2.0-dev`
439
+ if (args.method === "web3_clientVersion") {
440
+ return clientVersion(response.result);
441
+ } else if (
442
+ args.method === "debug_traceTransaction" ||
443
+ args.method === "debug_traceCall"
444
+ ) {
445
+ return edrRpcDebugTraceToHardhat(response.result);
446
+ } else {
447
+ return response.result;
214
448
  }
449
+ }
215
450
 
216
- if (method.startsWith("hardhat_")) {
217
- return this._hardhatModule!.processRequest(method, params);
218
- }
451
+ // temporarily added to make smock work with HH+EDR
452
+ private _setCallOverrideCallback(callback: CallOverrideCallback) {
453
+ this._callOverrideCallback = callback;
219
454
 
220
- if (method.startsWith("debug_")) {
221
- return this._debugModule!.processRequest(method, params);
222
- }
455
+ this._provider.setCallOverrideCallback(
456
+ async (address: Buffer, data: Buffer) => {
457
+ return this._callOverrideCallback?.(address, data);
458
+ }
459
+ );
460
+ }
223
461
 
224
- if (method.startsWith("personal_")) {
225
- return this._personalModule!.processRequest(method, params);
462
+ private _ethEventListener(event: SubscriptionEvent) {
463
+ const subscription = `0x${event.filterId.toString(16)}`;
464
+ const results = Array.isArray(event.result) ? event.result : [event.result];
465
+ for (const result of results) {
466
+ this._emitLegacySubscriptionEvent(subscription, result);
467
+ this._emitEip1193SubscriptionEvent(subscription, result);
226
468
  }
227
-
228
- throw new MethodNotFoundError(`Method ${method} not found`);
229
469
  }
230
470
 
231
- private async _init() {
232
- if (this._node !== undefined) {
233
- return;
234
- }
471
+ private _emitLegacySubscriptionEvent(subscription: string, result: any) {
472
+ this.emit("notification", {
473
+ subscription,
474
+ result,
475
+ });
476
+ }
235
477
 
236
- const config: NodeConfig = {
237
- automine: this._config.automine,
238
- blockGasLimit: this._config.blockGasLimit,
239
- minGasPrice: this._config.minGasPrice,
240
- genesisAccounts: this._config.genesisAccounts,
241
- allowUnlimitedContractSize: this._config.allowUnlimitedContractSize,
242
- tracingConfig: await this._makeTracingConfig(),
243
- initialBaseFeePerGas: this._config.initialBaseFeePerGas,
244
- mempoolOrder: this._config.mempoolOrder,
245
- hardfork: this._config.hardfork,
246
- chainId: this._config.chainId,
247
- networkId: this._config.networkId,
248
- initialDate: this._config.initialDate,
249
- forkConfig: this._config.forkConfig,
250
- forkCachePath:
251
- this._config.forkConfig !== undefined
252
- ? this._config.forkCachePath
253
- : undefined,
254
- coinbase: this._config.coinbase ?? DEFAULT_COINBASE,
255
- chains: this._config.chains,
256
- allowBlocksWithSameTimestamp: this._config.allowBlocksWithSameTimestamp,
257
- enableTransientStorage: this._config.enableTransientStorage,
478
+ private _emitEip1193SubscriptionEvent(subscription: string, result: unknown) {
479
+ const message: EthSubscription = {
480
+ type: "eth_subscription",
481
+ data: {
482
+ subscription,
483
+ result,
484
+ },
258
485
  };
259
486
 
260
- const [common, node] = await HardhatNode.create(config);
261
-
262
- this._common = common;
263
- this._node = node;
487
+ this.emit("message", message);
488
+ }
264
489
 
265
- this._ethModule = new EthModule(
266
- common,
267
- node,
268
- this._config.throwOnTransactionFailures,
269
- this._config.throwOnCallFailures,
270
- this._logger,
271
- this._config.experimentalHardhatNetworkMessageTraceHooks
490
+ private _addCompilationResultParams(
491
+ params: any[]
492
+ ): [string, CompilerInput, CompilerOutput] {
493
+ return validateParams(
494
+ params,
495
+ t.string,
496
+ rpcCompilerInput,
497
+ rpcCompilerOutput
272
498
  );
499
+ }
273
500
 
274
- const miningTimer = this._makeMiningTimer();
501
+ private async _addCompilationResultAction(
502
+ solcVersion: string,
503
+ compilerInput: CompilerInput,
504
+ compilerOutput: CompilerOutput
505
+ ): Promise<boolean> {
506
+ let bytecodes;
507
+ try {
508
+ bytecodes = createModelsAndDecodeBytecodes(
509
+ solcVersion,
510
+ compilerInput,
511
+ compilerOutput
512
+ );
513
+ } catch (error) {
514
+ console.warn(
515
+ chalk.yellow(
516
+ "The Hardhat Network tracing engine could not be updated. Run Hardhat with --verbose to learn more."
517
+ )
518
+ );
275
519
 
276
- this._netModule = new NetModule(common);
277
- this._web3Module = new Web3Module(node);
278
- this._evmModule = new EvmModule(
279
- node,
280
- miningTimer,
281
- this._logger,
282
- this._config.allowBlocksWithSameTimestamp,
283
- this._config.experimentalHardhatNetworkMessageTraceHooks
284
- );
285
- this._hardhatModule = new HardhatModule(
286
- node,
287
- (forkConfig?: ForkConfig) => this._reset(miningTimer, forkConfig),
288
- (loggingEnabled: boolean) => {
289
- this._logger.setEnabled(loggingEnabled);
290
- },
291
- this._logger,
292
- this._config.experimentalHardhatNetworkMessageTraceHooks
293
- );
294
- this._debugModule = new DebugModule(node);
295
- this._personalModule = new PersonalModule(node);
520
+ log(
521
+ "ContractsIdentifier failed to be updated. Please report this to help us improve Hardhat.\n",
522
+ error
523
+ );
296
524
 
297
- this._forwardNodeEvents(node);
298
- }
525
+ return false;
526
+ }
299
527
 
300
- private async _makeTracingConfig(): Promise<TracingConfig | undefined> {
301
- if (this._artifacts !== undefined) {
302
- const buildInfos = [];
528
+ for (const bytecode of bytecodes) {
529
+ this._vmTraceDecoder.addBytecode(bytecode);
530
+ }
303
531
 
304
- const buildInfoFiles = await this._artifacts.getBuildInfoPaths();
532
+ return true;
533
+ }
305
534
 
306
- try {
307
- for (const buildInfoFile of buildInfoFiles) {
308
- const buildInfo = await fsExtra.readJson(buildInfoFile);
309
- if (semver.gte(buildInfo.solcVersion, FIRST_SOLC_VERSION_SUPPORTED)) {
310
- buildInfos.push(buildInfo);
311
- }
312
- }
535
+ private _getStackTraceFailuresCountParams(params: any[]): [] {
536
+ return validateParams(params);
537
+ }
313
538
 
314
- return {
315
- buildInfos,
316
- };
317
- } catch (error) {
318
- console.warn(
319
- chalk.yellow(
320
- "Stack traces engine could not be initialized. Run Hardhat with --verbose to learn more."
321
- )
322
- );
323
-
324
- log(
325
- "Solidity stack traces disabled: Failed to read solc's input and output files. Please report this to help us improve Hardhat.\n",
326
- error
327
- );
328
- }
329
- }
539
+ private _getStackTraceFailuresCountAction(): number {
540
+ return this._failedStackTraces;
330
541
  }
331
542
 
332
- private _makeMiningTimer(): MiningTimer {
333
- const miningTimer = new MiningTimer(
334
- this._config.intervalMining,
335
- async () => {
336
- try {
337
- await this.request({ method: "hardhat_intervalMine" });
338
- } catch (e) {
339
- console.error("Unexpected error calling hardhat_intervalMine:", e);
340
- }
543
+ private async _rawTraceToSolidityStackTrace(
544
+ rawTrace: RawTrace
545
+ ): Promise<SolidityStackTrace | undefined> {
546
+ const vmTracer = new VMTracer(false);
547
+
548
+ const trace = rawTrace.trace();
549
+ for (const traceItem of trace) {
550
+ if ("pc" in traceItem) {
551
+ await vmTracer.addStep(traceItem);
552
+ } else if ("executionResult" in traceItem) {
553
+ await vmTracer.addAfterMessage(traceItem.executionResult);
554
+ } else {
555
+ await vmTracer.addBeforeMessage(traceItem);
341
556
  }
342
- );
343
-
344
- miningTimer.start();
557
+ }
345
558
 
346
- return miningTimer;
347
- }
559
+ let vmTrace = vmTracer.getLastTopLevelMessageTrace();
560
+ const vmTracerError = vmTracer.getLastError();
348
561
 
349
- private async _reset(miningTimer: MiningTimer, forkConfig?: ForkConfig) {
350
- this._config.forkConfig = forkConfig;
351
- if (this._node !== undefined) {
352
- this._stopForwardingNodeEvents(this._node);
562
+ if (vmTrace !== undefined) {
563
+ vmTrace = this._vmTraceDecoder.tryToDecodeMessageTrace(vmTrace);
353
564
  }
354
- this._node = undefined;
355
565
 
356
- miningTimer.stop();
566
+ try {
567
+ if (vmTrace === undefined || vmTracerError !== undefined) {
568
+ throw vmTracerError;
569
+ }
357
570
 
358
- await this._init();
571
+ const solidityTracer = new SolidityTracer();
572
+ return solidityTracer.getStackTrace(vmTrace);
573
+ } catch (err) {
574
+ this._failedStackTraces += 1;
575
+ log(
576
+ "Could not generate stack trace. Please report this to help us improve Hardhat.\n",
577
+ err
578
+ );
579
+ }
359
580
  }
581
+ }
360
582
 
361
- private _forwardNodeEvents(node: HardhatNode) {
362
- node.addListener("ethEvent", this._ethEventListener);
363
- }
583
+ async function clientVersion(edrClientVersion: string): Promise<string> {
584
+ const hardhatPackage = await getPackageJson();
585
+ const edrVersion = edrClientVersion.split("/")[1];
586
+ return `HardhatNetwork/${hardhatPackage.version}/@nomicfoundation/edr/${edrVersion}`;
587
+ }
364
588
 
365
- private _stopForwardingNodeEvents(node: HardhatNode) {
366
- node.removeListener("ethEvent", this._ethEventListener);
367
- }
589
+ export async function createHardhatNetworkProvider(
590
+ hardhatNetworkProviderConfig: HardhatNetworkProviderConfig,
591
+ loggerConfig: LoggerConfig,
592
+ artifacts?: Artifacts
593
+ ): Promise<EIP1193Provider> {
594
+ return EdrProviderWrapper.create(
595
+ hardhatNetworkProviderConfig,
596
+ loggerConfig,
597
+ {},
598
+ await makeTracingConfig(artifacts)
599
+ );
600
+ }
368
601
 
369
- private _ethEventListener = (payload: { filterId: bigint; result: any }) => {
370
- const subscription = `0x${payload.filterId.toString(16)}`;
371
- const result = payload.result;
372
- this._emitLegacySubscriptionEvent(subscription, result);
373
- this._emitEip1193SubscriptionEvent(subscription, result);
374
- };
602
+ async function makeTracingConfig(
603
+ artifacts: Artifacts | undefined
604
+ ): Promise<TracingConfig | undefined> {
605
+ if (artifacts !== undefined) {
606
+ const buildInfos = [];
375
607
 
376
- private _emitLegacySubscriptionEvent(subscription: string, result: any) {
377
- this.emit("notification", {
378
- subscription,
379
- result,
380
- });
381
- }
608
+ const buildInfoFiles = await artifacts.getBuildInfoPaths();
382
609
 
383
- private _emitEip1193SubscriptionEvent(subscription: string, result: unknown) {
384
- const message: EthSubscription = {
385
- type: "eth_subscription",
386
- data: {
387
- subscription,
388
- result,
389
- },
390
- };
610
+ try {
611
+ for (const buildInfoFile of buildInfoFiles) {
612
+ const buildInfo = await fsExtra.readJson(buildInfoFile);
613
+ if (semver.gte(buildInfo.solcVersion, FIRST_SOLC_VERSION_SUPPORTED)) {
614
+ buildInfos.push(buildInfo);
615
+ }
616
+ }
391
617
 
392
- this.emit("message", message);
618
+ return {
619
+ buildInfos,
620
+ };
621
+ } catch (error) {
622
+ console.warn(
623
+ chalk.yellow(
624
+ "Stack traces engine could not be initialized. Run Hardhat with --verbose to learn more."
625
+ )
626
+ );
627
+
628
+ log(
629
+ "Solidity stack traces disabled: Failed to read solc's input and output files. Please report this to help us improve Hardhat.\n",
630
+ error
631
+ );
632
+ }
393
633
  }
394
634
  }