hardhat 2.22.11 → 2.22.12

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 (90) hide show
  1. package/internal/hardhat-network/provider/provider.d.ts +2 -3
  2. package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
  3. package/internal/hardhat-network/provider/provider.js +5 -19
  4. package/internal/hardhat-network/provider/provider.js.map +1 -1
  5. package/internal/hardhat-network/provider/return-data.d.ts +2 -15
  6. package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
  7. package/internal/hardhat-network/provider/return-data.js +2 -50
  8. package/internal/hardhat-network/provider/return-data.js.map +1 -1
  9. package/internal/hardhat-network/provider/vm/exit.d.ts +2 -20
  10. package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -1
  11. package/internal/hardhat-network/provider/vm/exit.js +3 -78
  12. package/internal/hardhat-network/provider/vm/exit.js.map +1 -1
  13. package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts +2 -3
  14. package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts.map +1 -1
  15. package/internal/hardhat-network/stack-traces/compiler-to-model.js +2 -351
  16. package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
  17. package/internal/hardhat-network/stack-traces/debug.d.ts +2 -7
  18. package/internal/hardhat-network/stack-traces/debug.d.ts.map +1 -1
  19. package/internal/hardhat-network/stack-traces/debug.js +3 -143
  20. package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
  21. package/internal/hardhat-network/stack-traces/library-utils.d.ts +2 -11
  22. package/internal/hardhat-network/stack-traces/library-utils.d.ts.map +1 -1
  23. package/internal/hardhat-network/stack-traces/library-utils.js +3 -61
  24. package/internal/hardhat-network/stack-traces/library-utils.js.map +1 -1
  25. package/internal/hardhat-network/stack-traces/message-trace.d.ts +2 -51
  26. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  27. package/internal/hardhat-network/stack-traces/message-trace.js +0 -46
  28. package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
  29. package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
  30. package/internal/hardhat-network/stack-traces/solidity-errors.js +58 -53
  31. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  32. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +4 -155
  33. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
  34. package/internal/hardhat-network/stack-traces/solidity-stack-trace.js +12 -37
  35. package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
  36. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +2 -13
  37. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  38. package/internal/hardhat-network/stack-traces/solidityTracer.js +2 -162
  39. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  40. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +4 -15
  41. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
  42. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +6 -70
  43. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
  44. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +2 -19
  45. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  46. package/internal/hardhat-network/stack-traces/vm-tracer.js +3 -150
  47. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  48. package/package.json +4 -4
  49. package/src/internal/hardhat-network/provider/provider.ts +11 -24
  50. package/src/internal/hardhat-network/provider/return-data.ts +5 -73
  51. package/src/internal/hardhat-network/provider/vm/exit.ts +4 -92
  52. package/src/internal/hardhat-network/stack-traces/compiler-to-model.ts +5 -697
  53. package/src/internal/hardhat-network/stack-traces/debug.ts +5 -218
  54. package/src/internal/hardhat-network/stack-traces/library-utils.ts +5 -90
  55. package/src/internal/hardhat-network/stack-traces/message-trace.ts +5 -122
  56. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +16 -15
  57. package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +83 -186
  58. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +5 -253
  59. package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +15 -108
  60. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +5 -206
  61. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +0 -15
  62. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +0 -1
  63. package/internal/hardhat-network/stack-traces/contracts-identifier.js +0 -166
  64. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +0 -1
  65. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts +0 -85
  66. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +0 -1
  67. package/internal/hardhat-network/stack-traces/error-inferrer.js +0 -1168
  68. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +0 -1
  69. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts +0 -24
  70. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts.map +0 -1
  71. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js +0 -116
  72. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js.map +0 -1
  73. package/internal/hardhat-network/stack-traces/model.d.ts +0 -140
  74. package/internal/hardhat-network/stack-traces/model.d.ts.map +0 -1
  75. package/internal/hardhat-network/stack-traces/model.js +0 -328
  76. package/internal/hardhat-network/stack-traces/model.js.map +0 -1
  77. package/internal/hardhat-network/stack-traces/opcodes.d.ts +0 -266
  78. package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +0 -1
  79. package/internal/hardhat-network/stack-traces/opcodes.js +0 -320
  80. package/internal/hardhat-network/stack-traces/opcodes.js.map +0 -1
  81. package/internal/hardhat-network/stack-traces/source-maps.d.ts +0 -13
  82. package/internal/hardhat-network/stack-traces/source-maps.d.ts.map +0 -1
  83. package/internal/hardhat-network/stack-traces/source-maps.js +0 -106
  84. package/internal/hardhat-network/stack-traces/source-maps.js.map +0 -1
  85. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +0 -235
  86. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +0 -1845
  87. package/src/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.ts +0 -163
  88. package/src/internal/hardhat-network/stack-traces/model.ts +0 -409
  89. package/src/internal/hardhat-network/stack-traces/opcodes.ts +0 -344
  90. package/src/internal/hardhat-network/stack-traces/source-maps.ts +0 -167
