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,220 +1,7 @@
1
- import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util";
2
- import chalk from "chalk";
1
+ import { requireNapiRsModule } from "../../../common/napi-rs";
3
2
 
4
- import {
5
- CallMessageTrace,
6
- CreateMessageTrace,
7
- isCreateTrace,
8
- isEvmStep,
9
- isPrecompileTrace,
10
- MessageTrace,
11
- PrecompileMessageTrace,
12
- } from "./message-trace";
13
- import { JumpType } from "./model";
14
- import { isJump, isPush, Opcode } from "./opcodes";
15
- import {
16
- SolidityStackTrace,
17
- SourceReference,
18
- StackTraceEntryType,
19
- } from "./solidity-stack-trace";
3
+ const { printMessageTrace, printStackTrace } = requireNapiRsModule(
4
+ "@nomicfoundation/edr"
5
+ ) as typeof import("@nomicfoundation/edr");
20
6
 
21
- const MARGIN_SPACE = 6;
22
-
23
- export function printMessageTrace(trace: MessageTrace, depth = 0) {
24
- console.log("");
25
-
26
- if (isCreateTrace(trace)) {
27
- printCreateTrace(trace, depth);
28
- } else if (isPrecompileTrace(trace)) {
29
- printPrecompileTrace(trace, depth);
30
- } else {
31
- printCallTrace(trace, depth);
32
- }
33
-
34
- console.log("");
35
- }
36
-
37
- export function printCreateTrace(trace: CreateMessageTrace, depth: number) {
38
- const margin = "".padStart(depth * MARGIN_SPACE);
39
- console.log(`${margin}Create trace`);
40
-
41
- if (trace.bytecode !== undefined) {
42
- console.log(
43
- `${margin} deploying contract: ${trace.bytecode.contract.location.file.sourceName}:${trace.bytecode.contract.name}`
44
- );
45
-
46
- console.log(`${margin} code: ${bufferToHex(trace.code)}`);
47
- } else {
48
- console.log(
49
- `${margin} unrecognized deployment code: ${bufferToHex(trace.code)}`
50
- );
51
- }
52
-
53
- console.log(`${margin} value: ${trace.value.toString(10)}`);
54
-
55
- if (trace.deployedContract !== undefined) {
56
- console.log(
57
- `${margin} contract address: ${bufferToHex(trace.deployedContract)}`
58
- );
59
- }
60
-
61
- if (trace.exit.isError()) {
62
- console.log(`${margin} error: ${trace.exit.getReason()}`);
63
-
64
- // The return data is the deployed-bytecode if there was no error, so we don't show it
65
- console.log(`${margin} returnData: ${bufferToHex(trace.returnData)}`);
66
- }
67
-
68
- traceSteps(trace, depth);
69
- }
70
-
71
- export function printPrecompileTrace(
72
- trace: PrecompileMessageTrace,
73
- depth: number
74
- ) {
75
- const margin = "".padStart(depth * MARGIN_SPACE);
76
- console.log(`${margin}Precompile trace`);
77
-
78
- console.log(`${margin} precompile number: ${trace.precompile}`);
79
- console.log(`${margin} value: ${trace.value.toString(10)}`);
80
- console.log(`${margin} calldata: ${bufferToHex(trace.calldata)}`);
81
-
82
- if (trace.exit.isError()) {
83
- console.log(`${margin} error: ${trace.exit.getReason()}`);
84
- }
85
-
86
- console.log(`${margin} returnData: ${bufferToHex(trace.returnData)}`);
87
- }
88
-
89
- export function printCallTrace(trace: CallMessageTrace, depth: number) {
90
- const margin = "".padStart(depth * MARGIN_SPACE);
91
- console.log(`${margin}Call trace`);
92
-
93
- if (trace.bytecode !== undefined) {
94
- console.log(
95
- `${margin} calling contract: ${trace.bytecode.contract.location.file.sourceName}:${trace.bytecode.contract.name}`
96
- );
97
- } else {
98
- console.log(
99
- `${margin} unrecognized contract code: ${bufferToHex(trace.code)}`
100
- );
101
- console.log(`${margin} contract: ${bufferToHex(trace.address)}`);
102
- }
103
-
104
- console.log(`${margin} value: ${trace.value.toString(10)}`);
105
- console.log(`${margin} calldata: ${bufferToHex(trace.calldata)}`);
106
-
107
- if (trace.exit.isError()) {
108
- console.log(`${margin} error: ${trace.exit.getReason()}`);
109
- }
110
-
111
- console.log(`${margin} returnData: ${bufferToHex(trace.returnData)}`);
112
-
113
- traceSteps(trace, depth);
114
- }
115
-
116
- function traceSteps(
117
- trace: CreateMessageTrace | CallMessageTrace,
118
- depth: number
119
- ) {
120
- const margin = "".padStart(depth * MARGIN_SPACE);
121
-
122
- console.log(`${margin} steps:`);
123
- console.log("");
124
-
125
- for (const step of trace.steps) {
126
- if (isEvmStep(step)) {
127
- const pc = step.pc.toString(10).padStart(3, "0").padStart(5);
128
-
129
- if (trace.bytecode !== undefined) {
130
- const inst = trace.bytecode.getInstruction(step.pc);
131
-
132
- let location: string = "";
133
-
134
- if (inst.location !== undefined) {
135
- location += inst.location.file.sourceName;
136
-
137
- const func = inst.location.getContainingFunction();
138
- if (func !== undefined) {
139
- location += `:${
140
- func.contract?.name ?? func.location.file.sourceName
141
- }:${func.name}`;
142
- }
143
-
144
- location += ` - ${inst.location.offset}:${inst.location.length}`;
145
- }
146
-
147
- if (isJump(inst.opcode)) {
148
- const jump =
149
- inst.jumpType !== JumpType.NOT_JUMP
150
- ? chalk.bold(`(${JumpType[inst.jumpType]})`)
151
- : "";
152
-
153
- console.log(
154
- `${margin} ${pc} ${Opcode[inst.opcode]} ${jump}`.padEnd(50),
155
- location
156
- );
157
- } else if (isPush(inst.opcode)) {
158
- console.log(
159
- `${margin} ${pc} ${Opcode[inst.opcode]} ${bufferToHex(
160
- inst.pushData!
161
- )}`.padEnd(50),
162
- location
163
- );
164
- } else {
165
- console.log(
166
- `${margin} ${pc} ${Opcode[inst.opcode]}`.padEnd(50),
167
- location
168
- );
169
- }
170
- } else {
171
- console.log(`${margin} ${pc}`);
172
- }
173
- } else {
174
- printMessageTrace(step, depth + 1);
175
- }
176
- }
177
- }
178
-
179
- function flattenSourceReference(sourceReference?: SourceReference) {
180
- if (sourceReference === undefined) {
181
- return undefined;
182
- }
183
-
184
- return {
185
- ...sourceReference,
186
- file: sourceReference.sourceName,
187
- };
188
- }
189
-
190
- export function printStackTrace(trace: SolidityStackTrace) {
191
- const withDecodedMessages = trace.map((entry) =>
192
- entry.type === StackTraceEntryType.REVERT_ERROR
193
- ? { ...entry, message: entry.message.decodeError() }
194
- : entry
195
- );
196
-
197
- const withHexAddress = withDecodedMessages.map((entry) =>
198
- "address" in entry
199
- ? { ...entry, address: bufferToHex(entry.address) }
200
- : entry
201
- );
202
-
203
- const withTextualType = withHexAddress.map((entry) => ({
204
- ...entry,
205
- type: StackTraceEntryType[entry.type],
206
- }));
207
-
208
- const withFlattenedSourceReferences = withTextualType.map((entry) => ({
209
- ...entry,
210
- sourceReference: flattenSourceReference(entry.sourceReference),
211
- }));
212
-
213
- console.log(
214
- JSON.stringify(
215
- withFlattenedSourceReferences,
216
- (key, value) => (typeof value === "bigint" ? value.toString() : value),
217
- 2
218
- )
219
- );
220
- }
7
+ export { printMessageTrace, printStackTrace };
@@ -1,92 +1,7 @@
1
- import { CompilerOutputBytecode } from "../../../types";
1
+ import { requireNapiRsModule } from "../../../common/napi-rs";
2
2
 
