@coti-io/coti-contracts 1.0.0 → 1.0.2
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/.github/workflows/npm-publish.yml +2 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +1 -1
- package/README.md +18 -35
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +152 -0
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +11 -1
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +8 -0
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +33 -4
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +35 -10
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +3 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol +223 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.sol +265 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol +281 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +1 -1
- package/contracts/token/PrivateERC721/IERC721Errors.sol +57 -0
- package/contracts/token/PrivateERC721/PrivateERC721.sol +1 -1
- package/hardhat.config.ts +9 -1
- package/package.json +20 -4
- package/test/token/PrivateERC20/PrivateERC20.test.ts +2 -2
- package/test/utils/mpc/Precompile.test.ts +16 -2
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +66 -0
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +6 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +6 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +36 -6
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract.ts +251 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract.ts +250 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.ts +389 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.ts +306 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract.ts +125 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract.ts +125 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.ts +296 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +6 -0
- package/typechain-types/contracts/token/PrivateERC721/IERC721Errors.ts +69 -0
- package/typechain-types/contracts/token/PrivateERC721/index.ts +1 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +73 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +11 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +11 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +26 -30
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract__factory.ts +294 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +292 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract__factory.ts +720 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +507 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract__factory.ts +150 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +150 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +434 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +6 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +1 -1
- package/typechain-types/factories/contracts/token/PrivateERC721/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +1 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +1 -1
- package/typechain-types/hardhat.d.ts +126 -0
- package/typechain-types/index.ts +12 -0
- package/contracts/access/DataPrivacyFramework/README.md +0 -68
- package/contracts/token/PrivateERC20/README.md +0 -104
- package/contracts/token/PrivateERC721/README.md +0 -282
- package/contracts/utils/mpc/README.md +0 -82
|
@@ -43,8 +43,9 @@ jobs:
|
|
|
43
43
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
44
44
|
- uses: actions/setup-node@v3
|
|
45
45
|
with:
|
|
46
|
-
node-version:
|
|
46
|
+
node-version: 18
|
|
47
47
|
registry-url: https://registry.npmjs.org/
|
|
48
|
+
scope: '@coti-io'
|
|
48
49
|
- run: npm ci
|
|
49
50
|
- run: npm publish --access=public
|
|
50
51
|
env:
|
package/CONTRIBUTING.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
# Contributing to COTI
|
|
2
|
+
# Contributing to COTI Contracts
|
|
3
3
|
|
|
4
|
-
Thank you for your interest in contributing to the COTI
|
|
4
|
+
Thank you for your interest in contributing to the COTI Contracts project! We welcome contributions from the community and appreciate your efforts to improve our project.
|
|
5
5
|
|
|
6
6
|
## Table of Contents
|
|
7
7
|
|
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2024 COTI
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,48 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
> [!NOTE]
|
|
6
|
-
> This repository is meant to replace the now-deprecated [confidentiality-contracts](https://github.com/coti-io/confidentiality-contracts) repository.
|
|
7
|
-
|
|
8
|
-
#### Important Links
|
|
9
|
-
|
|
10
|
-
[Docs](https://docs.coti.io) | [Discord](https://discord.gg/cuCykh8P4m) | [Faucet](https://faucet.coti.io)
|
|
11
|
-
|
|
12
|
-
#### Network-Specific Links
|
|
1
|
+
[](https://telegram.coti.io)
|
|
2
|
+
[](https://discord.coti.io)
|
|
3
|
+
[](https://twitter.coti.io)
|
|
4
|
+
[](https://youtube.coti.io)
|
|
13
5
|
|
|
14
|
-
|
|
6
|
+
# COTI Contracts
|
|
15
7
|
|
|
16
|
-
|
|
8
|
+
[](https://www.npmjs.com/package/@coti-io/coti-contracts)
|
|
9
|
+
[](https://nodejs.org/download/release/v18.20.5/)
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
> Due to the nature of ongoing development, future versions might break existing functionality
|
|
11
|
+
Welcome to COTI Contracts, a library of smart contracts for COTI's GC technology, including MPC contract for secure computations, private ERC20 and ERC721 contracts, and test mocks for validation. These components enable privacy-focused and decentralized DeFi solutions.
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
- [DataPrivacyFramework](/contracts/access/DataPrivacyFramework/)
|
|
23
|
-
- [AccountOnboard](/contracts/onboard/)
|
|
24
|
-
- [PrivateERC20](/contracts/token/PrivateERC20/)
|
|
25
|
-
- [PrivateERC721](/contracts/token/PrivateERC721/)
|
|
26
|
-
- [MpcCore](/contracts/utils/mpc/)
|
|
13
|
+
## Documentation
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
Full API documentation is available in the [COTI docs](https://docs.coti.io/coti-v2-documentation/build-on-coti/tools/ethers.js)
|
|
29
16
|
|
|
30
|
-
|
|
17
|
+
## Build and Install
|
|
31
18
|
|
|
32
19
|
```bash
|
|
33
|
-
npm install
|
|
20
|
+
npm install
|
|
34
21
|
```
|
|
35
22
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Once installed, you can use the contracts in the library by importing them:
|
|
23
|
+
## Testing
|
|
39
24
|
|
|
40
|
-
```
|
|
41
|
-
|
|
25
|
+
```bash
|
|
26
|
+
npx hardhat test
|
|
27
|
+
```
|
|
42
28
|
|
|
43
|
-
|
|
29
|
+
---
|
|
44
30
|
|
|
45
|
-
|
|
46
|
-
constructor() ERC721("MyToken", "MTOK") {}
|
|
47
|
-
}
|
|
48
|
-
```
|
|
31
|
+
To report an issue, please see the [issues](https://github.com/coti-io/coti-contracts/issues/new) tab.
|
|
@@ -153,6 +153,57 @@ contract ArithmeticTestsContract {
|
|
|
153
153
|
return result;
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
function checkedAddTest(uint8 a, uint8 b) public returns (uint8) {
|
|
157
|
+
AllGTCastingValues memory castingValues;
|
|
158
|
+
Check16 memory check16;
|
|
159
|
+
Check32 memory check32;
|
|
160
|
+
Check64 memory check64;
|
|
161
|
+
setPublicValues(castingValues, a, b);
|
|
162
|
+
|
|
163
|
+
// Calculate the expected result
|
|
164
|
+
uint8 result = MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a8_s, castingValues.b8_s));
|
|
165
|
+
addResult = result;
|
|
166
|
+
|
|
167
|
+
// Calculate the results with casting to 16
|
|
168
|
+
check16.res16_16 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b16_s);
|
|
169
|
+
check16.res8_16 = MpcCore.checkedAdd(castingValues.a8_s, castingValues.b16_s);
|
|
170
|
+
check16.res16_8 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b8_s);
|
|
171
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
172
|
+
require(res16 == result, "addTest: cast 16 failed");
|
|
173
|
+
|
|
174
|
+
// Calculate the result with casting to 32
|
|
175
|
+
check32.res32_32 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b32_s);
|
|
176
|
+
check32.res8_32 = MpcCore.checkedAdd(castingValues.a8_s, castingValues.b32_s);
|
|
177
|
+
check32.res32_8 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b8_s);
|
|
178
|
+
check32.res16_32 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b32_s);
|
|
179
|
+
check32.res32_16 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b16_s);
|
|
180
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
181
|
+
require(result == res32, "addTest: cast 32 failed");
|
|
182
|
+
|
|
183
|
+
// Calculate the result with casting to 64
|
|
184
|
+
check64.res64_64 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b64_s);
|
|
185
|
+
check64.res8_64 = MpcCore.checkedAdd(castingValues.a8_s, castingValues.b64_s);
|
|
186
|
+
check64.res64_8 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b8_s);
|
|
187
|
+
check64.res16_64 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b64_s);
|
|
188
|
+
check64.res64_16 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b16_s);
|
|
189
|
+
check64.res32_64 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b64_s);
|
|
190
|
+
check64.res64_32 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b32_s);
|
|
191
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
192
|
+
require(result == res64, "addTest: cast 64 failed");
|
|
193
|
+
|
|
194
|
+
// Check the result with scalar
|
|
195
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a8_s, b)),
|
|
196
|
+
"addTest: test 8 bits with scalar failed");
|
|
197
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a16_s, b)),
|
|
198
|
+
"addTest: test 16 bits with scalar failed");
|
|
199
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a32_s, b)),
|
|
200
|
+
"addTest: test 32 bits with scalar failed");
|
|
201
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a64_s, b)),
|
|
202
|
+
"addTest: test 64 bits with scalar failed");
|
|
203
|
+
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
156
207
|
function subTest(uint8 a, uint8 b) public returns (uint8) {
|
|
157
208
|
AllGTCastingValues memory castingValues;
|
|
158
209
|
Check16 memory check16;
|
|
@@ -204,6 +255,57 @@ contract ArithmeticTestsContract {
|
|
|
204
255
|
return result;
|
|
205
256
|
}
|
|
206
257
|
|
|
258
|
+
function checkedSubTest(uint8 a, uint8 b) public returns (uint8) {
|
|
259
|
+
AllGTCastingValues memory castingValues;
|
|
260
|
+
Check16 memory check16;
|
|
261
|
+
Check32 memory check32;
|
|
262
|
+
Check64 memory check64;
|
|
263
|
+
setPublicValues(castingValues, a, b);
|
|
264
|
+
|
|
265
|
+
// Calculate the expected result
|
|
266
|
+
uint8 result = MpcCore.decrypt(MpcCore.checkedSub(castingValues.a8_s, castingValues.b8_s));
|
|
267
|
+
subResult = result;
|
|
268
|
+
|
|
269
|
+
// Calculate the results with casting to 16
|
|
270
|
+
check16.res16_16 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b16_s);
|
|
271
|
+
check16.res8_16 = MpcCore.checkedSub(castingValues.a8_s, castingValues.b16_s);
|
|
272
|
+
check16.res16_8 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b8_s);
|
|
273
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
274
|
+
require(res16 == result, "subTest: cast 16 failed");
|
|
275
|
+
|
|
276
|
+
// Calculate the result with casting to 32
|
|
277
|
+
check32.res32_32 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b32_s);
|
|
278
|
+
check32.res8_32 = MpcCore.checkedSub(castingValues.a8_s, castingValues.b32_s);
|
|
279
|
+
check32.res32_8 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b8_s);
|
|
280
|
+
check32.res16_32 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b32_s);
|
|
281
|
+
check32.res32_16 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b16_s);
|
|
282
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
283
|
+
require(result == res32, "subTest: cast 32 failed");
|
|
284
|
+
|
|
285
|
+
// Calculate the result with casting to 64
|
|
286
|
+
check64.res64_64 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b64_s);
|
|
287
|
+
check64.res8_64 = MpcCore.checkedSub(castingValues.a8_s, castingValues.b64_s);
|
|
288
|
+
check64.res64_8 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b8_s);
|
|
289
|
+
check64.res16_64 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b64_s);
|
|
290
|
+
check64.res64_16 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b16_s);
|
|
291
|
+
check64.res32_64 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b64_s);
|
|
292
|
+
check64.res64_32 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b32_s);
|
|
293
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
294
|
+
require(result == res64, "subTest: cast 64 failed");
|
|
295
|
+
|
|
296
|
+
// Check the result with scalar
|
|
297
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a8_s, b)),
|
|
298
|
+
"subTest: test 8 bits with scalar failed");
|
|
299
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a16_s, b)),
|
|
300
|
+
"subTest: test 16 bits with scalar failed");
|
|
301
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a32_s, b)),
|
|
302
|
+
"subTest: test 32 bits with scalar failed");
|
|
303
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a64_s, b)),
|
|
304
|
+
"subTest: test 64 bits with scalar failed");
|
|
305
|
+
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
|
|
207
309
|
function mulTest(uint8 a, uint8 b) public returns (uint8) {
|
|
208
310
|
AllGTCastingValues memory castingValues;
|
|
209
311
|
Check16 memory check16;
|
|
@@ -253,4 +355,54 @@ contract ArithmeticTestsContract {
|
|
|
253
355
|
|
|
254
356
|
return mulResult;
|
|
255
357
|
}
|
|
358
|
+
|
|
359
|
+
function checkedMulTest(uint8 a, uint8 b) public returns (uint8) {
|
|
360
|
+
AllGTCastingValues memory castingValues;
|
|
361
|
+
Check16 memory check16;
|
|
362
|
+
Check32 memory check32;
|
|
363
|
+
Check64 memory check64;
|
|
364
|
+
setPublicValues(castingValues, a, b);
|
|
365
|
+
|
|
366
|
+
// Calculate the expected result
|
|
367
|
+
mulResult = MpcCore.decrypt(MpcCore.checkedMul(castingValues.a8_s, castingValues.b8_s));
|
|
368
|
+
|
|
369
|
+
// Calculate the result with casting to 16
|
|
370
|
+
check16.res16_16 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b16_s);
|
|
371
|
+
check16.res8_16 = MpcCore.checkedMul(castingValues.a8_s, castingValues.b16_s);
|
|
372
|
+
check16.res16_8 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b8_s);
|
|
373
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
374
|
+
require(mulResult == res16, "mulTest: cast 16 failed");
|
|
375
|
+
|
|
376
|
+
// Calculate the result with casting to 32
|
|
377
|
+
check32.res32_32 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b32_s);
|
|
378
|
+
check32.res8_32 = MpcCore.checkedMul(castingValues.a8_s, castingValues.b32_s);
|
|
379
|
+
check32.res32_8 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b8_s);
|
|
380
|
+
check32.res16_32 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b32_s);
|
|
381
|
+
check32.res32_16 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b16_s);
|
|
382
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
383
|
+
require(mulResult == res32, "mulTest: cast 32 failed");
|
|
384
|
+
|
|
385
|
+
// Calculate the result with casting to 64
|
|
386
|
+
check64.res64_64 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b64_s);
|
|
387
|
+
check64.res8_64 = MpcCore.checkedMul(castingValues.a8_s, castingValues.b64_s);
|
|
388
|
+
check64.res64_8 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b8_s);
|
|
389
|
+
check64.res16_64 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b64_s);
|
|
390
|
+
check64.res64_16 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b16_s);
|
|
391
|
+
check64.res32_64 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b64_s);
|
|
392
|
+
check64.res64_32 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b32_s);
|
|
393
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
394
|
+
require(mulResult == res64, "mulTest: cast 64 failed");
|
|
395
|
+
|
|
396
|
+
// Check the result with scalar
|
|
397
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b8_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a8_s, b)),
|
|
398
|
+
"mulTest: test 8 bits with scalar failed");
|
|
399
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b16_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a16_s, b)),
|
|
400
|
+
"mulTest: test 16 bits with scalar failed");
|
|
401
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b32_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a32_s, b)),
|
|
402
|
+
"mulTest: test 32 bits with scalar failed");
|
|
403
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b64_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a64_s, b)),
|
|
404
|
+
"mulTest: test 64 bits with scalar failed");
|
|
405
|
+
|
|
406
|
+
return mulResult;
|
|
407
|
+
}
|
|
256
408
|
}
|
|
@@ -6,6 +6,8 @@ import "../../../utils/mpc/MpcCore.sol";
|
|
|
6
6
|
contract BitwiseTestsContract {
|
|
7
7
|
|
|
8
8
|
struct AllGTCastingValues {
|
|
9
|
+
gtBool aBool_s;
|
|
10
|
+
gtBool bBool_s;
|
|
9
11
|
gtUint8 a8_s;
|
|
10
12
|
gtUint8 b8_s;
|
|
11
13
|
gtUint16 a16_s;
|
|
@@ -54,7 +56,9 @@ contract BitwiseTestsContract {
|
|
|
54
56
|
return xorResult;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
59
|
+
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public {
|
|
60
|
+
castingValues.aBool_s = MpcCore.setPublic(a > b);
|
|
61
|
+
castingValues.bBool_s = MpcCore.setPublic(b > a);
|
|
58
62
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
59
63
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
60
64
|
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
@@ -108,6 +112,8 @@ contract BitwiseTestsContract {
|
|
|
108
112
|
Check64 memory check64;
|
|
109
113
|
setPublicValues(castingValues, a, b);
|
|
110
114
|
|
|
115
|
+
MpcCore.decrypt(MpcCore.and(castingValues.aBool_s, castingValues.bBool_s));
|
|
116
|
+
|
|
111
117
|
// Calculate the expected result
|
|
112
118
|
uint8 result = MpcCore.decrypt(MpcCore.and(castingValues.a8_s, castingValues.b8_s));
|
|
113
119
|
andResult = result;
|
|
@@ -159,6 +165,8 @@ contract BitwiseTestsContract {
|
|
|
159
165
|
Check64 memory check64;
|
|
160
166
|
setPublicValues(castingValues, a, b);
|
|
161
167
|
|
|
168
|
+
MpcCore.decrypt(MpcCore.or(castingValues.aBool_s, castingValues.bBool_s));
|
|
169
|
+
|
|
162
170
|
// Calculate the expected result
|
|
163
171
|
uint8 result = MpcCore.decrypt(MpcCore.or(castingValues.a8_s, castingValues.b8_s));
|
|
164
172
|
orResult = result;
|
|
@@ -210,6 +218,8 @@ contract BitwiseTestsContract {
|
|
|
210
218
|
Check64 memory check64;
|
|
211
219
|
setPublicValues(castingValues, a, b);
|
|
212
220
|
|
|
221
|
+
MpcCore.decrypt(MpcCore.xor(castingValues.aBool_s, castingValues.bBool_s));
|
|
222
|
+
|
|
213
223
|
// Calculate the expected result
|
|
214
224
|
uint8 result = MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, castingValues.b8_s));
|
|
215
225
|
xorResult = result;
|
|
@@ -6,6 +6,8 @@ import "../../../utils/mpc/MpcCore.sol";
|
|
|
6
6
|
contract Comparison2TestsContract {
|
|
7
7
|
|
|
8
8
|
struct AllGTCastingValues {
|
|
9
|
+
gtBool aBool_s;
|
|
10
|
+
gtBool bBool_s;
|
|
9
11
|
gtUint8 a8_s;
|
|
10
12
|
gtUint8 b8_s;
|
|
11
13
|
gtUint16 a16_s;
|
|
@@ -41,6 +43,8 @@ contract Comparison2TestsContract {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
46
|
+
castingValues.aBool_s = MpcCore.setPublic(a > b);
|
|
47
|
+
castingValues.bBool_s = MpcCore.setPublic(b > a);
|
|
44
48
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
45
49
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
46
50
|
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
@@ -110,6 +114,8 @@ contract Comparison2TestsContract {
|
|
|
110
114
|
Check64 memory check64;
|
|
111
115
|
setPublicValues(castingValues, a, b);
|
|
112
116
|
|
|
117
|
+
MpcCore.decrypt(MpcCore.eq(castingValues.aBool_s, castingValues.bBool_s));
|
|
118
|
+
|
|
113
119
|
// Calculate the expected result
|
|
114
120
|
bool result = MpcCore.decrypt(MpcCore.eq(castingValues.a8_s, castingValues.b8_s));
|
|
115
121
|
eqResult = result;
|
|
@@ -161,6 +167,8 @@ contract Comparison2TestsContract {
|
|
|
161
167
|
Check64 memory check64;
|
|
162
168
|
setPublicValues(castingValues, a, b);
|
|
163
169
|
|
|
170
|
+
MpcCore.decrypt(MpcCore.ne(castingValues.aBool_s, castingValues.bBool_s));
|
|
171
|
+
|
|
164
172
|
// Calculate the expected result
|
|
165
173
|
bool result = MpcCore.decrypt(MpcCore.ne(castingValues.a8_s, castingValues.b8_s));
|
|
166
174
|
neResult = result;
|
|
@@ -34,12 +34,24 @@ contract Miscellaneous1TestsContract {
|
|
|
34
34
|
return validateCiphertextRes;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
uint constant MAX_SIZE_1_BIT = 10;
|
|
37
38
|
uint constant MAX_SIZE_8_BITS = 10;
|
|
38
39
|
uint constant MAX_SIZE_16_BITS = 3;
|
|
39
40
|
uint constant MAX_SIZE_32_BITS = 3;
|
|
40
41
|
uint constant MAX_SIZE_64_BITS = 2;
|
|
41
42
|
uint constant MAX_BOOL_SIZE = 40;
|
|
42
43
|
|
|
44
|
+
function checkNotAllEqual(bool[MAX_SIZE_1_BIT] memory randoms, uint size) private {
|
|
45
|
+
// Count how many randoms are equal
|
|
46
|
+
uint numEqual = 1;
|
|
47
|
+
for (uint i = 1; i < size; i++) {
|
|
48
|
+
if (randoms[0] == randoms[i]){
|
|
49
|
+
numEqual++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
require(numEqual != size, "randomTest: random failed, all values are the same");
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
function checkNotAllEqual(uint64[MAX_SIZE_8_BITS] memory randoms, uint size) private {
|
|
44
56
|
// Count how many randoms are equal
|
|
45
57
|
uint numEqual = 1;
|
|
@@ -66,8 +78,28 @@ contract Miscellaneous1TestsContract {
|
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
function randTest_(bool isBounded, uint8 numBits) public returns (uint64) {
|
|
69
|
-
uint size =
|
|
81
|
+
uint size = MAX_SIZE_1_BIT;
|
|
82
|
+
bool[MAX_SIZE_1_BIT] memory randomBools;
|
|
83
|
+
|
|
84
|
+
if (!isBounded) {
|
|
85
|
+
// Generate gtBool randoms
|
|
86
|
+
for (uint i = 0; i < size; i++) {
|
|
87
|
+
randomBools[i] = MpcCore.decrypt(MpcCore.rand());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check that not all the generated random values are the same
|
|
91
|
+
checkNotAllEqual(randomBools, size);
|
|
92
|
+
}
|
|
93
|
+
|
|
70
94
|
uint64[MAX_SIZE_8_BITS] memory randoms;
|
|
95
|
+
|
|
96
|
+
// In case of bounded random, the bit size does not matter because the bounded bits can be small.
|
|
97
|
+
// So the max size remain as in 8 bits.
|
|
98
|
+
// In case of unbounded random, max size can be reduced.
|
|
99
|
+
if (!isBounded){
|
|
100
|
+
size = MAX_SIZE_8_BITS;
|
|
101
|
+
}
|
|
102
|
+
|
|
71
103
|
// Generate gtUint8 randoms
|
|
72
104
|
for (uint i = 0; i < size; i++) {
|
|
73
105
|
if(!isBounded){
|
|
@@ -84,9 +116,6 @@ contract Miscellaneous1TestsContract {
|
|
|
84
116
|
// Check that not all the generated random values are the same
|
|
85
117
|
checkNotAllEqual(randoms, size);
|
|
86
118
|
|
|
87
|
-
// In case of bounded random, the bit size does not matter because the bounded bits can be small.
|
|
88
|
-
// So the max size remain as in 8 bits.
|
|
89
|
-
// In case of unbounded random, max size can be reduced.
|
|
90
119
|
if (!isBounded){
|
|
91
120
|
size = MAX_SIZE_16_BITS;
|
|
92
121
|
}
|
|
@@ -11,6 +11,7 @@ contract OffboardToUserKeyTestContract {
|
|
|
11
11
|
uint8 x;
|
|
12
12
|
ctUint8 ctUserKey;
|
|
13
13
|
|
|
14
|
+
uint256 ct;
|
|
14
15
|
uint256 ct8;
|
|
15
16
|
uint256 ct16;
|
|
16
17
|
uint256 ct32;
|
|
@@ -22,8 +23,8 @@ contract OffboardToUserKeyTestContract {
|
|
|
22
23
|
return onboardOffboardResult;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
function getCTs() public view returns (uint256, uint256, uint256, uint256) {
|
|
26
|
-
return (ct8, ct16, ct32, ct64);
|
|
26
|
+
function getCTs() public view returns (uint256, uint256, uint256, uint256, uint256) {
|
|
27
|
+
return (ct, ct8, ct16, ct32, ct64);
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function getUserKeyTest(bytes calldata signedEK, bytes calldata signature, address addr) public returns (uint8) {
|
|
@@ -56,34 +57,60 @@ contract OffboardToUserKeyTestContract {
|
|
|
56
57
|
return (keyShare0, keyShare1);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
function offboardToUserTest(uint8 a, address addr) public
|
|
60
|
+
function offboardToUserTest(uint8 a, address addr) public {
|
|
61
|
+
gtBool aBool_s = MpcCore.setPublic(a > 0);
|
|
60
62
|
gtUint8 a8_s = MpcCore.setPublic8(a);
|
|
61
63
|
gtUint16 a16_s = MpcCore.setPublic16(a);
|
|
62
64
|
gtUint32 a32_s = MpcCore.setPublic32(a);
|
|
63
65
|
gtUint64 a64_s = MpcCore.setPublic64(a);
|
|
64
66
|
|
|
67
|
+
ctBool cipherBool = MpcCore.offBoardToUser(aBool_s, addr);
|
|
65
68
|
ctUint8 cipher8 = MpcCore.offBoardToUser(a8_s, addr);
|
|
66
69
|
ctUint16 cipher16 = MpcCore.offBoardToUser(a16_s, addr);
|
|
67
70
|
ctUint32 cipher32 = MpcCore.offBoardToUser(a32_s, addr);
|
|
68
71
|
ctUint64 cipher64 = MpcCore.offBoardToUser(a64_s, addr);
|
|
69
72
|
|
|
73
|
+
ct = ctBool.unwrap(cipherBool);
|
|
70
74
|
ct8 = ctUint8.unwrap(cipher8);
|
|
71
75
|
ct16 = ctUint16.unwrap(cipher16);
|
|
72
76
|
ct32 = ctUint32.unwrap(cipher32);
|
|
73
77
|
ct64 = ctUint64.unwrap(cipher64);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function offboardCombinedTest(uint8 a, address addr) public {
|
|
81
|
+
gtBool aBool_s = MpcCore.setPublic(a > 0);
|
|
82
|
+
gtUint8 a8_s = MpcCore.setPublic8(a);
|
|
83
|
+
gtUint16 a16_s = MpcCore.setPublic16(a);
|
|
84
|
+
gtUint32 a32_s = MpcCore.setPublic32(a);
|
|
85
|
+
gtUint64 a64_s = MpcCore.setPublic64(a);
|
|
74
86
|
|
|
75
|
-
|
|
87
|
+
utBool memory cipherBool = MpcCore.offBoardCombined(aBool_s, addr);
|
|
88
|
+
utUint8 memory cipher8 = MpcCore.offBoardCombined(a8_s, addr);
|
|
89
|
+
utUint16 memory cipher16 = MpcCore.offBoardCombined(a16_s, addr);
|
|
90
|
+
utUint32 memory cipher32 = MpcCore.offBoardCombined(a32_s, addr);
|
|
91
|
+
utUint64 memory cipher64 = MpcCore.offBoardCombined(a64_s, addr);
|
|
92
|
+
|
|
93
|
+
ct = ctBool.unwrap(cipherBool.userCiphertext);
|
|
94
|
+
ct8 = ctUint8.unwrap(cipher8.userCiphertext);
|
|
95
|
+
ct16 = ctUint16.unwrap(cipher16.userCiphertext);
|
|
96
|
+
ct32 = ctUint32.unwrap(cipher32.userCiphertext);
|
|
97
|
+
ct64 = ctUint64.unwrap(cipher64.userCiphertext);
|
|
76
98
|
}
|
|
77
99
|
|
|
78
|
-
function offboardOnboardTest(uint8 a8, uint16 a16, uint32 a32, uint32 a64) public
|
|
100
|
+
function offboardOnboardTest(uint8 a8, uint16 a16, uint32 a32, uint32 a64) public {
|
|
101
|
+
bool temp = a8 > 0;
|
|
102
|
+
gtBool aBool_s = MpcCore.setPublic(temp);
|
|
79
103
|
gtUint8 a8_s = MpcCore.setPublic8(a8);
|
|
80
104
|
gtUint16 a16_s = MpcCore.setPublic16(a16);
|
|
81
105
|
gtUint32 a32_s = MpcCore.setPublic32(a32);
|
|
82
106
|
gtUint64 a64_s = MpcCore.setPublic64(a64);
|
|
83
107
|
|
|
108
|
+
ctBool cipher = MpcCore.offBoard(aBool_s);
|
|
109
|
+
bool result = MpcCore.decrypt(MpcCore.onBoard(cipher));
|
|
110
|
+
|
|
84
111
|
ctUint8 cipher8 = MpcCore.offBoard(a8_s);
|
|
85
|
-
uint8
|
|
86
|
-
onboardOffboardResult =
|
|
112
|
+
uint8 result8 = MpcCore.decrypt(MpcCore.onBoard(cipher8));
|
|
113
|
+
onboardOffboardResult = result8;
|
|
87
114
|
|
|
88
115
|
ctUint16 cipher16 = MpcCore.offBoard(a16_s);
|
|
89
116
|
uint16 result16 = MpcCore.decrypt(MpcCore.onBoard(cipher16));
|
|
@@ -94,9 +121,7 @@ contract OffboardToUserKeyTestContract {
|
|
|
94
121
|
ctUint64 cipher64 = MpcCore.offBoard(a64_s);
|
|
95
122
|
uint64 result64 = MpcCore.decrypt(MpcCore.onBoard(cipher64));
|
|
96
123
|
|
|
97
|
-
require(result == result16 &&
|
|
124
|
+
require(result == temp && result8 == result16 && result8 == result32 && result8 == result64,
|
|
98
125
|
"Failed to offboard and onboard all values");
|
|
99
|
-
|
|
100
|
-
return result;
|
|
101
126
|
}
|
|
102
127
|
}
|
|
@@ -51,6 +51,9 @@ contract TransferTestsContract {
|
|
|
51
51
|
|
|
52
52
|
(newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b8_s, allAmountValues.amount16_s);
|
|
53
53
|
require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed");
|
|
54
|
+
|
|
55
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(allGTCastingValues.a16_s, allGTCastingValues.b16_s, allAmountValues.amount8_s);
|
|
56
|
+
require(new_a == MpcCore.decrypt(newA_s) && new_b == MpcCore.decrypt(newB_s) && res == MpcCore.decrypt(res_s), "transferTest: cast 16 failed");
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
function computeAndCheckTransfer32(AllGTCastingValues memory allGTCastingValues, AllAmountValues memory allAmountValues, uint8 new_a, uint8 new_b, bool res) public {
|