@@ -1,189 +1,86 @@
1
- import { ReturnData } from "../provider/return-data";
2
-
3
- import { ContractFunctionType } from "./model";
4
-
5
- export enum StackTraceEntryType {
6
- CALLSTACK_ENTRY,
7
- UNRECOGNIZED_CREATE_CALLSTACK_ENTRY,
8
- UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY,
9
- PRECOMPILE_ERROR,
10
- REVERT_ERROR,
11
- PANIC_ERROR,
12
- CUSTOM_ERROR,
13
- FUNCTION_NOT_PAYABLE_ERROR,
14
- INVALID_PARAMS_ERROR,
15
- FALLBACK_NOT_PAYABLE_ERROR,
16
- FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR,
17
- UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR, // TODO: Should trying to call a private/internal be a special case of this?
18
- MISSING_FALLBACK_OR_RECEIVE_ERROR,
19
- RETURNDATA_SIZE_ERROR,
20
- NONCONTRACT_ACCOUNT_CALLED_ERROR,
21
- CALL_FAILED_ERROR,
22
- DIRECT_LIBRARY_CALL_ERROR,
23
- UNRECOGNIZED_CREATE_ERROR,
24
- UNRECOGNIZED_CONTRACT_ERROR,
25
- OTHER_EXECUTION_ERROR,
26
- // This is a special case to handle a regression introduced in solc 0.6.3
27
- // For more info: https://github.com/ethereum/solidity/issues/9006
28
- UNMAPPED_SOLC_0_6_3_REVERT_ERROR,
29
- CONTRACT_TOO_LARGE_ERROR,
30
- INTERNAL_FUNCTION_CALLSTACK_ENTRY,
31
- CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR,
32
- }
33
-
34
- export const FALLBACK_FUNCTION_NAME = "<fallback>";
35
- export const RECEIVE_FUNCTION_NAME = "<receive>";
36
- export const CONSTRUCTOR_FUNCTION_NAME = "constructor";
37
- export const UNRECOGNIZED_FUNCTION_NAME = "<unrecognized-selector>";
38
- export const UNKNOWN_FUNCTION_NAME = "<unknown>";
39
- export const PRECOMPILE_FUNCTION_NAME = "<precompile>";
40
- export const UNRECOGNIZED_CONTRACT_NAME = "<UnrecognizedContract>";
41
-
42
- export interface SourceReference {
43
- sourceName: string;
44
- sourceContent: string;
45
- contract?: string;
46
- function?: string;
47
- line: number;
48
- range: [number, number];
49
- }
50
-
51
- export interface CallstackEntryStackTraceEntry {
52
- type: StackTraceEntryType.CALLSTACK_ENTRY;
53
- sourceReference: SourceReference;
54
- functionType: ContractFunctionType;
55
- }
56
-
57
- export interface UnrecognizedCreateCallstackEntryStackTraceEntry {
58
- type: StackTraceEntryType.UNRECOGNIZED_CREATE_CALLSTACK_ENTRY;
59
- sourceReference?: undefined;
60
- }
61
-
62
- export interface UnrecognizedContractCallstackEntryStackTraceEntry {
63
- type: StackTraceEntryType.UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY;
64
- address: Uint8Array;
65
- sourceReference?: undefined;
66
- }
67
-
68
- export interface PrecompileErrorStackTraceEntry {
69
- type: StackTraceEntryType.PRECOMPILE_ERROR;
70
- precompile: number;
71
- sourceReference?: undefined;
72
- }
73
-
74
- export interface RevertErrorStackTraceEntry {
75
- type: StackTraceEntryType.REVERT_ERROR;
76
- message: ReturnData;
77
- sourceReference: SourceReference;
78
- isInvalidOpcodeError: boolean;
79
- }
80
-
81
- export interface PanicErrorStackTraceEntry {
82
- type: StackTraceEntryType.PANIC_ERROR;
83
- errorCode: bigint;
84
- sourceReference?: SourceReference;
85
- }
86
-
87
- export interface CustomErrorStackTraceEntry {
88
- type: StackTraceEntryType.CUSTOM_ERROR;
89
- // unlike RevertErrorStackTraceEntry, this includes the message already parsed
90
- message: string;
91
- sourceReference: SourceReference;
92
- }
93
-
94
- export interface UnmappedSolc063RevertErrorStackTraceEntry {
95
- type: StackTraceEntryType.UNMAPPED_SOLC_0_6_3_REVERT_ERROR;
96
- sourceReference?: SourceReference;
97
- }
98
-
99
- export interface FunctionNotPayableErrorStackTraceEntry {
100
- type: StackTraceEntryType.FUNCTION_NOT_PAYABLE_ERROR;
101
- value: bigint;
102
- sourceReference: SourceReference;
103
- }
104
-
105
- export interface InvalidParamsErrorStackTraceEntry {
106
- type: StackTraceEntryType.INVALID_PARAMS_ERROR;
107
- sourceReference: SourceReference;
108
- }
109
-
110
- export interface FallbackNotPayableErrorStackTraceEntry {
111
- type: StackTraceEntryType.FALLBACK_NOT_PAYABLE_ERROR;
112
- value: bigint;
113
- sourceReference: SourceReference;
114
- }
115
-
116
- export interface FallbackNotPayableAndNoReceiveErrorStackTraceEntry {
117
- type: StackTraceEntryType.FALLBACK_NOT_PAYABLE_AND_NO_RECEIVE_ERROR;
118
- value: bigint;
119
- sourceReference: SourceReference;
120
- }
121
-
122
- export interface UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry {
123
- type: StackTraceEntryType.UNRECOGNIZED_FUNCTION_WITHOUT_FALLBACK_ERROR;
124
- sourceReference: SourceReference;
125
- }
126
-
127
- export interface MissingFallbackOrReceiveErrorStackTraceEntry {
128
- type: StackTraceEntryType.MISSING_FALLBACK_OR_RECEIVE_ERROR;
129
- sourceReference: SourceReference;
130
- }
131
-
132
- export interface ReturndataSizeErrorStackTraceEntry {
133
- type: StackTraceEntryType.RETURNDATA_SIZE_ERROR;
134
- sourceReference: SourceReference;
135
- }
136
-
137
- export interface NonContractAccountCalledErrorStackTraceEntry {
138
- type: StackTraceEntryType.NONCONTRACT_ACCOUNT_CALLED_ERROR;
139
- sourceReference: SourceReference;
140
- }
141
-
142
- export interface CallFailedErrorStackTraceEntry {
143
- type: StackTraceEntryType.CALL_FAILED_ERROR;
144
- sourceReference: SourceReference;
145
- }
146
-
147
- export interface DirectLibraryCallErrorStackTraceEntry {
148
- type: StackTraceEntryType.DIRECT_LIBRARY_CALL_ERROR;
149
- sourceReference: SourceReference;
150
- }
151
-
152
- export interface UnrecognizedCreateErrorStackTraceEntry {
153
- type: StackTraceEntryType.UNRECOGNIZED_CREATE_ERROR;
154
- message: ReturnData;
155
- sourceReference?: undefined;
156
- isInvalidOpcodeError: boolean;
157
- }
158
-
159
- export interface UnrecognizedContractErrorStackTraceEntry {
160
- type: StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR;
161
- address: Uint8Array;
162
- message: ReturnData;
163
- sourceReference?: undefined;
164
- isInvalidOpcodeError: boolean;
165
- }
166
-
167
- export interface OtherExecutionErrorStackTraceEntry {
168
- type: StackTraceEntryType.OTHER_EXECUTION_ERROR;
169
- sourceReference?: SourceReference;
170
- }
171
-
172
- export interface ContractTooLargeErrorStackTraceEntry {
173
- type: StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR;
174
- sourceReference?: SourceReference;
175
- }
176
-
177
- export interface InternalFunctionCallStackEntry {
178
- type: StackTraceEntryType.INTERNAL_FUNCTION_CALLSTACK_ENTRY;
179
- pc: number;
180
- sourceReference: SourceReference;
181
- }
182
-
183
- export interface ContractCallRunOutOfGasError {
184
- type: StackTraceEntryType.CONTRACT_CALL_RUN_OUT_OF_GAS_ERROR;
185
- sourceReference?: SourceReference;
186
- }
1
+ import type {
2
+ SourceReference,
3
+ CallstackEntryStackTraceEntry,
4
+ UnrecognizedCreateCallstackEntryStackTraceEntry,
5
+ UnrecognizedContractCallstackEntryStackTraceEntry,
6
+ PrecompileErrorStackTraceEntry,
7
+ RevertErrorStackTraceEntry,
8
+ PanicErrorStackTraceEntry,
9
+ CustomErrorStackTraceEntry,
10
+ FunctionNotPayableErrorStackTraceEntry,
11
+ InvalidParamsErrorStackTraceEntry,
12
+ FallbackNotPayableErrorStackTraceEntry,
13
+ FallbackNotPayableAndNoReceiveErrorStackTraceEntry,
14
+ UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry,
15
+ MissingFallbackOrReceiveErrorStackTraceEntry,
16
+ ReturndataSizeErrorStackTraceEntry,
17
+ NonContractAccountCalledErrorStackTraceEntry,
18
+ CallFailedErrorStackTraceEntry,
19
+ DirectLibraryCallErrorStackTraceEntry,
20
+ UnrecognizedCreateErrorStackTraceEntry,
21
+ UnrecognizedContractErrorStackTraceEntry,
22
+ OtherExecutionErrorStackTraceEntry,
23
+ UnmappedSolc063RevertErrorStackTraceEntry,
24
+ ContractTooLargeErrorStackTraceEntry,
25
+ InternalFunctionCallStackEntry,
26
+ ContractCallRunOutOfGasError,
27
+ } from "@nomicfoundation/edr";
28
+
29
+ import { requireNapiRsModule } from "../../../common/napi-rs";
30
+
31
+ const {
32
+ StackTraceEntryType,
33
+ stackTraceEntryTypeToString,
34
+ FALLBACK_FUNCTION_NAME,
35
+ RECEIVE_FUNCTION_NAME,
36
+ CONSTRUCTOR_FUNCTION_NAME,
37
+ UNRECOGNIZED_FUNCTION_NAME,
38
+ UNKNOWN_FUNCTION_NAME,
39
+ PRECOMPILE_FUNCTION_NAME,
40
+ UNRECOGNIZED_CONTRACT_NAME,
41
+ } = requireNapiRsModule(
42
+ "@nomicfoundation/edr"
43
+ ) as typeof import("@nomicfoundation/edr");
44
+
45
+ export {
46
+ SourceReference,
47
+ StackTraceEntryType,
48
+ stackTraceEntryTypeToString,
49
+ FALLBACK_FUNCTION_NAME,
50
+ RECEIVE_FUNCTION_NAME,
51
+ CONSTRUCTOR_FUNCTION_NAME,
52
+ UNRECOGNIZED_FUNCTION_NAME,
53
+ UNKNOWN_FUNCTION_NAME,
54
+ PRECOMPILE_FUNCTION_NAME,
55
+ UNRECOGNIZED_CONTRACT_NAME,
56
+ };
57
+
58
+ export type {
59
+ CallstackEntryStackTraceEntry,
60
+ UnrecognizedCreateCallstackEntryStackTraceEntry,
61
+ UnrecognizedContractCallstackEntryStackTraceEntry,
62
+ PrecompileErrorStackTraceEntry,
63
+ RevertErrorStackTraceEntry,
64
+ PanicErrorStackTraceEntry,
65
+ CustomErrorStackTraceEntry,
66
+ FunctionNotPayableErrorStackTraceEntry,
67
+ InvalidParamsErrorStackTraceEntry,
68
+ FallbackNotPayableErrorStackTraceEntry,
69
+ FallbackNotPayableAndNoReceiveErrorStackTraceEntry,
70
+ UnrecognizedFunctionWithoutFallbackErrorStackTraceEntry,
71
+ MissingFallbackOrReceiveErrorStackTraceEntry,
72
+ ReturndataSizeErrorStackTraceEntry,
73
+ NonContractAccountCalledErrorStackTraceEntry,
74
+ CallFailedErrorStackTraceEntry,
75
+ DirectLibraryCallErrorStackTraceEntry,
76
+ UnrecognizedCreateErrorStackTraceEntry,
77
+ UnrecognizedContractErrorStackTraceEntry,
78
+ OtherExecutionErrorStackTraceEntry,
79
+ UnmappedSolc063RevertErrorStackTraceEntry,
80
+ ContractTooLargeErrorStackTraceEntry,
81
+ InternalFunctionCallStackEntry,
82
+ ContractCallRunOutOfGasError,
83
+ };
187
84
 
