@cofhe/hardhat-plugin 0.2.0 → 0.2.1
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 +12 -0
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +168 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -193
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -8
- package/src/consts.ts +0 -5
- package/src/deploy.ts +112 -153
- package/src/index.ts +11 -25
- package/src/logging.ts +7 -13
- package/src/utils.ts +33 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @cofhe/hardhat-plugin Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0000d5e: Mock contracts deployed to alternate fixed addresses to avoid collision with hardhat pre-compiles.
|
|
8
|
+
- Updated dependencies [409bfdf]
|
|
9
|
+
- Updated dependencies [ac47e2f]
|
|
10
|
+
- Updated dependencies [0000d5e]
|
|
11
|
+
- Updated dependencies [8af1b70]
|
|
12
|
+
- @cofhe/sdk@0.2.1
|
|
13
|
+
- @cofhe/mock-contracts@0.2.1
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3,9 +3,9 @@ import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
|
|
|
3
3
|
import { CofhesdkInputConfig, CofhesdkConfig, CofhesdkClient } from '@cofhe/sdk';
|
|
4
4
|
import { HardhatRuntimeEnvironment } from 'hardhat/types';
|
|
5
5
|
import * as ethers from 'ethers';
|
|
6
|
-
import { ethers as ethers$1
|
|
7
|
-
export { MockACLArtifact, MockQueryDecrypterArtifact, MockTaskManagerArtifact, MockZkVerifierArtifact, TestBedArtifact } from '@cofhe/mock-contracts';
|
|
6
|
+
import { Contract, ethers as ethers$1 } from 'ethers';
|
|
8
7
|
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
|
|
8
|
+
import { MockArtifact } from '@cofhe/mock-contracts';
|
|
9
9
|
|
|
10
10
|
type DeployMocksArgs = {
|
|
11
11
|
deployTestBed?: boolean;
|
|
@@ -14,6 +14,12 @@ type DeployMocksArgs = {
|
|
|
14
14
|
};
|
|
15
15
|
declare const deployMocks: (hre: HardhatRuntimeEnvironment, options?: DeployMocksArgs) => Promise<void>;
|
|
16
16
|
|
|
17
|
+
declare const TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
18
|
+
declare const TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
19
|
+
declare const TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
20
|
+
|
|
21
|
+
declare const deployMockContractFromArtifact: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
|
|
22
|
+
declare const getFixedMockContract: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
|
|
17
23
|
declare const mock_getPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
|
|
18
24
|
declare const mock_getPlaintextExists: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
|
|
19
25
|
declare const mock_expectPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint, expectedValue: bigint) => Promise<void>;
|
|
@@ -199,4 +205,4 @@ declare module 'hardhat/types/runtime' {
|
|
|
199
205
|
}
|
|
200
206
|
}
|
|
201
207
|
|
|
202
|
-
export { type DeployMocksArgs, deployMocks, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
|
|
208
|
+
export { type DeployMocksArgs, TASK_COFHE_MOCKS_DEPLOY, TASK_COFHE_MOCKS_SET_LOG_OPS, TASK_COFHE_USE_FAUCET, deployMockContractFromArtifact, deployMocks, getFixedMockContract, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers';
|
|
|
3
3
|
import { CofhesdkInputConfig, CofhesdkConfig, CofhesdkClient } from '@cofhe/sdk';
|
|
4
4
|
import { HardhatRuntimeEnvironment } from 'hardhat/types';
|
|
5
5
|
import * as ethers from 'ethers';
|
|
6
|
-
import { ethers as ethers$1
|
|
7
|
-
export { MockACLArtifact, MockQueryDecrypterArtifact, MockTaskManagerArtifact, MockZkVerifierArtifact, TestBedArtifact } from '@cofhe/mock-contracts';
|
|
6
|
+
import { Contract, ethers as ethers$1 } from 'ethers';
|
|
8
7
|
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider';
|
|
8
|
+
import { MockArtifact } from '@cofhe/mock-contracts';
|
|
9
9
|
|
|
10
10
|
type DeployMocksArgs = {
|
|
11
11
|
deployTestBed?: boolean;
|
|
@@ -14,6 +14,12 @@ type DeployMocksArgs = {
|
|
|
14
14
|
};
|
|
15
15
|
declare const deployMocks: (hre: HardhatRuntimeEnvironment, options?: DeployMocksArgs) => Promise<void>;
|
|
16
16
|
|
|
17
|
+
declare const TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
18
|
+
declare const TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
19
|
+
declare const TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
20
|
+
|
|
21
|
+
declare const deployMockContractFromArtifact: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
|
|
22
|
+
declare const getFixedMockContract: (hre: HardhatRuntimeEnvironment, artifact: MockArtifact) => Promise<Contract>;
|
|
17
23
|
declare const mock_getPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
|
|
18
24
|
declare const mock_getPlaintextExists: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint) => Promise<any>;
|
|
19
25
|
declare const mock_expectPlaintext: (provider: HardhatEthersProvider | ethers$1.JsonRpcProvider, ctHash: bigint, expectedValue: bigint) => Promise<void>;
|
|
@@ -199,4 +205,4 @@ declare module 'hardhat/types/runtime' {
|
|
|
199
205
|
}
|
|
200
206
|
}
|
|
201
207
|
|
|
202
|
-
export { type DeployMocksArgs, deployMocks, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
|
|
208
|
+
export { type DeployMocksArgs, TASK_COFHE_MOCKS_DEPLOY, TASK_COFHE_MOCKS_SET_LOG_OPS, TASK_COFHE_USE_FAUCET, deployMockContractFromArtifact, deployMocks, getFixedMockContract, localcofheFundAccount, localcofheFundWalletIfNeeded, mock_expectPlaintext, mock_getPlaintext, mock_getPlaintextExists, mock_setLoggingEnabled, mock_withLogs };
|
package/dist/index.js
CHANGED
|
@@ -30,12 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
TestBedArtifact: () => import_mock_contracts4.TestBedArtifact,
|
|
33
|
+
TASK_COFHE_MOCKS_DEPLOY: () => TASK_COFHE_MOCKS_DEPLOY,
|
|
34
|
+
TASK_COFHE_MOCKS_SET_LOG_OPS: () => TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
35
|
+
TASK_COFHE_USE_FAUCET: () => TASK_COFHE_USE_FAUCET,
|
|
36
|
+
deployMockContractFromArtifact: () => deployMockContractFromArtifact,
|
|
38
37
|
deployMocks: () => deployMocks,
|
|
38
|
+
getFixedMockContract: () => getFixedMockContract,
|
|
39
39
|
localcofheFundAccount: () => localcofheFundAccount,
|
|
40
40
|
localcofheFundWalletIfNeeded: () => localcofheFundWalletIfNeeded,
|
|
41
41
|
mock_expectPlaintext: () => mock_expectPlaintext,
|
|
@@ -50,7 +50,7 @@ var import_viem = require("viem");
|
|
|
50
50
|
var import_config = require("hardhat/config");
|
|
51
51
|
var import_task_names = require("hardhat/builtin-tasks/task-names");
|
|
52
52
|
var import_signers = require("@nomicfoundation/hardhat-ethers/signers");
|
|
53
|
-
var
|
|
53
|
+
var import_sdk3 = require("@cofhe/sdk");
|
|
54
54
|
var import_node = require("@cofhe/sdk/node");
|
|
55
55
|
var import_adapters = require("@cofhe/sdk/adapters");
|
|
56
56
|
|
|
@@ -110,21 +110,128 @@ async function localcofheFundWalletIfNeeded(hre, walletAddress) {
|
|
|
110
110
|
var TASK_COFHE_USE_FAUCET = "task:cofhe:usefaucet";
|
|
111
111
|
var TASK_COFHE_MOCKS_SET_LOG_OPS = "task:cofhe-mocks:setlogops";
|
|
112
112
|
var TASK_COFHE_MOCKS_DEPLOY = "task:cofhe-mocks:deploy";
|
|
113
|
-
var TASK_MANAGER_ADDRESS = "0xeA30c4B8b44078Bbf8a6ef5b9f1eC1626C7848D9";
|
|
114
|
-
var MOCKS_ZK_VERIFIER_ADDRESS = "0x0000000000000000000000000000000000000100";
|
|
115
|
-
var MOCKS_QUERY_DECRYPTER_ADDRESS = "0x0000000000000000000000000000000000000200";
|
|
116
|
-
var TEST_BED_ADDRESS = "0x0000000000000000000000000000000000000300";
|
|
117
113
|
|
|
118
114
|
// src/deploy.ts
|
|
119
115
|
var import_types2 = require("hardhat/types");
|
|
120
116
|
var import_chalk = __toESM(require("chalk"));
|
|
121
|
-
var
|
|
117
|
+
var import_ethers2 = require("ethers");
|
|
122
118
|
var import_mock_contracts = require("@cofhe/mock-contracts");
|
|
119
|
+
var import_sdk2 = require("@cofhe/sdk");
|
|
120
|
+
|
|
121
|
+
// src/utils.ts
|
|
123
122
|
var import_sdk = require("@cofhe/sdk");
|
|
123
|
+
var import_chai = require("chai");
|
|
124
|
+
var import_ethers = require("ethers");
|
|
125
|
+
var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
|
|
126
|
+
var deployMockContractFromArtifact = async (hre, artifact) => {
|
|
127
|
+
if (artifact.isFixed) {
|
|
128
|
+
await hre.network.provider.send("hardhat_setCode", [artifact.fixedAddress, artifact.deployedBytecode]);
|
|
129
|
+
return getFixedMockContract(hre, artifact);
|
|
130
|
+
}
|
|
131
|
+
const [signer] = await hre.ethers.getSigners();
|
|
132
|
+
const factory = new hre.ethers.ContractFactory(artifact.abi, artifact.bytecode, signer);
|
|
133
|
+
const contract = await factory.deploy(
|
|
134
|
+
/* constructor args */
|
|
135
|
+
);
|
|
136
|
+
await contract.waitForDeployment();
|
|
137
|
+
return contract;
|
|
138
|
+
};
|
|
139
|
+
var getFixedMockContract = async (hre, artifact) => {
|
|
140
|
+
if (!artifact.isFixed) {
|
|
141
|
+
throw new Error("Artifact is not fixed");
|
|
142
|
+
}
|
|
143
|
+
return await hre.ethers.getContractAt(artifact.abi, artifact.fixedAddress);
|
|
144
|
+
};
|
|
145
|
+
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
146
|
+
const bytecode = await provider.getCode(import_sdk.MOCKS_ZK_VERIFIER_ADDRESS);
|
|
147
|
+
const isTestnet = bytecode.length === 0;
|
|
148
|
+
if (isTestnet) {
|
|
149
|
+
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
150
|
+
}
|
|
151
|
+
return isTestnet;
|
|
152
|
+
};
|
|
153
|
+
var mock_getPlaintext = async (provider, ctHash) => {
|
|
154
|
+
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
155
|
+
return;
|
|
156
|
+
const taskManager = new import_ethers.ethers.Contract(
|
|
157
|
+
import_sdk.TASK_MANAGER_ADDRESS,
|
|
158
|
+
["function mockStorage(uint256) view returns (uint256)"],
|
|
159
|
+
provider
|
|
160
|
+
);
|
|
161
|
+
const plaintext = await taskManager.mockStorage(ctHash);
|
|
162
|
+
return plaintext;
|
|
163
|
+
};
|
|
164
|
+
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
165
|
+
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
166
|
+
return;
|
|
167
|
+
const taskManager = new import_ethers.ethers.Contract(
|
|
168
|
+
import_sdk.TASK_MANAGER_ADDRESS,
|
|
169
|
+
["function inMockStorage(uint256) view returns (bool)"],
|
|
170
|
+
provider
|
|
171
|
+
);
|
|
172
|
+
const plaintextExists = await taskManager.inMockStorage(ctHash);
|
|
173
|
+
return plaintextExists;
|
|
174
|
+
};
|
|
175
|
+
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
176
|
+
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
177
|
+
return;
|
|
178
|
+
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
179
|
+
(0, import_chai.expect)(plaintextExists).equal(true, "Plaintext does not exist");
|
|
180
|
+
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
181
|
+
(0, import_chai.expect)(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// src/deploy.ts
|
|
185
|
+
var deployMocks = async (hre, options = {
|
|
186
|
+
deployTestBed: true,
|
|
187
|
+
gasWarning: true,
|
|
188
|
+
silent: false
|
|
189
|
+
}) => {
|
|
190
|
+
const isHardhat = await getIsHardhat(hre);
|
|
191
|
+
if (!isHardhat) {
|
|
192
|
+
logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${hre.network.name}`, 0);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
isSilent = options.silent ?? false;
|
|
196
|
+
logEmpty();
|
|
197
|
+
logSuccess(import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
198
|
+
logEmpty();
|
|
199
|
+
const taskManager = await deployMockTaskManager(hre);
|
|
200
|
+
logDeployment("MockTaskManager", await taskManager.getAddress());
|
|
201
|
+
const acl = await deployMockACL(hre);
|
|
202
|
+
logDeployment("MockACL", await acl.getAddress());
|
|
203
|
+
await linkTaskManagerAndACL(taskManager, acl);
|
|
204
|
+
logSuccess("ACL address set in TaskManager", 2);
|
|
205
|
+
await fundZkVerifierSigner(hre);
|
|
206
|
+
logSuccess(`ZkVerifier signer (${import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
|
|
207
|
+
const zkVerifierSignerBalance = await getZkVerifierSignerBalance(hre);
|
|
208
|
+
logSuccess(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
209
|
+
const zkVerifier = await deployMockZkVerifier(hre);
|
|
210
|
+
logDeployment("MockZkVerifier", await zkVerifier.getAddress());
|
|
211
|
+
const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
|
|
212
|
+
logDeployment("MockQueryDecrypter", await queryDecrypter.getAddress());
|
|
213
|
+
if (options.deployTestBed) {
|
|
214
|
+
logSuccess("TestBed deployment enabled", 2);
|
|
215
|
+
const testBed = await deployTestBedContract(hre);
|
|
216
|
+
logDeployment("TestBed", await testBed.getAddress());
|
|
217
|
+
}
|
|
218
|
+
logEmpty();
|
|
219
|
+
logSuccess(import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
|
|
220
|
+
if (options.gasWarning) {
|
|
221
|
+
logEmpty();
|
|
222
|
+
logWarning(
|
|
223
|
+
"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",
|
|
224
|
+
0
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
logEmpty();
|
|
228
|
+
};
|
|
229
|
+
var getIsHardhat = async (hre) => {
|
|
230
|
+
return hre.network.name === "hardhat";
|
|
231
|
+
};
|
|
124
232
|
var deployMockTaskManager = async (hre) => {
|
|
125
233
|
const [signer] = await hre.ethers.getSigners();
|
|
126
|
-
await
|
|
127
|
-
const taskManager = await hre.ethers.getContractAt(import_mock_contracts.MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
|
|
234
|
+
const taskManager = await deployMockContractFromArtifact(hre, import_mock_contracts.MockTaskManagerArtifact);
|
|
128
235
|
const initTx = await taskManager.initialize(signer.address);
|
|
129
236
|
await initTx.wait();
|
|
130
237
|
const tmExists = await taskManager.exists();
|
|
@@ -134,146 +241,68 @@ var deployMockTaskManager = async (hre) => {
|
|
|
134
241
|
return taskManager;
|
|
135
242
|
};
|
|
136
243
|
var deployMockACL = async (hre) => {
|
|
137
|
-
const acl = await
|
|
244
|
+
const acl = await deployMockContractFromArtifact(hre, import_mock_contracts.MockACLArtifact);
|
|
138
245
|
const exists = await acl.exists();
|
|
139
246
|
if (!exists) {
|
|
140
|
-
logError("MockACL does not exist", 2);
|
|
141
247
|
throw new Error("MockACL does not exist");
|
|
142
248
|
}
|
|
143
249
|
return acl;
|
|
144
250
|
};
|
|
251
|
+
var fundZkVerifierSigner = async (hre) => {
|
|
252
|
+
const zkVerifierSigner = await hre.ethers.getSigner(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
253
|
+
await hre.network.provider.send("hardhat_setBalance", [
|
|
254
|
+
zkVerifierSigner.address,
|
|
255
|
+
"0x" + hre.ethers.parseEther("10").toString(16)
|
|
256
|
+
]);
|
|
257
|
+
};
|
|
258
|
+
var getZkVerifierSignerBalance = async (hre) => {
|
|
259
|
+
return hre.ethers.provider.getBalance(import_sdk2.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
260
|
+
};
|
|
261
|
+
var linkTaskManagerAndACL = async (taskManager, acl) => {
|
|
262
|
+
const aclAddress = await acl.getAddress();
|
|
263
|
+
const linkAclTx = await taskManager.setACLContract(aclAddress);
|
|
264
|
+
await linkAclTx.wait();
|
|
265
|
+
};
|
|
145
266
|
var deployMockZkVerifier = async (hre) => {
|
|
146
|
-
await
|
|
147
|
-
const zkVerifier = await hre.ethers.getContractAt(import_mock_contracts.MockZkVerifierArtifact.abi, MOCKS_ZK_VERIFIER_ADDRESS);
|
|
267
|
+
const zkVerifier = await deployMockContractFromArtifact(hre, import_mock_contracts.MockZkVerifierArtifact);
|
|
148
268
|
const zkVerifierExists = await zkVerifier.exists();
|
|
149
269
|
if (!zkVerifierExists) {
|
|
150
|
-
logError("MockZkVerifier does not exist", 2);
|
|
151
270
|
throw new Error("MockZkVerifier does not exist");
|
|
152
271
|
}
|
|
153
272
|
return zkVerifier;
|
|
154
273
|
};
|
|
155
274
|
var deployMockQueryDecrypter = async (hre, acl) => {
|
|
156
|
-
await
|
|
157
|
-
const
|
|
158
|
-
const initTx = await queryDecrypter.initialize(TASK_MANAGER_ADDRESS, await acl.getAddress());
|
|
275
|
+
const queryDecrypter = await deployMockContractFromArtifact(hre, import_mock_contracts.MockQueryDecrypterArtifact);
|
|
276
|
+
const initTx = await queryDecrypter.initialize(import_sdk2.TASK_MANAGER_ADDRESS, await acl.getAddress());
|
|
159
277
|
await initTx.wait();
|
|
160
278
|
const queryDecrypterExists = await queryDecrypter.exists();
|
|
161
279
|
if (!queryDecrypterExists) {
|
|
162
|
-
logError("MockQueryDecrypter does not exist", 2);
|
|
163
280
|
throw new Error("MockQueryDecrypter does not exist");
|
|
164
281
|
}
|
|
165
282
|
return queryDecrypter;
|
|
166
283
|
};
|
|
167
284
|
var deployTestBedContract = async (hre) => {
|
|
168
|
-
|
|
169
|
-
const testBed = await hre.ethers.getContractAt(import_mock_contracts.TestBedArtifact.abi, TEST_BED_ADDRESS);
|
|
170
|
-
await testBed.waitForDeployment();
|
|
171
|
-
return testBed;
|
|
172
|
-
};
|
|
173
|
-
var fundZkVerifierSigner = async (hre) => {
|
|
174
|
-
const zkVerifierSigner = await hre.ethers.getSigner(import_sdk.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
175
|
-
await hre.network.provider.send("hardhat_setBalance", [
|
|
176
|
-
zkVerifierSigner.address,
|
|
177
|
-
"0x" + hre.ethers.parseEther("10").toString(16)
|
|
178
|
-
]);
|
|
179
|
-
};
|
|
180
|
-
var setTaskManagerACL = async (taskManager, acl) => {
|
|
181
|
-
const setAclTx = await taskManager.setACLContract(await acl.getAddress());
|
|
182
|
-
await setAclTx.wait();
|
|
183
|
-
};
|
|
184
|
-
var deployMocks = async (hre, options = {
|
|
185
|
-
deployTestBed: true,
|
|
186
|
-
gasWarning: true,
|
|
187
|
-
silent: false
|
|
188
|
-
}) => {
|
|
189
|
-
const isHardhat = await checkNetworkAndSkip(hre);
|
|
190
|
-
if (!isHardhat)
|
|
191
|
-
return;
|
|
192
|
-
const logEmptyIfNoisy = () => {
|
|
193
|
-
if (!options.silent) {
|
|
194
|
-
logEmpty();
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
const logSuccessIfNoisy = (message, indent = 0) => {
|
|
198
|
-
if (!options.silent) {
|
|
199
|
-
logSuccess(message, indent);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
const logDeploymentIfNoisy = (contractName, address) => {
|
|
203
|
-
if (!options.silent) {
|
|
204
|
-
logDeployment(contractName, address);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
const logWarningIfNoisy = (message, indent = 0) => {
|
|
208
|
-
if (!options.silent) {
|
|
209
|
-
logWarning(message, indent);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
logEmptyIfNoisy();
|
|
213
|
-
logSuccessIfNoisy(import_chalk.default.bold("cofhe-hardhat-plugin :: deploy mocks"), 0);
|
|
214
|
-
logEmptyIfNoisy();
|
|
215
|
-
const taskManager = await deployMockTaskManager(hre);
|
|
216
|
-
logDeploymentIfNoisy("MockTaskManager", await taskManager.getAddress());
|
|
217
|
-
const acl = await deployMockACL(hre);
|
|
218
|
-
logDeploymentIfNoisy("MockACL", await acl.getAddress());
|
|
219
|
-
await setTaskManagerACL(taskManager, acl);
|
|
220
|
-
logSuccessIfNoisy("ACL address set in TaskManager", 2);
|
|
221
|
-
await fundZkVerifierSigner(hre);
|
|
222
|
-
logSuccessIfNoisy(`ZkVerifier signer (${import_sdk.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS}) funded`, 1);
|
|
223
|
-
const zkVerifierSignerBalance = await hre.ethers.provider.getBalance(import_sdk.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
224
|
-
logSuccessIfNoisy(`ETH balance: ${zkVerifierSignerBalance.toString()}`, 2);
|
|
225
|
-
const zkVerifier = await deployMockZkVerifier(hre);
|
|
226
|
-
logDeploymentIfNoisy("MockZkVerifier", await zkVerifier.getAddress());
|
|
227
|
-
const queryDecrypter = await deployMockQueryDecrypter(hre, acl);
|
|
228
|
-
logDeploymentIfNoisy("MockQueryDecrypter", await queryDecrypter.getAddress());
|
|
229
|
-
if (options.deployTestBed) {
|
|
230
|
-
logSuccessIfNoisy("TestBed deployment enabled", 2);
|
|
231
|
-
const testBed = await deployTestBedContract(hre);
|
|
232
|
-
logDeploymentIfNoisy("TestBed", await testBed.getAddress());
|
|
233
|
-
}
|
|
234
|
-
logEmptyIfNoisy();
|
|
235
|
-
logSuccessIfNoisy(import_chalk.default.bold("cofhe-hardhat-plugin :: mocks deployed successfully"), 0);
|
|
236
|
-
if (options.gasWarning) {
|
|
237
|
-
logEmptyIfNoisy();
|
|
238
|
-
logWarningIfNoisy(
|
|
239
|
-
"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",
|
|
240
|
-
0
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
logEmptyIfNoisy();
|
|
244
|
-
};
|
|
245
|
-
var hardhatSetCode = async (hre, address, bytecode) => {
|
|
246
|
-
await hre.network.provider.send("hardhat_setCode", [address, bytecode]);
|
|
247
|
-
};
|
|
248
|
-
var ethersDeployContract = async (hre, abi, bytecode) => {
|
|
249
|
-
const [signer] = await hre.ethers.getSigners();
|
|
250
|
-
const factory = new hre.ethers.ContractFactory(abi, bytecode, signer);
|
|
251
|
-
const contract = await factory.deploy(
|
|
252
|
-
/* constructor args */
|
|
253
|
-
);
|
|
254
|
-
await contract.waitForDeployment();
|
|
255
|
-
return contract;
|
|
256
|
-
};
|
|
257
|
-
var checkNetworkAndSkip = async (hre) => {
|
|
258
|
-
const network = hre.network.name;
|
|
259
|
-
const isHardhat = network === "hardhat";
|
|
260
|
-
if (!isHardhat)
|
|
261
|
-
logSuccess(`cofhe-hardhat-plugin - deploy mocks - skipped on non-hardhat network ${network}`, 0);
|
|
262
|
-
return isHardhat;
|
|
285
|
+
return deployMockContractFromArtifact(hre, import_mock_contracts.TestBedArtifact);
|
|
263
286
|
};
|
|
287
|
+
var isSilent = false;
|
|
264
288
|
var logEmpty = () => {
|
|
289
|
+
if (isSilent)
|
|
290
|
+
return;
|
|
265
291
|
console.log("");
|
|
266
292
|
};
|
|
267
293
|
var logSuccess = (message, indent = 1) => {
|
|
294
|
+
if (isSilent)
|
|
295
|
+
return;
|
|
268
296
|
console.log(import_chalk.default.green(`${" ".repeat(indent)}\u2713 ${message}`));
|
|
269
297
|
};
|
|
270
298
|
var logWarning = (message, indent = 1) => {
|
|
299
|
+
if (isSilent)
|
|
300
|
+
return;
|
|
271
301
|
console.log(import_chalk.default.bold(import_chalk.default.yellow(`${" ".repeat(indent)}\u26A0 NOTE:`)), message);
|
|
272
302
|
};
|
|
273
|
-
var logError = (message, indent = 1) => {
|
|
274
|
-
console.log(import_chalk.default.red(`${" ".repeat(indent)}\u2717 ${message}`));
|
|
275
|
-
};
|
|
276
303
|
var logDeployment = (contractName, address) => {
|
|
304
|
+
if (isSilent)
|
|
305
|
+
return;
|
|
277
306
|
const paddedName = `${contractName} deployed`.padEnd(36);
|
|
278
307
|
logSuccess(`${paddedName} ${import_chalk.default.bold(address)}`);
|
|
279
308
|
};
|
|
@@ -282,17 +311,14 @@ var logDeployment = (contractName, address) => {
|
|
|
282
311
|
var import_chalk2 = __toESM(require("chalk"));
|
|
283
312
|
var import_types3 = require("hardhat/types");
|
|
284
313
|
var import_mock_contracts2 = require("@cofhe/mock-contracts");
|
|
285
|
-
var getDeployedMockTaskManager = async (hre) => {
|
|
286
|
-
const taskManager = await hre.ethers.getContractAt(import_mock_contracts2.MockTaskManagerArtifact.abi, TASK_MANAGER_ADDRESS);
|
|
287
|
-
return taskManager;
|
|
288
|
-
};
|
|
289
314
|
var getLoggingEnabled = async (hre) => {
|
|
290
|
-
const taskManager = await
|
|
291
|
-
return
|
|
315
|
+
const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
|
|
316
|
+
return taskManager.logOps();
|
|
292
317
|
};
|
|
293
318
|
var setLoggingEnabled = async (hre, enabled) => {
|
|
294
|
-
const taskManager = await
|
|
295
|
-
await taskManager.setLogOps(enabled);
|
|
319
|
+
const taskManager = await getFixedMockContract(hre, import_mock_contracts2.MockTaskManagerArtifact);
|
|
320
|
+
const tx = await taskManager.setLogOps(enabled);
|
|
321
|
+
await tx.wait();
|
|
296
322
|
};
|
|
297
323
|
var printLogsEnabledMessage = (closureMessage) => {
|
|
298
324
|
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");
|
|
@@ -327,53 +353,9 @@ var mock_withLogs = async (hre, closureName, closure) => {
|
|
|
327
353
|
}
|
|
328
354
|
};
|
|
329
355
|
|
|
330
|
-
// src/utils.ts
|
|
331
|
-
var import_chai = require("chai");
|
|
332
|
-
var import_ethers2 = require("ethers");
|
|
333
|
-
var import_hardhat_ethers_provider = require("@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider");
|
|
334
|
-
var mock_checkIsTestnet = async (fnName, provider) => {
|
|
335
|
-
const bytecode = await provider.getCode(MOCKS_ZK_VERIFIER_ADDRESS);
|
|
336
|
-
const isTestnet = bytecode.length === 0;
|
|
337
|
-
if (isTestnet) {
|
|
338
|
-
console.log(`${fnName} - skipped on non-testnet chain`);
|
|
339
|
-
}
|
|
340
|
-
return isTestnet;
|
|
341
|
-
};
|
|
342
|
-
var mock_getPlaintext = async (provider, ctHash) => {
|
|
343
|
-
if (await mock_checkIsTestnet(mock_getPlaintext.name, provider))
|
|
344
|
-
return;
|
|
345
|
-
const taskManager = new import_ethers2.ethers.Contract(
|
|
346
|
-
TASK_MANAGER_ADDRESS,
|
|
347
|
-
["function mockStorage(uint256) view returns (uint256)"],
|
|
348
|
-
provider
|
|
349
|
-
);
|
|
350
|
-
const plaintext = await taskManager.mockStorage(ctHash);
|
|
351
|
-
return plaintext;
|
|
352
|
-
};
|
|
353
|
-
var mock_getPlaintextExists = async (provider, ctHash) => {
|
|
354
|
-
if (await mock_checkIsTestnet(mock_getPlaintextExists.name, provider))
|
|
355
|
-
return;
|
|
356
|
-
const taskManager = new import_ethers2.ethers.Contract(
|
|
357
|
-
TASK_MANAGER_ADDRESS,
|
|
358
|
-
["function inMockStorage(uint256) view returns (bool)"],
|
|
359
|
-
provider
|
|
360
|
-
);
|
|
361
|
-
const plaintextExists = await taskManager.inMockStorage(ctHash);
|
|
362
|
-
return plaintextExists;
|
|
363
|
-
};
|
|
364
|
-
var mock_expectPlaintext = async (provider, ctHash, expectedValue) => {
|
|
365
|
-
if (await mock_checkIsTestnet(mock_expectPlaintext.name, provider))
|
|
366
|
-
return;
|
|
367
|
-
const plaintextExists = await mock_getPlaintextExists(provider, ctHash);
|
|
368
|
-
(0, import_chai.expect)(plaintextExists).equal(true, "Plaintext does not exist");
|
|
369
|
-
const plaintext = await mock_getPlaintext(provider, ctHash);
|
|
370
|
-
(0, import_chai.expect)(plaintext).equal(expectedValue, "Plaintext value is incorrect");
|
|
371
|
-
};
|
|
372
|
-
|
|
373
356
|
// src/index.ts
|
|
374
|
-
var import_mock_contracts3 = require("@cofhe/mock-contracts");
|
|
375
357
|
var import_chains = require("@cofhe/sdk/chains");
|
|
376
|
-
var
|
|
358
|
+
var import_mock_contracts3 = require("@cofhe/mock-contracts");
|
|
377
359
|
(0, import_config.extendConfig)((config, userConfig) => {
|
|
378
360
|
if (userConfig.networks && userConfig.networks.localcofhe) {
|
|
379
361
|
return;
|
|
@@ -466,7 +448,7 @@ var import_mock_contracts4 = require("@cofhe/mock-contracts");
|
|
|
466
448
|
(0, import_config.extendEnvironment)((hre) => {
|
|
467
449
|
hre.cofhesdk = {
|
|
468
450
|
createCofhesdkConfig: async (config) => {
|
|
469
|
-
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(
|
|
451
|
+
const zkvHhSigner = await hre.ethers.getImpersonatedSigner(import_sdk3.MOCKS_ZK_VERIFIER_SIGNER_ADDRESS);
|
|
470
452
|
const { walletClient: zkvWalletClient } = await (0, import_adapters.HardhatSignerAdapter)(zkvHhSigner);
|
|
471
453
|
const configWithZkvWalletClient = {
|
|
472
454
|
environment: "hardhat",
|
|
@@ -524,34 +506,26 @@ var import_mock_contracts4 = require("@cofhe/mock-contracts");
|
|
|
524
506
|
const [signer] = await hre.ethers.getSigners();
|
|
525
507
|
return mock_expectPlaintext(signer.provider, ctHash, expectedValue);
|
|
526
508
|
},
|
|
527
|
-
getMockTaskManager: async () =>
|
|
528
|
-
return await hre.ethers.getContractAt(import_mock_contracts3.MockTaskManagerArtifact.abi, import_mock_contracts3.MockTaskManagerArtifact.fixedAddress);
|
|
529
|
-
},
|
|
509
|
+
getMockTaskManager: async () => getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact),
|
|
530
510
|
getMockACL: async () => {
|
|
531
|
-
const
|
|
532
|
-
const aclAddress = await
|
|
533
|
-
return
|
|
534
|
-
},
|
|
535
|
-
getMockQueryDecrypter: async () => {
|
|
536
|
-
return await hre.ethers.getContractAt(import_mock_contracts3.MockQueryDecrypterArtifact.abi, import_mock_contracts3.MockQueryDecrypterArtifact.fixedAddress);
|
|
511
|
+
const taskManager = await getFixedMockContract(hre, import_mock_contracts3.MockTaskManagerArtifact);
|
|
512
|
+
const aclAddress = await taskManager.acl();
|
|
513
|
+
return hre.ethers.getContractAt(import_mock_contracts3.MockACLArtifact.abi, aclAddress);
|
|
537
514
|
},
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
getTestBed: async () => {
|
|
542
|
-
return await hre.ethers.getContractAt(import_mock_contracts3.TestBedArtifact.abi, import_mock_contracts3.TestBedArtifact.fixedAddress);
|
|
543
|
-
}
|
|
515
|
+
getMockQueryDecrypter: async () => getFixedMockContract(hre, import_mock_contracts3.MockQueryDecrypterArtifact),
|
|
516
|
+
getMockZkVerifier: async () => getFixedMockContract(hre, import_mock_contracts3.MockZkVerifierArtifact),
|
|
517
|
+
getTestBed: async () => getFixedMockContract(hre, import_mock_contracts3.TestBedArtifact)
|
|
544
518
|
}
|
|
545
519
|
};
|
|
546
520
|
});
|
|
547
521
|
// Annotate the CommonJS export names for ESM import in node:
|
|
548
522
|
0 && (module.exports = {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
TestBedArtifact,
|
|
523
|
+
TASK_COFHE_MOCKS_DEPLOY,
|
|
524
|
+
TASK_COFHE_MOCKS_SET_LOG_OPS,
|
|
525
|
+
TASK_COFHE_USE_FAUCET,
|
|
526
|
+
deployMockContractFromArtifact,
|
|
554
527
|
deployMocks,
|
|
528
|
+
getFixedMockContract,
|
|
555
529
|
localcofheFundAccount,
|
|
556
530
|
localcofheFundWalletIfNeeded,
|
|
557
531
|
mock_expectPlaintext,
|