3
- import { Opcode } from "./opcodes";
3
+ const { linkHexStringBytecode } = requireNapiRsModule(
4
+ "@nomicfoundation/edr"
5
+ ) as typeof import("@nomicfoundation/edr");
4
6
 
5
- export function getLibraryAddressPositions(
6
- bytecodeOutput: CompilerOutputBytecode
7
- ): number[] {
8
- const positions = [];
9
- for (const libs of Object.values(bytecodeOutput.linkReferences)) {
10
- for (const references of Object.values(libs)) {
11
- for (const ref of references) {
12
- positions.push(ref.start);
13
- }
14
- }
15
- }
16
-
17
- return positions;
18
- }
19
-
20
- export function normalizeCompilerOutputBytecode(
21
- compilerOutputBytecodeObject: string,
22
- addressesPositions: number[]
23
- ): Buffer {
24
- const ZERO_ADDRESS = "0000000000000000000000000000000000000000";
25
- for (const position of addressesPositions) {
26
- compilerOutputBytecodeObject = linkHexStringBytecode(
27
- compilerOutputBytecodeObject,
28
- ZERO_ADDRESS,
29
- position
30
- );
31
- }
32
-
33
- return Buffer.from(compilerOutputBytecodeObject, "hex");
34
- }
35
-
36
- export function linkHexStringBytecode(
37
- code: string,
38
- address: string,
39
- position: number
40
- ) {
41
- if (address.startsWith("0x")) {
42
- address = address.substring(2);
43
- }
44
-
45
- return (
46
- code.substring(0, position * 2) +
47
- address +
48
- code.slice(position * 2 + address.length)
49
- );
50
- }
51
-
52
- export function zeroOutAddresses(
53
- code: Uint8Array,
54
- addressesPositions: number[]
55
- ): Uint8Array {
56
- const addressesSlices = addressesPositions.map((start) => ({
57
- start,
58
- length: 20,
59
- }));
60
-
61
- return zeroOutSlices(code, addressesSlices);
62
- }
63
-
64
- export function zeroOutSlices(
65
- code: Uint8Array,
66
- slices: Array<{ start: number; length: number }>
67
- ): Uint8Array {
68
- for (const { start, length } of slices) {
69
- code = Buffer.concat([
70
- code.slice(0, start),
71
- Buffer.alloc(length, 0),
72
- code.slice(start + length),
73
- ]);
74
- }
75
-
76
- return code;
77
- }
78
-
79
- export function normalizeLibraryRuntimeBytecodeIfNecessary(
80
- code: Uint8Array
81
- ): Uint8Array {
82
- // Libraries' protection normalization:
83
- // Solidity 0.4.20 introduced a protection to prevent libraries from being called directly.
84
- // This is done by modifying the code on deployment, and hard-coding the contract address.
85
- // The first instruction is a PUSH20 of the address, which we zero-out as a way of normalizing
86
- // it. Note that it's also zeroed-out in the compiler output.
87
- if (code[0] === Opcode.PUSH20) {
88
- return zeroOutAddresses(code, [1]);
89
- }
90
-
91
- return code;
92
- }
7
+ export { linkHexStringBytecode };
@@ -1,129 +1,12 @@
1
- import type { Bytecode } from "./model";
2
- import type { Exit } from "../provider/vm/exit";
3
1
  import type {
4
- CallOutput,
5
- CreateOutput,
6
- HaltResult,
7
- RevertResult,
8
- SuccessResult,
2
+ PrecompileMessageTrace,
3
+ CreateMessageTrace,
4
+ CallMessageTrace,
9
5
  } from "@nomicfoundation/edr";