188
85
  export type SolidityStackTraceEntry =
189
86
  | CallstackEntryStackTraceEntry
@@ -1,255 +1,7 @@
1
- import { equalsBytes } from "@nomicfoundation/ethereumjs-util";
1
+ import { requireNapiRsModule } from "../../../common/napi-rs";
2
2
 
3
- import { ReturnData } from "../provider/return-data";
4
- import { ExitCode } from "../provider/vm/exit";
3
+ const { SolidityTracer } = requireNapiRsModule(
4
+ "@nomicfoundation/edr"
5
+ ) as typeof import("@nomicfoundation/edr");
5
6
 
6
- import {
7
- ErrorInferrer,
8
- instructionToCallstackStackTraceEntry,
9
- SubmessageData,
10
- } from "./error-inferrer";
11
- import {
12
- adjustStackTrace,
13
- stackTraceMayRequireAdjustments,
14
- } from "./mapped-inlined-internal-functions-heuristics";
15
- import {
16
- DecodedCallMessageTrace,
17
- DecodedCreateMessageTrace,
18
- DecodedEvmMessageTrace,
19
- EvmMessageTrace,
20
- EvmStep,
21
- isCreateTrace,
22
- isDecodedCallTrace,
23
- isDecodedCreateTrace,
24
- isEvmStep,
25
- isPrecompileTrace,
26
- MessageTrace,
27
- PrecompileMessageTrace,
28
- } from "./message-trace";
29
- import { Instruction, JumpType } from "./model";
30
- import { Opcode } from "./opcodes";
31
- import {
32
- SolidityStackTrace,
33
- SolidityStackTraceEntry,
34
- StackTraceEntryType,
35
- } from "./solidity-stack-trace";
36
-
37
- export class SolidityTracer {
38
- private _errorInferrer = new ErrorInferrer();
39
-
40
- public getStackTrace(
41
- maybeDecodedMessageTrace: MessageTrace
42
- ): SolidityStackTrace {
43
- if (!maybeDecodedMessageTrace.exit.isError()) {
44
- return [];
45
- }
46
-
47
- if (isPrecompileTrace(maybeDecodedMessageTrace)) {
48
- return this._getPrecompileMessageStackTrace(maybeDecodedMessageTrace);
49
- }
50
-
51
- if (isDecodedCreateTrace(maybeDecodedMessageTrace)) {
52
- return this._getCreateMessageStackTrace(maybeDecodedMessageTrace);
53
- }
54
-
55
- if (isDecodedCallTrace(maybeDecodedMessageTrace)) {
56
- return this._getCallMessageStackTrace(maybeDecodedMessageTrace);
57
- }
58
-
59
- return this._getUnrecognizedMessageStackTrace(maybeDecodedMessageTrace);
60
- }
61
-
62
- private _getCallMessageStackTrace(
63
- trace: DecodedCallMessageTrace
64
- ): SolidityStackTrace {
65
- const inferredError =
66
- this._errorInferrer.inferBeforeTracingCallMessage(trace);
67
-
68
- if (inferredError !== undefined) {
69
- return inferredError;
70
- }
71
-
72
- return this._traceEvmExecution(trace);
73
- }
74
-
75
- private _getUnrecognizedMessageStackTrace(
76
- trace: EvmMessageTrace
77
- ): SolidityStackTrace {
78
- const subtrace = this._getLastSubtrace(trace);
79
-
80
- if (subtrace !== undefined) {
81
- // This is not a very exact heuristic, but most of the time it will be right, as solidity
82
- // reverts if a call fails, and most contracts are in solidity
83
- if (
84
- subtrace.exit.isError() &&
85
- equalsBytes(trace.returnData, subtrace.returnData)
86
- ) {
87
- let unrecognizedEntry: SolidityStackTraceEntry;
88
-
89
- if (isCreateTrace(trace)) {
90
- unrecognizedEntry = {
91
- type: StackTraceEntryType.UNRECOGNIZED_CREATE_CALLSTACK_ENTRY,
92
- };
93
- } else {
94
- unrecognizedEntry = {
95
- type: StackTraceEntryType.UNRECOGNIZED_CONTRACT_CALLSTACK_ENTRY,
96
- address: trace.address,
97
- };
98
- }
99
-
100
- return [unrecognizedEntry, ...this.getStackTrace(subtrace)];
101
- }
102
- }
103
-
104
- if (trace.exit.kind === ExitCode.CODESIZE_EXCEEDS_MAXIMUM) {
105
- return [
106
- {
107
- type: StackTraceEntryType.CONTRACT_TOO_LARGE_ERROR,
108
- },
109
- ];
110
- }
111
-
112
- const isInvalidOpcodeError = trace.exit.kind === ExitCode.INVALID_OPCODE;
113
-
114
- if (isCreateTrace(trace)) {
115
- return [
116
- {
117
- type: StackTraceEntryType.UNRECOGNIZED_CREATE_ERROR,
118
- message: new ReturnData(trace.returnData),
119
- isInvalidOpcodeError,
120
- },
121
- ];
122
- }
123
-
124
- return [
125
- {
126
- type: StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR,
127
- address: trace.address,
128
- message: new ReturnData(trace.returnData),
129
- isInvalidOpcodeError,
130
- },
131
- ];
132
- }
133
-
134
- private _getCreateMessageStackTrace(
135
- trace: DecodedCreateMessageTrace
136
- ): SolidityStackTrace {
137
- const inferredError =
138
- this._errorInferrer.inferBeforeTracingCreateMessage(trace);
139
-
140
- if (inferredError !== undefined) {
141
- return inferredError;
142
- }
143
-
144
- return this._traceEvmExecution(trace);
145
- }
146
-
147
- private _getPrecompileMessageStackTrace(
148
- trace: PrecompileMessageTrace
149
- ): SolidityStackTrace {
150
- return [
151
- {
152
- type: StackTraceEntryType.PRECOMPILE_ERROR,
153
- precompile: trace.precompile,
154
- },
155
- ];
156
- }
157
-
158
- private _traceEvmExecution(
159
- trace: DecodedEvmMessageTrace
160
- ): SolidityStackTrace {
161
- const stackTrace = this._rawTraceEvmExecution(trace);
162
-
163
- if (stackTraceMayRequireAdjustments(stackTrace, trace)) {
164
- return adjustStackTrace(stackTrace, trace);
165
- }
166
-
167
- return stackTrace;
168
- }
169
-
170
- private _rawTraceEvmExecution(
171
- trace: DecodedEvmMessageTrace
172
- ): SolidityStackTrace {
173
- const stacktrace: SolidityStackTrace = [];
174
-
175
- let subtracesSeen = 0;
176
-
177
- // There was a jump into a function according to the sourcemaps
178
- let jumpedIntoFunction = false;
179
-
180
- const functionJumpdests: Instruction[] = [];
181
-
182
- let lastSubmessageData: SubmessageData | undefined;
183
-
184
- for (let stepIndex = 0; stepIndex < trace.steps.length; stepIndex++) {
185
- const step = trace.steps[stepIndex];
186
- const nextStep = trace.steps[stepIndex + 1];
187
-
188
- if (isEvmStep(step)) {
189
- const inst = trace.bytecode.getInstruction(step.pc);
190
-
191
- if (
192
- inst.jumpType === JumpType.INTO_FUNCTION &&
193
- nextStep !== undefined
194
- ) {
195
- const nextEvmStep = nextStep as EvmStep; // A jump can't be followed by a subtrace
196
- const nextInst = trace.bytecode.getInstruction(nextEvmStep.pc);
197
-
198
- if (nextInst !== undefined && nextInst.opcode === Opcode.JUMPDEST) {
199
- stacktrace.push(
200
- instructionToCallstackStackTraceEntry(trace.bytecode, inst)
201
- );
202
- if (nextInst.location !== undefined) {
203
- jumpedIntoFunction = true;
204
- }
205
- functionJumpdests.push(nextInst);
206
- }
207
- } else if (inst.jumpType === JumpType.OUTOF_FUNCTION) {
208
- stacktrace.pop();
209
- functionJumpdests.pop();
210
- }
211
- } else {
212
- subtracesSeen += 1;
213
-
214
- // If there are more subtraces, this one didn't terminate the execution
215
- if (subtracesSeen < trace.numberOfSubtraces) {
216
- continue;
217
- }
218
-
219
- const submessageTrace = this.getStackTrace(step);
220
-
221
- lastSubmessageData = {
222
- messageTrace: step,
223
- stepIndex,
224
- stacktrace: submessageTrace,
225
- };
226
- }
227
- }
228
-
229
- const stacktraceWithInferredError = this._errorInferrer.inferAfterTracing(
230
- trace,
231
- stacktrace,
232
- functionJumpdests,
233
- jumpedIntoFunction,
234
- lastSubmessageData
235
- );
236
-
237
- return this._errorInferrer.filterRedundantFrames(
238
- stacktraceWithInferredError
239
- );
240
- }
241
-
242
- private _getLastSubtrace(trace: EvmMessageTrace): MessageTrace | undefined {
243
- if (trace.numberOfSubtraces < 1) {
244
- return undefined;
245
- }
246
-
247
- let i = trace.steps.length - 1;
248
-
249
- while (isEvmStep(trace.steps[i])) {
250
- i -= 1;
251
- }
252
-
253
- return trace.steps[i] as MessageTrace;
254
- }
255
- }
7
+ export { SolidityTracer };
@@ -1,121 +1,22 @@
1
+ import type { VmTraceDecoder as VmTraceDecoderT } from "@nomicfoundation/edr";
1
2
  import chalk from "chalk";
