@coti-io/coti-contracts 0.1.0 → 1.0.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/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +3 -115
- package/contracts/mocks/README.md +1 -1
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +105 -280
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +83 -187
- package/contracts/mocks/utils/mpc/{Comparison1Tests.Contract.sol → Comparison1TestsContract.sol} +67 -115
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +68 -116
- package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +69 -164
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +70 -52
- package/contracts/mocks/utils/mpc/MiscellaneousTestsContract.sol +270 -0
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +102 -0
- package/contracts/mocks/utils/mpc/README.md +12 -12
- package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +54 -211
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +162 -640
- package/contracts/onboard/AccountOnboard.sol +3 -3
- package/contracts/utils/mpc/MpcCore.sol +2835 -988
- package/contracts/utils/mpc/MpcInterface.sol +6 -4
- package/hardhat.config.ts +8 -5
- package/package.json +2 -2
- package/test/utils/accounts.ts +1 -1
- package/test/utils/mpc/Precompile.test.ts +26 -37
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract.ts +374 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract.ts +374 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +30 -10
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +39 -5
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1TestsContract.ts +374 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +39 -5
- package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +25 -5
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +62 -0
- package/typechain-types/contracts/mocks/utils/mpc/MiscellaneousTestsContract.ts +396 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +221 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +11 -8
- package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +15 -15
- package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +15 -15
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +3 -6
- package/typechain-types/contracts/onboard/AccountOnboard.ts +9 -4
- package/typechain-types/contracts/utils/mpc/MpcCore.ts +84 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +81 -40
- package/typechain-types/contracts/utils/mpc/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.sol/ArithmeticTestsContract__factory.ts +387 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract__factory.ts +388 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +20 -7
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +28 -2
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +387 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +28 -2
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +15 -2
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +66 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +424 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +289 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +19 -3
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +4 -4
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +4 -4
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +3 -4
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +8 -2
- package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +77 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +124 -61
- package/typechain-types/factories/contracts/utils/mpc/index.ts +1 -0
- package/typechain-types/hardhat.d.ts +26 -26
- package/typechain-types/index.ts +8 -8
- package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +0 -448
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +0 -81
- package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +0 -311
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
2
|
pragma solidity ^0.8.19;
|
|
4
3
|
|
|
5
4
|
import "../../../utils/mpc/MpcCore.sol";
|
|
@@ -41,74 +40,63 @@ contract BitwiseTestsContract {
|
|
|
41
40
|
gtUint64 res64_32;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
uint8
|
|
43
|
+
uint8 andResult;
|
|
44
|
+
uint8 orResult;
|
|
45
|
+
uint8 xorResult;
|
|
45
46
|
|
|
46
|
-
function
|
|
47
|
-
return
|
|
47
|
+
function getAndResult() public view returns (uint8) {
|
|
48
|
+
return andResult;
|
|
49
|
+
}
|
|
50
|
+
function getOrResult() public view returns (uint8) {
|
|
51
|
+
return orResult;
|
|
52
|
+
}
|
|
53
|
+
function getXorResult() public view returns (uint8) {
|
|
54
|
+
return xorResult;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
function setPublicValues(
|
|
51
|
-
AllGTCastingValues memory castingValues,
|
|
52
|
-
uint8 a,
|
|
53
|
-
uint8 b
|
|
54
|
-
) public {
|
|
57
|
+
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
55
58
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
56
59
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
57
|
-
castingValues.a16_s =
|
|
58
|
-
castingValues.b16_s =
|
|
59
|
-
castingValues.a32_s =
|
|
60
|
-
castingValues.b32_s =
|
|
61
|
-
castingValues.a64_s =
|
|
62
|
-
castingValues.b64_s =
|
|
60
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
61
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
62
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
63
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
64
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
65
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
function decryptAndCompareResults16(
|
|
66
|
-
|
|
67
|
-
) public returns (uint16) {
|
|
68
|
+
function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){
|
|
69
|
+
|
|
68
70
|
// Calculate the result
|
|
69
71
|
uint16 result = MpcCore.decrypt(check16.res16_16);
|
|
70
72
|
|
|
71
|
-
require(
|
|
72
|
-
|
|
73
|
-
result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
75
|
-
);
|
|
73
|
+
require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
76
75
|
|
|
77
76
|
return result;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
function decryptAndCompareResults32(
|
|
81
|
-
|
|
82
|
-
) public returns (uint32) {
|
|
79
|
+
function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){
|
|
80
|
+
|
|
83
81
|
// Calculate the result
|
|
84
82
|
uint32 result = MpcCore.decrypt(check32.res32_32);
|
|
85
83
|
|
|
86
|
-
require(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
result == MpcCore.decrypt(check32.res32_16) &&
|
|
90
|
-
result == MpcCore.decrypt(check32.res16_32),
|
|
91
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
92
|
-
);
|
|
84
|
+
require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
|
|
85
|
+
&& result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
|
|
86
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
93
87
|
|
|
94
88
|
return result;
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
function decryptAndCompareResults64(
|
|
98
|
-
|
|
99
|
-
) public returns (uint64) {
|
|
91
|
+
function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){
|
|
92
|
+
|
|
100
93
|
// Calculate the result
|
|
101
94
|
uint64 result = MpcCore.decrypt(check64.res64_64);
|
|
102
95
|
|
|
103
|
-
require(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
);
|
|
96
|
+
require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
|
|
97
|
+
&& result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
|
|
98
|
+
&& result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
|
|
99
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
112
100
|
|
|
113
101
|
return result;
|
|
114
102
|
}
|
|
@@ -121,85 +109,45 @@ contract BitwiseTestsContract {
|
|
|
121
109
|
setPublicValues(castingValues, a, b);
|
|
122
110
|
|
|
123
111
|
// Calculate the expected result
|
|
124
|
-
result =
|
|
125
|
-
|
|
126
|
-
);
|
|
112
|
+
uint8 result = MpcCore.decrypt(MpcCore.and(castingValues.a8_s, castingValues.b8_s));
|
|
113
|
+
andResult = result;
|
|
127
114
|
|
|
128
115
|
// Calculate the results with casting to 16
|
|
129
|
-
check16.res16_16 = MpcCore.and(
|
|
130
|
-
castingValues.a16_s,
|
|
131
|
-
castingValues.b16_s
|
|
132
|
-
);
|
|
116
|
+
check16.res16_16 = MpcCore.and(castingValues.a16_s, castingValues.b16_s);
|
|
133
117
|
check16.res8_16 = MpcCore.and(castingValues.a8_s, castingValues.b16_s);
|
|
134
118
|
check16.res16_8 = MpcCore.and(castingValues.a16_s, castingValues.b8_s);
|
|
135
119
|
uint16 res16 = decryptAndCompareResults16(check16);
|
|
136
120
|
require(res16 == result, "andTest: cast 16 failed");
|
|
137
121
|
|
|
138
122
|
// Calculate the result with casting to 32
|
|
139
|
-
check32.res32_32 = MpcCore.and(
|
|
140
|
-
castingValues.a32_s,
|
|
141
|
-
castingValues.b32_s
|
|
142
|
-
);
|
|
123
|
+
check32.res32_32 = MpcCore.and(castingValues.a32_s, castingValues.b32_s);
|
|
143
124
|
check32.res8_32 = MpcCore.and(castingValues.a8_s, castingValues.b32_s);
|
|
144
125
|
check32.res32_8 = MpcCore.and(castingValues.a32_s, castingValues.b8_s);
|
|
145
|
-
check32.res16_32 = MpcCore.and(
|
|
146
|
-
|
|
147
|
-
castingValues.b32_s
|
|
148
|
-
);
|
|
149
|
-
check32.res32_16 = MpcCore.and(
|
|
150
|
-
castingValues.a32_s,
|
|
151
|
-
castingValues.b16_s
|
|
152
|
-
);
|
|
126
|
+
check32.res16_32 = MpcCore.and(castingValues.a16_s, castingValues.b32_s);
|
|
127
|
+
check32.res32_16 = MpcCore.and(castingValues.a32_s, castingValues.b16_s);
|
|
153
128
|
uint32 res32 = decryptAndCompareResults32(check32);
|
|
154
129
|
require(result == res32, "andTest: cast 32 failed");
|
|
155
130
|
|
|
156
131
|
// Calculate the result with casting to 64
|
|
157
|
-
check64.res64_64 = MpcCore.and(
|
|
158
|
-
castingValues.a64_s,
|
|
159
|
-
castingValues.b64_s
|
|
160
|
-
);
|
|
132
|
+
check64.res64_64 = MpcCore.and(castingValues.a64_s, castingValues.b64_s);
|
|
161
133
|
check64.res8_64 = MpcCore.and(castingValues.a8_s, castingValues.b64_s);
|
|
162
134
|
check64.res64_8 = MpcCore.and(castingValues.a64_s, castingValues.b8_s);
|
|
163
|
-
check64.res16_64 = MpcCore.and(
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
);
|
|
135
|
+
check64.res16_64 = MpcCore.and(castingValues.a16_s, castingValues.b64_s);
|
|
136
|
+
check64.res64_16 = MpcCore.and(castingValues.a64_s, castingValues.b16_s);
|
|
137
|
+
check64.res32_64 = MpcCore.and(castingValues.a32_s, castingValues.b64_s);
|
|
138
|
+
check64.res64_32 = MpcCore.and(castingValues.a64_s, castingValues.b32_s);
|
|
179
139
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
180
140
|
require(result == res64, "andTest: cast 64 failed");
|
|
181
141
|
|
|
182
142
|
// Check the result with scalar
|
|
183
|
-
require(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
"andTest: test
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
);
|
|
143
|
+
require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a8_s, b)),
|
|
144
|
+
"andTest: test 8 bits with scalar failed");
|
|
145
|
+
require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a16_s, b)),
|
|
146
|
+
"andTest: test 16 bits with scalar failed");
|
|
147
|
+
require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a32_s, b)),
|
|
148
|
+
"andTest: test 32 bits with scalar failed");
|
|
149
|
+
require(result == MpcCore.decrypt(MpcCore.and(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.and(castingValues.a64_s, b)),
|
|
150
|
+
"andTest: test 64 bits with scalar failed");
|
|
203
151
|
|
|
204
152
|
return result;
|
|
205
153
|
}
|
|
@@ -212,9 +160,8 @@ contract BitwiseTestsContract {
|
|
|
212
160
|
setPublicValues(castingValues, a, b);
|
|
213
161
|
|
|
214
162
|
// Calculate the expected result
|
|
215
|
-
result =
|
|
216
|
-
|
|
217
|
-
);
|
|
163
|
+
uint8 result = MpcCore.decrypt(MpcCore.or(castingValues.a8_s, castingValues.b8_s));
|
|
164
|
+
orResult = result;
|
|
218
165
|
|
|
219
166
|
// Calculate the results with casting to 16
|
|
220
167
|
check16.res16_16 = MpcCore.or(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -244,26 +191,14 @@ contract BitwiseTestsContract {
|
|
|
244
191
|
require(result == res64, "orTest: cast 64 failed");
|
|
245
192
|
|
|
246
193
|
// Check the result with scalar
|
|
247
|
-
require(
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
"orTest: test
|
|
251
|
-
)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
);
|
|
194
|
+
require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a8_s, b)),
|
|
195
|
+
"orTest: test 8 bits with scalar failed");
|
|
196
|
+
require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a16_s, b)),
|
|
197
|
+
"orTest: test 16 bits with scalar failed");
|
|
198
|
+
require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a32_s, b)),
|
|
199
|
+
"orTest: test 32 bits with scalar failed");
|
|
200
|
+
require(result == MpcCore.decrypt(MpcCore.or(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.or(castingValues.a64_s, b)),
|
|
201
|
+
"orTest: test 64 bits with scalar failed");
|
|
267
202
|
|
|
268
203
|
return result;
|
|
269
204
|
}
|
|
@@ -276,86 +211,47 @@ contract BitwiseTestsContract {
|
|
|
276
211
|
setPublicValues(castingValues, a, b);
|
|
277
212
|
|
|
278
213
|
// Calculate the expected result
|
|
279
|
-
result =
|
|
280
|
-
|
|
281
|
-
);
|
|
214
|
+
uint8 result = MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, castingValues.b8_s));
|
|
215
|
+
xorResult = result;
|
|
282
216
|
|
|
283
217
|
// Calculate the results with casting to 16
|
|
284
|
-
check16.res16_16 = MpcCore.xor(
|
|
285
|
-
castingValues.a16_s,
|
|
286
|
-
castingValues.b16_s
|
|
287
|
-
);
|
|
218
|
+
check16.res16_16 = MpcCore.xor(castingValues.a16_s, castingValues.b16_s);
|
|
288
219
|
check16.res8_16 = MpcCore.xor(castingValues.a8_s, castingValues.b16_s);
|
|
289
220
|
check16.res16_8 = MpcCore.xor(castingValues.a16_s, castingValues.b8_s);
|
|
290
221
|
uint16 res16 = decryptAndCompareResults16(check16);
|
|
291
222
|
require(res16 == result, "xorTest: cast 16 failed");
|
|
292
223
|
|
|
293
224
|
// Calculate the result with casting to 32
|
|
294
|
-
check32.res32_32 = MpcCore.xor(
|
|
295
|
-
castingValues.a32_s,
|
|
296
|
-
castingValues.b32_s
|
|
297
|
-
);
|
|
225
|
+
check32.res32_32 = MpcCore.xor(castingValues.a32_s, castingValues.b32_s);
|
|
298
226
|
check32.res8_32 = MpcCore.xor(castingValues.a8_s, castingValues.b32_s);
|
|
299
227
|
check32.res32_8 = MpcCore.xor(castingValues.a32_s, castingValues.b8_s);
|
|
300
|
-
check32.res16_32 = MpcCore.xor(
|
|
301
|
-
|
|
302
|
-
castingValues.b32_s
|
|
303
|
-
);
|
|
304
|
-
check32.res32_16 = MpcCore.xor(
|
|
305
|
-
castingValues.a32_s,
|
|
306
|
-
castingValues.b16_s
|
|
307
|
-
);
|
|
228
|
+
check32.res16_32 = MpcCore.xor(castingValues.a16_s, castingValues.b32_s);
|
|
229
|
+
check32.res32_16 = MpcCore.xor(castingValues.a32_s, castingValues.b16_s);
|
|
308
230
|
uint32 res32 = decryptAndCompareResults32(check32);
|
|
309
231
|
require(result == res32, "xorTest: cast 32 failed");
|
|
310
232
|
|
|
311
233
|
// Calculate the result with casting to 64
|
|
312
|
-
check64.res64_64 = MpcCore.xor(
|
|
313
|
-
castingValues.a64_s,
|
|
314
|
-
castingValues.b64_s
|
|
315
|
-
);
|
|
234
|
+
check64.res64_64 = MpcCore.xor(castingValues.a64_s, castingValues.b64_s);
|
|
316
235
|
check64.res8_64 = MpcCore.xor(castingValues.a8_s, castingValues.b64_s);
|
|
317
236
|
check64.res64_8 = MpcCore.xor(castingValues.a64_s, castingValues.b8_s);
|
|
318
|
-
check64.res16_64 = MpcCore.xor(
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
);
|
|
237
|
+
check64.res16_64 = MpcCore.xor(castingValues.a16_s, castingValues.b64_s);
|
|
238
|
+
check64.res64_16 = MpcCore.xor(castingValues.a64_s, castingValues.b16_s);
|
|
239
|
+
check64.res32_64 = MpcCore.xor(castingValues.a32_s, castingValues.b64_s);
|
|
240
|
+
check64.res64_32 = MpcCore.xor(castingValues.a64_s, castingValues.b32_s);
|
|
334
241
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
335
242
|
require(result == res64, "xorTest: cast 64 failed");
|
|
336
243
|
|
|
337
244
|
// Check the result with scalar
|
|
338
|
-
require(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
"xorTest: test
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
);
|
|
245
|
+
require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a8_s, b)),
|
|
246
|
+
"xorTest: test 8 bits with scalar failed");
|
|
247
|
+
require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a16_s, b)),
|
|
248
|
+
"xorTest: test 16 bits with scalar failed");
|
|
249
|
+
require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a32_s, b)),
|
|
250
|
+
"xorTest: test 32 bits with scalar failed");
|
|
251
|
+
require(result == MpcCore.decrypt(MpcCore.xor(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.xor(castingValues.a64_s, b)),
|
|
252
|
+
"xorTest: test 64 bits with scalar failed");
|
|
358
253
|
|
|
359
254
|
return result;
|
|
360
255
|
}
|
|
361
|
-
|
|
256
|
+
|
|
257
|
+
}
|
package/contracts/mocks/utils/mpc/{Comparison1Tests.Contract.sol → Comparison1TestsContract.sol}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
2
|
pragma solidity ^0.8.19;
|
|
4
3
|
|
|
5
4
|
import "../../../utils/mpc/MpcCore.sol";
|
|
@@ -41,74 +40,63 @@ contract Comparison1TestsContract {
|
|
|
41
40
|
gtBool res64_32;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
bool
|
|
43
|
+
bool gtResult;
|
|
44
|
+
bool leResult;
|
|
45
|
+
bool ltResult;
|
|
45
46
|
|
|
46
|
-
function
|
|
47
|
-
return
|
|
47
|
+
function getGtResult() public view returns (bool) {
|
|
48
|
+
return gtResult;
|
|
49
|
+
}
|
|
50
|
+
function getLeResult() public view returns (bool) {
|
|
51
|
+
return leResult;
|
|
52
|
+
}
|
|
53
|
+
function getLtResult() public view returns (bool) {
|
|
54
|
+
return ltResult;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
|
-
function setPublicValues(
|
|
51
|
-
AllGTCastingValues memory castingValues,
|
|
52
|
-
uint8 a,
|
|
53
|
-
uint8 b
|
|
54
|
-
) public {
|
|
57
|
+
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
55
58
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
56
59
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
57
|
-
castingValues.a16_s =
|
|
58
|
-
castingValues.b16_s =
|
|
59
|
-
castingValues.a32_s =
|
|
60
|
-
castingValues.b32_s =
|
|
61
|
-
castingValues.a64_s =
|
|
62
|
-
castingValues.b64_s =
|
|
60
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
61
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
62
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
63
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
64
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
65
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
function decryptAndCompareResults16(
|
|
66
|
-
|
|
67
|
-
) public returns (bool) {
|
|
68
|
+
function decryptAndCompareResults16(Check16 memory check16) public returns (bool){
|
|
69
|
+
|
|
68
70
|
// Calculate the result
|
|
69
71
|
bool result = MpcCore.decrypt(check16.res16_16);
|
|
70
72
|
|
|
71
|
-
require(
|
|
72
|
-
|
|
73
|
-
result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
75
|
-
);
|
|
73
|
+
require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
76
75
|
|
|
77
76
|
return result;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
function decryptAndCompareResults32(
|
|
81
|
-
|
|
82
|
-
) public returns (bool) {
|
|
79
|
+
function decryptAndCompareResults32(Check32 memory check32) public returns (bool){
|
|
80
|
+
|
|
83
81
|
// Calculate the result
|
|
84
82
|
bool result = MpcCore.decrypt(check32.res32_32);
|
|
85
83
|
|
|
86
|
-
require(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
result == MpcCore.decrypt(check32.res32_16) &&
|
|
90
|
-
result == MpcCore.decrypt(check32.res16_32),
|
|
91
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
92
|
-
);
|
|
84
|
+
require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
|
|
85
|
+
&& result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
|
|
86
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
93
87
|
|
|
94
88
|
return result;
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
function decryptAndCompareResults64(
|
|
98
|
-
|
|
99
|
-
) public returns (bool) {
|
|
91
|
+
function decryptAndCompareResults64(Check64 memory check64) public returns (bool){
|
|
92
|
+
|
|
100
93
|
// Calculate the result
|
|
101
94
|
bool result = MpcCore.decrypt(check64.res64_64);
|
|
102
95
|
|
|
103
|
-
require(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
);
|
|
96
|
+
require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
|
|
97
|
+
&& result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
|
|
98
|
+
&& result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
|
|
99
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
112
100
|
|
|
113
101
|
return result;
|
|
114
102
|
}
|
|
@@ -121,9 +109,8 @@ contract Comparison1TestsContract {
|
|
|
121
109
|
setPublicValues(castingValues, a, b);
|
|
122
110
|
|
|
123
111
|
// Calculate the expected result
|
|
124
|
-
result =
|
|
125
|
-
|
|
126
|
-
);
|
|
112
|
+
bool result = MpcCore.decrypt(MpcCore.gt(castingValues.a8_s, castingValues.b8_s));
|
|
113
|
+
gtResult = result;
|
|
127
114
|
|
|
128
115
|
// Calculate the results with cating to 16
|
|
129
116
|
check16.res16_16 = MpcCore.gt(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -153,26 +140,14 @@ contract Comparison1TestsContract {
|
|
|
153
140
|
require(result == res64, "gtTest: cast 64 failed");
|
|
154
141
|
|
|
155
142
|
// Check the result with scalar
|
|
156
|
-
require(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"gtTest: test
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
);
|
|
143
|
+
require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a8_s, b)),
|
|
144
|
+
"gtTest: test 8 bits with scalar failed");
|
|
145
|
+
require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a16_s, b)),
|
|
146
|
+
"gtTest: test 16 bits with scalar failed");
|
|
147
|
+
require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a32_s, b)),
|
|
148
|
+
"gtTest: test 32 bits with scalar failed");
|
|
149
|
+
require(result == MpcCore.decrypt(MpcCore.gt(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.gt(castingValues.a64_s, b)),
|
|
150
|
+
"gtTest: test 64 bits with scalar failed");
|
|
176
151
|
|
|
177
152
|
return result;
|
|
178
153
|
}
|
|
@@ -185,9 +160,8 @@ contract Comparison1TestsContract {
|
|
|
185
160
|
setPublicValues(castingValues, a, b);
|
|
186
161
|
|
|
187
162
|
// Calculate the expected result
|
|
188
|
-
result =
|
|
189
|
-
|
|
190
|
-
);
|
|
163
|
+
bool result = MpcCore.decrypt(MpcCore.le(castingValues.a8_s, castingValues.b8_s));
|
|
164
|
+
leResult = result;
|
|
191
165
|
|
|
192
166
|
// Calculate the results with cating to 16
|
|
193
167
|
check16.res16_16 = MpcCore.le(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -217,26 +191,14 @@ contract Comparison1TestsContract {
|
|
|
217
191
|
require(result == res64, "leTest: cast 64 failed");
|
|
218
192
|
|
|
219
193
|
// Check the result with scalar
|
|
220
|
-
require(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"leTest: test
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
);
|
|
194
|
+
require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a8_s, b)),
|
|
195
|
+
"leTest: test 8 bits with scalar failed");
|
|
196
|
+
require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a16_s, b)),
|
|
197
|
+
"leTest: test 16 bits with scalar failed");
|
|
198
|
+
require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a32_s, b)),
|
|
199
|
+
"leTest: test 32 bits with scalar failed");
|
|
200
|
+
require(result == MpcCore.decrypt(MpcCore.le(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.le(castingValues.a64_s, b)),
|
|
201
|
+
"leTest: test 64 bits with scalar failed");
|
|
240
202
|
|
|
241
203
|
return result;
|
|
242
204
|
}
|
|
@@ -249,9 +211,8 @@ contract Comparison1TestsContract {
|
|
|
249
211
|
setPublicValues(castingValues, a, b);
|
|
250
212
|
|
|
251
213
|
// Calculate the expected result
|
|
252
|
-
result =
|
|
253
|
-
|
|
254
|
-
);
|
|
214
|
+
bool result = MpcCore.decrypt(MpcCore.lt(castingValues.a8_s, castingValues.b8_s));
|
|
215
|
+
ltResult = result;
|
|
255
216
|
|
|
256
217
|
// Calculate the results with cating to 16
|
|
257
218
|
check16.res16_16 = MpcCore.lt(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -281,27 +242,18 @@ contract Comparison1TestsContract {
|
|
|
281
242
|
require(result == res64, "letTest: cast 64 failed");
|
|
282
243
|
|
|
283
244
|
// Check the result with scalar
|
|
284
|
-
require(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
"letTest: test
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
);
|
|
245
|
+
require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a8_s, b)),
|
|
246
|
+
"letTest: test 8 bits with scalar failed");
|
|
247
|
+
require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a16_s, b)),
|
|
248
|
+
"letTest: test 16 bits with scalar failed");
|
|
249
|
+
require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a32_s, b)),
|
|
250
|
+
"letTest: test 32 bits with scalar failed");
|
|
251
|
+
require(result == MpcCore.decrypt(MpcCore.lt(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.lt(castingValues.a64_s, b)),
|
|
252
|
+
"letTest: test 64 bits with scalar failed");
|
|
304
253
|
|
|
305
254
|
return result;
|
|
306
255
|
}
|
|
307
|
-
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
}
|