10
6
 
7
+ export type { PrecompileMessageTrace, CreateMessageTrace, CallMessageTrace };
8
+
11
9
  export type MessageTrace =
12
10
  | CreateMessageTrace
13
11
  | CallMessageTrace
14
12
  | PrecompileMessageTrace;
15
-
16
- export type EvmMessageTrace = CreateMessageTrace | CallMessageTrace;
17
-
18
- export type DecodedEvmMessageTrace =
19
- | DecodedCreateMessageTrace
20
- | DecodedCallMessageTrace;
21
-
22
- export interface BaseMessageTrace {
23
- value: bigint;
24
- returnData: Uint8Array;
25
- exit: Exit;
26
- gasUsed: bigint;
27
- depth: number;
28
- }
29
-
30
- export interface PrecompileMessageTrace extends BaseMessageTrace {
31
- precompile: number;
32
- calldata: Uint8Array;
33
- }
34
-
35
- export interface BaseEvmMessageTrace extends BaseMessageTrace {
36
- code: Uint8Array;
37
- steps: MessageTraceStep[];
38
- bytecode?: Bytecode;
39
- // The following is just an optimization: When processing this traces it's useful to know ahead of
40
- // time how many subtraces there are.
41
- numberOfSubtraces: number;
42
- }
43
-
44
- export interface CreateMessageTrace extends BaseEvmMessageTrace {
45
- deployedContract: Uint8Array | undefined;
46
- }
47
-
48
- export interface CallMessageTrace extends BaseEvmMessageTrace {
49
- calldata: Uint8Array;
50
- address: Uint8Array;
51
- codeAddress: Uint8Array;
52
- }
53
-
54
- export interface DecodedCreateMessageTrace extends CreateMessageTrace {
55
- bytecode: Bytecode;
56
- }
57
-
58
- export interface DecodedCallMessageTrace extends CallMessageTrace {
59
- bytecode: Bytecode;
60
- }
61
-
62
- export function isPrecompileTrace(
63
- trace: MessageTrace
64
- ): trace is PrecompileMessageTrace {
65
- return "precompile" in trace;
66
- }
67
-
68
- export function isCreateTrace(
69
- trace: MessageTrace
70
- ): trace is CreateMessageTrace {
71
- return "code" in trace && !isCallTrace(trace);
72
- }
73
-
74
- export function isDecodedCreateTrace(
75
- trace: MessageTrace
76
- ): trace is DecodedCreateMessageTrace {
77
- return isCreateTrace(trace) && trace.bytecode !== undefined;
78
- }
79
-
80
- export function isCallTrace(trace: MessageTrace): trace is CallMessageTrace {
81
- return "code" in trace && "calldata" in trace;
82
- }
83
-
84
- export function isDecodedCallTrace(
85
- trace: MessageTrace
86
- ): trace is DecodedCallMessageTrace {
87
- return isCallTrace(trace) && trace.bytecode !== undefined;
88
- }
89
-
90
- export function isEvmStep(step: MessageTraceStep): step is EvmStep {
91
- return "pc" in step && step.pc !== undefined;
92
- }
93
-
94
- export type MessageTraceStep = MessageTrace | EvmStep;
95
-
96
- export interface EvmStep {
97
- pc: number;
98
- }
99
-
100
- export function isCallOutput(
101
- output: CallOutput | CreateOutput
102
- ): output is CallOutput {
103
- return !isCreateOutput(output);
104
- }
105
-
106
- export function isCreateOutput(
107
- output: CallOutput | CreateOutput
108
- ): output is CreateOutput {
109
- return "address" in output;
110
- }
111
-
112
- export function isSuccessResult(
113
- result: SuccessResult | RevertResult | HaltResult
114
- ): result is SuccessResult {
115
- // Only need to check for one unique field
116
- return "gasRefunded" in result;
117
- }
118
-
119
- export function isRevertResult(
120
- result: SuccessResult | RevertResult | HaltResult
121
- ): result is RevertResult {
122
- return !("reason" in result);
123
- }
124
-
125
- export function isHaltResult(
126
- result: SuccessResult | RevertResult | HaltResult
127
- ): result is HaltResult {
128
- return !("output" in result);
129
- }
@@ -1,5 +1,6 @@
1
1
  import { bytesToHex as bufferToHex } from "@nomicfoundation/ethereumjs-util";
