@cofhe/hardhat-plugin 0.7.1 → 1.0.0-alpha.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 +24 -0
- package/README.md +57 -11
- package/dist/index.d.mts +59 -3
- package/dist/index.d.ts +59 -3
- package/dist/index.js +226 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +224 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -6
- package/src/deploy.ts +46 -7
- package/src/gas.ts +227 -0
- package/src/index.ts +75 -20
- package/src/utils.ts +13 -7
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
|
|
|
@@ -126,7 +130,7 @@ var import_sdk = require("@cofhe/sdk");
|
|
|
126
130
|
var import_chai = require("chai");
|
|
127
131
|
var import_ethers = require("ethers");
|
|
128
132
|
var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
|
|
129
|
-
var deployMockContractFromArtifact = async (hre, artifact) => {
|
|
133
|
+
var deployMockContractFromArtifact = async (hre, artifact, constructorArgs = []) => {
|
|
130
134
|
const hardhatArtifact = await hre.artifacts.readArtifact(artifact.contractName);
|
|
131
135
|
if (artifact.isFixed) {
|
|
132
136
|
await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, hardhatArtifact.deployedBytecode]);
|
|
@@ -134,7 +138,7 @@ var deployMockContractFromArtifact = async (hre, artifact) => {
|
|
|
134
138
|
}
|
|
135
139
|
const [signer] = await hre.ethers.getSigners();
|
|
136
140
|
const factory = new hre.ethers.ContractFactory(hardhatArtifact.abi, hardhatArtifact.bytecode, signer);
|
|
137
|
-
const contract = await factory.deploy();
|
|
141
|
+
const contract = await factory.deploy(...constructorArgs);
|
|
138
142
|
await contract.waitForDeployment();
|
|
139
143
|
return contract;
|
|
140
144
|
};
|
|
@@ -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,20 +201,30 @@ 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);
|
|
205
213
|
logDeployment("ACPTimestampRevoker", await acpRevoker.getAddress());
|
|
206
214
|
await (await acl.setDefaultRevokerContract(await acpRevoker.getAddress())).wait();
|
|
207
215
|
log("vv", "Default revoker contract set in ACL", 2);
|
|
208
|
-
const
|
|
216
|
+
const acpShareRegistryImpl = await deployMockContractFromArtifact(hre, import_mock_contracts.ACPShareRegistryArtifact);
|
|
217
|
+
const [registryAdmin] = await hre.ethers.getSigners();
|
|
218
|
+
const acpShareRegistryProxy = await deployMockContractFromArtifact(hre, import_mock_contracts.MockERC1967ProxyArtifact, [
|
|
219
|
+
await acpShareRegistryImpl.getAddress(),
|
|
220
|
+
acpShareRegistryImpl.interface.encodeFunctionData("initialize", [registryAdmin.address])
|
|
221
|
+
]);
|
|
222
|
+
const acpShareRegistry = acpShareRegistryImpl.attach(await acpShareRegistryProxy.getAddress());
|
|
209
223
|
logDeployment("ACPShareRegistry", await acpShareRegistry.getAddress());
|
|
210
224
|
await (await acl.setShareRegistry(await acpShareRegistry.getAddress())).wait();
|
|
211
225
|
log("vv", "Share registry set in ACL", 2);
|
|
212
226
|
await linkTaskManagerAndACL(taskManager, acl);
|
|
213
|
-
log("vv", "ACL address set in TaskManager", 2);
|
|
227
|
+
log("vv", "ACL address set in TaskManager, TaskManager address set in ACL", 2);
|
|
214
228
|
await setVerifierSigner(taskManager);
|
|
215
229
|
log("vv", "Verifier signer set", 2);
|
|
216
230
|
await setDecryptResultSigner(taskManager);
|
|
@@ -221,13 +235,13 @@ var deployMocks = async (hre, options = {
|
|
|
221
235
|
log("vv", `ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
222
236
|
const zkVerifier = await deployMockZkVerifier(hre);
|
|
223
237
|
logDeployment("MockZkVerifier", await zkVerifier.getAddress());
|
|
224
|
-
const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
|
|
238
|
+
const thresholdNetwork = await deployMockThresholdNetwork(hre, taskManager, acl);
|
|
225
239
|
logDeployment("MockThresholdNetwork", await thresholdNetwork.getAddress());
|
|
226
240
|
log("v", import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed"), 0);
|
|
227
241
|
if (options.gasWarning) {
|
|
228
242
|
logEmpty("v");
|
|
229
243
|
logWarning(
|
|
230
|
-
"When using mocks, FHE operations (eg FHE.add / FHE.mul)
|
|
244
|
+
"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
245
|
0
|
|
232
246
|
);
|
|
233
247
|
}
|
|
@@ -236,11 +250,25 @@ var deployMocks = async (hre, options = {
|
|
|
236
250
|
var getIsHardhat = async (hre) => {
|
|
237
251
|
return hre.network.name === "hardhat";
|
|
238
252
|
};
|
|
253
|
+
var deployMockAddressBook = async (hre) => {
|
|
254
|
+
const addressBook = await deployMockContractFromArtifact(hre, import_mock_contracts.MockCoFHEAddressBookArtifact);
|
|
255
|
+
const bookExists = await addressBook.exists();
|
|
256
|
+
if (!bookExists) {
|
|
257
|
+
throw new Error("MockCoFHEAddressBook does not exist");
|
|
258
|
+
}
|
|
259
|
+
return addressBook;
|
|
260
|
+
};
|
|
261
|
+
var registerTaskManager = async (addressBook, taskManager) => {
|
|
262
|
+
const setTmTx = await addressBook.setTm(import_sdk2.TASK_MANAGER_ID, await taskManager.getAddress());
|
|
263
|
+
await setTmTx.wait();
|
|
264
|
+
};
|
|
239
265
|
var deployMockTaskManager = async (hre) => {
|
|
240
266
|
const [signer] = await hre.ethers.getSigners();
|
|
241
267
|
const taskManager = await deployMockContractFromArtifact(hre, import_mock_contracts.MockTaskManagerArtifact);
|
|
242
268
|
const initTx = await taskManager.initialize(signer.address);
|
|
243
269
|
await initTx.wait();
|
|
270
|
+
const securityZonesTx = await taskManager.setSecurityZones(0, 1);
|
|
271
|
+
await securityZonesTx.wait();
|
|
244
272
|
const tmExists = await taskManager.exists();
|
|
245
273
|
if (!tmExists) {
|
|
246
274
|
throw new Error("MockTaskManager does not exist");
|
|
@@ -269,6 +297,8 @@ var linkTaskManagerAndACL = async (taskManager, acl) => {
|
|
|
269
297
|
const aclAddress = await acl.getAddress();
|
|
270
298
|
const linkAclTx = await taskManager.setACLContract(aclAddress);
|
|
271
299
|
await linkAclTx.wait();
|
|
300
|
+
const linkTaskManagerTx = await acl.setTaskManager(await taskManager.getAddress());
|
|
301
|
+
await linkTaskManagerTx.wait();
|
|
272
302
|
};
|
|
273
303
|
var setVerifierSigner = async (taskManager) => {
|
|
274
304
|
const signer = new import_ethers2.Wallet(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY);
|
|
@@ -288,9 +318,9 @@ var deployMockZkVerifier = async (hre) => {
|
|
|
288
318
|
}
|
|
289
319
|
return zkVerifier;
|
|
290
320
|
};
|
|
291
|
-
var deployMockThresholdNetwork = async (hre, acl) => {
|
|
321
|
+
var deployMockThresholdNetwork = async (hre, taskManager, acl) => {
|
|
292
322
|
const thresholdNetwork = await deployMockContractFromArtifact(hre, import_mock_contracts.MockThresholdNetworkArtifact);
|
|
293
|
-
const initTx = await thresholdNetwork.initialize(
|
|
323
|
+
const initTx = await thresholdNetwork.initialize(await taskManager.getAddress(), await acl.getAddress());
|
|
294
324
|
await initTx.wait();
|
|
295
325
|
const exists = await thresholdNetwork.exists();
|
|
296
326
|
if (!exists) {
|
|
@@ -374,6 +404,154 @@ var mock_withLogs = async (hre, closureName, closure) => {
|
|
|
374
404
|
}
|
|
375
405
|
};
|
|
376
406
|
|
|
407
|
+
// src/gas.ts
|
|
408
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
409
|
+
var import_ethers3 = require("ethers");
|
|
410
|
+
var import_sdk3 = require("@cofhe/sdk");
|
|
411
|
+
var MOCK_GAS_CONSUMED_TOPIC = import_ethers3.ethers.id("MockGasConsumed(uint256)");
|
|
412
|
+
var mock_getAdjustedGasBreakdown = (receipt) => {
|
|
413
|
+
let mockGas = 0n;
|
|
414
|
+
let mockGasEvents = 0;
|
|
415
|
+
for (const log2 of receipt.logs ?? []) {
|
|
416
|
+
if (log2.address.toLowerCase() === import_sdk3.MOCKS_TASK_MANAGER_ADDRESS.toLowerCase() && log2.topics[0] === MOCK_GAS_CONSUMED_TOPIC) {
|
|
417
|
+
mockGas += BigInt(log2.data);
|
|
418
|
+
mockGasEvents += 1;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const gasUsed = BigInt(receipt.gasUsed);
|
|
422
|
+
return { gasUsed, mockGas, adjustedGasUsed: mockGas > gasUsed ? 0n : gasUsed - mockGas, mockGasEvents };
|
|
423
|
+
};
|
|
424
|
+
var mock_getAdjustedGasUsed = (receipt) => mock_getAdjustedGasBreakdown(receipt).adjustedGasUsed;
|
|
425
|
+
var shortAddress = (address) => `${address.slice(0, 6)}..${address.slice(-4)}`;
|
|
426
|
+
var buildSelectorNameMap = async (hre) => {
|
|
427
|
+
const selectorNames = /* @__PURE__ */ new Map();
|
|
428
|
+
for (const fqn of await hre.artifacts.getAllFullyQualifiedNames()) {
|
|
429
|
+
try {
|
|
430
|
+
const artifact = await hre.artifacts.readArtifact(fqn);
|
|
431
|
+
const iface = new import_ethers3.ethers.Interface(artifact.abi);
|
|
432
|
+
iface.forEachFunction((fn) => {
|
|
433
|
+
if (!selectorNames.has(fn.selector))
|
|
434
|
+
selectorNames.set(fn.selector, fn.format("sighash"));
|
|
435
|
+
});
|
|
436
|
+
} catch {
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return selectorNames;
|
|
440
|
+
};
|
|
441
|
+
var buildAddressNameMap = async (hre, addresses) => {
|
|
442
|
+
const codeToName = /* @__PURE__ */ new Map();
|
|
443
|
+
for (const fqn of await hre.artifacts.getAllFullyQualifiedNames()) {
|
|
444
|
+
try {
|
|
445
|
+
const artifact = await hre.artifacts.readArtifact(fqn);
|
|
446
|
+
if (artifact.deployedBytecode && artifact.deployedBytecode !== "0x") {
|
|
447
|
+
codeToName.set(artifact.deployedBytecode.toLowerCase(), artifact.contractName);
|
|
448
|
+
}
|
|
449
|
+
} catch {
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const addressNames = /* @__PURE__ */ new Map();
|
|
453
|
+
for (const address of addresses) {
|
|
454
|
+
try {
|
|
455
|
+
const code = await hre.network.provider.send("eth_getCode", [address, "latest"]);
|
|
456
|
+
addressNames.set(address, codeToName.get(code.toLowerCase()) ?? shortAddress(address));
|
|
457
|
+
} catch {
|
|
458
|
+
addressNames.set(address, shortAddress(address));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return addressNames;
|
|
462
|
+
};
|
|
463
|
+
var printMockGasSummary = async (hre) => {
|
|
464
|
+
if (hre.network.name !== "hardhat")
|
|
465
|
+
return;
|
|
466
|
+
let logs;
|
|
467
|
+
try {
|
|
468
|
+
logs = await hre.network.provider.send("eth_getLogs", [
|
|
469
|
+
{ fromBlock: "0x0", toBlock: "latest", address: import_sdk3.MOCKS_TASK_MANAGER_ADDRESS, topics: [MOCK_GAS_CONSUMED_TOPIC] }
|
|
470
|
+
]);
|
|
471
|
+
} catch {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (!logs || logs.length === 0)
|
|
475
|
+
return;
|
|
476
|
+
const mockGasPerTx = /* @__PURE__ */ new Map();
|
|
477
|
+
for (const log2 of logs) {
|
|
478
|
+
mockGasPerTx.set(log2.transactionHash, (mockGasPerTx.get(log2.transactionHash) ?? 0n) + BigInt(log2.data));
|
|
479
|
+
}
|
|
480
|
+
const aggregates = /* @__PURE__ */ new Map();
|
|
481
|
+
for (const [txHash, mockGas] of mockGasPerTx) {
|
|
482
|
+
try {
|
|
483
|
+
const receipt = await hre.network.provider.send("eth_getTransactionReceipt", [txHash]);
|
|
484
|
+
const tx = await hre.network.provider.send("eth_getTransactionByHash", [txHash]);
|
|
485
|
+
if (!receipt)
|
|
486
|
+
continue;
|
|
487
|
+
const target = tx?.to ?? receipt.contractAddress;
|
|
488
|
+
if (!target)
|
|
489
|
+
continue;
|
|
490
|
+
const to = import_ethers3.ethers.getAddress(target);
|
|
491
|
+
const selector = tx?.to ? (tx.input ?? "0x").slice(0, 10) : "(deployment)";
|
|
492
|
+
const key = `${to}:${selector}`;
|
|
493
|
+
const aggregate = aggregates.get(key) ?? { to, selector, calls: 0, totalGasUsed: 0n, totalMockGas: 0n };
|
|
494
|
+
aggregate.calls += 1;
|
|
495
|
+
aggregate.totalGasUsed += BigInt(receipt.gasUsed);
|
|
496
|
+
aggregate.totalMockGas += mockGas;
|
|
497
|
+
aggregates.set(key, aggregate);
|
|
498
|
+
} catch {
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
if (aggregates.size === 0)
|
|
502
|
+
return;
|
|
503
|
+
const selectorNames = await buildSelectorNameMap(hre);
|
|
504
|
+
const addressNames = await buildAddressNameMap(hre, [...new Set([...aggregates.values()].map((a) => a.to))]);
|
|
505
|
+
const merged = /* @__PURE__ */ new Map();
|
|
506
|
+
for (const a of aggregates.values()) {
|
|
507
|
+
const contract = addressNames.get(a.to) ?? shortAddress(a.to);
|
|
508
|
+
const method = selectorNames.get(a.selector) ?? a.selector;
|
|
509
|
+
const key = `${contract}:${method}`;
|
|
510
|
+
const row = merged.get(key) ?? { contract, method, calls: 0, totalGasUsed: 0n, totalMockGas: 0n };
|
|
511
|
+
row.calls += a.calls;
|
|
512
|
+
row.totalGasUsed += a.totalGasUsed;
|
|
513
|
+
row.totalMockGas += a.totalMockGas;
|
|
514
|
+
merged.set(key, row);
|
|
515
|
+
}
|
|
516
|
+
const rows = [...merged.values()].map((r) => {
|
|
517
|
+
const avgGasUsed = r.totalGasUsed / BigInt(r.calls);
|
|
518
|
+
const avgMockGas = r.totalMockGas / BigInt(r.calls);
|
|
519
|
+
return {
|
|
520
|
+
contract: r.contract,
|
|
521
|
+
method: r.method,
|
|
522
|
+
calls: r.calls,
|
|
523
|
+
avgGasUsed,
|
|
524
|
+
avgAdjusted: avgMockGas > avgGasUsed ? 0n : avgGasUsed - avgMockGas,
|
|
525
|
+
overheadPct: avgGasUsed === 0n ? 0 : Math.min(100, Number(avgMockGas * 100n / avgGasUsed))
|
|
526
|
+
};
|
|
527
|
+
}).sort((a, b) => a.contract.localeCompare(b.contract) || a.method.localeCompare(b.method));
|
|
528
|
+
const headers = ["Contract", "Method", "Calls", "Avg gas (mocks)", "Avg gas (adjusted)", "Mock overhead"];
|
|
529
|
+
const cells = rows.map((r) => [
|
|
530
|
+
r.contract,
|
|
531
|
+
r.method,
|
|
532
|
+
String(r.calls),
|
|
533
|
+
r.avgGasUsed.toLocaleString(),
|
|
534
|
+
r.avgAdjusted.toLocaleString(),
|
|
535
|
+
`${r.overheadPct}%`
|
|
536
|
+
]);
|
|
537
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...cells.map((row) => row[i].length)));
|
|
538
|
+
const line = (row) => `\u2502 ${row.map((cell, i) => cell.padEnd(widths[i])).join(" \u2502 ")} \u2502`;
|
|
539
|
+
const divider = (l, m, r) => `${l}${widths.map((w) => "\u2500".repeat(w + 2)).join(m)}${r}`;
|
|
540
|
+
console.log("");
|
|
541
|
+
console.log(import_chalk3.default.bold("[COFHE-MOCKS] Gas summary") + import_chalk3.default.dim(" \u2014 adjusted \u2248 cost excluding mock-only overhead"));
|
|
542
|
+
console.log(divider("\u250C", "\u252C", "\u2510"));
|
|
543
|
+
console.log(line(headers));
|
|
544
|
+
console.log(divider("\u251C", "\u253C", "\u2524"));
|
|
545
|
+
for (const row of cells)
|
|
546
|
+
console.log(line(row));
|
|
547
|
+
console.log(divider("\u2514", "\u2534", "\u2518"));
|
|
548
|
+
console.log(
|
|
549
|
+
import_chalk3.default.dim(
|
|
550
|
+
"Raw numbers include on-chain replication of off-chain CoFHE work; adjusted numbers estimate real-network cost. estimateGas remains unadjusted."
|
|
551
|
+
)
|
|
552
|
+
);
|
|
553
|
+
};
|
|
554
|
+
|
|
377
555
|
// src/index.ts
|
|
378
556
|
var import_chains = require("@cofhe/sdk/chains");
|
|
379
557
|
var import_mock_contracts3 = require("@cofhe/mock-contracts");
|
|
@@ -414,23 +592,22 @@ function generateMockContractsStubContent() {
|
|
|
414
592
|
return [.../* @__PURE__ */ new Set([...existing, stubPath])];
|
|
415
593
|
});
|
|
416
594
|
(0, import_config.extendConfig)((config, userConfig) => {
|
|
417
|
-
if (userConfig.networks
|
|
418
|
-
|
|
595
|
+
if (!userConfig.networks?.localcofhe) {
|
|
596
|
+
config.networks.localcofhe = {
|
|
597
|
+
gas: "auto",
|
|
598
|
+
gasMultiplier: 1.2,
|
|
599
|
+
gasPrice: "auto",
|
|
600
|
+
timeout: 1e4,
|
|
601
|
+
httpHeaders: {},
|
|
602
|
+
url: "http://127.0.0.1:42069",
|
|
603
|
+
accounts: [
|
|
604
|
+
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
|
|
605
|
+
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
|
|
606
|
+
"0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a",
|
|
607
|
+
"0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6"
|
|
608
|
+
]
|
|
609
|
+
};
|
|
419
610
|
}
|
|
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
611
|
if (!userConfig.networks?.["eth-sepolia"]) {
|
|
435
612
|
config.networks["eth-sepolia"] = {
|
|
436
613
|
url: process.env.SEPOLIA_RPC_URL ?? "https://ethereum-sepolia.publicnode.com",
|
|
@@ -458,6 +635,7 @@ function generateMockContractsStubContent() {
|
|
|
458
635
|
config.cofhe = {
|
|
459
636
|
logMocks: userConfig.cofhe?.logMocks ?? false,
|
|
460
637
|
gasWarning: userConfig.cofhe?.gasWarning ?? false,
|
|
638
|
+
gasSummary: userConfig.cofhe?.gasSummary ?? false,
|
|
461
639
|
mocksDeployVerbosity: userConfig.cofhe?.mocksDeployVerbosity ?? "v"
|
|
462
640
|
};
|
|
463
641
|
});
|
|
@@ -465,18 +643,18 @@ function generateMockContractsStubContent() {
|
|
|
465
643
|
const { network } = hre;
|
|
466
644
|
const { name: networkName } = network;
|
|
467
645
|
if (networkName !== "localcofhe") {
|
|
468
|
-
console.info(
|
|
646
|
+
console.info(import_chalk4.default.yellow(`Programmatic faucet only supported for localcofhe`));
|
|
469
647
|
return;
|
|
470
648
|
}
|
|
471
649
|
if (!address) {
|
|
472
|
-
console.info(
|
|
650
|
+
console.info(import_chalk4.default.red(`Failed to get address to fund`));
|
|
473
651
|
return;
|
|
474
652
|
}
|
|
475
|
-
console.info(
|
|
653
|
+
console.info(import_chalk4.default.green(`Getting funds from faucet for ${address}`));
|
|
476
654
|
try {
|
|
477
655
|
await localcofheFundAccount(hre, address);
|
|
478
656
|
} catch (e) {
|
|
479
|
-
console.info(
|
|
657
|
+
console.info(import_chalk4.default.red(`failed to get funds from localcofhe for ${address}: ${e}`));
|
|
480
658
|
}
|
|
481
659
|
});
|
|
482
660
|
(0, import_config.task)(TASK_COFHE_MOCKS_DEPLOY, "Deploys the mock contracts on the Hardhat network").setAction(
|
|
@@ -499,7 +677,11 @@ function generateMockContractsStubContent() {
|
|
|
499
677
|
mocksDeployVerbosity: hre.config.cofhe.mocksDeployVerbosity
|
|
500
678
|
});
|
|
501
679
|
}
|
|
502
|
-
|
|
680
|
+
const result = await runSuper();
|
|
681
|
+
if (hre.config.cofhe.gasSummary) {
|
|
682
|
+
await printMockGasSummary(hre);
|
|
683
|
+
}
|
|
684
|
+
return result;
|
|
503
685
|
});
|
|
504
686
|
(0, import_config.task)(import_task_names.TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
505
687
|
const skipAutoDeploy = (() => {
|
|
@@ -527,7 +709,7 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
527
709
|
(0, import_config.extendEnvironment)((hre) => {
|
|
528
710
|
hre.cofhe = {
|
|
529
711
|
createConfig: async (config) => {
|
|
530
|
-
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(
|
|
712
|
+
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk4.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
531
713
|
const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
|
|
532
714
|
const configWithZkvWalletClient = {
|
|
533
715
|
environment: "hardhat",
|
|
@@ -565,6 +747,8 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
565
747
|
});
|
|
566
748
|
return client;
|
|
567
749
|
},
|
|
750
|
+
getAdjustedGasUsed: mock_getAdjustedGasUsed,
|
|
751
|
+
getAdjustedGasBreakdown: mock_getAdjustedGasBreakdown,
|
|
568
752
|
mocks: {
|
|
569
753
|
withLogs: async (closureName, closure) => {
|
|
570
754
|
return mock_withLogs(hre, closureName, closure);
|
|
@@ -586,6 +770,7 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
586
770
|
const [signer] = await hre.ethers.getSigners();
|
|
587
771
|
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
588
772
|
},
|
|
773
|
+
getMockCoFHEAddressBook: async () => getFixedMockContract(hre, import_mock_contracts3.MockCoFHEAddressBookArtifact),
|
|
589
774
|
getMockTaskManager: async () => getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact),
|
|
590
775
|
getMockACL: async () => {
|
|
591
776
|
const taskManager = await getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact);
|
|
@@ -600,6 +785,7 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
600
785
|
});
|
|
601
786
|
// Annotate the CommonJS export names for ESM import in node:
|
|
602
787
|
0 && (module.exports = {
|
|
788
|
+
MOCK_GAS_CONSUMED_TOPIC,
|
|
603
789
|
TASK_COFHE_MOCKS_DEPLOY,
|
|
604
790
|
TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
605
791
|
TASK_COFHE_USE_FAUCET,
|
|
@@ -610,9 +796,12 @@ function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
|
610
796
|
localcofheFundAccount,
|
|
611
797
|
localcofheFundWalletIfNeeded,
|
|
612
798
|
mock_expectPlaintext,
|
|
799
|
+
mock_getAdjustedGasBreakdown,
|
|
800
|
+
mock_getAdjustedGasUsed,
|
|
613
801
|
mock_getPlaintext,
|
|
614
802
|
mock_getPlaintextExists,
|
|
615
803
|
mock_setLoggingEnabled,
|
|
616
|
-
mock_withLogs
|
|
804
|
+
mock_withLogs,
|
|
805
|
+
printMockGasSummary
|
|
617
806
|
});
|
|
618
807
|
//# sourceMappingURL=index.js.map
|