hardhat 2.22.10 → 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.
- package/console.sol +1 -1
- package/internal/cli/project-creation.d.ts +1 -1
- package/internal/cli/project-creation.js +1 -1
- package/internal/core/providers/lazy-initialization.d.ts.map +1 -1
- package/internal/core/providers/lazy-initialization.js +10 -10
- package/internal/core/providers/lazy-initialization.js.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.d.ts.map +1 -1
- package/internal/hardhat-network/jsonrpc/handler.js +2 -1
- package/internal/hardhat-network/jsonrpc/handler.js.map +1 -1
- package/internal/hardhat-network/provider/provider.d.ts +2 -3
- package/internal/hardhat-network/provider/provider.d.ts.map +1 -1
- package/internal/hardhat-network/provider/provider.js +5 -19
- package/internal/hardhat-network/provider/provider.js.map +1 -1
- package/internal/hardhat-network/provider/return-data.d.ts +2 -15
- package/internal/hardhat-network/provider/return-data.d.ts.map +1 -1
- package/internal/hardhat-network/provider/return-data.js +2 -50
- package/internal/hardhat-network/provider/return-data.js.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.d.ts +2 -20
- package/internal/hardhat-network/provider/vm/exit.d.ts.map +1 -1
- package/internal/hardhat-network/provider/vm/exit.js +3 -78
- package/internal/hardhat-network/provider/vm/exit.js.map +1 -1
- package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts +2 -3
- package/internal/hardhat-network/stack-traces/compiler-to-model.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/compiler-to-model.js +2 -351
- package/internal/hardhat-network/stack-traces/compiler-to-model.js.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts +2 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js +2 -1
- package/internal/hardhat-network/stack-traces/consoleLogger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/constants.d.ts +1 -1
- package/internal/hardhat-network/stack-traces/constants.js +1 -1
- package/internal/hardhat-network/stack-traces/debug.d.ts +2 -7
- package/internal/hardhat-network/stack-traces/debug.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/debug.js +3 -143
- package/internal/hardhat-network/stack-traces/debug.js.map +1 -1
- package/internal/hardhat-network/stack-traces/library-utils.d.ts +2 -11
- package/internal/hardhat-network/stack-traces/library-utils.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/library-utils.js +3 -61
- package/internal/hardhat-network/stack-traces/library-utils.js.map +1 -1
- package/internal/hardhat-network/stack-traces/logger.js +596 -596
- package/internal/hardhat-network/stack-traces/logger.js.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.d.ts +2 -51
- package/internal/hardhat-network/stack-traces/message-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/message-trace.js +0 -46
- package/internal/hardhat-network/stack-traces/message-trace.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-errors.js +58 -53
- package/internal/hardhat-network/stack-traces/solidity-errors.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts +4 -155
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.js +12 -37
- package/internal/hardhat-network/stack-traces/solidity-stack-trace.js.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts +2 -13
- package/internal/hardhat-network/stack-traces/solidityTracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/solidityTracer.js +2 -162
- package/internal/hardhat-network/stack-traces/solidityTracer.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts +4 -15
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js +6 -70
- package/internal/hardhat-network/stack-traces/vm-trace-decoder.js.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts +2 -19
- package/internal/hardhat-network/stack-traces/vm-tracer.d.ts.map +1 -1
- package/internal/hardhat-network/stack-traces/vm-tracer.js +3 -150
- package/internal/hardhat-network/stack-traces/vm-tracer.js.map +1 -1
- package/internal/solidity/compiler/solc-info.d.ts.map +1 -1
- package/internal/solidity/compiler/solc-info.js +3 -0
- package/internal/solidity/compiler/solc-info.js.map +1 -1
- package/package.json +6 -5
- package/sample-projects/javascript/contracts/Lock.sol +1 -1
- package/sample-projects/javascript/hardhat.config.js +1 -1
- package/sample-projects/javascript/ignition/modules/Lock.js +3 -0
- package/sample-projects/javascript-esm/contracts/Lock.sol +1 -1
- package/sample-projects/javascript-esm/hardhat.config.cjs +1 -1
- package/sample-projects/javascript-esm/ignition/modules/Lock.js +3 -0
- package/sample-projects/typescript/contracts/Lock.sol +1 -1
- package/sample-projects/typescript/hardhat.config.ts +1 -1
- package/sample-projects/typescript/ignition/modules/Lock.ts +3 -0
- package/sample-projects/typescript-viem/contracts/Lock.sol +1 -1
- package/sample-projects/typescript-viem/hardhat.config.ts +1 -1
- package/sample-projects/typescript-viem/ignition/modules/Lock.ts +3 -0
- package/src/internal/cli/project-creation.ts +1 -1
- package/src/internal/core/providers/lazy-initialization.ts +13 -13
- package/src/internal/hardhat-network/jsonrpc/handler.ts +2 -1
- package/src/internal/hardhat-network/provider/provider.ts +11 -24
- package/src/internal/hardhat-network/provider/return-data.ts +5 -73
- package/src/internal/hardhat-network/provider/vm/exit.ts +4 -92
- package/src/internal/hardhat-network/stack-traces/compiler-to-model.ts +5 -697
- package/src/internal/hardhat-network/stack-traces/consoleLogger.ts +2 -1
- package/src/internal/hardhat-network/stack-traces/constants.ts +1 -1
- package/src/internal/hardhat-network/stack-traces/debug.ts +5 -218
- package/src/internal/hardhat-network/stack-traces/library-utils.ts +5 -90
- package/src/internal/hardhat-network/stack-traces/logger.ts +596 -596
- package/src/internal/hardhat-network/stack-traces/message-trace.ts +5 -122
- package/src/internal/hardhat-network/stack-traces/solidity-errors.ts +16 -15
- package/src/internal/hardhat-network/stack-traces/solidity-stack-trace.ts +83 -186
- package/src/internal/hardhat-network/stack-traces/solidityTracer.ts +5 -253
- package/src/internal/hardhat-network/stack-traces/vm-trace-decoder.ts +15 -108
- package/src/internal/hardhat-network/stack-traces/vm-tracer.ts +5 -206
- package/src/internal/solidity/compiler/solc-info.ts +3 -0
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts +0 -15
- package/internal/hardhat-network/stack-traces/contracts-identifier.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/contracts-identifier.js +0 -166
- package/internal/hardhat-network/stack-traces/contracts-identifier.js.map +0 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts +0 -85
- package/internal/hardhat-network/stack-traces/error-inferrer.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/error-inferrer.js +0 -1168
- package/internal/hardhat-network/stack-traces/error-inferrer.js.map +0 -1
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts +0 -24
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js +0 -116
- package/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.js.map +0 -1
- package/internal/hardhat-network/stack-traces/model.d.ts +0 -140
- package/internal/hardhat-network/stack-traces/model.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/model.js +0 -328
- package/internal/hardhat-network/stack-traces/model.js.map +0 -1
- package/internal/hardhat-network/stack-traces/opcodes.d.ts +0 -266
- package/internal/hardhat-network/stack-traces/opcodes.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/opcodes.js +0 -320
- package/internal/hardhat-network/stack-traces/opcodes.js.map +0 -1
- package/internal/hardhat-network/stack-traces/source-maps.d.ts +0 -13
- package/internal/hardhat-network/stack-traces/source-maps.d.ts.map +0 -1
- package/internal/hardhat-network/stack-traces/source-maps.js +0 -106
- package/internal/hardhat-network/stack-traces/source-maps.js.map +0 -1
- package/src/internal/hardhat-network/stack-traces/contracts-identifier.ts +0 -235
- package/src/internal/hardhat-network/stack-traces/error-inferrer.ts +0 -1845
- package/src/internal/hardhat-network/stack-traces/mapped-inlined-internal-functions-heuristics.ts +0 -163
- package/src/internal/hardhat-network/stack-traces/model.ts +0 -409
- package/src/internal/hardhat-network/stack-traces/opcodes.ts +0 -344
- package/src/internal/hardhat-network/stack-traces/source-maps.ts +0 -167
|
@@ -1,220 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import chalk from "chalk";
|
|
1
|
+
import { requireNapiRsModule } from "../../../common/napi-rs";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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 {
|
|
1
|
+
import { requireNapiRsModule } from "../../../common/napi-rs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const { linkHexStringBytecode } = requireNapiRsModule(
|
|
4
|
+
"@nomicfoundation/edr"
|
|
5
|
+
) as typeof import("@nomicfoundation/edr");
|
|
4
6
|
|
|
5
|
-
export
|
|
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 };
|