@coti-io/coti-contracts 1.0.9 → 1.1.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.
Files changed (35) hide show
  1. package/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.sol +260 -0
  2. package/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.sol +264 -0
  3. package/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.sol +91 -0
  4. package/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.sol +91 -0
  5. package/contracts/mocks/utils/mpc/Comparison128BitTestsContract.sol +158 -0
  6. package/contracts/mocks/utils/mpc/Comparison256BitTestsContract.sol +158 -0
  7. package/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.sol +185 -0
  8. package/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.sol +190 -0
  9. package/contracts/utils/mpc/MpcCore.sol +2804 -180
  10. package/package.json +1 -1
  11. package/test/token/PrivateERC20/PrivateERC20.test.ts +3 -3
  12. package/test/utils/mpc/Unsigned128BitIntegers.test.ts +945 -0
  13. package/test/utils/mpc/Unsigned256BitIntegers.test.ts +1124 -0
  14. package/test/utils/mpc/helpers.ts +77 -0
  15. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.ts +341 -0
  16. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.ts +347 -0
  17. package/typechain-types/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.ts +186 -0
  18. package/typechain-types/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.ts +186 -0
  19. package/typechain-types/contracts/mocks/utils/mpc/Comparison128BitTestsContract.ts +260 -0
  20. package/typechain-types/contracts/mocks/utils/mpc/Comparison256BitTestsContract.ts +260 -0
  21. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.ts +302 -0
  22. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.ts +322 -0
  23. package/typechain-types/contracts/mocks/utils/mpc/index.ts +8 -0
  24. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract__factory.ts +349 -0
  25. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract__factory.ts +364 -0
  26. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128BitTestsContract__factory.ts +182 -0
  27. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256BitTestsContract__factory.ts +182 -0
  28. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128BitTestsContract__factory.ts +255 -0
  29. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256BitTestsContract__factory.ts +255 -0
  30. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract__factory.ts +332 -0
  31. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract__factory.ts +380 -0
  32. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +8 -0
  33. package/typechain-types/hardhat.d.ts +144 -0
  34. package/typechain-types/index.ts +16 -0
  35. package/contracts/package.json +0 -11
