hardhat 2.22.11 → 2.22.13

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 (94) 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/logger.d.ts.map +1 -1
  26. package/internal/hardhat-network/stack-traces/logger.js +0 -221
  27. package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
  28. package/internal/hardhat-network/stack-traces/message-trace.d.ts +2 -51
  29. package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
  30. package/internal/hardhat-network/stack-traces/message-trace.js +0 -46
  31. package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
  32. package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
  33. package/internal/hardhat-network/stack-traces/solidity-errors.js +58 -53
  34. package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
  35. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +4 -155
  36. package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
  37. package/internal/hardhat-network/stack-traces/solidity-stack-trace.js +12 -37
  38. package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
  39. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +2 -13
  40. package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
  41. package/internal/hardhat-network/stack-traces/solidityTracer.js +2 -162
  42. package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
  43. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +4 -15
  44. package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
  45. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +6 -70
  46. package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
  47. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +2 -19
  48. package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
  49. package/internal/hardhat-network/stack-traces/vm-tracer.js +3 -150
  50. package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/internal/hardhat-network/provider/provider.ts +11 -24
  53. package/src/internal/hardhat-network/provider/return-data.ts +5 -73
  54. package/src/internal/hardhat-network/provider/vm/exit.ts +4 -92
  55. package/src/internal/hardhat-network/stack-traces/compiler-to-model.ts +5 -697
  56. package/src/internal/hardhat-network/stack-traces/debug.ts +5 -218
  57. package/src/internal/hardhat-network/stack-traces/library-utils.ts +5 -90
  58. package/src/internal/hardhat-network/stack-traces/logger.ts +0 -221
  59. package/src/internal/hardhat-network/stack-traces/message-trace.ts +5 -122
  60. package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +16 -15
  61. package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +83 -186
  62. package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +5 -253
  63. package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +15 -108
  64. package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +5 -206
  65. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +0 -15
  66. package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +0 -1
  67. package/internal/hardhat-network/stack-traces/contracts-identifier.js +0 -166
  68. package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +0 -1
  69. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts +0 -85
  70. package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +0 -1
  71. package/internal/hardhat-network/stack-traces/error-inferrer.js +0 -1168
  72. package/internal/hardhat-network/stack-traces/error-inferrer.js.map +0 -1
  73. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts +0 -24
  74. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts.map +0 -1
  75. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js +0 -116
  76. package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js.map +0 -1
  77. package/internal/hardhat-network/stack-traces/model.d.ts +0 -140
  78. package/internal/hardhat-network/stack-traces/model.d.ts.map +0 -1
  79. package/internal/hardhat-network/stack-traces/model.js +0 -328
  80. package/internal/hardhat-network/stack-traces/model.js.map +0 -1
  81. package/internal/hardhat-network/stack-traces/opcodes.d.ts +0 -266
  82. package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +0 -1
  83. package/internal/hardhat-network/stack-traces/opcodes.js +0 -320
  84. package/internal/hardhat-network/stack-traces/opcodes.js.map +0 -1
  85. package/internal/hardhat-network/stack-traces/source-maps.d.ts +0 -13
  86. package/internal/hardhat-network/stack-traces/source-maps.d.ts.map +0 -1
  87. package/internal/hardhat-network/stack-traces/source-maps.js +0 -106
  88. package/internal/hardhat-network/stack-traces/source-maps.js.map +0 -1
  89. package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +0 -235
  90. package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +0 -1845
  91. package/src/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.ts +0 -163
  92. package/src/internal/hardhat-network/stack-traces/model.ts +0 -409
  93. package/src/internal/hardhat-network/stack-traces/opcodes.ts +0 -344
  94. package/src/internal/hardhat-network/stack-traces/source-maps.ts +0 -167