2
2
 
3
+ import { ReturnData } from "../provider/return-data";
3
4
  import { panicErrorCodeToMessage } from "./panic-errors";
4
5
  import {
5
6
  CONSTRUCTOR_FUNCTION_NAME,
@@ -258,24 +259,21 @@ function getMessageFromLastStackTraceEntry(
258
259
  return `Transaction reverted: library was called directly`;
259
260
 
260
261
  case StackTraceEntryType.UNRECOGNIZED_CREATE_ERROR:
261
- case StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR:
262
- if (stackTraceEntry.message.isErrorReturnData()) {
263
- return `VM Exception while processing transaction: reverted with reason string '${stackTraceEntry.message.decodeError()}'`;
262
+ case StackTraceEntryType.UNRECOGNIZED_CONTRACT_ERROR: {
263
+ const returnData = new ReturnData(stackTraceEntry.returnData);
264
+ if (returnData.isErrorReturnData()) {
265
+ return `VM Exception while processing transaction: reverted with reason string '${returnData.decodeError()}'`;
264
266
  }
265
267
 
266
- if (stackTraceEntry.message.isPanicReturnData()) {
267
- const message = panicErrorCodeToMessage(
268
- stackTraceEntry.message.decodePanic()
269
- );
268
+ if (returnData.isPanicReturnData()) {
269
+ const message = panicErrorCodeToMessage(returnData.decodePanic());
270
270
  return `VM Exception while processing transaction: ${message}`;
271
271
  }
272
272
 
273
- if (!stackTraceEntry.message.isEmpty()) {
274
- const returnData = Buffer.from(stackTraceEntry.message.value).toString(
275
- "hex"
276
- );
273
+ if (!returnData.isEmpty()) {
274
+ const buffer = Buffer.from(returnData.value).toString("hex");
277
275
 
278
- return `VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x${returnData})`;
276
+ return `VM Exception while processing transaction: reverted with an unrecognized custom error (return data: 0x${buffer})`;
279
277
  }
280
278
 
281
279
  if (stackTraceEntry.isInvalidOpcodeError) {
@@ -283,10 +281,12 @@ function getMessageFromLastStackTraceEntry(
283
281
  }
284
282
 
285
283
  return "Transaction reverted without a reason string";
284
+ }
286
285
 
287
- case StackTraceEntryType.REVERT_ERROR:
288
- if (stackTraceEntry.message.isErrorReturnData()) {
289
- return `VM Exception while processing transaction: reverted with reason string '${stackTraceEntry.message.decodeError()}'`;
286
+ case StackTraceEntryType.REVERT_ERROR: {
287
+ const returnData = new ReturnData(stackTraceEntry.returnData);
288
+ if (returnData.isErrorReturnData()) {
289
+ return `VM Exception while processing transaction: reverted with reason string '${returnData.decodeError()}'`;
290
290
  }
291
291
 
292
292
  if (stackTraceEntry.isInvalidOpcodeError) {
@@ -294,6 +294,7 @@ function getMessageFromLastStackTraceEntry(
294
294
  }
295
295
 
296
296
  return "Transaction reverted without a reason string";
297
+ }
297
298
 
298
299
  case StackTraceEntryType.PANIC_ERROR:
299
300
  const panicMessage = panicErrorCodeToMessage(stackTraceEntry.errorCode);