@cofhe/hardhat-plugin 0.7.0 → 0.8.0
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/CHANGELOG.md +38 -0
- package/README.md +42 -1
- package/dist/index.d.mts +58 -2
- package/dist/index.d.ts +58 -2
- package/dist/index.js +217 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +214 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -5
- package/src/deploy.ts +37 -6
- package/src/gas.ts +227 -0
- package/src/index.ts +75 -20
- package/src/utils.ts +7 -5
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
MOCK_GAS_CONSUMED_TOPIC: () => MOCK_GAS_CONSUMED_TOPIC,
|
|
33
34
|
TASK_COFHE_MOCKS_DEPLOY: () => TASK_COFHE_MOCKS_DEPLOY,
|
|
34
35
|
TASK_COFHE_MOCKS_SET_LOG_OPS: () => TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
35
36
|
TASK_COFHE_USE_FAUCET: () => TASK_COFHE_USE_FAUCET,
|
|
@@ -40,20 +41,23 @@ __export(src_exports, {
|
|
|
40
41
|
localcofheFundAccount: () => localcofheFundAccount,
|
|
41
42
|
localcofheFundWalletIfNeeded: () => localcofheFundWalletIfNeeded,
|
|
42
43
|
mock_expectPlaintext: () => mock_expectPlaintext,
|
|
44
|
+
mock_getAdjustedGasBreakdown: () => mock_getAdjustedGasBreakdown,
|
|
45
|
+
mock_getAdjustedGasUsed: () => mock_getAdjustedGasUsed,
|
|
43
46
|
mock_getPlaintext: () => mock_getPlaintext,
|
|
44
47
|
mock_getPlaintextExists: () => mock_getPlaintextExists,
|
|
45
48
|
mock_setLoggingEnabled: () => mock_setLoggingEnabled,
|
|
46
|
-
mock_withLogs: () => mock_withLogs
|
|
49
|
+
mock_withLogs: () => mock_withLogs,
|
|
50
|
+
printMockGasSummary: () => printMockGasSummary
|
|
47
51
|
});
|
|
48
52
|
module.exports = __toCommonJS(src_exports);
|
|
49
|
-
var
|
|
53
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
50
54
|
var import_path = __toESM(require("path"));
|
|
51
55
|
var import_fs = __toESM(require("fs"));
|
|
52
56
|
var import_viem = require("viem");
|
|
53
57
|
var import_config = require("hardhat/config");
|
|
54
58
|
var import_task_names = require("hardhat/builtin-tasks/task-names");
|
|
55
59
|
var import_signers = require("@nomicfoundation/hardhat-ethers/signers");
|
|
56
|
-
var
|
|
60
|
+
var import_sdk4 = require("@cofhe/sdk");
|
|
57
61
|
var import_node = require("@cofhe/sdk/node");
|
|
58
62
|
var import_adapters = require("@cofhe/sdk/adapters");
|
|
59
63
|
|
|
@@ -147,7 +151,7 @@ var getFixedMockContract = async (hre, artifact) => {
|
|
|
147
151
|
};
|
|
148
152
|
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
149
153
|
const bytecode = await provider.getCode(import_sdk.MOCKS_ZK_VERIFIER_ADDRESS);
|
|
150
|
-
const isTestnet = bytecode.length
|
|
154
|
+
const isTestnet = !bytecode || bytecode.length <= 2;
|
|
151
155
|
if (isTestnet) {
|
|
152
156
|
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
153
157
|
}
|
|
@@ -157,7 +161,7 @@ var mock_getPlaintext = async (provider, ctHash) => {
|
|
|
157
161
|
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
158
162
|
return;
|
|
159
163
|
const taskManager = new import_ethers.ethers.Contract(
|
|
160
|
-
import_sdk.
|
|
164
|
+
import_sdk.MOCKS_TASK_MANAGER_ADDRESS,
|
|
161
165
|
["function mockStorage(uint256) view returns (uint256)"],
|
|
162
166
|
provider
|
|
163
167
|
);
|
|
@@ -168,7 +172,7 @@ var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
|
168
172
|
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
169
173
|
return;
|
|
170
174
|
const taskManager = new import_ethers.ethers.Contract(
|
|
171
|
-
import_sdk.
|
|
175
|
+
import_sdk.MOCKS_TASK_MANAGER_ADDRESS,
|
|
172
176
|
["function inMockStorage(uint256) view returns (bool)"],
|
|
173
177
|
provider
|
|
174
178
|
);
|
|
@@ -197,8 +201,12 @@ var deployMocks = async (hre, options = {
|
|
|
197
201
|
}
|
|
198
202
|
await hre.run("compile", { quiet: true });
|
|
199
203
|
log("vv", import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
204
|
+
const addressBook = await deployMockAddressBook(hre);
|
|
205
|
+
logDeployment("MockCoFHEAddressBook", await addressBook.getAddress());
|
|
200
206
|
const taskManager = await deployMockTaskManager(hre);
|
|
201
207
|
logDeployment("MockTaskManager", await taskManager.getAddress());
|
|
208
|
+
await registerTaskManager(addressBook, taskManager);
|
|
209
|
+
log("vv", "TaskManager registered in CoFHEAddressBook", 2);
|
|
202
210
|
const acl = await deployMockACL(hre);
|
|
203
211
|
logDeployment("MockACL", await acl.getAddress());
|
|
204
212
|
const acpRevoker = await deployMockContractFromArtifact(hre, import_mock_contracts.ACPTimestampRevokerArtifact);
|
|
@@ -210,7 +218,7 @@ var deployMocks = async (hre, options = {
|
|
|
210
218
|
await (await acl.setShareRegistry(await acpShareRegistry.getAddress())).wait();
|
|
211
219
|
log("vv", "Share registry set in ACL", 2);
|
|
212
220
|
await linkTaskManagerAndACL(taskManager, acl);
|
|
213
|
-
log("vv", "ACL address set in TaskManager", 2);
|
|
221
|
+
log("vv", "ACL address set in TaskManager, TaskManager address set in ACL", 2);
|
|
214
222
|
await setVerifierSigner(taskManager);
|
|
215
223
|
log("vv", "Verifier signer set", 2);
|
|
216
224
|
await setDecryptResultSigner(taskManager);
|
|
@@ -221,13 +229,13 @@ var deployMocks = async (hre, options = {
|
|
|
221
229
|
log("vv", `ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
222
230
|
const zkVerifier = await deployMockZkVerifier(hre);
|
|
223
231
|
logDeployment("MockZkVerifier", await zkVerifier.getAddress());
|
|
224
|
-
const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
|
|
232
|
+
const thresholdNetwork = await deployMockThresholdNetwork(hre, taskManager, acl);
|
|
225
233
|
logDeployment("MockThresholdNetwork", await thresholdNetwork.getAddress());
|
|
226
234
|
log("v", import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed"), 0);
|
|
227
235
|
if (options.gasWarning) {
|
|
228
236
|
logEmpty("v");
|
|
229
237
|
logWarning(
|
|
230
|
-
"When using mocks, FHE operations (eg FHE.add / FHE.mul)
|
|
238
|
+
"When using mocks, FHE operations (eg FHE.add / FHE.mul) consume extra gas replicating off-chain CoFHE work on-chain. Use hre.cofhe.getAdjustedGasUsed(receipt) or set 'cofhe.gasSummary: true' to see gas numbers with that overhead excluded.\n(Disable this warning by setting 'cofhe.gasWarning: false' in your hardhat config)",
|
|
231
239
|
0
|
|
232
240
|
);
|
|
233
241
|
}
|
|
@@ -236,11 +244,25 @@ var deployMocks = async (hre, options = {
|
|
|
236
244
|
var getIsHardhat = async (hre) => {
|
|
237
245
|
return hre.network.name === "hardhat";
|
|
238
246
|
};
|
|
247
|
+
var deployMockAddressBook = async (hre) => {
|
|
248
|
+
const addressBook = await deployMockContractFromArtifact(hre, import_mock_contracts.MockCoFHEAddressBookArtifact);
|
|
249
|
+
const bookExists = await addressBook.exists();
|
|
250
|
+
if (!bookExists) {
|
|
251
|
+
throw new Error("MockCoFHEAddressBook does not exist");
|
|
252
|
+
}
|
|
253
|
+
return addressBook;
|
|
254
|
+
};
|
|
255
|
+
var registerTaskManager = async (addressBook, taskManager) => {
|
|
256
|
+
const setTmTx = await addressBook.setTm(import_sdk2.TASK_MANAGER_ID, await taskManager.getAddress());
|
|
257
|
+
await setTmTx.wait();
|
|
258
|
+
};
|
|
239
259
|
var deployMockTaskManager = async (hre) => {
|
|
240
260
|
const [signer] = await hre.ethers.getSigners();
|
|
241
261
|
const taskManager = await deployMockContractFromArtifact(hre, import_mock_contracts.MockTaskManagerArtifact);
|
|
242
262
|
const initTx = await taskManager.initialize(signer.address);
|
|
243
263
|
await initTx.wait();
|
|
264
|
+
const securityZonesTx = await taskManager.setSecurityZones(0, 1);
|
|
265
|
+
await securityZonesTx.wait();
|
|
244
266
|
const tmExists = await taskManager.exists();
|
|
245
267
|
if (!tmExists) {
|
|
246
268
|
throw new Error("MockTaskManager does not exist");
|
|
@@ -269,6 +291,8 @@ var linkTaskManagerAndACL = async (taskManager, acl) => {
|
|
|
269
291
|
const aclAddress = await acl.getAddress();
|
|
270
292
|
const linkAclTx = await taskManager.setACLContract(aclAddress);
|
|
271
293
|
await linkAclTx.wait();
|
|
294
|
+
const linkTaskManagerTx = await acl.setTaskManager(await taskManager.getAddress());
|
|
295
|
+
await linkTaskManagerTx.wait();
|
|
272
296
|
};
|
|
273
297
|
var setVerifierSigner = async (taskManager) => {
|
|
274
298
|
const signer = new import_ethers2.Wallet(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY);
|
|
@@ -288,9 +312,9 @@ var deployMockZkVerifier = async (hre) => {
|
|
|
288
312
|
}
|
|
289
313
|
return zkVerifier;
|
|
290
314
|
};
|
|
291
|
-
var deployMockThresholdNetwork = async (hre, acl) => {
|
|
315
|
+
var deployMockThresholdNetwork = async (hre, taskManager, acl) => {
|
|
292
316
|
const thresholdNetwork = await deployMockContractFromArtifact(hre, import_mock_contracts.MockThresholdNetworkArtifact);
|
|
293
|
-
const initTx = await thresholdNetwork.initialize(
|
|
317
|
+
const initTx = await thresholdNetwork.initialize(await taskManager.getAddress(), await acl.getAddress());
|
|
294
318
|
await initTx.wait();
|
|
295
319
|
const exists = await thresholdNetwork.exists();
|
|
296
320
|
if (!exists) {
|
|
@@ -374,6 +398,154 @@ var mock_withLogs = async (hre, closureName, closure) => {
|
|
|
374
398
|
}
|
|
375
399
|
};
|
|
376
400
|
|
|
401
|
+
// src/gas.ts
|
|
402
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
403
|
+
var import_ethers3 = require("ethers");
|
|
404
|
+
var import_sdk3 = require("@cofhe/sdk");
|
|
405
|
+
var MOCK_GAS_CONSUMED_TOPIC = import_ethers3.ethers.id("MockGasConsumed(uint256)");
|
|
406
|
+
var mock_getAdjustedGasBreakdown = (receipt) => {
|
|
407
|
+
let mockGas = 0n;
|
|
408
|
+
let mockGasEvents = 0;
|
|
409
|
+
for (const log2 of receipt.logs ?? []) {
|
|
410
|
+
if (log2.address.toLowerCase() === import_sdk3.MOCKS_TASK_MANAGER_ADDRESS.toLowerCase() && log2.topics[0] === MOCK_GAS_CONSUMED_TOPIC) {
|
|
411
|
+
mockGas += BigInt(log2.data);
|
|
412
|
+
mockGasEvents += 1;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const gasUsed = BigInt(receipt.gasUsed);
|
|
416
|
+
return { gasUsed, mockGas, adjustedGasUsed: mockGas > gasUsed ? 0n : gasUsed - mockGas, mockGasEvents };
|
|
417
|
+
};
|
|
418
|
+
var mock_getAdjustedGasUsed = (receipt) => mock_getAdjustedGasBreakdown(receipt).adjustedGasUsed;
|
|
419
|
+
var shortAddress = (address) => `${address.slice(0, 6)}..${address.slice(-4)}`;
|
|
420
|
+
var buildSelectorNameMap = async (hre) => {
|
|
421
|
+
const selectorNames = /* @__PURE__ */ new Map();
|
|
422
|
+
for (const fqn of await hre.artifacts.getAllFullyQualifiedNames()) {
|
|
423
|
+
try {
|
|
424
|
+
const artifact = await hre.artifacts.readArtifact(fqn);
|
|
425
|
+
const iface = new import_ethers3.ethers.Interface(artifact.abi);
|
|
426
|
+
iface.forEachFunction((fn) => {
|
|
427
|
+
if (!selectorNames.has(fn.selector))
|
|
428
|
+
selectorNames.set(fn.selector, fn.format("sighash"));
|
|
429
|
+
});
|
|
430
|
+
} catch {
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return selectorNames;
|
|
434
|
+
};
|
|
435
|
+
var buildAddressNameMap = async (hre, addresses) => {
|
|
436
|
+
const codeToName = /* @__PURE__ */ new Map();
|
|
437
|
+
for (const fqn of await hre.artifacts.getAllFullyQualifiedNames()) {
|
|
438
|
+
try {
|
|
439
|
+
const artifact = await hre.artifacts.readArtifact(fqn);
|
|
440
|
+
if (artifact.deployedBytecode && artifact.deployedBytecode !== "0x") {
|
|
441
|
+
codeToName.set(artifact.deployedBytecode.toLowerCase(), artifact.contractName);
|
|
442
|
+
}
|
|
443
|
+
} catch {
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
const addressNames = /* @__PURE__ */ new Map();
|
|
447
|
+
for (const address of addresses) {
|
|
448
|
+
try {
|
|
449
|
+
const code = await hre.network.provider.send("eth_getCode", [address, "latest"]);
|
|
450
|
+
addressNames.set(address, codeToName.get(code.toLowerCase()) ?? shortAddress(address));
|
|
451
|
+
} catch {
|
|
452
|
+
addressNames.set(address, shortAddress(address));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return addressNames;
|
|
456
|
+
};
|
|
457
|
+
var printMockGasSummary = async (hre) => {
|
|
458
|
+
if (hre.network.name !== "hardhat")
|
|
459
|
+
return;
|
|
460
|
+
let logs;
|
|
461
|
+
try {
|
|
462
|
+
logs = await hre.network.provider.send("eth_getLogs", [
|
|
463
|
+
{ fromBlock: "0x0", toBlock: "latest", address: import_sdk3.MOCKS_TASK_MANAGER_ADDRESS, topics: [MOCK_GAS_CONSUMED_TOPIC] }
|
|
464
|
+
]);
|
|
465
|
+
} catch {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (!logs || logs.length === 0)
|
|
469
|
+
return;
|
|
470
|
+
const mockGasPerTx = /* @__PURE__ */ new Map();
|
|
471
|
+
for (const log2 of logs) {
|
|
472
|
+
mockGasPerTx.set(log2.transactionHash, (mockGasPerTx.get(log2.transactionHash) ?? 0n) + BigInt(log2.data));
|
|
473
|
+
}
|
|
474
|
+
const aggregates = /* @__PURE__ */ new Map();
|
|
475
|
+
for (const [txHash, mockGas] of mockGasPerTx) {
|
|
476
|
+
try {
|
|
477
|
+
const receipt = await hre.network.provider.send("eth_getTransactionReceipt", [txHash]);
|
|
478
|
+
const tx = await hre.network.provider.send("eth_getTransactionByHash", [txHash]);
|
|
479
|
+
if (!receipt)
|
|
480
|
+
continue;
|
|
481
|
+
const target = tx?.to ?? receipt.contractAddress;
|
|
482
|
+
if (!target)
|
|
483
|
+
continue;
|
|
484
|
+
const to = import_ethers3.ethers.getAddress(target);
|
|
485
|
+
const selector = tx?.to ? (tx.input ?? "0x").slice(0, 10) : "(deployment)";
|
|
486
|
+
const key = `${to}:${selector}`;
|
|
487
|
+
const aggregate = aggregates.get(key) ?? { to, selector, calls: 0, totalGasUsed: 0n, totalMockGas: 0n };
|
|
488
|
+
aggregate.calls += 1;
|
|
489
|
+
aggregate.totalGasUsed += BigInt(receipt.gasUsed);
|
|
490
|
+
aggregate.totalMockGas += mockGas;
|
|
491
|
+
aggregates.set(key, aggregate);
|
|
492
|
+
} catch {
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
if (aggregates.size === 0)
|
|
496
|
+
return;
|
|
497
|
+
const selectorNames = await buildSelectorNameMap(hre);
|
|
498
|
+
const addressNames = await buildAddressNameMap(hre, [...new Set([...aggregates.values()].map((a) => a.to))]);
|
|
499
|
+
const merged = /* @__PURE__ */ new Map();
|
|
500
|
+
for (const a of aggregates.values()) {
|
|
501
|
+
const contract = addressNames.get(a.to) ?? shortAddress(a.to);
|
|
502
|
+
const method = selectorNames.get(a.selector) ?? a.selector;
|
|
503
|
+
const key = `${contract}:${method}`;
|
|
504
|
+
const row = merged.get(key) ?? { contract, method, calls: 0, totalGasUsed: 0n, totalMockGas: 0n };
|
|
505
|
+
row.calls += a.calls;
|
|
506
|
+
row.totalGasUsed += a.totalGasUsed;
|
|
507
|
+
row.totalMockGas += a.totalMockGas;
|
|
508
|
+
merged.set(key, row);
|
|
509
|
+
}
|
|
510
|
+
const rows = [...merged.values()].map((r) => {
|
|
511
|
+
const avgGasUsed = r.totalGasUsed / BigInt(r.calls);
|
|
512
|
+
const avgMockGas = r.totalMockGas / BigInt(r.calls);
|
|
513
|
+
return {
|
|
514
|
+
contract: r.contract,
|
|
515
|
+
method: r.method,
|
|
516
|
+
calls: r.calls,
|
|
517
|
+
avgGasUsed,
|
|
518
|
+
avgAdjusted: avgMockGas > avgGasUsed ? 0n : avgGasUsed - avgMockGas,
|
|
519
|
+
overheadPct: avgGasUsed === 0n ? 0 : Math.min(100, Number(avgMockGas * 100n / avgGasUsed))
|
|
520
|
+
};
|
|
521
|
+
}).sort((a, b) => a.contract.localeCompare(b.contract) || a.method.localeCompare(b.method));
|
|
522
|
+
const headers = ["Contract", "Method", "Calls", "Avg gas (mocks)", "Avg gas (adjusted)", "Mock overhead"];
|
|
523
|
+
const cells = rows.map((r) => [
|
|
524
|
+
r.contract,
|
|
525
|
+
r.method,
|
|
526
|
+
String(r.calls),
|
|
527
|
+
r.avgGasUsed.toLocaleString(),
|
|
528
|
+
r.avgAdjusted.toLocaleString(),
|
|
529
|
+
`${r.overheadPct}%`
|
|
530
|
+
]);
|
|
531
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...cells.map((row) => row[i].length)));
|
|
532
|
+
const line = (row) => `\u2502 ${row.map((cell, i) => cell.padEnd(widths[i])).join(" \u2502 ")} \u2502`;
|
|
533
|
+
const divider = (l, m, r) => `${l}${widths.map((w) => "\u2500".repeat(w + 2)).join(m)}${r}`;
|
|
534
|
+
console.log("");
|
|
535
|
+
console.log(import_chalk3.default.bold("[COFHE-MOCKS] Gas summary") + import_chalk3.default.dim(" \u2014 adjusted \u2248 cost excluding mock-only overhead"));
|
|
536
|
+
console.log(divider("\u250C", "\u252C", "\u2510"));
|
|
537
|
+
console.log(line(headers));
|
|
538
|
+
console.log(divider("\u251C", "\u253C", "\u2524"));
|
|
539
|
+
for (const row of cells)
|
|
540
|
+
console.log(line(row));
|
|
541
|
+
console.log(divider("\u2514", "\u2534", "\u2518"));
|
|
542
|
+
console.log(
|
|
543
|
+
import_chalk3.default.dim(
|
|
544
|
+
"Raw numbers include on-chain replication of off-chain CoFHE work; adjusted numbers estimate real-network cost. estimateGas remains unadjusted."
|
|
545
|
+
)
|
|
546
|
+
);
|
|
547
|
+
};
|
|
548
|
+
|
|
377
549
|
// src/index.ts
|
|
378
550
|
var import_chains = require("@cofhe/sdk/chains");
|
|
379
551
|
var import_mock_contracts3 = require("@cofhe/mock-contracts");
|
|
@@ -414,23 +586,22 @@ function generateMockContractsStubContent() {
|
|
|
414
586
|
return [.../* @__PURE__ */ new Set([...existing, stubPath])];
|
|
415
587
|
});
|
|
416
588
|
(0, import_config.extendConfig)((config, userConfig) => {
|
|
417
|
-
if (userConfig.networks
|
|
418
|
-
|
|
589
|
+
if (!userConfig.networks?.localcofhe) {
|
|
590
|
+
config.networks.localcofhe = {
|
|
591
|
+
gas: "auto",
|
|
592
|
+
gasMultiplier: 1.2,
|
|
593
|
+
gasPrice: "auto",
|
|
594
|
+
timeout: 1e4,
|
|
595
|
+
httpHeaders: {},
|
|
596
|
+
url: "http://127.0.0.1:42069",
|
|
597
|
+
accounts: [
|
|
598
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
599
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
600
|
+
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
|
|
601
|
+
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
|
|
602
|
+
]
|
|
603
|
+
};
|
|
419
604
|
}
|
|
420
|
-
config.networks.localcofhe = {
|
|
421
|
-
gas: "auto",
|
|
422
|
-
gasMultiplier: 1.2,
|
|
423
|
-
gasPrice: "auto",
|
|
424
|
-
timeout: 1e4,
|
|
425
|
-
httpHeaders: {},
|
|
426
|
-
url: "http://127.0.0.1:42069",
|
|
427
|
-
accounts: [
|
|
428
|
-
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
429
|
-
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
430
|
-
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
|
|
431
|
-
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
|
|
432
|
-
]
|
|
433
|
-
};
|
|
434
605
|
if (!userConfig.networks?.["eth-sepolia"]) {
|
|
435
606
|
config.networks["eth-sepolia"] = {
|
|
436
607
|
url: process.env.SEPOLIA_RPC_URL ?? "https://ethereum-sepolia.publicnode.com",
|
|
@@ -458,6 +629,7 @@ function generateMockContractsStubContent() {
|
|
|
458
629
|
config.cofhe = {
|
|
459
630
|
logMocks: userConfig.cofhe?.logMocks ?? false,
|
|
460
631
|
gasWarning: userConfig.cofhe?.gasWarning ?? false,
|
|
632
|
+
gasSummary: userConfig.cofhe?.gasSummary ?? false,
|
|
461
633
|
mocksDeployVerbosity: userConfig.cofhe?.mocksDeployVerbosity ?? "v"
|
|
462
634
|
};
|
|
463
635
|
});
|
|
@@ -465,18 +637,18 @@ function generateMockContractsStubContent() {
|
|
|
465
637
|
const { network } = hre;
|
|
466
638
|
const { name: networkName } = network;
|
|
467
639
|
if (networkName !== "localcofhe") {
|
|
468
|
-
console.info(
|
|
640
|
+
console.info(import_chalk4.default.yellow(`Programmatic faucet only supported for localcofhe`));
|
|
469
641
|
return;
|
|
470
642
|
}
|
|
471
643
|
if (!address) {
|
|
472
|
-
console.info(
|
|
644
|
+
console.info(import_chalk4.default.red(`Failed to get address to fund`));
|
|
473
645
|
return;
|
|
474
646
|
}
|
|
475
|
-
console.info(
|
|
647
|
+
console.info(import_chalk4.default.green(`Getting funds from faucet for ${address}`));
|
|
476
648
|
try {
|
|
477
649
|
await localcofheFundAccount(hre, address);
|
|
478
650
|
} catch (e) {
|
|
479
|
-
console.info(
|
|
651
|
+
console.info(import_chalk4.default.red(`failed to get funds from localcofhe for ${address}: ${e}`));
|
|
480
652
|
}
|
|
481
653
|
});
|
|
482
654
|
(0, import_config.task)(TASK_COFHE_MOCKS_DEPLOY, "Deploys the mock contracts on the Hardhat network").setAction(
|
|
@@ -499,7 +671,11 @@ function generateMockContractsStubContent() {
|
|
|
499
671
|
mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
|
|
500
672
|
});
|
|
501
673
|
}
|
|
502
|
-
|
|
674
|
+
const result = await runSuper();
|
|
675
|
+
if (hre.config.cofhe.gasSummary) {
|
|
676
|
+
await printMockGasSummary(hre);
|
|
677
|
+
}
|
|
678
|
+
return result;
|
|
503
679
|
});
|
|
504
680
|
(0, import_config.task)(import_task_names.TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
505
681
|
const skipAutoDeploy = (() => {
|
|
@@ -527,7 +703,7 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
527
703
|
(0, import_config.extendEnvironment)((hre) => {
|
|
528
704
|
hre.cofhe = {
|
|
529
705
|
createConfig: async (config) => {
|
|
530
|
-
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(
|
|
706
|
+
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk4.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
531
707
|
const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
|
|
532
708
|
const configWithZkvWalletClient = {
|
|
533
709
|
environment: "hardhat",
|
|
@@ -565,6 +741,8 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
565
741
|
});
|
|
566
742
|
return client;
|
|
567
743
|
},
|
|
744
|
+
getAdjustedGasUsed: mock_getAdjustedGasUsed,
|
|
745
|
+
getAdjustedGasBreakdown: mock_getAdjustedGasBreakdown,
|
|
568
746
|
mocks: {
|
|
569
747
|
withLogs: async (closureName, closure) => {
|
|
570
748
|
return mock_withLogs(hre, closureName, closure);
|
|
@@ -586,6 +764,7 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
586
764
|
const [signer] = await hre.ethers.getSigners();
|
|
587
765
|
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
588
766
|
},
|
|
767
|
+
getMockCoFHEAddressBook: async () => getFixedMockContract(hre, import_mock_contracts3.MockCoFHEAddressBookArtifact),
|
|
589
768
|
getMockTaskManager: async () => getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact),
|
|
590
769
|
getMockACL: async () => {
|
|
591
770
|
const taskManager = await getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact);
|
|
@@ -600,6 +779,7 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
600
779
|
});
|
|
601
780
|
// Annotate the CommonJS export names for ESM import in node:
|
|
602
781
|
0 && (module.exports = {
|
|
782
|
+
MOCK_GAS_CONSUMED_TOPIC,
|
|
603
783
|
TASK_COFHE_MOCKS_DEPLOY,
|
|
604
784
|
TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
605
785
|
TASK_COFHE_USE_FAUCET,
|
|
@@ -610,9 +790,12 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
610
790
|
localcofheFundAccount,
|
|
611
791
|
localcofheFundWalletIfNeeded,
|
|
612
792
|
mock_expectPlaintext,
|
|
793
|
+
mock_getAdjustedGasBreakdown,
|
|
794
|
+
mock_getAdjustedGasUsed,
|
|
613
795
|
mock_getPlaintext,
|
|
614
796
|
mock_getPlaintextExists,
|
|
615
797
|
mock_setLoggingEnabled,
|
|
616
|
-
mock_withLogs
|
|
798
|
+
mock_withLogs,
|
|
799
|
+
printMockGasSummary
|
|
617
800
|
});
|
|
618
801
|
//# sourceMappingURL=index.js.map
|