@@ -1,344 +0,0 @@
1
- export enum Opcode {
2
- // Arithmetic operations
3
- STOP = 0x00,
4
- ADD = 0x01,
5
- MUL = 0x02,
6
- SUB = 0x03,
7
- DIV = 0x04,
8
- SDIV = 0x05,
9
- MOD = 0x06,
10
- SMOD = 0x07,
11
- ADDMOD = 0x08,
12
- MULMOD = 0x09,
13
- EXP = 0x0a,
14
- SIGNEXTEND = 0x0b,
15
-
16
- // Unallocated
17
- UNRECOGNIZED_0C = 0x0c,
18
- UNRECOGNIZED_0D = 0x0d,
19
- UNRECOGNIZED_0E = 0x0e,
20
- UNRECOGNIZED_0F = 0x0f,
21
-
22
- // Comparison and bitwise operations
23
- LT = 0x10,
24
- GT = 0x11,
25
- SLT = 0x12,
26
- SGT = 0x13,
27
- EQ = 0x14,
28
- ISZERO = 0x15,
29
- AND = 0x16,
30
- OR = 0x17,
31
- XOR = 0x18,
32
- NOT = 0x19,
33
- BYTE = 0x1a,
34
- SHL = 0x1b,
35
- SHR = 0x1c,
36
- SAR = 0x1d,
37
-
38
- // Unallocated
39
- UNRECOGNIZED_1E = 0x1e,
40
- UNRECOGNIZED_1F = 0x1f,
41
-
42
- // Cryptographic operations
43
- SHA3 = 0x20,
44
-
45
- // Unallocated
46
- UNRECOGNIZED_21 = 0x21,
47
- UNRECOGNIZED_22 = 0x22,
48
- UNRECOGNIZED_23 = 0x23,
49
- UNRECOGNIZED_24 = 0x24,
50
- UNRECOGNIZED_25 = 0x25,
51
- UNRECOGNIZED_26 = 0x26,
52
- UNRECOGNIZED_27 = 0x27,
53
- UNRECOGNIZED_28 = 0x28,
54
- UNRECOGNIZED_29 = 0x29,
55
- UNRECOGNIZED_2A = 0x2a,
56
- UNRECOGNIZED_2B = 0x2b,
57
- UNRECOGNIZED_2C = 0x2c,
58
- UNRECOGNIZED_2D = 0x2d,
59
- UNRECOGNIZED_2E = 0x2e,
60
- UNRECOGNIZED_2F = 0x2f,
61
-
62
- // Message info operations
63
- ADDRESS = 0x30,
64
- BALANCE = 0x31,
65
- ORIGIN = 0x32,
66
- CALLER = 0x33,
67
- CALLVALUE = 0x34,
68
- CALLDATALOAD = 0x35,
69
- CALLDATASIZE = 0x36,
70
- CALLDATACOPY = 0x37,
71
- CODESIZE = 0x38,
72
- CODECOPY = 0x39,
73
- GASPRICE = 0x3a,
74
- EXTCODESIZE = 0x3b,
75
- EXTCODECOPY = 0x3c,
76
- RETURNDATASIZE = 0x3d,
77
- RETURNDATACOPY = 0x3e,
78
- EXTCODEHASH = 0x3f,
79
-
80
- // Block info operations
81
- BLOCKHASH = 0x40,
82
- COINBASE = 0x41,
83
- TIMESTAMP = 0x42,
84
- NUMBER = 0x43,
85
- DIFFICULTY = 0x44,
86
- GASLIMIT = 0x45,
87
-
88
- // Istanbul opcodes
89
- CHAINID = 0x46,
90
- SELFBALANCE = 0x47,
91
-
92
- // London opcodes
93
- BASEFEE = 0x48,
94
-
95
- // Unallocated
96
- UNRECOGNIZED_49 = 0x49,
97
- UNRECOGNIZED_4A = 0x4a,
98
- UNRECOGNIZED_4B = 0x4b,
99
- UNRECOGNIZED_4C = 0x4c,
100
- UNRECOGNIZED_4D = 0x4d,
101
- UNRECOGNIZED_4E = 0x4e,
102
- UNRECOGNIZED_4F = 0x4f,
103
-
104
- // Storage, memory, and other operations
105
- POP = 0x50,
106
- MLOAD = 0x51,
107
- MSTORE = 0x52,
108
- MSTORE8 = 0x53,
109
- SLOAD = 0x54,
110
- SSTORE = 0x55,
111
- JUMP = 0x56,
112
- JUMPI = 0x57,
113
- PC = 0x58,
114
- MSIZE = 0x59,
115
- GAS = 0x5a,
116
- JUMPDEST = 0x5b,
117
-
118
- // Uncallocated
119
- UNRECOGNIZED_5C = 0x5c,
120
- UNRECOGNIZED_5D = 0x5d,
121
- UNRECOGNIZED_5E = 0x5e,
122
- UNRECOGNIZED_5F = 0x5f,
123
-
124
- // Push operations
125
- PUSH1 = 0x60,
126
- PUSH2 = 0x61,
127
- PUSH3 = 0x62,
128
- PUSH4 = 0x63,
129
- PUSH5 = 0x64,
130
- PUSH6 = 0x65,
131
- PUSH7 = 0x66,
132
- PUSH8 = 0x67,
133
- PUSH9 = 0x68,
134
- PUSH10 = 0x69,
135
- PUSH11 = 0x6a,
136
- PUSH12 = 0x6b,
137
- PUSH13 = 0x6c,
138
- PUSH14 = 0x6d,
139
- PUSH15 = 0x6e,
140
- PUSH16 = 0x6f,
141
- PUSH17 = 0x70,
142
- PUSH18 = 0x71,
143
- PUSH19 = 0x72,
144
- PUSH20 = 0x73,
145
- PUSH21 = 0x74,
146
- PUSH22 = 0x75,
147
- PUSH23 = 0x76,
148
- PUSH24 = 0x77,
149
- PUSH25 = 0x78,
150
- PUSH26 = 0x79,
151
- PUSH27 = 0x7a,
152
- PUSH28 = 0x7b,
153
- PUSH29 = 0x7c,
154
- PUSH30 = 0x7d,
155
- PUSH31 = 0x7e,
156
- PUSH32 = 0x7f,
157
-
158
- // Dup operations
159
- DUP1 = 0x80,
160
- DUP2 = 0x81,
161
- DUP3 = 0x82,
162
- DUP4 = 0x83,
163
- DUP5 = 0x84,
164
- DUP6 = 0x85,
165
- DUP7 = 0x86,
166
- DUP8 = 0x87,
167
- DUP9 = 0x88,
168
- DUP10 = 0x89,
169
- DUP11 = 0x8a,
170
- DUP12 = 0x8b,
171
- DUP13 = 0x8c,
172
- DUP14 = 0x8d,
173
- DUP15 = 0x8e,
174
- DUP16 = 0x8f,
175
-
176
- // Swap operations
177
- SWAP1 = 0x90,
178
- SWAP2 = 0x91,
179
- SWAP3 = 0x92,
180
- SWAP4 = 0x93,
181
- SWAP5 = 0x94,
182
- SWAP6 = 0x95,
183
- SWAP7 = 0x96,
184
- SWAP8 = 0x97,
185
- SWAP9 = 0x98,
186
- SWAP10 = 0x99,
187
- SWAP11 = 0x9a,
188
- SWAP12 = 0x9b,
189
- SWAP13 = 0x9c,
190
- SWAP14 = 0x9d,
191
- SWAP15 = 0x9e,
192
- SWAP16 = 0x9f,
193
-
194
- // Log operations
195
- LOG0 = 0xa0,
196
- LOG1 = 0xa1,
197
- LOG2 = 0xa2,
198
- LOG3 = 0xa3,
199
- LOG4 = 0xa4,
200
-
201
- // Unallocated
202
- UNRECOGNIZED_A5 = 0xa5,
203
- UNRECOGNIZED_A6 = 0xa6,
204
- UNRECOGNIZED_A7 = 0xa7,
205
- UNRECOGNIZED_A8 = 0xa8,
206
- UNRECOGNIZED_A9 = 0xa9,
207
- UNRECOGNIZED_AA = 0xaa,
208
- UNRECOGNIZED_AB = 0xab,
209
- UNRECOGNIZED_AC = 0xac,
210
- UNRECOGNIZED_AD = 0xad,
211
- UNRECOGNIZED_AE = 0xae,
212
- UNRECOGNIZED_AF = 0xaf,
213
-
214
- UNRECOGNIZED_B0 = 0xb0,
215
- UNRECOGNIZED_B1 = 0xb1,
216
- UNRECOGNIZED_B2 = 0xb2,
217
- UNRECOGNIZED_B3 = 0xb3,
218
- UNRECOGNIZED_B4 = 0xb4,
219
- UNRECOGNIZED_B5 = 0xb5,
220
- UNRECOGNIZED_B6 = 0xb6,
221
- UNRECOGNIZED_B7 = 0xb7,
222
- UNRECOGNIZED_B8 = 0xb8,
223
- UNRECOGNIZED_B9 = 0xb9,
224
- UNRECOGNIZED_BA = 0xba,
225
- UNRECOGNIZED_BB = 0xbb,
226
- UNRECOGNIZED_BC = 0xbc,
227
- UNRECOGNIZED_BD = 0xbd,
228
- UNRECOGNIZED_BE = 0xbe,
229
- UNRECOGNIZED_BF = 0xbf,
230
-
231
- UNRECOGNIZED_C0 = 0xc0,
232
- UNRECOGNIZED_C1 = 0xc1,
233
- UNRECOGNIZED_C2 = 0xc2,
234
- UNRECOGNIZED_C3 = 0xc3,
235
- UNRECOGNIZED_C4 = 0xc4,
236
- UNRECOGNIZED_C5 = 0xc5,
237
- UNRECOGNIZED_C6 = 0xc6,
238
- UNRECOGNIZED_C7 = 0xc7,
239
- UNRECOGNIZED_C8 = 0xc8,
240
- UNRECOGNIZED_C9 = 0xc9,
241
- UNRECOGNIZED_CA = 0xca,
242
- UNRECOGNIZED_CB = 0xcb,
243
- UNRECOGNIZED_CC = 0xcc,
244
- UNRECOGNIZED_CD = 0xcd,
245
- UNRECOGNIZED_CE = 0xce,
246
- UNRECOGNIZED_CF = 0xcf,
247
-
248
- UNRECOGNIZED_D0 = 0xd0,
249
- UNRECOGNIZED_D1 = 0xd1,
250
- UNRECOGNIZED_D2 = 0xd2,
251
- UNRECOGNIZED_D3 = 0xd3,
252
- UNRECOGNIZED_D4 = 0xd4,
253
- UNRECOGNIZED_D5 = 0xd5,
254
- UNRECOGNIZED_D6 = 0xd6,
255
- UNRECOGNIZED_D7 = 0xd7,
256
- UNRECOGNIZED_D8 = 0xd8,
257
- UNRECOGNIZED_D9 = 0xd9,
258
- UNRECOGNIZED_DA = 0xda,
259
- UNRECOGNIZED_DB = 0xdb,
260
- UNRECOGNIZED_DC = 0xdc,
261
- UNRECOGNIZED_DD = 0xdd,
262
- UNRECOGNIZED_DE = 0xde,
263
- UNRECOGNIZED_DF = 0xdf,
264
-
265
- UNRECOGNIZED_E0 = 0xe0,
266
- UNRECOGNIZED_E1 = 0xe1,
267
- UNRECOGNIZED_E2 = 0xe2,
268
- UNRECOGNIZED_E3 = 0xe3,
269
- UNRECOGNIZED_E4 = 0xe4,
270
- UNRECOGNIZED_E5 = 0xe5,
271
- UNRECOGNIZED_E6 = 0xe6,
272
- UNRECOGNIZED_E7 = 0xe7,
273
- UNRECOGNIZED_E8 = 0xe8,
274
- UNRECOGNIZED_E9 = 0xe9,
275
- UNRECOGNIZED_EA = 0xea,
276
- UNRECOGNIZED_EB = 0xeb,
277
- UNRECOGNIZED_EC = 0xec,
278
- UNRECOGNIZED_ED = 0xed,
279
- UNRECOGNIZED_EE = 0xee,
280
- UNRECOGNIZED_EF = 0xef,
281
-
282
- // Call operations
283
- CREATE = 0xf0,
284
- CALL = 0xf1,
285
- CALLCODE = 0xf2,
286
- RETURN = 0xf3,
287
- DELEGATECALL = 0xf4,
288
- CREATE2 = 0xf5,
289
-
290
- // Unallocated
291
- UNRECOGNIZED_F6 = 0xf6,
292
- UNRECOGNIZED_F7 = 0xf7,
293
- UNRECOGNIZED_F8 = 0xf8,
294
- UNRECOGNIZED_F9 = 0xf9,
295
-
296
- // Other operations
297
- STATICCALL = 0xfa,
298
-
299
- // Unallocated
300
- UNRECOGNIZED_FB = 0xfb,
301
- UNRECOGNIZED_FC = 0xfc,
302
-
303
- // Other operations
304
- REVERT = 0xfd,
305
- INVALID = 0xfe,
306
- SELFDESTRUCT = 0xff,
307
- }
308
-
309
- export function opcodeName(opcode: number): string {
310
- return Opcode[opcode] ?? `<unrecognized opcode ${opcode}>`;
311
- }
312
-
313
- export function isPush(opcode: Opcode) {
314
- return opcode >= Opcode.PUSH1 && opcode <= Opcode.PUSH32;
315
- }
316
-
317
- export function isJump(opcode: Opcode) {
318
- return opcode === Opcode.JUMP || opcode === Opcode.JUMPI;
319
- }
320
-
321
- export function getPushLength(opcode: Opcode) {
322
- return opcode - Opcode.PUSH1 + 1;
323
- }
324
-
325
- export function getOpcodeLength(opcode: Opcode) {
326
- if (!isPush(opcode)) {
327
- return 1;
328
- }
329
-
330
- return 1 + getPushLength(opcode);
331
- }
332
-
333
- export function isCall(opcode: Opcode) {
334
- return (
335
- opcode === Opcode.CALL ||
336
- opcode === Opcode.CALLCODE ||
337
- opcode === Opcode.DELEGATECALL ||
338
- opcode === Opcode.STATICCALL
339
- );
340
- }
341
-
342
- export function isCreate(opcode: Opcode) {
343
- return opcode === Opcode.CREATE || opcode === Opcode.CREATE2;
344
- }
@@ -1,167 +0,0 @@
1
- import { Instruction, JumpType, SourceFile, SourceLocation } from "./model";
2
- import {
3
- getOpcodeLength,
4
- getPushLength,
5
- isJump,
6
- isPush,
7
- Opcode,
8
- } from "./opcodes";
9
-
10
- export interface SourceMapLocation {
11
- offset: number;
12
- length: number;
13
- file: number;
14
- }
15
-
16
- export interface SourceMap {
17
- location: SourceMapLocation;
18
- jumpType: JumpType;
19
- }
20
-
21
- function jumpLetterToJumpType(letter: string): JumpType {
22
- if (letter === "i") {
23
- return JumpType.INTO_FUNCTION;
24
- }
25
-
26
- if (letter === "o") {
27
- return JumpType.OUTOF_FUNCTION;
28
- }
29
- return JumpType.NOT_JUMP;
30
- }
31
-
32
- function uncompressSourcemaps(compressedSourcemap: string): SourceMap[] {
33
- const mappings: SourceMap[] = [];
34
-
35
- const compressedMappings = compressedSourcemap.split(";");
36
-
37
- for (let i = 0; i < compressedMappings.length; i++) {
38
- const parts = compressedMappings[i].split(":");
39
-
40
- const hasParts0 = parts[0] !== undefined && parts[0] !== "";
41
- const hasParts1 = parts[1] !== undefined && parts[1] !== "";
42
- const hasParts2 = parts[2] !== undefined && parts[2] !== "";
43
- const hasParts3 = parts[3] !== undefined && parts[3] !== "";
44
-
45
- const hasEveryPart = hasParts0 && hasParts1 && hasParts2 && hasParts3;
46
-
47
- // See: https://github.com/nomiclabs/hardhat/issues/593
48
- if (i === 0 && !hasEveryPart) {
49
- mappings.push({
50
- jumpType: JumpType.NOT_JUMP,
51
- location: {
52
- file: -1,
53
- offset: 0,
54
- length: 0,
55
- },
56
- });
57
-
58
- continue;
59
- }
60
-
61
- mappings.push({
62
- location: {
63
- offset: hasParts0 ? +parts[0] : mappings[i - 1].location.offset,
64
- length: hasParts1 ? +parts[1] : mappings[i - 1].location.length,
65
- file: hasParts2 ? +parts[2] : mappings[i - 1].location.file,
66
- },
67
- jumpType: hasParts3
68
- ? jumpLetterToJumpType(parts[3])
69
- : mappings[i - 1].jumpType,
70
- });
71
- }
72
-
73
- return mappings;
74
- }
75
-
76
- function addUnmappedInstructions(
77
- instructions: Instruction[],
78
- bytecode: Buffer
79
- ) {
80
- const lastInstrPc = instructions[instructions.length - 1].pc;
81
- let bytesIndex = lastInstrPc + 1;
82
-
83
- while (bytecode[bytesIndex] !== Opcode.INVALID) {
84
- const opcode = bytecode[bytesIndex];
85
- let pushData: Buffer | undefined;
86
-
87
- let pushDataLenth = 0;
88
- if (isPush(opcode)) {
89
- pushDataLenth = getPushLength(opcode);
90
- pushData = bytecode.slice(bytesIndex + 1, bytesIndex + 1 + pushDataLenth);
91
- }
92
-
93
- const jumpType = isJump(opcode)
94
- ? JumpType.INTERNAL_JUMP
95
- : JumpType.NOT_JUMP;
96
-
97
- const instruction = new Instruction(bytesIndex, opcode, jumpType, pushData);
98
- instructions.push(instruction);
99
-
100
- bytesIndex += getOpcodeLength(opcode);
101
- }
102
- }
103
-
104
- export function decodeInstructions(
105
- bytecode: Buffer,
106
- compressedSourcemaps: string,
107
- fileIdToSourceFile: Map<number, SourceFile>,
108
- isDeployment: boolean
109
- ): Instruction[] {
110
- const sourceMaps = uncompressSourcemaps(compressedSourcemaps);
111
-
112
- const instructions: Instruction[] = [];
113
-
114
- let bytesIndex = 0;
115
-
116
- // Solidity inlines some data after the contract, so we stop decoding
117
- // as soon as we have enough instructions as uncompressed mappings. This is
118
- // not very documented, but we manually tested that it works.
119
- while (instructions.length < sourceMaps.length) {
120
- const pc = bytesIndex;
121
- const opcode = bytecode[pc];
122
- const sourceMap = sourceMaps[instructions.length];
123
- let pushData: Buffer | undefined;
124
- let location: SourceLocation | undefined;
125
-
126
- const jumpType =
127
- isJump(opcode) && sourceMap.jumpType === JumpType.NOT_JUMP
128
- ? JumpType.INTERNAL_JUMP
129
- : sourceMap.jumpType;
130
-
131
- if (isPush(opcode)) {
132
- const length = getPushLength(opcode);
133
- pushData = bytecode.slice(bytesIndex + 1, bytesIndex + 1 + length);
134
- }
135
-
136
- if (sourceMap.location.file !== -1) {
137
- const file = fileIdToSourceFile.get(sourceMap.location.file);
138
-
139
- if (file !== undefined) {
140
- location = new SourceLocation(
141
- file,
142
- sourceMap.location.offset,
143
- sourceMap.location.length
144
- );
145
- }
146
- }
147
-
148
- const instruction = new Instruction(
149
- pc,
150
- opcode,
151
- jumpType,
152
- pushData,
153
- location
154
- );
155
-
156
- instructions.push(instruction);
157
-
158
- bytesIndex += getOpcodeLength(opcode);
159
- }
160
-
161
- // See: https://github.com/ethereum/solidity/issues/9133
162
- if (isDeployment) {
163
- addUnmappedInstructions(instructions, bytecode);
164
- }
165
-
166
- return instructions;
167
- }