@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,11 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
2
|
pragma solidity ^0.8.19;
|
|
4
3
|
|
|
5
4
|
import "../../../utils/mpc/MpcCore.sol";
|
|
6
5
|
|
|
7
6
|
contract Comparison2TestsContract {
|
|
8
|
-
|
|
7
|
+
|
|
9
8
|
struct AllGTCastingValues {
|
|
10
9
|
gtUint8 a8_s;
|
|
11
10
|
gtUint8 b8_s;
|
|
@@ -41,74 +40,65 @@ contract Comparison2TestsContract {
|
|
|
41
40
|
gtBool res64_32;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
function setPublicValues(
|
|
45
|
-
AllGTCastingValues memory castingValues,
|
|
46
|
-
uint8 a,
|
|
47
|
-
uint8 b
|
|
48
|
-
) public {
|
|
43
|
+
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
49
44
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
50
45
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
51
|
-
castingValues.a16_s =
|
|
52
|
-
castingValues.b16_s =
|
|
53
|
-
castingValues.a32_s =
|
|
54
|
-
castingValues.b32_s =
|
|
55
|
-
castingValues.a64_s =
|
|
56
|
-
castingValues.b64_s =
|
|
46
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
47
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
48
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
49
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
50
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
51
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
bool
|
|
54
|
+
bool eqResult;
|
|
55
|
+
bool neResult;
|
|
56
|
+
bool geResult;
|
|
60
57
|
|
|
61
|
-
function
|
|
62
|
-
return
|
|
58
|
+
function getEqResult() public view returns (bool) {
|
|
59
|
+
return eqResult;
|
|
63
60
|
}
|
|
64
61
|
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
function getNeResult() public view returns (bool) {
|
|
63
|
+
return neResult;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getGeResult() public view returns (bool) {
|
|
67
|
+
return geResult;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function decryptAndCompareResults16(Check16 memory check16) public returns (bool){
|
|
71
|
+
|
|
68
72
|
// Calculate the result
|
|
69
73
|
bool result = MpcCore.decrypt(check16.res16_16);
|
|
70
74
|
|
|
71
|
-
require(
|
|
72
|
-
|
|
73
|
-
result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
75
|
-
);
|
|
75
|
+
require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
|
|
76
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
76
77
|
|
|
77
78
|
return result;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
function decryptAndCompareResults32(
|
|
81
|
-
|
|
82
|
-
) public returns (bool) {
|
|
81
|
+
function decryptAndCompareResults32(Check32 memory check32) public returns (bool){
|
|
82
|
+
|
|
83
83
|
// Calculate the result
|
|
84
84
|
bool result = MpcCore.decrypt(check32.res32_32);
|
|
85
85
|
|
|
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
|
-
);
|
|
86
|
+
require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
|
|
87
|
+
&& result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
|
|
88
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
93
89
|
|
|
94
90
|
return result;
|
|
95
91
|
}
|
|
96
92
|
|
|
97
|
-
function decryptAndCompareResults64(
|
|
98
|
-
|
|
99
|
-
) public returns (bool) {
|
|
93
|
+
function decryptAndCompareResults64(Check64 memory check64) public returns (bool){
|
|
94
|
+
|
|
100
95
|
// Calculate the result
|
|
101
96
|
bool result = MpcCore.decrypt(check64.res64_64);
|
|
102
97
|
|
|
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
|
-
);
|
|
98
|
+
require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
|
|
99
|
+
&& result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
|
|
100
|
+
&& result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
|
|
101
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
112
102
|
|
|
113
103
|
return result;
|
|
114
104
|
}
|
|
@@ -121,9 +111,8 @@ contract Comparison2TestsContract {
|
|
|
121
111
|
setPublicValues(castingValues, a, b);
|
|
122
112
|
|
|
123
113
|
// Calculate the expected result
|
|
124
|
-
result =
|
|
125
|
-
|
|
126
|
-
);
|
|
114
|
+
bool result = MpcCore.decrypt(MpcCore.eq(castingValues.a8_s, castingValues.b8_s));
|
|
115
|
+
eqResult = result;
|
|
127
116
|
|
|
128
117
|
// Calculate the results with casting to 16
|
|
129
118
|
check16.res16_16 = MpcCore.eq(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -153,26 +142,14 @@ contract Comparison2TestsContract {
|
|
|
153
142
|
require(result == res64, "eqTest: cast 64 failed");
|
|
154
143
|
|
|
155
144
|
// Check the result with scalar
|
|
156
|
-
require(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
"eqTest: test
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
"eqTest: test 16 bits with scalar failed"
|
|
165
|
-
);
|
|
166
|
-
require(
|
|
167
|
-
result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b32_s)) &&
|
|
168
|
-
result == MpcCore.decrypt(MpcCore.eq(castingValues.a32_s, b)),
|
|
169
|
-
"eqTest: test 32 bits with scalar failed"
|
|
170
|
-
);
|
|
171
|
-
require(
|
|
172
|
-
result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b64_s)) &&
|
|
173
|
-
result == MpcCore.decrypt(MpcCore.eq(castingValues.a64_s, b)),
|
|
174
|
-
"eqTest: test 64 bits with scalar failed"
|
|
175
|
-
);
|
|
145
|
+
require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a8_s, b)),
|
|
146
|
+
"eqTest: test 8 bits with scalar failed");
|
|
147
|
+
require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a16_s, b)),
|
|
148
|
+
"eqTest: test 16 bits with scalar failed");
|
|
149
|
+
require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a32_s, b)),
|
|
150
|
+
"eqTest: test 32 bits with scalar failed");
|
|
151
|
+
require(result == MpcCore.decrypt(MpcCore.eq(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.eq(castingValues.a64_s, b)),
|
|
152
|
+
"eqTest: test 64 bits with scalar failed");
|
|
176
153
|
|
|
177
154
|
return result;
|
|
178
155
|
}
|
|
@@ -185,9 +162,8 @@ contract Comparison2TestsContract {
|
|
|
185
162
|
setPublicValues(castingValues, a, b);
|
|
186
163
|
|
|
187
164
|
// Calculate the expected result
|
|
188
|
-
result =
|
|
189
|
-
|
|
190
|
-
);
|
|
165
|
+
bool result = MpcCore.decrypt(MpcCore.ne(castingValues.a8_s, castingValues.b8_s));
|
|
166
|
+
neResult = result;
|
|
191
167
|
|
|
192
168
|
// Calculate the results with casting to 16
|
|
193
169
|
check16.res16_16 = MpcCore.ne(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -217,26 +193,14 @@ contract Comparison2TestsContract {
|
|
|
217
193
|
require(result == res64, "neTest: cast 64 failed");
|
|
218
194
|
|
|
219
195
|
// Check the result with scalar
|
|
220
|
-
require(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
"neTest: test
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
"neTest: test 16 bits with scalar failed"
|
|
229
|
-
);
|
|
230
|
-
require(
|
|
231
|
-
result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b32_s)) &&
|
|
232
|
-
result == MpcCore.decrypt(MpcCore.ne(castingValues.a32_s, b)),
|
|
233
|
-
"neTest: test 32 bits with scalar failed"
|
|
234
|
-
);
|
|
235
|
-
require(
|
|
236
|
-
result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b64_s)) &&
|
|
237
|
-
result == MpcCore.decrypt(MpcCore.ne(castingValues.a64_s, b)),
|
|
238
|
-
"neTest: test 64 bits with scalar failed"
|
|
239
|
-
);
|
|
196
|
+
require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a8_s, b)),
|
|
197
|
+
"neTest: test 8 bits with scalar failed");
|
|
198
|
+
require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a16_s, b)),
|
|
199
|
+
"neTest: test 16 bits with scalar failed");
|
|
200
|
+
require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a32_s, b)),
|
|
201
|
+
"neTest: test 32 bits with scalar failed");
|
|
202
|
+
require(result == MpcCore.decrypt(MpcCore.ne(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.ne(castingValues.a64_s, b)),
|
|
203
|
+
"neTest: test 64 bits with scalar failed");
|
|
240
204
|
|
|
241
205
|
return result;
|
|
242
206
|
}
|
|
@@ -249,9 +213,8 @@ contract Comparison2TestsContract {
|
|
|
249
213
|
setPublicValues(castingValues, a, b);
|
|
250
214
|
|
|
251
215
|
// Calculate the expected result
|
|
252
|
-
result =
|
|
253
|
-
|
|
254
|
-
);
|
|
216
|
+
bool result = MpcCore.decrypt(MpcCore.ge(castingValues.a8_s, castingValues.b8_s));
|
|
217
|
+
geResult = result;
|
|
255
218
|
|
|
256
219
|
// Calculate the results with casting to 16
|
|
257
220
|
check16.res16_16 = MpcCore.ge(castingValues.a16_s, castingValues.b16_s);
|
|
@@ -281,27 +244,16 @@ contract Comparison2TestsContract {
|
|
|
281
244
|
require(result == res64, "geTest: cast 64 failed");
|
|
282
245
|
|
|
283
246
|
// Check the result with scalar
|
|
284
|
-
require(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
"geTest: test
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
"geTest: test 16 bits with scalar failed"
|
|
293
|
-
);
|
|
294
|
-
require(
|
|
295
|
-
result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b32_s)) &&
|
|
296
|
-
result == MpcCore.decrypt(MpcCore.ge(castingValues.a32_s, b)),
|
|
297
|
-
"geTest: test 32 bits with scalar failed"
|
|
298
|
-
);
|
|
299
|
-
require(
|
|
300
|
-
result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b64_s)) &&
|
|
301
|
-
result == MpcCore.decrypt(MpcCore.ge(castingValues.a64_s, b)),
|
|
302
|
-
"geTest: test 64 bits with scalar failed"
|
|
303
|
-
);
|
|
247
|
+
require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a8_s, b)),
|
|
248
|
+
"geTest: test 8 bits with scalar failed");
|
|
249
|
+
require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a16_s, b)),
|
|
250
|
+
"geTest: test 16 bits with scalar failed");
|
|
251
|
+
require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a32_s, b)),
|
|
252
|
+
"geTest: test 32 bits with scalar failed");
|
|
253
|
+
require(result == MpcCore.decrypt(MpcCore.ge(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.ge(castingValues.a64_s, b)),
|
|
254
|
+
"geTest: test 64 bits with scalar failed");
|
|
304
255
|
|
|
305
256
|
return result;
|
|
306
257
|
}
|
|
307
|
-
|
|
258
|
+
|
|
259
|
+
}
|
|
@@ -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,59 @@ contract MinMaxTestsContract {
|
|
|
41
40
|
gtUint64 res64_32;
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
function setPublicValues(
|
|
45
|
-
AllGTCastingValues memory castingValues,
|
|
46
|
-
uint8 a,
|
|
47
|
-
uint8 b
|
|
48
|
-
) public {
|
|
43
|
+
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
49
44
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
50
45
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
51
|
-
castingValues.a16_s =
|
|
52
|
-
castingValues.b16_s =
|
|
53
|
-
castingValues.a32_s =
|
|
54
|
-
castingValues.b32_s =
|
|
55
|
-
castingValues.a64_s =
|
|
56
|
-
castingValues.b64_s =
|
|
46
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
47
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
48
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
49
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
50
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
51
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
uint8
|
|
54
|
+
uint8 minResult;
|
|
55
|
+
uint8 maxResult;
|
|
60
56
|
|
|
61
|
-
function
|
|
62
|
-
return
|
|
57
|
+
function getMinResult() public view returns (uint8) {
|
|
58
|
+
return minResult;
|
|
63
59
|
}
|
|
60
|
+
function getMaxResult() public view returns (uint8) {
|
|
61
|
+
return maxResult;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){
|
|
64
65
|
|
|
65
|
-
function decryptAndCompareResults16(
|
|
66
|
-
Check16 memory check16
|
|
67
|
-
) public returns (uint16) {
|
|
68
66
|
// Calculate the result
|
|
69
67
|
uint16 result = MpcCore.decrypt(check16.res16_16);
|
|
70
68
|
|
|
71
|
-
require(
|
|
72
|
-
|
|
73
|
-
result == MpcCore.decrypt(check16.res16_8),
|
|
74
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
75
|
-
);
|
|
69
|
+
require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
|
|
70
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
76
71
|
|
|
77
72
|
return result;
|
|
78
73
|
}
|
|
79
74
|
|
|
80
|
-
function decryptAndCompareResults32(
|
|
81
|
-
|
|
82
|
-
) public returns (uint32) {
|
|
75
|
+
function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){
|
|
76
|
+
|
|
83
77
|
// Calculate the result
|
|
84
78
|
uint32 result = MpcCore.decrypt(check32.res32_32);
|
|
85
79
|
|
|
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
|
-
);
|
|
80
|
+
require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
|
|
81
|
+
&& result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
|
|
82
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
93
83
|
|
|
94
84
|
return result;
|
|
95
85
|
}
|
|
96
86
|
|
|
97
|
-
function decryptAndCompareResults64(
|
|
98
|
-
|
|
99
|
-
) public returns (uint64) {
|
|
87
|
+
function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){
|
|
88
|
+
|
|
100
89
|
// Calculate the result
|
|
101
90
|
uint64 result = MpcCore.decrypt(check64.res64_64);
|
|
102
91
|
|
|
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
|
-
);
|
|
92
|
+
require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
|
|
93
|
+
&& result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
|
|
94
|
+
&& result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
|
|
95
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
112
96
|
|
|
113
97
|
return result;
|
|
114
98
|
}
|
|
@@ -121,85 +105,45 @@ contract MinMaxTestsContract {
|
|
|
121
105
|
setPublicValues(castingValues, a, b);
|
|
122
106
|
|
|
123
107
|
// Calculate the expected result
|
|
124
|
-
result =
|
|
125
|
-
|
|
126
|
-
);
|
|
108
|
+
uint8 result = MpcCore.decrypt(MpcCore.min(castingValues.a8_s, castingValues.b8_s));
|
|
109
|
+
minResult = result;
|
|
127
110
|
|
|
128
111
|
// Calculate the results with casting to 16
|
|
129
|
-
check16.res16_16 = MpcCore.min(
|
|
130
|
-
castingValues.a16_s,
|
|
131
|
-
castingValues.b16_s
|
|
132
|
-
);
|
|
112
|
+
check16.res16_16 = MpcCore.min(castingValues.a16_s, castingValues.b16_s);
|
|
133
113
|
check16.res8_16 = MpcCore.min(castingValues.a8_s, castingValues.b16_s);
|
|
134
114
|
check16.res16_8 = MpcCore.min(castingValues.a16_s, castingValues.b8_s);
|
|
135
115
|
uint16 res16 = decryptAndCompareResults16(check16);
|
|
136
116
|
require(res16 == result, "minTest: cast 16 failed");
|
|
137
117
|
|
|
138
118
|
// Calculate the result with casting to 32
|
|
139
|
-
check32.res32_32 = MpcCore.min(
|
|
140
|
-
castingValues.a32_s,
|
|
141
|
-
castingValues.b32_s
|
|
142
|
-
);
|
|
119
|
+
check32.res32_32 = MpcCore.min(castingValues.a32_s, castingValues.b32_s);
|
|
143
120
|
check32.res8_32 = MpcCore.min(castingValues.a8_s, castingValues.b32_s);
|
|
144
121
|
check32.res32_8 = MpcCore.min(castingValues.a32_s, castingValues.b8_s);
|
|
145
|
-
check32.res16_32 = MpcCore.min(
|
|
146
|
-
|
|
147
|
-
castingValues.b32_s
|
|
148
|
-
);
|
|
149
|
-
check32.res32_16 = MpcCore.min(
|
|
150
|
-
castingValues.a32_s,
|
|
151
|
-
castingValues.b16_s
|
|
152
|
-
);
|
|
122
|
+
check32.res16_32 = MpcCore.min(castingValues.a16_s, castingValues.b32_s);
|
|
123
|
+
check32.res32_16 = MpcCore.min(castingValues.a32_s, castingValues.b16_s);
|
|
153
124
|
uint32 res32 = decryptAndCompareResults32(check32);
|
|
154
125
|
require(result == res32, "minTest: cast 32 failed");
|
|
155
126
|
|
|
156
127
|
// Calculate the result with casting to 64
|
|
157
|
-
check64.res64_64 = MpcCore.min(
|
|
158
|
-
castingValues.a64_s,
|
|
159
|
-
castingValues.b64_s
|
|
160
|
-
);
|
|
128
|
+
check64.res64_64 = MpcCore.min(castingValues.a64_s, castingValues.b64_s);
|
|
161
129
|
check64.res8_64 = MpcCore.min(castingValues.a8_s, castingValues.b64_s);
|
|
162
130
|
check64.res64_8 = MpcCore.min(castingValues.a64_s, castingValues.b8_s);
|
|
163
|
-
check64.res16_64 = MpcCore.min(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
167
|
-
check64.res64_16 = MpcCore.min(
|
|
168
|
-
castingValues.a64_s,
|
|
169
|
-
castingValues.b16_s
|
|
170
|
-
);
|
|
171
|
-
check64.res32_64 = MpcCore.min(
|
|
172
|
-
castingValues.a32_s,
|
|
173
|
-
castingValues.b64_s
|
|
174
|
-
);
|
|
175
|
-
check64.res64_32 = MpcCore.min(
|
|
176
|
-
castingValues.a64_s,
|
|
177
|
-
castingValues.b32_s
|
|
178
|
-
);
|
|
131
|
+
check64.res16_64 = MpcCore.min(castingValues.a16_s, castingValues.b64_s);
|
|
132
|
+
check64.res64_16 = MpcCore.min(castingValues.a64_s, castingValues.b16_s);
|
|
133
|
+
check64.res32_64 = MpcCore.min(castingValues.a32_s, castingValues.b64_s);
|
|
134
|
+
check64.res64_32 = MpcCore.min(castingValues.a64_s, castingValues.b32_s);
|
|
179
135
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
180
136
|
require(result == res64, "minTest: cast 64 failed");
|
|
181
137
|
|
|
182
138
|
// Check the result with scalar
|
|
183
|
-
require(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
"minTest: test
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
"minTest: test 16 bits with scalar failed"
|
|
192
|
-
);
|
|
193
|
-
require(
|
|
194
|
-
res32 == MpcCore.decrypt(MpcCore.min(a, castingValues.b32_s)) &&
|
|
195
|
-
res32 == MpcCore.decrypt(MpcCore.min(castingValues.a32_s, b)),
|
|
196
|
-
"minTest: test 32 bits with scalar failed"
|
|
197
|
-
);
|
|
198
|
-
require(
|
|
199
|
-
res64 == MpcCore.decrypt(MpcCore.min(a, castingValues.b64_s)) &&
|
|
200
|
-
res64 == MpcCore.decrypt(MpcCore.min(castingValues.a64_s, b)),
|
|
201
|
-
"minTest: test 64 bits with scalar failed"
|
|
202
|
-
);
|
|
139
|
+
require(result == MpcCore.decrypt(MpcCore.min(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.min(castingValues.a8_s, b)),
|
|
140
|
+
"minTest: test 8 bits with scalar failed");
|
|
141
|
+
require(res16 == MpcCore.decrypt(MpcCore.min(a, castingValues.b16_s)) && res16 == MpcCore.decrypt(MpcCore.min(castingValues.a16_s, b)),
|
|
142
|
+
"minTest: test 16 bits with scalar failed");
|
|
143
|
+
require(res32 == MpcCore.decrypt(MpcCore.min(a, castingValues.b32_s)) && res32 == MpcCore.decrypt(MpcCore.min(castingValues.a32_s, b)),
|
|
144
|
+
"minTest: test 32 bits with scalar failed");
|
|
145
|
+
require(res64 == MpcCore.decrypt(MpcCore.min(a, castingValues.b64_s)) && res64 == MpcCore.decrypt(MpcCore.min(castingValues.a64_s, b)),
|
|
146
|
+
"minTest: test 64 bits with scalar failed");
|
|
203
147
|
|
|
204
148
|
return result;
|
|
205
149
|
}
|
|
@@ -212,86 +156,47 @@ contract MinMaxTestsContract {
|
|
|
212
156
|
setPublicValues(castingValues, a, b);
|
|
213
157
|
|
|
214
158
|
// Calculate the expected result
|
|
215
|
-
result =
|
|
216
|
-
|
|
217
|
-
);
|
|
159
|
+
uint8 result = MpcCore.decrypt(MpcCore.max(castingValues.a8_s, castingValues.b8_s));
|
|
160
|
+
maxResult = result;
|
|
218
161
|
|
|
219
162
|
// Calculate the results with casting to 16
|
|
220
|
-
check16.res16_16 = MpcCore.max(
|
|
221
|
-
castingValues.a16_s,
|
|
222
|
-
castingValues.b16_s
|
|
223
|
-
);
|
|
163
|
+
check16.res16_16 = MpcCore.max(castingValues.a16_s, castingValues.b16_s);
|
|
224
164
|
check16.res8_16 = MpcCore.max(castingValues.a8_s, castingValues.b16_s);
|
|
225
165
|
check16.res16_8 = MpcCore.max(castingValues.a16_s, castingValues.b8_s);
|
|
226
166
|
uint16 res16 = decryptAndCompareResults16(check16);
|
|
227
167
|
require(res16 == result, "maxTest: cast 16 failed");
|
|
228
168
|
|
|
229
169
|
// Calculate the result with casting to 32
|
|
230
|
-
check32.res32_32 = MpcCore.max(
|
|
231
|
-
castingValues.a32_s,
|
|
232
|
-
castingValues.b32_s
|
|
233
|
-
);
|
|
170
|
+
check32.res32_32 = MpcCore.max(castingValues.a32_s, castingValues.b32_s);
|
|
234
171
|
check32.res8_32 = MpcCore.max(castingValues.a8_s, castingValues.b32_s);
|
|
235
172
|
check32.res32_8 = MpcCore.max(castingValues.a32_s, castingValues.b8_s);
|
|
236
|
-
check32.res16_32 = MpcCore.max(
|
|
237
|
-
|
|
238
|
-
castingValues.b32_s
|
|
239
|
-
);
|
|
240
|
-
check32.res32_16 = MpcCore.max(
|
|
241
|
-
castingValues.a32_s,
|
|
242
|
-
castingValues.b16_s
|
|
243
|
-
);
|
|
173
|
+
check32.res16_32 = MpcCore.max(castingValues.a16_s, castingValues.b32_s);
|
|
174
|
+
check32.res32_16 = MpcCore.max(castingValues.a32_s, castingValues.b16_s);
|
|
244
175
|
uint32 res32 = decryptAndCompareResults32(check32);
|
|
245
176
|
require(result == res32, "maxTest: cast 32 failed");
|
|
246
177
|
|
|
247
178
|
// Calculate the result with casting to 64
|
|
248
|
-
check64.res64_64 = MpcCore.max(
|
|
249
|
-
castingValues.a64_s,
|
|
250
|
-
castingValues.b64_s
|
|
251
|
-
);
|
|
179
|
+
check64.res64_64 = MpcCore.max(castingValues.a64_s, castingValues.b64_s);
|
|
252
180
|
check64.res8_64 = MpcCore.max(castingValues.a8_s, castingValues.b64_s);
|
|
253
181
|
check64.res64_8 = MpcCore.max(castingValues.a64_s, castingValues.b8_s);
|
|
254
|
-
check64.res16_64 = MpcCore.max(
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
);
|
|
258
|
-
check64.res64_16 = MpcCore.max(
|
|
259
|
-
castingValues.a64_s,
|
|
260
|
-
castingValues.b16_s
|
|
261
|
-
);
|
|
262
|
-
check64.res32_64 = MpcCore.max(
|
|
263
|
-
castingValues.a32_s,
|
|
264
|
-
castingValues.b64_s
|
|
265
|
-
);
|
|
266
|
-
check64.res64_32 = MpcCore.max(
|
|
267
|
-
castingValues.a64_s,
|
|
268
|
-
castingValues.b32_s
|
|
269
|
-
);
|
|
182
|
+
check64.res16_64 = MpcCore.max(castingValues.a16_s, castingValues.b64_s);
|
|
183
|
+
check64.res64_16 = MpcCore.max(castingValues.a64_s, castingValues.b16_s);
|
|
184
|
+
check64.res32_64 = MpcCore.max(castingValues.a32_s, castingValues.b64_s);
|
|
185
|
+
check64.res64_32 = MpcCore.max(castingValues.a64_s, castingValues.b32_s);
|
|
270
186
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
271
187
|
require(result == res64, "maxTest: cast 64 failed");
|
|
272
188
|
|
|
273
189
|
// Check the result with scalar
|
|
274
|
-
require(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
"minTest: test
|
|
278
|
-
)
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
"minTest: test 16 bits with scalar failed"
|
|
283
|
-
);
|
|
284
|
-
require(
|
|
285
|
-
res32 == MpcCore.decrypt(MpcCore.max(a, castingValues.b32_s)) &&
|
|
286
|
-
res32 == MpcCore.decrypt(MpcCore.max(castingValues.a32_s, b)),
|
|
287
|
-
"minTest: test 32 bits with scalar failed"
|
|
288
|
-
);
|
|
289
|
-
require(
|
|
290
|
-
res64 == MpcCore.decrypt(MpcCore.max(a, castingValues.b64_s)) &&
|
|
291
|
-
res64 == MpcCore.decrypt(MpcCore.max(castingValues.a64_s, b)),
|
|
292
|
-
"minTest: test 64 bits with scalar failed"
|
|
293
|
-
);
|
|
190
|
+
require(result == MpcCore.decrypt(MpcCore.max(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.max(castingValues.a8_s, b)),
|
|
191
|
+
"minTest: test 8 bits with scalar failed");
|
|
192
|
+
require(res16 == MpcCore.decrypt(MpcCore.max(a, castingValues.b16_s)) && res16 == MpcCore.decrypt(MpcCore.max(castingValues.a16_s, b)),
|
|
193
|
+
"minTest: test 16 bits with scalar failed");
|
|
194
|
+
require(res32 == MpcCore.decrypt(MpcCore.max(a, castingValues.b32_s)) && res32 == MpcCore.decrypt(MpcCore.max(castingValues.a32_s, b)),
|
|
195
|
+
"minTest: test 32 bits with scalar failed");
|
|
196
|
+
require(res64 == MpcCore.decrypt(MpcCore.max(a, castingValues.b64_s)) && res64 == MpcCore.decrypt(MpcCore.max(castingValues.a64_s, b)),
|
|
197
|
+
"minTest: test 64 bits with scalar failed");
|
|
294
198
|
|
|
295
199
|
return result;
|
|
296
200
|
}
|
|
297
|
-
|
|
201
|
+
|
|
202
|
+
}
|