-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest-public-decrypt.js
More file actions
executable file
·72 lines (59 loc) · 2.49 KB
/
test-public-decrypt.js
File metadata and controls
executable file
·72 lines (59 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
import { logCLI, parseCommonOptions } from '../../utils.js';
import { FHETestAddresses } from './fheTest.js';
import { ethers } from 'ethers';
import { publicDecrypt } from '../../publicDecrypt.js';
import { safeJSONstringify } from '../../../lib/internal.js';
// Testnet public handles:
// =======================
// 0xf1673094de7c833604f1b62183cbcdf2cdc968db90ff0000000000aa36a70400 euint32 1083783185
// 0x9797f8eb707b0a32c47a80ea86c0648df36bfe7cd0ff0000000000aa36a70300 euint16 15764
// 0x6f17228bda73a5e57b94511c5bab2665e6a2870399ff0000000000aa36a70200 euint8 171
// 0x821c6ef4218b335278214b00b1ad41757c7bc644ffff0000000000aa36a70500 euint64 12168711736151452489
// 0x9d430a3e950560ba22013ce885d6d90f0da36efdf1ff0000000000aa36a70600 euint128 308429577281045301472547520724787086512
// 0xf6751d547a5c06123575aad93f22f76b7d841c4cacff0000000000aa36a70000 ebool false
//
// npx . test public-decrypt --types euint32 --network testnet --version 1
// npx . test public-decrypt --types euint32 --network testnet --version 2
// npx . test public-decrypt --types euint32 --network mainnet --version 2
export async function testFHETestPublicDecryptCommand(options) {
const { config, provider, signer, zamaFhevmApiKey } =
parseCommonOptions(options);
if (!FHETestAddresses[config.name]) {
logCLI(`❌ FHETest is not deployed on network ${config.name}`, options);
process.exit(1);
}
const contractAddress = FHETestAddresses[config.name];
const abi = [];
const getFuncNames = [];
// Turn 'euint32' into 'Euint32'
for (let i = 0; i < options.types.length; ++i) {
const t = 'E' + options.types[i].substring(1);
const getFuncName = `get${t}`;
getFuncNames.push(getFuncName);
abi.push(`function ${getFuncName}() view returns (bytes32)`);
}
abi.push(`function verify(bytes32[] calldata, bytes memory, bytes memory)`);
const contract = new ethers.Contract(contractAddress, abi, signer);
const handles = [];
for (let i = 0; i < getFuncNames.length; ++i) {
const handle = await contract[getFuncNames[i]]();
handles.push(handle);
logCLI(`🏈 handle: ${handle}`, options);
}
const res = await publicDecrypt({
handles,
config,
zamaFhevmApiKey,
options,
});
console.log(safeJSONstringify(res, 2));
logCLI(`Verify ...`, options);
// Simulate the transaction using staticCall (dry run)
await contract.verify.staticCall(
handles,
res.abiEncodedClearValues,
res.decryptionProof,
);
logCLI(`✅ Verification succeeded!`, options);
}