@coti-io/coti-contracts 0.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.
- package/.github/workflows/npm-publish.yml +52 -0
- package/CODE_OF_CONDUCT.md +44 -0
- package/CONTRIBUTING.md +101 -0
- package/LICENSE +201 -0
- package/README.md +48 -0
- package/contracts/access/DataPrivacyFramework/DataPrivacyFramework.sol +480 -0
- package/contracts/access/DataPrivacyFramework/README.md +68 -0
- package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +1139 -0
- package/contracts/mocks/README.md +5 -0
- package/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.sol +9 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +17 -0
- package/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.sol +34 -0
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +431 -0
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +361 -0
- package/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol +307 -0
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +307 -0
- package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +297 -0
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +185 -0
- package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +448 -0
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +81 -0
- package/contracts/mocks/utils/mpc/README.md +486 -0
- package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +311 -0
- package/contracts/mocks/utils/mpc/StringTestsContract.sol +59 -0
- package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +271 -0
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +715 -0
- package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +25 -0
- package/contracts/onboard/AccountOnboard.sol +21 -0
- package/contracts/onboard/README.md +65 -0
- package/contracts/package.json +11 -0
- package/contracts/token/PrivateERC20/IPrivateERC20.sol +142 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +478 -0
- package/contracts/token/PrivateERC20/README.md +104 -0
- package/contracts/token/PrivateERC721/PrivateERC721.sol +458 -0
- package/contracts/token/PrivateERC721/README.md +282 -0
- package/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.sol +87 -0
- package/contracts/utils/mpc/MpcCore.sol +3215 -0
- package/contracts/utils/mpc/MpcInterface.sol +41 -0
- package/contracts/utils/mpc/README.md +82 -0
- package/hardhat.config.ts +18 -0
- package/package.json +14 -0
- package/test/access/DataPrivacyFramework/DataPrivacyFramework.test.ts +780 -0
- package/test/onboard/AccountOnboard.test.ts +45 -0
- package/test/token/PrivateERC20/PrivateERC20.test.ts +546 -0
- package/test/token/PrivateERC721/PrivateERC721.test.ts +223 -0
- package/test/utils/accounts.ts +55 -0
- package/test/utils/mpc/Precompile.test.ts +113 -0
- package/test/utils/mpc/String.test.ts +227 -0
- package/tsconfig.json +11 -0
- package/typechain-types/@openzeppelin/contracts/index.ts +9 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +462 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +393 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +110 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/token/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/@openzeppelin/index.ts +5 -0
- package/typechain-types/common.ts +131 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/DataPrivacyFramework.ts +598 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.ts +598 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/index.ts +6 -0
- package/typechain-types/contracts/access/index.ts +5 -0
- package/typechain-types/contracts/index.ts +13 -0
- package/typechain-types/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.ts +598 -0
- package/typechain-types/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
- package/typechain-types/contracts/mocks/access/index.ts +5 -0
- package/typechain-types/contracts/mocks/index.ts +11 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +543 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/index.ts +4 -0
- package/typechain-types/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.ts +576 -0
- package/typechain-types/contracts/mocks/token/PrivateERC721/index.ts +4 -0
- package/typechain-types/contracts/mocks/token/index.ts +7 -0
- package/typechain-types/contracts/mocks/utils/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +354 -0
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +321 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +199 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.ts +384 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +218 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
- package/typechain-types/contracts/mocks/utils/mpc/ShiftTestsContract.ts +339 -0
- package/typechain-types/contracts/mocks/utils/mpc/StringTestsContract.ts +211 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +266 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +288 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +17 -0
- package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.ts +173 -0
- package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
- package/typechain-types/contracts/mocks/wallet/index.ts +5 -0
- package/typechain-types/contracts/onboard/AccountOnboard.ts +135 -0
- package/typechain-types/contracts/onboard/index.ts +4 -0
- package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +437 -0
- package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +505 -0
- package/typechain-types/contracts/token/PrivateERC20/index.ts +5 -0
- package/typechain-types/contracts/token/PrivateERC721/PrivateERC721.ts +409 -0
- package/typechain-types/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.ts +501 -0
- package/typechain-types/contracts/token/PrivateERC721/extensions/index.ts +4 -0
- package/typechain-types/contracts/token/PrivateERC721/index.ts +6 -0
- package/typechain-types/contracts/token/index.ts +7 -0
- package/typechain-types/contracts/utils/index.ts +5 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +698 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
- package/typechain-types/contracts/utils/mpc/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +339 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +127 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +111 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +59 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +307 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/index.ts +4 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/DataPrivacyFramework__factory.ts +621 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc__factory.ts +621 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/index.ts +5 -0
- package/typechain-types/factories/contracts/access/index.ts +4 -0
- package/typechain-types/factories/contracts/index.ts +8 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +670 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/access/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/index.ts +7 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +615 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +630 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/token/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +374 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +337 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +236 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +432 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +245 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +374 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +264 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +360 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +441 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +15 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +194 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/wallet/index.ts +4 -0
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +104 -0
- package/typechain-types/factories/contracts/onboard/index.ts +4 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +406 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +532 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/index.ts +5 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/PrivateERC721__factory.ts +439 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage__factory.ts +512 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/extensions/index.ts +4 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +5 -0
- package/typechain-types/factories/contracts/token/index.ts +5 -0
- package/typechain-types/factories/contracts/utils/index.ts +4 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +919 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/utils/mpc/index.ts +4 -0
- package/typechain-types/factories/index.ts +5 -0
- package/typechain-types/hardhat.d.ts +621 -0
- package/typechain-types/index.ts +72 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
|
+
|
|
7
|
+
contract BitwiseTestsContract {
|
|
8
|
+
|
|
9
|
+
struct AllGTCastingValues {
|
|
10
|
+
gtUint8 a8_s;
|
|
11
|
+
gtUint8 b8_s;
|
|
12
|
+
gtUint16 a16_s;
|
|
13
|
+
gtUint16 b16_s;
|
|
14
|
+
gtUint32 a32_s;
|
|
15
|
+
gtUint32 b32_s;
|
|
16
|
+
gtUint64 a64_s;
|
|
17
|
+
gtUint64 b64_s;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
struct Check16 {
|
|
21
|
+
gtUint16 res16_16;
|
|
22
|
+
gtUint16 res8_16;
|
|
23
|
+
gtUint16 res16_8;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct Check32 {
|
|
27
|
+
gtUint32 res32_32;
|
|
28
|
+
gtUint32 res8_32;
|
|
29
|
+
gtUint32 res32_8;
|
|
30
|
+
gtUint32 res16_32;
|
|
31
|
+
gtUint32 res32_16;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct Check64 {
|
|
35
|
+
gtUint64 res64_64;
|
|
36
|
+
gtUint64 res8_64;
|
|
37
|
+
gtUint64 res64_8;
|
|
38
|
+
gtUint64 res16_64;
|
|
39
|
+
gtUint64 res64_16;
|
|
40
|
+
gtUint64 res32_64;
|
|
41
|
+
gtUint64 res64_32;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
uint8 result;
|
|
45
|
+
|
|
46
|
+
function getResult() public view returns (uint8) {
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function setPublicValues(
|
|
51
|
+
AllGTCastingValues memory castingValues,
|
|
52
|
+
uint8 a,
|
|
53
|
+
uint8 b
|
|
54
|
+
) public {
|
|
55
|
+
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
56
|
+
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
57
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
58
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
59
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
60
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
61
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
62
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function decryptAndCompareResults16(
|
|
66
|
+
Check16 memory check16
|
|
67
|
+
) public returns (uint16) {
|
|
68
|
+
// Calculate the result
|
|
69
|
+
uint16 result = MpcCore.decrypt(check16.res16_16);
|
|
70
|
+
|
|
71
|
+
require(
|
|
72
|
+
result == MpcCore.decrypt(check16.res8_16) &&
|
|
73
|
+
result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function decryptAndCompareResults32(
|
|
81
|
+
Check32 memory check32
|
|
82
|
+
) public returns (uint32) {
|
|
83
|
+
// Calculate the result
|
|
84
|
+
uint32 result = MpcCore.decrypt(check32.res32_32);
|
|
85
|
+
|
|
86
|
+
require(
|
|
87
|
+
result == MpcCore.decrypt(check32.res8_32) &&
|
|
88
|
+
result == MpcCore.decrypt(check32.res32_8) &&
|
|
89
|
+
result == MpcCore.decrypt(check32.res32_16) &&
|
|
90
|
+
result == MpcCore.decrypt(check32.res16_32),
|
|
91
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function decryptAndCompareResults64(
|
|
98
|
+
Check64 memory check64
|
|
99
|
+
) public returns (uint64) {
|
|
100
|
+
// Calculate the result
|
|
101
|
+
uint64 result = MpcCore.decrypt(check64.res64_64);
|
|
102
|
+
|
|
103
|
+
require(
|
|
104
|
+
result == MpcCore.decrypt(check64.res8_64) &&
|
|
105
|
+
result == MpcCore.decrypt(check64.res64_8) &&
|
|
106
|
+
result == MpcCore.decrypt(check64.res64_16) &&
|
|
107
|
+
result == MpcCore.decrypt(check64.res16_64) &&
|
|
108
|
+
result == MpcCore.decrypt(check64.res64_32) &&
|
|
109
|
+
result == MpcCore.decrypt(check64.res32_64),
|
|
110
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function andTest(uint8 a, uint8 b) public returns (uint8) {
|
|
117
|
+
AllGTCastingValues memory castingValues;
|
|
118
|
+
Check16 memory check16;
|
|
119
|
+
Check32 memory check32;
|
|
120
|
+
Check64 memory check64;
|
|
121
|
+
setPublicValues(castingValues, a, b);
|
|
122
|
+
|
|
123
|
+
// Calculate the expected result
|
|
124
|
+
result = MpcCore.decrypt(
|
|
125
|
+
MpcCore.and(castingValues.a8_s, castingValues.b8_s)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// Calculate the results with casting to 16
|
|
129
|
+
check16.res16_16 = MpcCore.and(
|
|
130
|
+
castingValues.a16_s,
|
|
131
|
+
castingValues.b16_s
|
|
132
|
+
);
|
|
133
|
+
check16.res8_16 = MpcCore.and(castingValues.a8_s, castingValues.b16_s);
|
|
134
|
+
check16.res16_8 = MpcCore.and(castingValues.a16_s, castingValues.b8_s);
|
|
135
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
136
|
+
require(res16 == result, "andTest: cast 16 failed");
|
|
137
|
+
|
|
138
|
+
// Calculate the result with casting to 32
|
|
139
|
+
check32.res32_32 = MpcCore.and(
|
|
140
|
+
castingValues.a32_s,
|
|
141
|
+
castingValues.b32_s
|
|
142
|
+
);
|
|
143
|
+
check32.res8_32 = MpcCore.and(castingValues.a8_s, castingValues.b32_s);
|
|
144
|
+
check32.res32_8 = MpcCore.and(castingValues.a32_s, castingValues.b8_s);
|
|
145
|
+
check32.res16_32 = MpcCore.and(
|
|
146
|
+
castingValues.a16_s,
|
|
147
|
+
castingValues.b32_s
|
|
148
|
+
);
|
|
149
|
+
check32.res32_16 = MpcCore.and(
|
|
150
|
+
castingValues.a32_s,
|
|
151
|
+
castingValues.b16_s
|
|
152
|
+
);
|
|
153
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
154
|
+
require(result == res32, "andTest: cast 32 failed");
|
|
155
|
+
|
|
156
|
+
// Calculate the result with casting to 64
|
|
157
|
+
check64.res64_64 = MpcCore.and(
|
|
158
|
+
castingValues.a64_s,
|
|
159
|
+
castingValues.b64_s
|
|
160
|
+
);
|
|
161
|
+
check64.res8_64 = MpcCore.and(castingValues.a8_s, castingValues.b64_s);
|
|
162
|
+
check64.res64_8 = MpcCore.and(castingValues.a64_s, castingValues.b8_s);
|
|
163
|
+
check64.res16_64 = MpcCore.and(
|
|
164
|
+
castingValues.a16_s,
|
|
165
|
+
castingValues.b64_s
|
|
166
|
+
);
|
|
167
|
+
check64.res64_16 = MpcCore.and(
|
|
168
|
+
castingValues.a64_s,
|
|
169
|
+
castingValues.b16_s
|
|
170
|
+
);
|
|
171
|
+
check64.res32_64 = MpcCore.and(
|
|
172
|
+
castingValues.a32_s,
|
|
173
|
+
castingValues.b64_s
|
|
174
|
+
);
|
|
175
|
+
check64.res64_32 = MpcCore.and(
|
|
176
|
+
castingValues.a64_s,
|
|
177
|
+
castingValues.b32_s
|
|
178
|
+
);
|
|
179
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
180
|
+
require(result == res64, "andTest: cast 64 failed");
|
|
181
|
+
|
|
182
|
+
// Check the result with scalar
|
|
183
|
+
require(
|
|
184
|
+
result == MpcCore.decrypt(MpcCore.and(a, castingValues.b8_s)) &&
|
|
185
|
+
result == MpcCore.decrypt(MpcCore.and(castingValues.a8_s, b)),
|
|
186
|
+
"andTest: test 8 bits with scalar failed"
|
|
187
|
+
);
|
|
188
|
+
require(
|
|
189
|
+
result == MpcCore.decrypt(MpcCore.and(a, castingValues.b16_s)) &&
|
|
190
|
+
result == MpcCore.decrypt(MpcCore.and(castingValues.a16_s, b)),
|
|
191
|
+
"andTest: test 16 bits with scalar failed"
|
|
192
|
+
);
|
|
193
|
+
require(
|
|
194
|
+
result == MpcCore.decrypt(MpcCore.and(a, castingValues.b32_s)) &&
|
|
195
|
+
result == MpcCore.decrypt(MpcCore.and(castingValues.a32_s, b)),
|
|
196
|
+
"andTest: test 32 bits with scalar failed"
|
|
197
|
+
);
|
|
198
|
+
require(
|
|
199
|
+
result == MpcCore.decrypt(MpcCore.and(a, castingValues.b64_s)) &&
|
|
200
|
+
result == MpcCore.decrypt(MpcCore.and(castingValues.a64_s, b)),
|
|
201
|
+
"andTest: test 64 bits with scalar failed"
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function orTest(uint8 a, uint8 b) public returns (uint8) {
|
|
208
|
+
AllGTCastingValues memory castingValues;
|
|
209
|
+
Check16 memory check16;
|
|
210
|
+
Check32 memory check32;
|
|
211
|
+
Check64 memory check64;
|
|
212
|
+
setPublicValues(castingValues, a, b);
|
|
213
|
+
|
|
214
|
+
// Calculate the expected result
|
|
215
|
+
result = MpcCore.decrypt(
|
|
216
|
+
MpcCore.or(castingValues.a8_s, castingValues.b8_s)
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// Calculate the results with casting to 16
|
|
220
|
+
check16.res16_16 = MpcCore.or(castingValues.a16_s, castingValues.b16_s);
|
|
221
|
+
check16.res8_16 = MpcCore.or(castingValues.a8_s, castingValues.b16_s);
|
|
222
|
+
check16.res16_8 = MpcCore.or(castingValues.a16_s, castingValues.b8_s);
|
|
223
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
224
|
+
require(res16 == result, "orTest: cast 16 failed");
|
|
225
|
+
|
|
226
|
+
// Calculate the result with casting to 32
|
|
227
|
+
check32.res32_32 = MpcCore.or(castingValues.a32_s, castingValues.b32_s);
|
|
228
|
+
check32.res8_32 = MpcCore.or(castingValues.a8_s, castingValues.b32_s);
|
|
229
|
+
check32.res32_8 = MpcCore.or(castingValues.a32_s, castingValues.b8_s);
|
|
230
|
+
check32.res16_32 = MpcCore.or(castingValues.a16_s, castingValues.b32_s);
|
|
231
|
+
check32.res32_16 = MpcCore.or(castingValues.a32_s, castingValues.b16_s);
|
|
232
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
233
|
+
require(result == res32, "orTest: cast 32 failed");
|
|
234
|
+
|
|
235
|
+
// Calculate the result with casting to 64
|
|
236
|
+
check64.res64_64 = MpcCore.or(castingValues.a64_s, castingValues.b64_s);
|
|
237
|
+
check64.res8_64 = MpcCore.or(castingValues.a8_s, castingValues.b64_s);
|
|
238
|
+
check64.res64_8 = MpcCore.or(castingValues.a64_s, castingValues.b8_s);
|
|
239
|
+
check64.res16_64 = MpcCore.or(castingValues.a16_s, castingValues.b64_s);
|
|
240
|
+
check64.res64_16 = MpcCore.or(castingValues.a64_s, castingValues.b16_s);
|
|
241
|
+
check64.res32_64 = MpcCore.or(castingValues.a32_s, castingValues.b64_s);
|
|
242
|
+
check64.res64_32 = MpcCore.or(castingValues.a64_s, castingValues.b32_s);
|
|
243
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
244
|
+
require(result == res64, "orTest: cast 64 failed");
|
|
245
|
+
|
|
246
|
+
// Check the result with scalar
|
|
247
|
+
require(
|
|
248
|
+
result == MpcCore.decrypt(MpcCore.or(a, castingValues.b8_s)) &&
|
|
249
|
+
result == MpcCore.decrypt(MpcCore.or(castingValues.a8_s, b)),
|
|
250
|
+
"orTest: test 8 bits with scalar failed"
|
|
251
|
+
);
|
|
252
|
+
require(
|
|
253
|
+
result == MpcCore.decrypt(MpcCore.or(a, castingValues.b16_s)) &&
|
|
254
|
+
result == MpcCore.decrypt(MpcCore.or(castingValues.a16_s, b)),
|
|
255
|
+
"orTest: test 16 bits with scalar failed"
|
|
256
|
+
);
|
|
257
|
+
require(
|
|
258
|
+
result == MpcCore.decrypt(MpcCore.or(a, castingValues.b32_s)) &&
|
|
259
|
+
result == MpcCore.decrypt(MpcCore.or(castingValues.a32_s, b)),
|
|
260
|
+
"orTest: test 32 bits with scalar failed"
|
|
261
|
+
);
|
|
262
|
+
require(
|
|
263
|
+
result == MpcCore.decrypt(MpcCore.or(a, castingValues.b64_s)) &&
|
|
264
|
+
result == MpcCore.decrypt(MpcCore.or(castingValues.a64_s, b)),
|
|
265
|
+
"orTest: test 64 bits with scalar failed"
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function xorTest(uint8 a, uint8 b) public returns (uint8) {
|
|
272
|
+
AllGTCastingValues memory castingValues;
|
|
273
|
+
Check16 memory check16;
|
|
274
|
+
Check32 memory check32;
|
|
275
|
+
Check64 memory check64;
|
|
276
|
+
setPublicValues(castingValues, a, b);
|
|
277
|
+
|
|
278
|
+
// Calculate the expected result
|
|
279
|
+
result = MpcCore.decrypt(
|
|
280
|
+
MpcCore.xor(castingValues.a8_s, castingValues.b8_s)
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
// Calculate the results with casting to 16
|
|
284
|
+
check16.res16_16 = MpcCore.xor(
|
|
285
|
+
castingValues.a16_s,
|
|
286
|
+
castingValues.b16_s
|
|
287
|
+
);
|
|
288
|
+
check16.res8_16 = MpcCore.xor(castingValues.a8_s, castingValues.b16_s);
|
|
289
|
+
check16.res16_8 = MpcCore.xor(castingValues.a16_s, castingValues.b8_s);
|
|
290
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
291
|
+
require(res16 == result, "xorTest: cast 16 failed");
|
|
292
|
+
|
|
293
|
+
// Calculate the result with casting to 32
|
|
294
|
+
check32.res32_32 = MpcCore.xor(
|
|
295
|
+
castingValues.a32_s,
|
|
296
|
+
castingValues.b32_s
|
|
297
|
+
);
|
|
298
|
+
check32.res8_32 = MpcCore.xor(castingValues.a8_s, castingValues.b32_s);
|
|
299
|
+
check32.res32_8 = MpcCore.xor(castingValues.a32_s, castingValues.b8_s);
|
|
300
|
+
check32.res16_32 = MpcCore.xor(
|
|
301
|
+
castingValues.a16_s,
|
|
302
|
+
castingValues.b32_s
|
|
303
|
+
);
|
|
304
|
+
check32.res32_16 = MpcCore.xor(
|
|
305
|
+
castingValues.a32_s,
|
|
306
|
+
castingValues.b16_s
|
|
307
|
+
);
|
|
308
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
309
|
+
require(result == res32, "xorTest: cast 32 failed");
|
|
310
|
+
|
|
311
|
+
// Calculate the result with casting to 64
|
|
312
|
+
check64.res64_64 = MpcCore.xor(
|
|
313
|
+
castingValues.a64_s,
|
|
314
|
+
castingValues.b64_s
|
|
315
|
+
);
|
|
316
|
+
check64.res8_64 = MpcCore.xor(castingValues.a8_s, castingValues.b64_s);
|
|
317
|
+
check64.res64_8 = MpcCore.xor(castingValues.a64_s, castingValues.b8_s);
|
|
318
|
+
check64.res16_64 = MpcCore.xor(
|
|
319
|
+
castingValues.a16_s,
|
|
320
|
+
castingValues.b64_s
|
|
321
|
+
);
|
|
322
|
+
check64.res64_16 = MpcCore.xor(
|
|
323
|
+
castingValues.a64_s,
|
|
324
|
+
castingValues.b16_s
|
|
325
|
+
);
|
|
326
|
+
check64.res32_64 = MpcCore.xor(
|
|
327
|
+
castingValues.a32_s,
|
|
328
|
+
castingValues.b64_s
|
|
329
|
+
);
|
|
330
|
+
check64.res64_32 = MpcCore.xor(
|
|
331
|
+
castingValues.a64_s,
|
|
332
|
+
castingValues.b32_s
|
|
333
|
+
);
|
|
334
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
335
|
+
require(result == res64, "xorTest: cast 64 failed");
|
|
336
|
+
|
|
337
|
+
// Check the result with scalar
|
|
338
|
+
require(
|
|
339
|
+
result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b8_s)) &&
|
|
340
|
+
result == MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, b)),
|
|
341
|
+
"xorTest: test 8 bits with scalar failed"
|
|
342
|
+
);
|
|
343
|
+
require(
|
|
344
|
+
result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b16_s)) &&
|
|
345
|
+
result == MpcCore.decrypt(MpcCore.xor(castingValues.a16_s, b)),
|
|
346
|
+
"xorTest: test 16 bits with scalar failed"
|
|
347
|
+
);
|
|
348
|
+
require(
|
|
349
|
+
result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b32_s)) &&
|
|
350
|
+
result == MpcCore.decrypt(MpcCore.xor(castingValues.a32_s, b)),
|
|
351
|
+
"xorTest: test 32 bits with scalar failed"
|
|
352
|
+
);
|
|
353
|
+
require(
|
|
354
|
+
result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b64_s)) &&
|
|
355
|
+
result == MpcCore.decrypt(MpcCore.xor(castingValues.a64_s, b)),
|
|
356
|
+
"xorTest: test 64 bits with scalar failed"
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
|
+
|
|
7
|
+
contract Comparison1TestsContract {
|
|
8
|
+
|
|
9
|
+
struct AllGTCastingValues {
|
|
10
|
+
gtUint8 a8_s;
|
|
11
|
+
gtUint8 b8_s;
|
|
12
|
+
gtUint16 a16_s;
|
|
13
|
+
gtUint16 b16_s;
|
|
14
|
+
gtUint32 a32_s;
|
|
15
|
+
gtUint32 b32_s;
|
|
16
|
+
gtUint64 a64_s;
|
|
17
|
+
gtUint64 b64_s;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
struct Check16 {
|
|
21
|
+
gtBool res16_16;
|
|
22
|
+
gtBool res8_16;
|
|
23
|
+
gtBool res16_8;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
struct Check32 {
|
|
27
|
+
gtBool res32_32;
|
|
28
|
+
gtBool res8_32;
|
|
29
|
+
gtBool res32_8;
|
|
30
|
+
gtBool res16_32;
|
|
31
|
+
gtBool res32_16;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct Check64 {
|
|
35
|
+
gtBool res64_64;
|
|
36
|
+
gtBool res8_64;
|
|
37
|
+
gtBool res64_8;
|
|
38
|
+
gtBool res16_64;
|
|
39
|
+
gtBool res64_16;
|
|
40
|
+
gtBool res32_64;
|
|
41
|
+
gtBool res64_32;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
bool result;
|
|
45
|
+
|
|
46
|
+
function getResult() public view returns (bool) {
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function setPublicValues(
|
|
51
|
+
AllGTCastingValues memory castingValues,
|
|
52
|
+
uint8 a,
|
|
53
|
+
uint8 b
|
|
54
|
+
) public {
|
|
55
|
+
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
56
|
+
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
57
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
58
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
59
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
60
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
61
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
62
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function decryptAndCompareResults16(
|
|
66
|
+
Check16 memory check16
|
|
67
|
+
) public returns (bool) {
|
|
68
|
+
// Calculate the result
|
|
69
|
+
bool result = MpcCore.decrypt(check16.res16_16);
|
|
70
|
+
|
|
71
|
+
require(
|
|
72
|
+
result == MpcCore.decrypt(check16.res8_16) &&
|
|
73
|
+
result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function decryptAndCompareResults32(
|
|
81
|
+
Check32 memory check32
|
|
82
|
+
) public returns (bool) {
|
|
83
|
+
// Calculate the result
|
|
84
|
+
bool result = MpcCore.decrypt(check32.res32_32);
|
|
85
|
+
|
|
86
|
+
require(
|
|
87
|
+
result == MpcCore.decrypt(check32.res8_32) &&
|
|
88
|
+
result == MpcCore.decrypt(check32.res32_8) &&
|
|
89
|
+
result == MpcCore.decrypt(check32.res32_16) &&
|
|
90
|
+
result == MpcCore.decrypt(check32.res16_32),
|
|
91
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function decryptAndCompareResults64(
|
|
98
|
+
Check64 memory check64
|
|
99
|
+
) public returns (bool) {
|
|
100
|
+
// Calculate the result
|
|
101
|
+
bool result = MpcCore.decrypt(check64.res64_64);
|
|
102
|
+
|
|
103
|
+
require(
|
|
104
|
+
result == MpcCore.decrypt(check64.res8_64) &&
|
|
105
|
+
result == MpcCore.decrypt(check64.res64_8) &&
|
|
106
|
+
result == MpcCore.decrypt(check64.res64_16) &&
|
|
107
|
+
result == MpcCore.decrypt(check64.res16_64) &&
|
|
108
|
+
result == MpcCore.decrypt(check64.res64_32) &&
|
|
109
|
+
result == MpcCore.decrypt(check64.res32_64),
|
|
110
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function gtTest(uint8 a, uint8 b) public returns (bool) {
|
|
117
|
+
AllGTCastingValues memory castingValues;
|
|
118
|
+
Check16 memory check16;
|
|
119
|
+
Check32 memory check32;
|
|
120
|
+
Check64 memory check64;
|
|
121
|
+
setPublicValues(castingValues, a, b);
|
|
122
|
+
|
|
123
|
+
// Calculate the expected result
|
|
124
|
+
result = MpcCore.decrypt(
|
|
125
|
+
MpcCore.gt(castingValues.a8_s, castingValues.b8_s)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// Calculate the results with cating to 16
|
|
129
|
+
check16.res16_16 = MpcCore.gt(castingValues.a16_s, castingValues.b16_s);
|
|
130
|
+
check16.res8_16 = MpcCore.gt(castingValues.a8_s, castingValues.b16_s);
|
|
131
|
+
check16.res16_8 = MpcCore.gt(castingValues.a16_s, castingValues.b8_s);
|
|
132
|
+
bool res16 = decryptAndCompareResults16(check16);
|
|
133
|
+
require(res16 == result, "gtTest: cast 16 failed");
|
|
134
|
+
|
|
135
|
+
// Calculate the result with cating to 32
|
|
136
|
+
check32.res32_32 = MpcCore.gt(castingValues.a32_s, castingValues.b32_s);
|
|
137
|
+
check32.res8_32 = MpcCore.gt(castingValues.a8_s, castingValues.b32_s);
|
|
138
|
+
check32.res32_8 = MpcCore.gt(castingValues.a32_s, castingValues.b8_s);
|
|
139
|
+
check32.res16_32 = MpcCore.gt(castingValues.a16_s, castingValues.b32_s);
|
|
140
|
+
check32.res32_16 = MpcCore.gt(castingValues.a32_s, castingValues.b16_s);
|
|
141
|
+
bool res32 = decryptAndCompareResults32(check32);
|
|
142
|
+
require(result == res32, "gtTest: cast 32 failed");
|
|
143
|
+
|
|
144
|
+
// Calculate the result with cating to 64
|
|
145
|
+
check64.res64_64 = MpcCore.gt(castingValues.a64_s, castingValues.b64_s);
|
|
146
|
+
check64.res8_64 = MpcCore.gt(castingValues.a8_s, castingValues.b64_s);
|
|
147
|
+
check64.res64_8 = MpcCore.gt(castingValues.a64_s, castingValues.b8_s);
|
|
148
|
+
check64.res16_64 = MpcCore.gt(castingValues.a16_s, castingValues.b64_s);
|
|
149
|
+
check64.res64_16 = MpcCore.gt(castingValues.a64_s, castingValues.b16_s);
|
|
150
|
+
check64.res32_64 = MpcCore.gt(castingValues.a32_s, castingValues.b64_s);
|
|
151
|
+
check64.res64_32 = MpcCore.gt(castingValues.a64_s, castingValues.b32_s);
|
|
152
|
+
bool res64 = decryptAndCompareResults64(check64);
|
|
153
|
+
require(result == res64, "gtTest: cast 64 failed");
|
|
154
|
+
|
|
155
|
+
// Check the result with scalar
|
|
156
|
+
require(
|
|
157
|
+
result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b8_s)) &&
|
|
158
|
+
result == MpcCore.decrypt(MpcCore.gt(castingValues.a8_s, b)),
|
|
159
|
+
"gtTest: test 8 bits with scalar failed"
|
|
160
|
+
);
|
|
161
|
+
require(
|
|
162
|
+
result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b16_s)) &&
|
|
163
|
+
result == MpcCore.decrypt(MpcCore.gt(castingValues.a16_s, b)),
|
|
164
|
+
"gtTest: test 16 bits with scalar failed"
|
|
165
|
+
);
|
|
166
|
+
require(
|
|
167
|
+
result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b32_s)) &&
|
|
168
|
+
result == MpcCore.decrypt(MpcCore.gt(castingValues.a32_s, b)),
|
|
169
|
+
"gtTest: test 32 bits with scalar failed"
|
|
170
|
+
);
|
|
171
|
+
require(
|
|
172
|
+
result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b64_s)) &&
|
|
173
|
+
result == MpcCore.decrypt(MpcCore.gt(castingValues.a64_s, b)),
|
|
174
|
+
"gtTest: test 64 bits with scalar failed"
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function leTest(uint8 a, uint8 b) public returns (bool) {
|
|
181
|
+
AllGTCastingValues memory castingValues;
|
|
182
|
+
Check16 memory check16;
|
|
183
|
+
Check32 memory check32;
|
|
184
|
+
Check64 memory check64;
|
|
185
|
+
setPublicValues(castingValues, a, b);
|
|
186
|
+
|
|
187
|
+
// Calculate the expected result
|
|
188
|
+
result = MpcCore.decrypt(
|
|
189
|
+
MpcCore.le(castingValues.a8_s, castingValues.b8_s)
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// Calculate the results with cating to 16
|
|
193
|
+
check16.res16_16 = MpcCore.le(castingValues.a16_s, castingValues.b16_s);
|
|
194
|
+
check16.res8_16 = MpcCore.le(castingValues.a8_s, castingValues.b16_s);
|
|
195
|
+
check16.res16_8 = MpcCore.le(castingValues.a16_s, castingValues.b8_s);
|
|
196
|
+
bool res16 = decryptAndCompareResults16(check16);
|
|
197
|
+
require(res16 == result, "leTest: cast 16 failed");
|
|
198
|
+
|
|
199
|
+
// Calculate the result with cating to 32
|
|
200
|
+
check32.res32_32 = MpcCore.le(castingValues.a32_s, castingValues.b32_s);
|
|
201
|
+
check32.res8_32 = MpcCore.le(castingValues.a8_s, castingValues.b32_s);
|
|
202
|
+
check32.res32_8 = MpcCore.le(castingValues.a32_s, castingValues.b8_s);
|
|
203
|
+
check32.res16_32 = MpcCore.le(castingValues.a16_s, castingValues.b32_s);
|
|
204
|
+
check32.res32_16 = MpcCore.le(castingValues.a32_s, castingValues.b16_s);
|
|
205
|
+
bool res32 = decryptAndCompareResults32(check32);
|
|
206
|
+
require(result == res32, "leTest: cast 32 failed");
|
|
207
|
+
|
|
208
|
+
// Calculate the result with cating to 64
|
|
209
|
+
check64.res64_64 = MpcCore.le(castingValues.a64_s, castingValues.b64_s);
|
|
210
|
+
check64.res8_64 = MpcCore.le(castingValues.a8_s, castingValues.b64_s);
|
|
211
|
+
check64.res64_8 = MpcCore.le(castingValues.a64_s, castingValues.b8_s);
|
|
212
|
+
check64.res16_64 = MpcCore.le(castingValues.a16_s, castingValues.b64_s);
|
|
213
|
+
check64.res64_16 = MpcCore.le(castingValues.a64_s, castingValues.b16_s);
|
|
214
|
+
check64.res32_64 = MpcCore.le(castingValues.a32_s, castingValues.b64_s);
|
|
215
|
+
check64.res64_32 = MpcCore.le(castingValues.a64_s, castingValues.b32_s);
|
|
216
|
+
bool res64 = decryptAndCompareResults64(check64);
|
|
217
|
+
require(result == res64, "leTest: cast 64 failed");
|
|
218
|
+
|
|
219
|
+
// Check the result with scalar
|
|
220
|
+
require(
|
|
221
|
+
result == MpcCore.decrypt(MpcCore.le(a, castingValues.b8_s)) &&
|
|
222
|
+
result == MpcCore.decrypt(MpcCore.le(castingValues.a8_s, b)),
|
|
223
|
+
"leTest: test 8 bits with scalar failed"
|
|
224
|
+
);
|
|
225
|
+
require(
|
|
226
|
+
result == MpcCore.decrypt(MpcCore.le(a, castingValues.b16_s)) &&
|
|
227
|
+
result == MpcCore.decrypt(MpcCore.le(castingValues.a16_s, b)),
|
|
228
|
+
"leTest: test 16 bits with scalar failed"
|
|
229
|
+
);
|
|
230
|
+
require(
|
|
231
|
+
result == MpcCore.decrypt(MpcCore.le(a, castingValues.b32_s)) &&
|
|
232
|
+
result == MpcCore.decrypt(MpcCore.le(castingValues.a32_s, b)),
|
|
233
|
+
"leTest: test 32 bits with scalar failed"
|
|
234
|
+
);
|
|
235
|
+
require(
|
|
236
|
+
result == MpcCore.decrypt(MpcCore.le(a, castingValues.b64_s)) &&
|
|
237
|
+
result == MpcCore.decrypt(MpcCore.le(castingValues.a64_s, b)),
|
|
238
|
+
"leTest: test 64 bits with scalar failed"
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function ltTest(uint8 a, uint8 b) public returns (bool) {
|
|
245
|
+
AllGTCastingValues memory castingValues;
|
|
246
|
+
Check16 memory check16;
|
|
247
|
+
Check32 memory check32;
|
|
248
|
+
Check64 memory check64;
|
|
249
|
+
setPublicValues(castingValues, a, b);
|
|
250
|
+
|
|
251
|
+
// Calculate the expected result
|
|
252
|
+
result = MpcCore.decrypt(
|
|
253
|
+
MpcCore.lt(castingValues.a8_s, castingValues.b8_s)
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
// Calculate the results with cating to 16
|
|
257
|
+
check16.res16_16 = MpcCore.lt(castingValues.a16_s, castingValues.b16_s);
|
|
258
|
+
check16.res8_16 = MpcCore.lt(castingValues.a8_s, castingValues.b16_s);
|
|
259
|
+
check16.res16_8 = MpcCore.lt(castingValues.a16_s, castingValues.b8_s);
|
|
260
|
+
bool res16 = decryptAndCompareResults16(check16);
|
|
261
|
+
require(res16 == result, "letTest: cast 16 failed");
|
|
262
|
+
|
|
263
|
+
// Calculate the result with cating to 32
|
|
264
|
+
check32.res32_32 = MpcCore.lt(castingValues.a32_s, castingValues.b32_s);
|
|
265
|
+
check32.res8_32 = MpcCore.lt(castingValues.a8_s, castingValues.b32_s);
|
|
266
|
+
check32.res32_8 = MpcCore.lt(castingValues.a32_s, castingValues.b8_s);
|
|
267
|
+
check32.res16_32 = MpcCore.lt(castingValues.a16_s, castingValues.b32_s);
|
|
268
|
+
check32.res32_16 = MpcCore.lt(castingValues.a32_s, castingValues.b16_s);
|
|
269
|
+
bool res32 = decryptAndCompareResults32(check32);
|
|
270
|
+
require(result == res32, "letTest: cast 32 failed");
|
|
271
|
+
|
|
272
|
+
// Calculate the result with cating to 64
|
|
273
|
+
check64.res64_64 = MpcCore.lt(castingValues.a64_s, castingValues.b64_s);
|
|
274
|
+
check64.res8_64 = MpcCore.lt(castingValues.a8_s, castingValues.b64_s);
|
|
275
|
+
check64.res64_8 = MpcCore.lt(castingValues.a64_s, castingValues.b8_s);
|
|
276
|
+
check64.res16_64 = MpcCore.lt(castingValues.a16_s, castingValues.b64_s);
|
|
277
|
+
check64.res64_16 = MpcCore.lt(castingValues.a64_s, castingValues.b16_s);
|
|
278
|
+
check64.res32_64 = MpcCore.lt(castingValues.a32_s, castingValues.b64_s);
|
|
279
|
+
check64.res64_32 = MpcCore.lt(castingValues.a64_s, castingValues.b32_s);
|
|
280
|
+
bool res64 = decryptAndCompareResults64(check64);
|
|
281
|
+
require(result == res64, "letTest: cast 64 failed");
|
|
282
|
+
|
|
283
|
+
// Check the result with scalar
|
|
284
|
+
require(
|
|
285
|
+
result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b8_s)) &&
|
|
286
|
+
result == MpcCore.decrypt(MpcCore.lt(castingValues.a8_s, b)),
|
|
287
|
+
"letTest: test 8 bits with scalar failed"
|
|
288
|
+
);
|
|
289
|
+
require(
|
|
290
|
+
result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b16_s)) &&
|
|
291
|
+
result == MpcCore.decrypt(MpcCore.lt(castingValues.a16_s, b)),
|
|
292
|
+
"letTest: test 16 bits with scalar failed"
|
|
293
|
+
);
|
|
294
|
+
require(
|
|
295
|
+
result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b32_s)) &&
|
|
296
|
+
result == MpcCore.decrypt(MpcCore.lt(castingValues.a32_s, b)),
|
|
297
|
+
"letTest: test 32 bits with scalar failed"
|
|
298
|
+
);
|
|
299
|
+
require(
|
|
300
|
+
result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b64_s)) &&
|
|
301
|
+
result == MpcCore.decrypt(MpcCore.lt(castingValues.a64_s, b)),
|
|
302
|
+
"letTest: test 64 bits with scalar failed"
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
}
|