@@ -0,0 +1,77 @@
1
+ import crypto from "crypto"
2
+ import { itUint, Wallet } from "@coti-io/coti-ethers"
3
+ import { CtUint128Struct, ItUint128Struct } from "../../../typechain-types/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract"
4
+ import { CtUint256Struct, ItUint256Struct } from "../../../typechain-types/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract"
5
+
6
+ export function generateRandomNumber(numBytes: number): bigint {
7
+ const bytes = crypto.randomBytes(numBytes)
8
+ // Convert bytes to BigInt
9
+ return BigInt('0x' + bytes.toString('hex'))
10
+ }
11
+
12
+ export async function encryptUint128(number: bigint, account: Wallet, contractAddress: string, functionSelector: string): Promise<ItUint128Struct> {
13
+ // Convert to hex string and ensure it is 32 characters (16 bytes)
14
+ const hexString = number.toString(16).padStart(32, '0');
15
+
16
+ // Split into two 8-byte (16-character) segments
17
+ const high = hexString.slice(0, 16);
18
+ const low = hexString.slice(16, 32);
19
+
20
+ const itHigh = await account.encryptValue(
21
+ BigInt(`0x${high}`),
22
+ contractAddress,
23
+ functionSelector
24
+ ) as itUint
25
+
26
+ const itLow = await account.encryptValue(
27
+ BigInt(`0x${low}`),
28
+ contractAddress,
29
+ functionSelector
30
+ ) as itUint
31
+
32
+ return {
33
+ ciphertext: { high: itHigh.ciphertext, low: itLow.ciphertext },
34
+ signature: [itHigh.signature, itLow.signature]
35
+ }
36
+ }
37
+
38
+ export async function decryptUint128(ctNumber: CtUint128Struct, account: Wallet): Promise<bigint> {
39
+ const high = await account.decryptValue(ctNumber.high as bigint)
40
+ const low = await account.decryptValue(ctNumber.low as bigint)
41
+
42
+ // Convert both high and low parts to hex strings, ensuring they are 16 characters (8 bytes) long
43
+ let highHex = high.toString(16).padStart(16, '0');
44
+ let lowHex = low.toString(16).padStart(16, '0');
45
+
46
+ // Concatenate and convert back to a single bigint
47
+ return BigInt(`0x${highHex + lowHex}`);
48
+ }
49
+
50
+ export async function encryptUint256(number: bigint, account: Wallet, contractAddress: string, functionSelector: string): Promise<ItUint256Struct> {
51
+ // Convert to hex string and ensure it is 64 characters (32 bytes)
52
+ const hexString = number.toString(16).padStart(64, '0');
53
+
54
+ // Split into two 16-byte (-character) segments
55
+ const high = hexString.slice(0, 32);
56
+ const low = hexString.slice(32, 64);
57
+
58
+ const itHigh = await encryptUint128(BigInt(`0x${high}`), account, contractAddress, functionSelector)
59
+ const itLow = await encryptUint128(BigInt(`0x${low}`), account, contractAddress, functionSelector)
60
+
61
+ return {
62
+ ciphertext: { high: itHigh.ciphertext, low: itLow.ciphertext },
63
+ signature: [itHigh.signature, itLow.signature]
64
+ }
65
+ }
66
+
67
+ export async function decryptUint256(ctNumber: CtUint256Struct, account: Wallet): Promise<bigint> {
68
+ const high = await decryptUint128(ctNumber.high, account)
69
+ const low = await decryptUint128(ctNumber.low, account)
70
+
71
+ // Convert both high and low parts to hex strings, ensuring they are 16 characters (8 bytes) long
72
+ let highHex = high.toString(16).padStart(32, '0');
73
+ let lowHex = low.toString(16).padStart(32, '0');
74
+
75
+ // Concatenate and convert back to a single bigint
76
+ return BigInt(`0x${highHex + lowHex}`);
77
+ }
@@ -0,0 +1,341 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ import type {
5
+ BaseContract,
6
+ BigNumberish,
7
+ BytesLike,
8
+ FunctionFragment,
9
+ Result,
10
+ Interface,
11
+ ContractRunner,
12
+ ContractMethod,
13
+ Listener,
14
+ } from "ethers";
15
+ import type {
16
+ TypedContractEvent,
17
+ TypedDeferredTopicFilter,
18
+ TypedEventLog,
19
+ TypedListener,
20
+ TypedContractMethod,
21
+ } from "../../../../common";
22
+
23
+ export interface Arithmetic128BitTestsContractInterface extends Interface {
24
+ getFunction(
25
+ nameOrSignature:
26
+ | "addTest"
27
+ | "checkedAddTest"
28
+ | "checkedAddWithOverflowBitTest"
29
+ | "checkedMulTest"
30
+ | "checkedMulWithOverflowBitTest"
31
+ | "checkedSubTest"
32
+ | "checkedSubWithOverflowBitTest"
33
+ | "mulTest"
34
+ | "numbers"
35
+ | "numbersLHS"
36
+ | "numbersRHS"
37
+ | "overflows"
38
+ | "overflowsLHS"
39
+ | "overflowsRHS"
40
+ | "subTest"
41
+ ): FunctionFragment;
42
+
43
+ encodeFunctionData(
44
+ functionFragment: "addTest",
45
+ values: [BigNumberish[], BigNumberish[]]
46
+ ): string;
47
+ encodeFunctionData(
48
+ functionFragment: "checkedAddTest",
49
+ values: [BigNumberish, BigNumberish]
50
+ ): string;
51
+ encodeFunctionData(
52
+ functionFragment: "checkedAddWithOverflowBitTest",
53
+ values: [BigNumberish[], BigNumberish[]]
54
+ ): string;
55
+ encodeFunctionData(
56
+ functionFragment: "checkedMulTest",
57
+ values: [BigNumberish, BigNumberish]
58
+ ): string;
59
+ encodeFunctionData(
60
+ functionFragment: "checkedMulWithOverflowBitTest",
61
+ values: [BigNumberish[], BigNumberish[]]
62
+ ): string;
63
+ encodeFunctionData(
64
+ functionFragment: "checkedSubTest",
65
+ values: [BigNumberish, BigNumberish]
66
+ ): string;
67
+ encodeFunctionData(
68
+ functionFragment: "checkedSubWithOverflowBitTest",
69
+ values: [BigNumberish[], BigNumberish[]]
70
+ ): string;
71
+ encodeFunctionData(
72
+ functionFragment: "mulTest",
73
+ values: [BigNumberish[], BigNumberish[]]
74
+ ): string;
75
+ encodeFunctionData(
76
+ functionFragment: "numbers",
77
+ values: [BigNumberish]
78
+ ): string;
79
+ encodeFunctionData(
80
+ functionFragment: "numbersLHS",
81
+ values: [BigNumberish]
82
+ ): string;
83
+ encodeFunctionData(
84
+ functionFragment: "numbersRHS",
85
+ values: [BigNumberish]
86
+ ): string;
87
+ encodeFunctionData(
88
+ functionFragment: "overflows",
89
+ values: [BigNumberish]
90
+ ): string;
91
+ encodeFunctionData(
92
+ functionFragment: "overflowsLHS",
93
+ values: [BigNumberish]
94
+ ): string;
95
+ encodeFunctionData(
96
+ functionFragment: "overflowsRHS",
97
+ values: [BigNumberish]
98
+ ): string;
99
+ encodeFunctionData(
100
+ functionFragment: "subTest",
101
+ values: [BigNumberish[], BigNumberish[]]
102
+ ): string;
103
+
104
+ decodeFunctionResult(functionFragment: "addTest", data: BytesLike): Result;
105
+ decodeFunctionResult(
106
+ functionFragment: "checkedAddTest",
107
+ data: BytesLike
108
+ ): Result;
109
+ decodeFunctionResult(
110
+ functionFragment: "checkedAddWithOverflowBitTest",
111
+ data: BytesLike
112
+ ): Result;
113
+ decodeFunctionResult(
114
+ functionFragment: "checkedMulTest",
115
+ data: BytesLike
116
+ ): Result;
117
+ decodeFunctionResult(
118
+ functionFragment: "checkedMulWithOverflowBitTest",
119
+ data: BytesLike
120
+ ): Result;
121
+ decodeFunctionResult(
122
+ functionFragment: "checkedSubTest",
123
+ data: BytesLike
124
+ ): Result;
125
+ decodeFunctionResult(
126
+ functionFragment: "checkedSubWithOverflowBitTest",
127
+ data: BytesLike
128
+ ): Result;
129
+ decodeFunctionResult(functionFragment: "mulTest", data: BytesLike): Result;
130
+ decodeFunctionResult(functionFragment: "numbers", data: BytesLike): Result;
131
+ decodeFunctionResult(functionFragment: "numbersLHS", data: BytesLike): Result;
132
+ decodeFunctionResult(functionFragment: "numbersRHS", data: BytesLike): Result;
133
+ decodeFunctionResult(functionFragment: "overflows", data: BytesLike): Result;
134
+ decodeFunctionResult(
135
+ functionFragment: "overflowsLHS",
136
+ data: BytesLike
137
+ ): Result;
138
+ decodeFunctionResult(
139
+ functionFragment: "overflowsRHS",
140
+ data: BytesLike
141
+ ): Result;
142
+ decodeFunctionResult(functionFragment: "subTest", data: BytesLike): Result;
143
+ }
144
+
145
+ export interface Arithmetic128BitTestsContract extends BaseContract {
146
+ connect(runner?: ContractRunner | null): Arithmetic128BitTestsContract;
147
+ waitForDeployment(): Promise<this>;
148
+
149
+ interface: Arithmetic128BitTestsContractInterface;
150
+
151
+ queryFilter<TCEvent extends TypedContractEvent>(
152
+ event: TCEvent,
153
+ fromBlockOrBlockhash?: string | number | undefined,
154
+ toBlock?: string | number | undefined
155
+ ): Promise<Array<TypedEventLog<TCEvent>>>;
156
+ queryFilter<TCEvent extends TypedContractEvent>(
157
+ filter: TypedDeferredTopicFilter<TCEvent>,
158
+ fromBlockOrBlockhash?: string | number | undefined,
159
+ toBlock?: string | number | undefined
160
+ ): Promise<Array<TypedEventLog<TCEvent>>>;
161
+
162
+ on<TCEvent extends TypedContractEvent>(
163
+ event: TCEvent,
164
+ listener: TypedListener<TCEvent>
165
+ ): Promise<this>;
166
+ on<TCEvent extends TypedContractEvent>(
167
+ filter: TypedDeferredTopicFilter<TCEvent>,
168
+ listener: TypedListener<TCEvent>
169
+ ): Promise<this>;
170
+
171
+ once<TCEvent extends TypedContractEvent>(
172
+ event: TCEvent,
173
+ listener: TypedListener<TCEvent>
174
+ ): Promise<this>;
175
+ once<TCEvent extends TypedContractEvent>(
176
+ filter: TypedDeferredTopicFilter<TCEvent>,
177
+ listener: TypedListener<TCEvent>
178
+ ): Promise<this>;
179
+
180
+ listeners<TCEvent extends TypedContractEvent>(
181
+ event: TCEvent
182
+ ): Promise<Array<TypedListener<TCEvent>>>;
183
+ listeners(eventName?: string): Promise<Array<Listener>>;
184
+ removeAllListeners<TCEvent extends TypedContractEvent>(
185
+ event?: TCEvent
186
+ ): Promise<this>;
187
+
188
+ addTest: TypedContractMethod<
189
+ [a: BigNumberish[], b: BigNumberish[]],
190
+ [void],
191
+ "nonpayable"
192
+ >;
193
+
194
+ checkedAddTest: TypedContractMethod<
195
+ [a: BigNumberish, b: BigNumberish],
196
+ [void],
197
+ "nonpayable"
198
+ >;
199
+
200
+ checkedAddWithOverflowBitTest: TypedContractMethod<
201
+ [a: BigNumberish[], b: BigNumberish[]],
202
+ [void],
203
+ "nonpayable"
204
+ >;
205
+
206
+ checkedMulTest: TypedContractMethod<
207
+ [a: BigNumberish, b: BigNumberish],
208
+ [void],
209
+ "nonpayable"
210
+ >;
211
+
212
+ checkedMulWithOverflowBitTest: TypedContractMethod<
213
+ [a: BigNumberish[], b: BigNumberish[]],
214
+ [void],
215
+ "nonpayable"
216
+ >;
217
+
218
+ checkedSubTest: TypedContractMethod<
219
+ [a: BigNumberish, b: BigNumberish],
220
+ [void],
221
+ "nonpayable"
222
+ >;
223
+
224
+ checkedSubWithOverflowBitTest: TypedContractMethod<
225
+ [a: BigNumberish[], b: BigNumberish[]],
226
+ [void],
227
+ "nonpayable"
228
+ >;
229
+
230
+ mulTest: TypedContractMethod<
231
+ [a: BigNumberish[], b: BigNumberish[]],
232
+ [void],
233
+ "nonpayable"
234
+ >;
235
+
236
+ numbers: TypedContractMethod<[arg0: BigNumberish], [bigint], "view">;
237
+
238
+ numbersLHS: TypedContractMethod<[arg0: BigNumberish], [bigint], "view">;
239
+
240
+ numbersRHS: TypedContractMethod<[arg0: BigNumberish], [bigint], "view">;
241
+
242
+ overflows: TypedContractMethod<[arg0: BigNumberish], [boolean], "view">;
243
+
244
+ overflowsLHS: TypedContractMethod<[arg0: BigNumberish], [boolean], "view">;
245
+
246
+ overflowsRHS: TypedContractMethod<[arg0: BigNumberish], [boolean], "view">;
247
+
248
+ subTest: TypedContractMethod<
249
+ [a: BigNumberish[], b: BigNumberish[]],
250
+ [void],
251
+ "nonpayable"
252
+ >;
253
+
254
+ getFunction<T extends ContractMethod = ContractMethod>(
255
+ key: string | FunctionFragment
256
+ ): T;
257
+
258
+ getFunction(
259
+ nameOrSignature: "addTest"
260
+ ): TypedContractMethod<
261
+ [a: BigNumberish[], b: BigNumberish[]],
262
+ [void],
263
+ "nonpayable"
264
+ >;
265
+ getFunction(
266
+ nameOrSignature: "checkedAddTest"
267
+ ): TypedContractMethod<
268
+ [a: BigNumberish, b: BigNumberish],
269
+ [void],
270
+ "nonpayable"
271
+ >;
272
+ getFunction(
273
+ nameOrSignature: "checkedAddWithOverflowBitTest"
274
+ ): TypedContractMethod<
275
+ [a: BigNumberish[], b: BigNumberish[]],
276
+ [void],
277
+ "nonpayable"
278
+ >;
279
+ getFunction(
280
+ nameOrSignature: "checkedMulTest"
281
+ ): TypedContractMethod<
282
+ [a: BigNumberish, b: BigNumberish],
283
+ [void],
284
+ "nonpayable"
285
+ >;
286
+ getFunction(
287
+ nameOrSignature: "checkedMulWithOverflowBitTest"
288
+ ): TypedContractMethod<
289
+ [a: BigNumberish[], b: BigNumberish[]],
290
+ [void],
291
+ "nonpayable"
292
+ >;
293
+ getFunction(
294
+ nameOrSignature: "checkedSubTest"
295
+ ): TypedContractMethod<
296
+ [a: BigNumberish, b: BigNumberish],
297
+ [void],
298
+ "nonpayable"
299
+ >;
300
+ getFunction(
301
+ nameOrSignature: "checkedSubWithOverflowBitTest"
302
+ ): TypedContractMethod<
303
+ [a: BigNumberish[], b: BigNumberish[]],
304
+ [void],
305
+ "nonpayable"
306
+ >;
307
+ getFunction(
308
+ nameOrSignature: "mulTest"
309
+ ): TypedContractMethod<
310
+ [a: BigNumberish[], b: BigNumberish[]],
311
+ [void],
312
+ "nonpayable"
313
+ >;
314
+ getFunction(
315
+ nameOrSignature: "numbers"
316
+ ): TypedContractMethod<[arg0: BigNumberish], [bigint], "view">;
317
+ getFunction(
318
+ nameOrSignature: "numbersLHS"
319
+ ): TypedContractMethod<[arg0: BigNumberish], [bigint], "view">;
320
+ getFunction(
321
+ nameOrSignature: "numbersRHS"
322
+ ): TypedContractMethod<[arg0: BigNumberish], [bigint], "view">;
323
+ getFunction(
324
+ nameOrSignature: "overflows"
325
+ ): TypedContractMethod<[arg0: BigNumberish], [boolean], "view">;
326
+ getFunction(
327
+ nameOrSignature: "overflowsLHS"
328
+ ): TypedContractMethod<[arg0: BigNumberish], [boolean], "view">;
329
+ getFunction(
330
+ nameOrSignature: "overflowsRHS"
331
+ ): TypedContractMethod<[arg0: BigNumberish], [boolean], "view">;
332
+ getFunction(
333
+ nameOrSignature: "subTest"
334
+ ): TypedContractMethod<
335
+ [a: BigNumberish[], b: BigNumberish[]],
336
+ [void],
337
+ "nonpayable"
338
+ >;
339
+
340
+ filters: {};
341
+ }