2
3
  import debug from "debug";
3
4
  import { Reporter } from "../../sentry/reporter";
4
5
  import { TracingConfig } from "../provider/node-types";
5
- import { createModelsAndDecodeBytecodes } from "./compiler-to-model";
6
- import { ContractsIdentifier } from "./contracts-identifier";
7
- import {
8
- isCreateTrace,
9
- isEvmStep,
10
- isPrecompileTrace,
11
- MessageTrace,
12
- } from "./message-trace";
13
- import { Bytecode, ContractFunctionType } from "./model";
14
- import {
15
- FALLBACK_FUNCTION_NAME,
16
- RECEIVE_FUNCTION_NAME,
17
- UNRECOGNIZED_CONTRACT_NAME,
18
- UNRECOGNIZED_FUNCTION_NAME,
19
- } from "./solidity-stack-trace";
6
+ import { requireNapiRsModule } from "../../../common/napi-rs";
20
7
 
21
8
  const log = debug("hardhat:core:hardhat-network:node");
22
9
 
23
- export class VmTraceDecoder {
24
- constructor(private readonly _contractsIdentifier: ContractsIdentifier) {}
10
+ const { VmTraceDecoder, initializeVmTraceDecoder } = requireNapiRsModule(
11
+ "@nomicfoundation/edr"
12
+ ) as typeof import("@nomicfoundation/edr");
25
13
 
26
- public getContractAndFunctionNamesForCall(
27
- code: Buffer,
28
- calldata?: Buffer
29
- ): { contractName: string; functionName?: string } {
30
- const isCreate = calldata === undefined;
31
- const bytecode = this._contractsIdentifier.getBytecodeForCall(
32
- code,
33
- isCreate
34
- );
35
-
36
- const contractName = bytecode?.contract.name ?? UNRECOGNIZED_CONTRACT_NAME;
37
-
38
- if (isCreate) {
39
- return {
40
- contractName,
41
- };
42
- } else {
43
- if (bytecode === undefined) {
44
- return {
45
- contractName,
46
- functionName: "",
47
- };
48
- } else {
49
- const func = bytecode.contract.getFunctionFromSelector(
50
- calldata.slice(0, 4)
51
- );
52
-
53
- const functionName: string =
54
- func === undefined
55
- ? UNRECOGNIZED_FUNCTION_NAME
56
- : func.type === ContractFunctionType.FALLBACK
57
- ? FALLBACK_FUNCTION_NAME
58
- : func.type === ContractFunctionType.RECEIVE
59
- ? RECEIVE_FUNCTION_NAME
60
- : func.name;
61
-
62
- return {
63
- contractName,
64
- functionName,
65
- };
66
- }
67
- }
68
- }
69
-
70
- public tryToDecodeMessageTrace(messageTrace: MessageTrace): MessageTrace {
71
- if (isPrecompileTrace(messageTrace)) {
72
- return messageTrace;
73
- }
74
-
75
- return {
76
- ...messageTrace,
77
- bytecode: this._contractsIdentifier.getBytecodeForCall(
78
- messageTrace.code,
79
- isCreateTrace(messageTrace)
80
- ),
81
- steps: messageTrace.steps.map((s) =>
82
- isEvmStep(s) ? s : this.tryToDecodeMessageTrace(s)
83
- ),
84
- };
85
- }
86
-
87
- public addBytecode(bytecode: Bytecode) {
88
- this._contractsIdentifier.addBytecode(bytecode);
89
- }
90
- }
91
-
92
- export function initializeVmTraceDecoder(
93
- vmTraceDecoder: VmTraceDecoder,
14
+ function initializeVmTraceDecoderWrapper(
15
+ vmTraceDecoder: VmTraceDecoderT,
94
16
  tracingConfig: TracingConfig
95
17
  ) {
96
- if (tracingConfig.buildInfos === undefined) {
97
- return;
98
- }
99
-
100
18
  try {
101
- for (const buildInfo of tracingConfig.buildInfos) {
102
- const bytecodes = createModelsAndDecodeBytecodes(
103
- buildInfo.solcVersion,
104
- buildInfo.input,
105
- buildInfo.output
106
- );
107
-
108
- for (const bytecode of bytecodes) {
109
- if (
110
- tracingConfig.ignoreContracts === true &&
111
- bytecode.contract.name.startsWith("Ignored")
112
- ) {
113
- continue;
114
- }
115
-
116
- vmTraceDecoder.addBytecode(bytecode);
117
- }
118
- }
19
+ initializeVmTraceDecoder(vmTraceDecoder, tracingConfig);
119
20
  } catch (error) {
120
21
  console.warn(
121
22
  chalk.yellow(
@@ -124,7 +25,7 @@ export function initializeVmTraceDecoder(
124
25
  );
125
26
 
126
27
  log(
127
- "Hardhat Network tracing disabled: ContractsIdentifier failed to be initialized. Please report this to help us improve Hardhat.\n",
28
+ "Hardhat Network tracing disabled: VmTraceDecoder failed to be initialized. Please report this to help us improve Hardhat.\n",
128
29
  error
129
30
  );
130
31
 
@@ -133,3 +34,9 @@ export function initializeVmTraceDecoder(
133
34
  }
134
35
  }
135
36
  }
37
+
38
+ export {
39
+ VmTraceDecoder,
40
+ VmTraceDecoderT,
41
+ initializeVmTraceDecoderWrapper as initializeVmTraceDecoder,
42
+ };