@cofhe/hardhat-plugin 0.2.0 → 0.3.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 +42 -0
- package/README.md +7 -1
- package/dist/index.d.mts +38 -26
- package/dist/index.d.ts +38 -26
- package/dist/index.js +214 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +209 -219
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -8
- package/src/consts.ts +0 -5
- package/src/deploy.ts +114 -155
- package/src/index.ts +92 -73
- package/src/logging.ts +7 -13
- package/src/utils.ts +33 -2
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import "@nomicfoundation/hardhat-ethers/signers";
|
|
|
7
7
|
import {
|
|
8
8
|
MOCKS_ZK_VERIFIER_SIGNER_ADDRESS as MOCKS_ZK_VERIFIER_SIGNER_ADDRESS2
|
|
9
9
|
} from "@cofhe/sdk";
|
|
10
|
-
import {
|
|
10
|
+
import { createCofheClient, createCofheConfig } from "@cofhe/sdk/node";
|
|
11
11
|
import { HardhatSignerAdapter } from "@cofhe/sdk/adapters";
|
|
12
12
|
|
|
13
13
|
// src/fund.ts
|
|
@@ -66,10 +66,6 @@ async function localcofheFundWalletIfNeeded(hre, walletAddress) {
|
|
|
66
66
|
var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
67
67
|
var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
68
68
|
var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
69
|
-
var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
70
|
-
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000000100";
|
|
71
|
-
var MOCKS_QUERY_DECRYPTER_ADDRESS = "0x0000000000000000000000000000000000000200";
|
|
72
|
-
var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000000300";
|
|
73
69
|
|
|
74
70
|
// src/deploy.ts
|
|
75
71
|
import "hardhat/types";
|
|
@@ -79,163 +75,196 @@ import {
|
|
|
79
75
|
MockTaskManagerArtifact,
|
|
80
76
|
MockACLArtifact,
|
|
81
77
|
MockZkVerifierArtifact,
|
|
82
|
-
|
|
78
|
+
MockThresholdNetworkArtifact,
|
|
83
79
|
TestBedArtifact
|
|
84
80
|
} from "@cofhe/mock-contracts";
|
|
85
|
-
import { MOCKS_ZK_VERIFIER_SIGNER_ADDRESS } from "@cofhe/sdk";
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return taskManager;
|
|
97
|
-
};
|
|
98
|
-
var deployMockACL = async (hre) => {
|
|
99
|
-
const acl = await ethersDeployContract(hre, MockACLArtifact.abi, MockACLArtifact.bytecode);
|
|
100
|
-
const exists = await acl.exists();
|
|
101
|
-
if (!exists) {
|
|
102
|
-
logError("MockACL does not exist", 2);
|
|
103
|
-
throw new Error("MockACL does not exist");
|
|
81
|
+
import { TASK_MANAGER_ADDRESS as TASK_MANAGER_ADDRESS2, MOCKS_ZK_VERIFIER_SIGNER_ADDRESS } from "@cofhe/sdk";
|
|
82
|
+
|
|
83
|
+
// src/utils.ts
|
|
84
|
+
import { TASK_MANAGER_ADDRESS, MOCKS_ZK_VERIFIER_ADDRESS } from "@cofhe/sdk";
|
|
85
|
+
import { expect } from "chai";
|
|
86
|
+
import { ethers } from "ethers";
|
|
87
|
+
import "@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider";
|
|
88
|
+
var deployMockContractFromArtifact = async (hre, artifact) => {
|
|
89
|
+
if (artifact.isFixed) {
|
|
90
|
+
await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, artifact.deployedBytecode]);
|
|
91
|
+
return getFixedMockContract(hre, artifact);
|
|
104
92
|
}
|
|
105
|
-
|
|
93
|
+
const [signer] = await hre.ethers.getSigners();
|
|
94
|
+
const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
|
|
95
|
+
const contract = await factory.deploy(
|
|
96
|
+
/* constructor args */
|
|
97
|
+
);
|
|
98
|
+
await contract.waitForDeployment();
|
|
99
|
+
return contract;
|
|
106
100
|
};
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const zkVerifierExists = await zkVerifier.exists();
|
|
111
|
-
if (!zkVerifierExists) {
|
|
112
|
-
logError("MockZkVerifier does not exist", 2);
|
|
113
|
-
throw new Error("MockZkVerifier does not exist");
|
|
101
|
+
var getFixedMockContract = async (hre, artifact) => {
|
|
102
|
+
if (!artifact.isFixed) {
|
|
103
|
+
throw new Error("Artifact is not fixed");
|
|
114
104
|
}
|
|
115
|
-
return
|
|
105
|
+
return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
|
|
116
106
|
};
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const queryDecrypterExists = await queryDecrypter.exists();
|
|
123
|
-
if (!queryDecrypterExists) {
|
|
124
|
-
logError("MockQueryDecrypter does not exist", 2);
|
|
125
|
-
throw new Error("MockQueryDecrypter does not exist");
|
|
107
|
+
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
108
|
+
const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
|
|
109
|
+
const isTestnet = bytecode.length === 0;
|
|
110
|
+
if (isTestnet) {
|
|
111
|
+
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
126
112
|
}
|
|
127
|
-
return
|
|
113
|
+
return isTestnet;
|
|
128
114
|
};
|
|
129
|
-
var
|
|
130
|
-
await
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
115
|
+
var mock_getPlaintext = async (provider, ctHash) => {
|
|
116
|
+
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
117
|
+
return;
|
|
118
|
+
const taskManager = new ethers.Contract(
|
|
119
|
+
TASK_MANAGER_ADDRESS,
|
|
120
|
+
["function mockStorage(uint256) view returns (uint256)"],
|
|
121
|
+
provider
|
|
122
|
+
);
|
|
123
|
+
const plaintext = await taskManager.mockStorage(ctHash);
|
|
124
|
+
return plaintext;
|
|
134
125
|
};
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
126
|
+
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
127
|
+
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
128
|
+
return;
|
|
129
|
+
const taskManager = new ethers.Contract(
|
|
130
|
+
TASK_MANAGER_ADDRESS,
|
|
131
|
+
["function inMockStorage(uint256) view returns (bool)"],
|
|
132
|
+
provider
|
|
133
|
+
);
|
|
134
|
+
const plaintextExists = await taskManager.inMockStorage(ctHash);
|
|
135
|
+
return plaintextExists;
|
|
141
136
|
};
|
|
142
|
-
var
|
|
143
|
-
|
|
144
|
-
|
|
137
|
+
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
138
|
+
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
139
|
+
return;
|
|
140
|
+
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
141
|
+
expect(plaintextExists).equal(true, "Plaintext does not exist");
|
|
142
|
+
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
143
|
+
expect(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
145
144
|
};
|
|
145
|
+
|
|
146
|
+
// src/deploy.ts
|
|
146
147
|
var deployMocks = async (hre, options = {
|
|
147
148
|
deployTestBed: true,
|
|
148
149
|
gasWarning: true,
|
|
149
150
|
silent: false
|
|
150
151
|
}) => {
|
|
151
|
-
const isHardhat = await
|
|
152
|
-
if (!isHardhat)
|
|
152
|
+
const isHardhat = await getIsHardhat(hre);
|
|
153
|
+
if (!isHardhat) {
|
|
154
|
+
logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
|
|
153
155
|
return;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const logSuccessIfNoisy = (message, indent = 0) => {
|
|
160
|
-
if (!options.silent) {
|
|
161
|
-
logSuccess(message, indent);
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const logDeploymentIfNoisy = (contractName, address) => {
|
|
165
|
-
if (!options.silent) {
|
|
166
|
-
logDeployment(contractName, address);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
const logWarningIfNoisy = (message, indent = 0) => {
|
|
170
|
-
if (!options.silent) {
|
|
171
|
-
logWarning(message, indent);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
logEmptyIfNoisy();
|
|
175
|
-
logSuccessIfNoisy(chalk.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
176
|
-
logEmptyIfNoisy();
|
|
156
|
+
}
|
|
157
|
+
isSilent = options.silent ?? false;
|
|
158
|
+
logEmpty();
|
|
159
|
+
logSuccess(chalk.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
160
|
+
logEmpty();
|
|
177
161
|
const taskManager = await deployMockTaskManager(hre);
|
|
178
|
-
|
|
162
|
+
logDeployment("MockTaskManager", await taskManager.getAddress());
|
|
179
163
|
const acl = await deployMockACL(hre);
|
|
180
|
-
|
|
181
|
-
await
|
|
182
|
-
|
|
164
|
+
logDeployment("MockACL", await acl.getAddress());
|
|
165
|
+
await linkTaskManagerAndACL(taskManager, acl);
|
|
166
|
+
logSuccess("ACL address set in TaskManager", 2);
|
|
183
167
|
await fundZkVerifierSigner(hre);
|
|
184
|
-
|
|
185
|
-
const zkVerifierSignerBalance = await hre
|
|
186
|
-
|
|
168
|
+
logSuccess(`ZkVerifier signer (${MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
|
|
169
|
+
const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
|
|
170
|
+
logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
187
171
|
const zkVerifier = await deployMockZkVerifier(hre);
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
172
|
+
logDeployment("MockZkVerifier", await zkVerifier.getAddress());
|
|
173
|
+
const thresholdNetwork = await deployMockThresholdNetwork(hre, acl);
|
|
174
|
+
logDeployment("MockThresholdNetwork", await thresholdNetwork.getAddress());
|
|
191
175
|
if (options.deployTestBed) {
|
|
192
|
-
|
|
176
|
+
logSuccess("TestBed deployment enabled", 2);
|
|
193
177
|
const testBed = await deployTestBedContract(hre);
|
|
194
|
-
|
|
178
|
+
logDeployment("TestBed", await testBed.getAddress());
|
|
195
179
|
}
|
|
196
|
-
|
|
197
|
-
|
|
180
|
+
logEmpty();
|
|
181
|
+
logSuccess(chalk.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
|
|
198
182
|
if (options.gasWarning) {
|
|
199
|
-
|
|
200
|
-
|
|
183
|
+
logEmpty();
|
|
184
|
+
logWarning(
|
|
201
185
|
"When using mocks, FHE operations (eg FHE.add / FHE.mul) report a higher gas price due to additional on-chain mocking logic. Deploy your contracts on a testnet chain to check the true gas costs.\n(Disable this warning by setting '@cofhe/sdk.gasWarning' to false in your hardhat config",
|
|
202
186
|
0
|
|
203
187
|
);
|
|
204
188
|
}
|
|
205
|
-
|
|
189
|
+
logEmpty();
|
|
206
190
|
};
|
|
207
|
-
var
|
|
208
|
-
|
|
191
|
+
var getIsHardhat = async (hre) => {
|
|
192
|
+
return hre.network.name === "hardhat";
|
|
209
193
|
};
|
|
210
|
-
var
|
|
194
|
+
var deployMockTaskManager = async (hre) => {
|
|
211
195
|
const [signer] = await hre.ethers.getSigners();
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
const taskManager = await deployMockContractFromArtifact(hre, MockTaskManagerArtifact);
|
|
197
|
+
const initTx = await taskManager.initialize(signer.address);
|
|
198
|
+
await initTx.wait();
|
|
199
|
+
const tmExists = await taskManager.exists();
|
|
200
|
+
if (!tmExists) {
|
|
201
|
+
throw new Error("MockTaskManager does not exist");
|
|
202
|
+
}
|
|
203
|
+
return taskManager;
|
|
218
204
|
};
|
|
219
|
-
var
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
if (!
|
|
223
|
-
|
|
224
|
-
|
|
205
|
+
var deployMockACL = async (hre) => {
|
|
206
|
+
const acl = await deployMockContractFromArtifact(hre, MockACLArtifact);
|
|
207
|
+
const exists = await acl.exists();
|
|
208
|
+
if (!exists) {
|
|
209
|
+
throw new Error("MockACL does not exist");
|
|
210
|
+
}
|
|
211
|
+
return acl;
|
|
212
|
+
};
|
|
213
|
+
var fundZkVerifierSigner = async (hre) => {
|
|
214
|
+
const zkVerifierSigner = await hre.ethers.getSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
215
|
+
await hre.network.provider.send("hardhat_setBalance", [
|
|
216
|
+
zkVerifierSigner.address,
|
|
217
|
+
"0x" + hre.ethers.parseEther("10").toString(16)
|
|
218
|
+
]);
|
|
219
|
+
};
|
|
220
|
+
var getZkVerifierSignerBalance = async (hre) => {
|
|
221
|
+
return hre.ethers.provider.getBalance(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
222
|
+
};
|
|
223
|
+
var linkTaskManagerAndACL = async (taskManager, acl) => {
|
|
224
|
+
const aclAddress = await acl.getAddress();
|
|
225
|
+
const linkAclTx = await taskManager.setACLContract(aclAddress);
|
|
226
|
+
await linkAclTx.wait();
|
|
227
|
+
};
|
|
228
|
+
var deployMockZkVerifier = async (hre) => {
|
|
229
|
+
const zkVerifier = await deployMockContractFromArtifact(hre, MockZkVerifierArtifact);
|
|
230
|
+
const zkVerifierExists = await zkVerifier.exists();
|
|
231
|
+
if (!zkVerifierExists) {
|
|
232
|
+
throw new Error("MockZkVerifier does not exist");
|
|
233
|
+
}
|
|
234
|
+
return zkVerifier;
|
|
235
|
+
};
|
|
236
|
+
var deployMockThresholdNetwork = async (hre, acl) => {
|
|
237
|
+
const thresholdNetwork = await deployMockContractFromArtifact(hre, MockThresholdNetworkArtifact);
|
|
238
|
+
const initTx = await thresholdNetwork.initialize(TASK_MANAGER_ADDRESS2, await acl.getAddress());
|
|
239
|
+
await initTx.wait();
|
|
240
|
+
const exists = await thresholdNetwork.exists();
|
|
241
|
+
if (!exists) {
|
|
242
|
+
throw new Error("MockThresholdNetwork does not exist");
|
|
243
|
+
}
|
|
244
|
+
return thresholdNetwork;
|
|
245
|
+
};
|
|
246
|
+
var deployTestBedContract = async (hre) => {
|
|
247
|
+
return deployMockContractFromArtifact(hre, TestBedArtifact);
|
|
225
248
|
};
|
|
249
|
+
var isSilent = false;
|
|
226
250
|
var logEmpty = () => {
|
|
251
|
+
if (isSilent)
|
|
252
|
+
return;
|
|
227
253
|
console.log("");
|
|
228
254
|
};
|
|
229
255
|
var logSuccess = (message, indent = 1) => {
|
|
256
|
+
if (isSilent)
|
|
257
|
+
return;
|
|
230
258
|
console.log(chalk.green(`${" ".repeat(indent)}\u2713 ${message}`));
|
|
231
259
|
};
|
|
232
260
|
var logWarning = (message, indent = 1) => {
|
|
261
|
+
if (isSilent)
|
|
262
|
+
return;
|
|
233
263
|
console.log(chalk.bold(chalk.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
|
|
234
264
|
};
|
|
235
|
-
var logError = (message, indent = 1) => {
|
|
236
|
-
console.log(chalk.red(`${" ".repeat(indent)}\u2717 ${message}`));
|
|
237
|
-
};
|
|
238
265
|
var logDeployment = (contractName, address) => {
|
|
266
|
+
if (isSilent)
|
|
267
|
+
return;
|
|
239
268
|
const paddedName = `${contractName} deployed`.padEnd(36);
|
|
240
269
|
logSuccess(`${paddedName} ${chalk.bold(address)}`);
|
|
241
270
|
};
|
|
@@ -244,17 +273,14 @@ var logDeployment = (contractName, address) => {
|
|
|
244
273
|
import chalk2 from "chalk";
|
|
245
274
|
import "hardhat/types";
|
|
246
275
|
import { MockTaskManagerArtifact as MockTaskManagerArtifact2 } from "@cofhe/mock-contracts";
|
|
247
|
-
var getDeployedMockTaskManager = async (hre) => {
|
|
248
|
-
const taskManager = await hre.ethers.getContractAt(MockTaskManagerArtifact2.abi, TASK_MANAGER_ADDRESS);
|
|
249
|
-
return taskManager;
|
|
250
|
-
};
|
|
251
276
|
var getLoggingEnabled = async (hre) => {
|
|
252
|
-
const taskManager = await
|
|
253
|
-
return
|
|
277
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact2);
|
|
278
|
+
return taskManager.logOps();
|
|
254
279
|
};
|
|
255
280
|
var setLoggingEnabled = async (hre, enabled) => {
|
|
256
|
-
const taskManager = await
|
|
257
|
-
await taskManager.setLogOps(enabled);
|
|
281
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact2);
|
|
282
|
+
const tx = await taskManager.setLogOps(enabled);
|
|
283
|
+
await tx.wait();
|
|
258
284
|
};
|
|
259
285
|
var printLogsEnabledMessage = (closureMessage) => {
|
|
260
286
|
console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
@@ -289,65 +315,15 @@ var mock_withLogs = async (hre, closureName, closure) => {
|
|
|
289
315
|
}
|
|
290
316
|
};
|
|
291
317
|
|
|
292
|
-
// src/utils.ts
|
|
293
|
-
import { expect } from "chai";
|
|
294
|
-
import { ethers } from "ethers";
|
|
295
|
-
import "@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider";
|
|
296
|
-
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
297
|
-
const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
|
|
298
|
-
const isTestnet = bytecode.length === 0;
|
|
299
|
-
if (isTestnet) {
|
|
300
|
-
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
301
|
-
}
|
|
302
|
-
return isTestnet;
|
|
303
|
-
};
|
|
304
|
-
var mock_getPlaintext = async (provider, ctHash) => {
|
|
305
|
-
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
306
|
-
return;
|
|
307
|
-
const taskManager = new ethers.Contract(
|
|
308
|
-
TASK_MANAGER_ADDRESS,
|
|
309
|
-
["function mockStorage(uint256) view returns (uint256)"],
|
|
310
|
-
provider
|
|
311
|
-
);
|
|
312
|
-
const plaintext = await taskManager.mockStorage(ctHash);
|
|
313
|
-
return plaintext;
|
|
314
|
-
};
|
|
315
|
-
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
316
|
-
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
317
|
-
return;
|
|
318
|
-
const taskManager = new ethers.Contract(
|
|
319
|
-
TASK_MANAGER_ADDRESS,
|
|
320
|
-
["function inMockStorage(uint256) view returns (bool)"],
|
|
321
|
-
provider
|
|
322
|
-
);
|
|
323
|
-
const plaintextExists = await taskManager.inMockStorage(ctHash);
|
|
324
|
-
return plaintextExists;
|
|
325
|
-
};
|
|
326
|
-
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
327
|
-
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
328
|
-
return;
|
|
329
|
-
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
330
|
-
expect(plaintextExists).equal(true, "Plaintext does not exist");
|
|
331
|
-
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
332
|
-
expect(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
333
|
-
};
|
|
334
|
-
|
|
335
318
|
// src/index.ts
|
|
319
|
+
import { hardhat } from "@cofhe/sdk/chains";
|
|
336
320
|
import {
|
|
337
321
|
MockACLArtifact as MockACLArtifact2,
|
|
338
|
-
|
|
322
|
+
MockThresholdNetworkArtifact as MockThresholdNetworkArtifact2,
|
|
339
323
|
MockTaskManagerArtifact as MockTaskManagerArtifact3,
|
|
340
324
|
MockZkVerifierArtifact as MockZkVerifierArtifact2,
|
|
341
325
|
TestBedArtifact as TestBedArtifact2
|
|
342
326
|
} from "@cofhe/mock-contracts";
|
|
343
|
-
import { hardhat } from "@cofhe/sdk/chains";
|
|
344
|
-
import {
|
|
345
|
-
MockACLArtifact as MockACLArtifact3,
|
|
346
|
-
MockQueryDecrypterArtifact as MockQueryDecrypterArtifact3,
|
|
347
|
-
MockTaskManagerArtifact as MockTaskManagerArtifact4,
|
|
348
|
-
MockZkVerifierArtifact as MockZkVerifierArtifact3,
|
|
349
|
-
TestBedArtifact as TestBedArtifact3
|
|
350
|
-
} from "@cofhe/mock-contracts";
|
|
351
327
|
extendConfig((config, userConfig) => {
|
|
352
328
|
if (userConfig.networks && userConfig.networks.localcofhe) {
|
|
353
329
|
return;
|
|
@@ -390,9 +366,9 @@ extendConfig((config, userConfig) => {
|
|
|
390
366
|
httpHeaders: {}
|
|
391
367
|
};
|
|
392
368
|
}
|
|
393
|
-
config.
|
|
394
|
-
logMocks: userConfig.
|
|
395
|
-
gasWarning: userConfig.
|
|
369
|
+
config.cofhe = {
|
|
370
|
+
logMocks: userConfig.cofhe?.logMocks ?? true,
|
|
371
|
+
gasWarning: userConfig.cofhe?.gasWarning ?? true
|
|
396
372
|
};
|
|
397
373
|
});
|
|
398
374
|
task(TASK_COFHE_USE_FAUCET, "Fund an account from the funder").addOptionalParam("address", "Address to fund", void 0, types.string).setAction(async ({ address }, hre) => {
|
|
@@ -416,44 +392,65 @@ task(TASK_COFHE_USE_FAUCET, "Fund an account from the funder").addOptionalParam(
|
|
|
416
392
|
task(TASK_COFHE_MOCKS_DEPLOY, "Deploys the mock contracts on the Hardhat network").addOptionalParam("deployTestBed", "Whether to deploy the test bed", true, types.boolean).addOptionalParam("silent", "Whether to suppress output", false, types.boolean).setAction(async ({ deployTestBed, silent }, hre) => {
|
|
417
393
|
await deployMocks(hre, {
|
|
418
394
|
deployTestBed: deployTestBed ?? true,
|
|
419
|
-
gasWarning: hre.config.
|
|
395
|
+
gasWarning: hre.config.cofhe.gasWarning ?? true,
|
|
420
396
|
silent: silent ?? false
|
|
421
397
|
});
|
|
422
398
|
});
|
|
423
399
|
task(TASK_TEST, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
400
|
+
const skipAutoDeploy = (() => {
|
|
401
|
+
const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
|
|
402
|
+
const normalized = raw.trim().toLowerCase();
|
|
403
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
404
|
+
})();
|
|
405
|
+
if (!skipAutoDeploy) {
|
|
406
|
+
await deployMocks(hre, {
|
|
407
|
+
deployTestBed: true,
|
|
408
|
+
gasWarning: hre.config.cofhe.gasWarning ?? true
|
|
409
|
+
});
|
|
410
|
+
}
|
|
428
411
|
return runSuper();
|
|
429
412
|
});
|
|
430
413
|
task(TASK_NODE, "Deploy mock contracts on hardhat").setAction(async ({}, hre, runSuper) => {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
414
|
+
const skipAutoDeploy = (() => {
|
|
415
|
+
const raw = process.env.COFHE_SKIP_MOCKS_DEPLOY ?? "";
|
|
416
|
+
const normalized = raw.trim().toLowerCase();
|
|
417
|
+
return normalized === "1" || normalized === "true" || normalized === "yes";
|
|
418
|
+
})();
|
|
419
|
+
if (!skipAutoDeploy) {
|
|
420
|
+
await deployMocks(hre, {
|
|
421
|
+
deployTestBed: true,
|
|
422
|
+
gasWarning: hre.config.cofhe.gasWarning ?? true
|
|
423
|
+
});
|
|
424
|
+
}
|
|
435
425
|
return runSuper();
|
|
436
426
|
});
|
|
437
427
|
task(TASK_COFHE_MOCKS_SET_LOG_OPS, "Set logging for the Mock CoFHE contracts").addParam("enable", "Whether to enable logging", false, types.boolean).setAction(async ({ enable }, hre) => {
|
|
438
428
|
await mock_setLoggingEnabled(hre, enable);
|
|
439
429
|
});
|
|
430
|
+
function buildHardhatPluginMocksConfig(mocksConfig) {
|
|
431
|
+
return {
|
|
432
|
+
...mocksConfig,
|
|
433
|
+
encryptDelay: mocksConfig?.encryptDelay ?? 0
|
|
434
|
+
};
|
|
435
|
+
}
|
|
440
436
|
extendEnvironment((hre) => {
|
|
441
|
-
hre.
|
|
442
|
-
|
|
437
|
+
hre.cofhe = {
|
|
438
|
+
createConfig: async (config) => {
|
|
443
439
|
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(MOCKS_ZK_VERIFIER_SIGNER_ADDRESS2);
|
|
444
440
|
const { walletClient: zkvWalletClient } = await HardhatSignerAdapter(zkvHhSigner);
|
|
445
441
|
const configWithZkvWalletClient = {
|
|
446
442
|
environment: "hardhat",
|
|
447
443
|
...config,
|
|
444
|
+
mocks: buildHardhatPluginMocksConfig(config.mocks),
|
|
448
445
|
_internal: {
|
|
449
446
|
...config._internal,
|
|
450
447
|
zkvWalletClient
|
|
451
448
|
}
|
|
452
449
|
};
|
|
453
|
-
return
|
|
450
|
+
return createCofheConfig(configWithZkvWalletClient);
|
|
454
451
|
},
|
|
455
|
-
|
|
456
|
-
return
|
|
452
|
+
createClient: (config) => {
|
|
453
|
+
return createCofheClient(config);
|
|
457
454
|
},
|
|
458
455
|
hardhatSignerAdapter: async (signer) => {
|
|
459
456
|
return HardhatSignerAdapter(signer);
|
|
@@ -462,16 +459,16 @@ extendEnvironment((hre) => {
|
|
|
462
459
|
const { publicClient, walletClient } = await HardhatSignerAdapter(signer);
|
|
463
460
|
return client.connect(publicClient, walletClient);
|
|
464
461
|
},
|
|
465
|
-
|
|
462
|
+
createClientWithBatteries: async (signer) => {
|
|
466
463
|
if (!signer) {
|
|
467
464
|
[signer] = await hre.ethers.getSigners();
|
|
468
465
|
}
|
|
469
|
-
const config = await hre.
|
|
466
|
+
const config = await hre.cofhe.createConfig({
|
|
470
467
|
environment: "hardhat",
|
|
471
468
|
supportedChains: [hardhat]
|
|
472
469
|
});
|
|
473
|
-
const client = hre.
|
|
474
|
-
await hre.
|
|
470
|
+
const client = hre.cofhe.createClient(config);
|
|
471
|
+
await hre.cofhe.connectWithHardhatSigner(client, signer);
|
|
475
472
|
await client.permits.createSelf({
|
|
476
473
|
issuer: signer.address
|
|
477
474
|
});
|
|
@@ -498,33 +495,26 @@ extendEnvironment((hre) => {
|
|
|
498
495
|
const [signer] = await hre.ethers.getSigners();
|
|
499
496
|
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
500
497
|
},
|
|
501
|
-
getMockTaskManager: async () =>
|
|
502
|
-
return await hre.ethers.getContractAt(MockTaskManagerArtifact3.abi, MockTaskManagerArtifact3.fixedAddress);
|
|
503
|
-
},
|
|
498
|
+
getMockTaskManager: async () => getFixedMockContract(hre, MockTaskManagerArtifact3),
|
|
504
499
|
getMockACL: async () => {
|
|
505
|
-
const
|
|
506
|
-
const aclAddress = await
|
|
507
|
-
return
|
|
500
|
+
const taskManager = await getFixedMockContract(hre, MockTaskManagerArtifact3);
|
|
501
|
+
const aclAddress = await taskManager.acl();
|
|
502
|
+
return hre.ethers.getContractAt(MockACLArtifact2.abi, aclAddress);
|
|
508
503
|
},
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
getMockZkVerifier: async () => {
|
|
513
|
-
return await hre.ethers.getContractAt(MockZkVerifierArtifact2.abi, MockZkVerifierArtifact2.fixedAddress);
|
|
514
|
-
},
|
|
515
|
-
getTestBed: async () => {
|
|
516
|
-
return await hre.ethers.getContractAt(TestBedArtifact2.abi, TestBedArtifact2.fixedAddress);
|
|
517
|
-
}
|
|
504
|
+
getMockThresholdNetwork: async () => getFixedMockContract(hre, MockThresholdNetworkArtifact2),
|
|
505
|
+
getMockZkVerifier: async () => getFixedMockContract(hre, MockZkVerifierArtifact2),
|
|
506
|
+
getTestBed: async () => getFixedMockContract(hre, TestBedArtifact2)
|
|
518
507
|
}
|
|
519
508
|
};
|
|
520
509
|
});
|
|
521
510
|
export {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
511
|
+
TASK_COFHE_MOCKS_DEPLOY,
|
|
512
|
+
TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
513
|
+
TASK_COFHE_USE_FAUCET,
|
|
514
|
+
buildHardhatPluginMocksConfig,
|
|
515
|
+
deployMockContractFromArtifact,
|
|
527
516
|
deployMocks,
|
|
517
|
+
getFixedMockContract,
|
|
528
518
|
localcofheFundAccount,
|
|
529
519
|
localcofheFundWalletIfNeeded,
|
|
530
520
|
mock_expectPlaintext,
|