@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.
Files changed (71) hide show
  1. package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +3 -115
  2. package/contracts/mocks/README.md +1 -1
  3. package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +105 -280
  4. package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +83 -187
  5. package/contracts/mocks/utils/mpc/{Comparison1Tests.Contract.sol → Comparison1TestsContract.sol} +67 -115
  6. package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +68 -116
  7. package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +69 -164
  8. package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +70 -52
  9. package/contracts/mocks/utils/mpc/MiscellaneousTestsContract.sol +270 -0
  10. package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +102 -0
  11. package/contracts/mocks/utils/mpc/README.md +12 -12
  12. package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +54 -211
  13. package/contracts/mocks/utils/mpc/TransferTestsContract.sol +162 -640
  14. package/contracts/onboard/AccountOnboard.sol +3 -3
  15. package/contracts/utils/mpc/MpcCore.sol +2835 -988
  16. package/contracts/utils/mpc/MpcInterface.sol +6 -4
  17. package/hardhat.config.ts +8 -5
  18. package/package.json +2 -2
  19. package/test/utils/accounts.ts +1 -1
  20. package/test/utils/mpc/Precompile.test.ts +26 -37
  21. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract.ts +374 -0
  22. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract.ts +374 -0
  23. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
  24. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +30 -10
  25. package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +39 -5
  26. package/typechain-types/contracts/mocks/utils/mpc/Comparison1TestsContract.ts +374 -0
  27. package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +39 -5
  28. package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +25 -5
  29. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +62 -0
  30. package/typechain-types/contracts/mocks/utils/mpc/MiscellaneousTestsContract.ts +396 -0
  31. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +221 -0
  32. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +11 -8
  33. package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +15 -15
  34. package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +15 -15
  35. package/typechain-types/contracts/mocks/utils/mpc/index.ts +3 -6
  36. package/typechain-types/contracts/onboard/AccountOnboard.ts +9 -4
  37. package/typechain-types/contracts/utils/mpc/MpcCore.ts +84 -0
  38. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +81 -40
  39. package/typechain-types/contracts/utils/mpc/index.ts +1 -0
  40. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
  41. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
  42. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
  43. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract__factory.ts +387 -0
  44. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract__factory.ts +388 -0
  45. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
  46. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +20 -7
  47. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +28 -2
  48. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +1 -1
  49. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +387 -0
  50. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +28 -2
  51. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +15 -2
  52. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +66 -1
  53. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +1 -1
  54. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +424 -0
  55. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +289 -0
  56. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +19 -3
  57. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  58. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  59. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +4 -4
  60. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +4 -4
  61. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +3 -4
  62. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
  63. package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +8 -2
  64. package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +77 -0
  65. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +124 -61
  66. package/typechain-types/factories/contracts/utils/mpc/index.ts +1 -0
  67. package/typechain-types/hardhat.d.ts +26 -26
  68. package/typechain-types/index.ts +8 -8
  69. package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +0 -448
  70. package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +0 -81
  71. 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 ArithmeticTestsContract {
8
-
7
+
9
8
  struct AllGTCastingValues {
10
9
  gtUint8 a8_s;
11
10
  gtUint8 b8_s;
@@ -23,12 +22,6 @@ contract ArithmeticTestsContract {
23
22
  gtUint16 res16_8;
24
23
  }
25
24
 
26
- struct CheckMul16 {
27
- gtUint32 res16_16;
28
- gtUint32 res8_16;
29
- gtUint32 res16_8;
30
- }
31
-
32
25
  struct Check32 {
33
26
  gtUint32 res32_32;
34
27
  gtUint32 res8_32;
@@ -37,14 +30,6 @@ contract ArithmeticTestsContract {
37
30
  gtUint32 res32_16;
38
31
  }
39
32
 
40
- struct CheckMul32 {
41
- gtUint64 res32_32;
42
- gtUint64 res8_32;
43
- gtUint64 res32_8;
44
- gtUint64 res16_32;
45
- gtUint64 res32_16;
46
- }
47
-
48
33
  struct Check64 {
49
34
  gtUint64 res64_64;
50
35
  gtUint64 res8_64;
@@ -55,78 +40,64 @@ contract ArithmeticTestsContract {
55
40
  gtUint64 res64_32;
56
41
  }
57
42
 
58
- uint8 result;
59
- uint16 result16;
43
+ uint8 addResult;
44
+ uint8 subResult;
45
+ uint8 mulResult;
60
46
 
61
- function getResult() public view returns (uint8) {
62
- return result;
47
+ function getAddResult() public view returns (uint8) {
48
+ return addResult;
49
+ }
50
+
51
+ function getSubResult() public view returns (uint8) {
52
+ return subResult;
63
53
  }
64
54
 
65
- function getResult16() public view returns (uint16) {
66
- return result16;
55
+ function getMulResult() public view returns (uint8) {
56
+ return mulResult;
67
57
  }
68
58
 
69
- function setPublicValues(
70
- AllGTCastingValues memory castingValues,
71
- uint8 a,
72
- uint8 b
73
- ) public {
59
+ function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
74
60
  castingValues.a8_s = MpcCore.setPublic8(a);
75
61
  castingValues.b8_s = MpcCore.setPublic8(b);
76
- castingValues.a16_s = MpcCore.setPublic16(a);
77
- castingValues.b16_s = MpcCore.setPublic16(b);
78
- castingValues.a32_s = MpcCore.setPublic32(a);
79
- castingValues.b32_s = MpcCore.setPublic32(b);
80
- castingValues.a64_s = MpcCore.setPublic64(a);
81
- castingValues.b64_s = MpcCore.setPublic64(b);
62
+ castingValues.a16_s = MpcCore.setPublic16(a);
63
+ castingValues.b16_s = MpcCore.setPublic16(b);
64
+ castingValues.a32_s = MpcCore.setPublic32(a);
65
+ castingValues.b32_s = MpcCore.setPublic32(b);
66
+ castingValues.a64_s = MpcCore.setPublic64(a);
67
+ castingValues.b64_s = MpcCore.setPublic64(b);
82
68
  }
83
69
 
84
- function decryptAndCompareResults16(
85
- Check16 memory check16
86
- ) public returns (uint16) {
70
+ function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){
71
+
87
72
  // Calculate the result
88
73
  uint16 result = MpcCore.decrypt(check16.res16_16);
89
74
 
90
- require(
91
- result == MpcCore.decrypt(check16.res8_16) &&
92
- result == MpcCore.decrypt(check16.res16_8),
93
- "decryptAndCompareAllResults: Failed to decrypt and compare all results"
94
- );
75
+ require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
76
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
95
77
  return result;
96
78
  }
97
79
 
98
- function decryptAndCompareResults32(
99
- Check32 memory check32
100
- ) public returns (uint32) {
80
+ function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){
81
+
101
82
  // Calculate the result
102
83
  uint32 result = MpcCore.decrypt(check32.res32_32);
103
84
 
104
- require(
105
- result == MpcCore.decrypt(check32.res8_32) &&
106
- result == MpcCore.decrypt(check32.res32_8) &&
107
- result == MpcCore.decrypt(check32.res32_16) &&
108
- result == MpcCore.decrypt(check32.res16_32),
109
- "decryptAndCompareAllResults: Failed to decrypt and compare all results"
110
- );
85
+ require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
86
+ && result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
87
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
111
88
 
112
89
  return result;
113
90
  }
114
91
 
115
- function decryptAndCompareResults64(
116
- Check64 memory check64
117
- ) public returns (uint64) {
92
+ function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){
93
+
118
94
  // Calculate the result
119
95
  uint64 result = MpcCore.decrypt(check64.res64_64);
120
96
 
121
- require(
122
- result == MpcCore.decrypt(check64.res8_64) &&
123
- result == MpcCore.decrypt(check64.res64_8) &&
124
- result == MpcCore.decrypt(check64.res64_16) &&
125
- result == MpcCore.decrypt(check64.res16_64) &&
126
- result == MpcCore.decrypt(check64.res64_32) &&
127
- result == MpcCore.decrypt(check64.res32_64),
128
- "decryptAndCompareAllResults: Failed to decrypt and compare all results"
129
- );
97
+ require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
98
+ && result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
99
+ && result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
100
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
130
101
 
131
102
  return result;
132
103
  }
@@ -139,85 +110,45 @@ contract ArithmeticTestsContract {
139
110
  setPublicValues(castingValues, a, b);
140
111
 
141
112
  // Calculate the expected result
142
- result = MpcCore.decrypt(
143
- MpcCore.add(castingValues.a8_s, castingValues.b8_s)
144
- );
113
+ uint8 result = MpcCore.decrypt(MpcCore.add(castingValues.a8_s, castingValues.b8_s));
114
+ addResult = result;
145
115
 
146
116
  // Calculate the results with casting to 16
147
- check16.res16_16 = MpcCore.add(
148
- castingValues.a16_s,
149
- castingValues.b16_s
150
- );
117
+ check16.res16_16 = MpcCore.add(castingValues.a16_s, castingValues.b16_s);
151
118
  check16.res8_16 = MpcCore.add(castingValues.a8_s, castingValues.b16_s);
152
119
  check16.res16_8 = MpcCore.add(castingValues.a16_s, castingValues.b8_s);
153
120
  uint16 res16 = decryptAndCompareResults16(check16);
154
121
  require(res16 == result, "addTest: cast 16 failed");
155
122
 
156
123
  // Calculate the result with casting to 32
157
- check32.res32_32 = MpcCore.add(
158
- castingValues.a32_s,
159
- castingValues.b32_s
160
- );
124
+ check32.res32_32 = MpcCore.add(castingValues.a32_s, castingValues.b32_s);
161
125
  check32.res8_32 = MpcCore.add(castingValues.a8_s, castingValues.b32_s);
162
126
  check32.res32_8 = MpcCore.add(castingValues.a32_s, castingValues.b8_s);
163
- check32.res16_32 = MpcCore.add(
164
- castingValues.a16_s,
165
- castingValues.b32_s
166
- );
167
- check32.res32_16 = MpcCore.add(
168
- castingValues.a32_s,
169
- castingValues.b16_s
170
- );
127
+ check32.res16_32 = MpcCore.add(castingValues.a16_s, castingValues.b32_s);
128
+ check32.res32_16 = MpcCore.add(castingValues.a32_s, castingValues.b16_s);
171
129
  uint32 res32 = decryptAndCompareResults32(check32);
172
130
  require(result == res32, "addTest: cast 32 failed");
173
131
 
174
132
  // Calculate the result with casting to 64
175
- check64.res64_64 = MpcCore.add(
176
- castingValues.a64_s,
177
- castingValues.b64_s
178
- );
133
+ check64.res64_64 = MpcCore.add(castingValues.a64_s, castingValues.b64_s);
179
134
  check64.res8_64 = MpcCore.add(castingValues.a8_s, castingValues.b64_s);
180
135
  check64.res64_8 = MpcCore.add(castingValues.a64_s, castingValues.b8_s);
181
- check64.res16_64 = MpcCore.add(
182
- castingValues.a16_s,
183
- castingValues.b64_s
184
- );
185
- check64.res64_16 = MpcCore.add(
186
- castingValues.a64_s,
187
- castingValues.b16_s
188
- );
189
- check64.res32_64 = MpcCore.add(
190
- castingValues.a32_s,
191
- castingValues.b64_s
192
- );
193
- check64.res64_32 = MpcCore.add(
194
- castingValues.a64_s,
195
- castingValues.b32_s
196
- );
136
+ check64.res16_64 = MpcCore.add(castingValues.a16_s, castingValues.b64_s);
137
+ check64.res64_16 = MpcCore.add(castingValues.a64_s, castingValues.b16_s);
138
+ check64.res32_64 = MpcCore.add(castingValues.a32_s, castingValues.b64_s);
139
+ check64.res64_32 = MpcCore.add(castingValues.a64_s, castingValues.b32_s);
197
140
  uint64 res64 = decryptAndCompareResults64(check64);
198
141
  require(result == res64, "addTest: cast 64 failed");
199
142
 
200
143
  // Check the result with scalar
201
- require(
202
- result == MpcCore.decrypt(MpcCore.add(a, castingValues.b8_s)) &&
203
- result == MpcCore.decrypt(MpcCore.add(castingValues.a8_s, b)),
204
- "addTest: test 8 bits with scalar failed"
205
- );
206
- require(
207
- result == MpcCore.decrypt(MpcCore.add(a, castingValues.b16_s)) &&
208
- result == MpcCore.decrypt(MpcCore.add(castingValues.a16_s, b)),
209
- "addTest: test 16 bits with scalar failed"
210
- );
211
- require(
212
- result == MpcCore.decrypt(MpcCore.add(a, castingValues.b32_s)) &&
213
- result == MpcCore.decrypt(MpcCore.add(castingValues.a32_s, b)),
214
- "addTest: test 32 bits with scalar failed"
215
- );
216
- require(
217
- result == MpcCore.decrypt(MpcCore.add(a, castingValues.b64_s)) &&
218
- result == MpcCore.decrypt(MpcCore.add(castingValues.a64_s, b)),
219
- "addTest: test 64 bits with scalar failed"
220
- );
144
+ require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a8_s, b)),
145
+ "addTest: test 8 bits with scalar failed");
146
+ require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a16_s, b)),
147
+ "addTest: test 16 bits with scalar failed");
148
+ require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a32_s, b)),
149
+ "addTest: test 32 bits with scalar failed");
150
+ require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a64_s, b)),
151
+ "addTest: test 64 bits with scalar failed");
221
152
 
222
153
  return result;
223
154
  }
@@ -230,202 +161,96 @@ contract ArithmeticTestsContract {
230
161
  setPublicValues(castingValues, a, b);
231
162
 
232
163
  // Calculate the expected result
233
- result = MpcCore.decrypt(
234
- MpcCore.sub(castingValues.a8_s, castingValues.b8_s)
235
- );
164
+ uint8 result = MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, castingValues.b8_s));
165
+ subResult = result;
236
166
 
237
167
  // Calculate the results with casting to 16
238
- check16.res16_16 = MpcCore.sub(
239
- castingValues.a16_s,
240
- castingValues.b16_s
241
- );
168
+ check16.res16_16 = MpcCore.sub(castingValues.a16_s, castingValues.b16_s);
242
169
  check16.res8_16 = MpcCore.sub(castingValues.a8_s, castingValues.b16_s);
243
170
  check16.res16_8 = MpcCore.sub(castingValues.a16_s, castingValues.b8_s);
244
171
  uint16 res16 = decryptAndCompareResults16(check16);
245
172
  require(res16 == result, "subTest: cast 16 failed");
246
173
 
247
174
  // Calculate the result with casting to 32
248
- check32.res32_32 = MpcCore.sub(
249
- castingValues.a32_s,
250
- castingValues.b32_s
251
- );
175
+ check32.res32_32 = MpcCore.sub(castingValues.a32_s, castingValues.b32_s);
252
176
  check32.res8_32 = MpcCore.sub(castingValues.a8_s, castingValues.b32_s);
253
177
  check32.res32_8 = MpcCore.sub(castingValues.a32_s, castingValues.b8_s);
254
- check32.res16_32 = MpcCore.sub(
255
- castingValues.a16_s,
256
- castingValues.b32_s
257
- );
258
- check32.res32_16 = MpcCore.sub(
259
- castingValues.a32_s,
260
- castingValues.b16_s
261
- );
178
+ check32.res16_32 = MpcCore.sub(castingValues.a16_s, castingValues.b32_s);
179
+ check32.res32_16 = MpcCore.sub(castingValues.a32_s, castingValues.b16_s);
262
180
  uint32 res32 = decryptAndCompareResults32(check32);
263
181
  require(result == res32, "subTest: cast 32 failed");
264
182
 
265
183
  // Calculate the result with casting to 64
266
- check64.res64_64 = MpcCore.sub(
267
- castingValues.a64_s,
268
- castingValues.b64_s
269
- );
184
+ check64.res64_64 = MpcCore.sub(castingValues.a64_s, castingValues.b64_s);
270
185
  check64.res8_64 = MpcCore.sub(castingValues.a8_s, castingValues.b64_s);
271
186
  check64.res64_8 = MpcCore.sub(castingValues.a64_s, castingValues.b8_s);
272
- check64.res16_64 = MpcCore.sub(
273
- castingValues.a16_s,
274
- castingValues.b64_s
275
- );
276
- check64.res64_16 = MpcCore.sub(
277
- castingValues.a64_s,
278
- castingValues.b16_s
279
- );
280
- check64.res32_64 = MpcCore.sub(
281
- castingValues.a32_s,
282
- castingValues.b64_s
283
- );
284
- check64.res64_32 = MpcCore.sub(
285
- castingValues.a64_s,
286
- castingValues.b32_s
287
- );
187
+ check64.res16_64 = MpcCore.sub(castingValues.a16_s, castingValues.b64_s);
188
+ check64.res64_16 = MpcCore.sub(castingValues.a64_s, castingValues.b16_s);
189
+ check64.res32_64 = MpcCore.sub(castingValues.a32_s, castingValues.b64_s);
190
+ check64.res64_32 = MpcCore.sub(castingValues.a64_s, castingValues.b32_s);
288
191
  uint64 res64 = decryptAndCompareResults64(check64);
289
192
  require(result == res64, "subTest: cast 64 failed");
290
193
 
291
194
  // Check the result with scalar
292
- require(
293
- result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b8_s)) &&
294
- result == MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, b)),
295
- "subTest: test 8 bits with scalar failed"
296
- );
297
- require(
298
- result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b16_s)) &&
299
- result == MpcCore.decrypt(MpcCore.sub(castingValues.a16_s, b)),
300
- "subTest: test 16 bits with scalar failed"
301
- );
302
- require(
303
- result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b32_s)) &&
304
- result == MpcCore.decrypt(MpcCore.sub(castingValues.a32_s, b)),
305
- "subTest: test 32 bits with scalar failed"
306
- );
307
- require(
308
- result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b64_s)) &&
309
- result == MpcCore.decrypt(MpcCore.sub(castingValues.a64_s, b)),
310
- "subTest: test 64 bits with scalar failed"
311
- );
195
+ require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, b)),
196
+ "subTest: test 8 bits with scalar failed");
197
+ require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a16_s, b)),
198
+ "subTest: test 16 bits with scalar failed");
199
+ require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a32_s, b)),
200
+ "subTest: test 32 bits with scalar failed");
201
+ require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a64_s, b)),
202
+ "subTest: test 64 bits with scalar failed");
312
203
 
313
204
  return result;
314
205
  }
315
206
 
316
- function mulTest(uint8 a, uint8 b) public returns (uint16) {
207
+ function mulTest(uint8 a, uint8 b) public returns (uint8) {
317
208
  AllGTCastingValues memory castingValues;
318
- CheckMul16 memory checkMul16;
319
- CheckMul32 memory checkMul32;
209
+ Check16 memory check16;
210
+ Check32 memory check32;
320
211
  Check64 memory check64;
321
212
  setPublicValues(castingValues, a, b);
322
213
 
323
214
  // Calculate the expected result
324
- result16 = MpcCore.decrypt(
325
- MpcCore.mul(castingValues.a8_s, castingValues.b8_s)
326
- );
215
+ mulResult = MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, castingValues.b8_s));
327
216
 
328
217
  // Calculate the result with casting to 16
329
- checkMul16.res16_16 = MpcCore.mul(
330
- castingValues.a16_s,
331
- castingValues.b16_s
332
- );
333
- checkMul16.res8_16 = MpcCore.mul(
334
- castingValues.a8_s,
335
- castingValues.b16_s
336
- );
337
- checkMul16.res16_8 = MpcCore.mul(
338
- castingValues.a16_s,
339
- castingValues.b8_s
340
- );
341
- require(
342
- result16 == MpcCore.decrypt(checkMul16.res16_16) &&
343
- result16 == MpcCore.decrypt(checkMul16.res8_16) &&
344
- result16 == MpcCore.decrypt(checkMul16.res16_8),
345
- "mulTest: cast 16 failed"
346
- );
218
+ check16.res16_16 = MpcCore.mul(castingValues.a16_s, castingValues.b16_s);
219
+ check16.res8_16 = MpcCore.mul(castingValues.a8_s, castingValues.b16_s);
220
+ check16.res16_8 = MpcCore.mul(castingValues.a16_s, castingValues.b8_s);
221
+ uint16 res16 = decryptAndCompareResults16(check16);
222
+ require(mulResult == res16, "mulTest: cast 16 failed");
347
223
 
348
224
  // Calculate the result with casting to 32
349
- checkMul32.res32_32 = MpcCore.mul(
350
- castingValues.a32_s,
351
- castingValues.b32_s
352
- );
353
- checkMul32.res8_32 = MpcCore.mul(
354
- castingValues.a8_s,
355
- castingValues.b32_s
356
- );
357
- checkMul32.res32_8 = MpcCore.mul(
358
- castingValues.a32_s,
359
- castingValues.b8_s
360
- );
361
- checkMul32.res16_32 = MpcCore.mul(
362
- castingValues.a16_s,
363
- castingValues.b32_s
364
- );
365
- checkMul32.res32_16 = MpcCore.mul(
366
- castingValues.a32_s,
367
- castingValues.b16_s
368
- );
369
- require(
370
- result16 == MpcCore.decrypt(checkMul32.res32_32) &&
371
- result16 == MpcCore.decrypt(checkMul32.res8_32) &&
372
- result16 == MpcCore.decrypt(checkMul32.res32_8) &&
373
- result16 == MpcCore.decrypt(checkMul32.res32_16) &&
374
- result16 == MpcCore.decrypt(checkMul32.res16_32),
375
- "mulTest: cast 32 failed"
376
- );
225
+ check32.res32_32 = MpcCore.mul(castingValues.a32_s, castingValues.b32_s);
226
+ check32.res8_32 = MpcCore.mul(castingValues.a8_s, castingValues.b32_s);
227
+ check32.res32_8 = MpcCore.mul(castingValues.a32_s, castingValues.b8_s);
228
+ check32.res16_32 = MpcCore.mul(castingValues.a16_s, castingValues.b32_s);
229
+ check32.res32_16 = MpcCore.mul(castingValues.a32_s, castingValues.b16_s);
230
+ uint32 res32 = decryptAndCompareResults32(check32);
231
+ require(mulResult == res32, "mulTest: cast 32 failed");
377
232
 
378
233
  // Calculate the result with casting to 64
379
- check64.res64_64 = MpcCore.mul(
380
- castingValues.a64_s,
381
- castingValues.b64_s
382
- );
234
+ check64.res64_64 = MpcCore.mul(castingValues.a64_s, castingValues.b64_s);
383
235
  check64.res8_64 = MpcCore.mul(castingValues.a8_s, castingValues.b64_s);
384
236
  check64.res64_8 = MpcCore.mul(castingValues.a64_s, castingValues.b8_s);
385
- check64.res16_64 = MpcCore.mul(
386
- castingValues.a16_s,
387
- castingValues.b64_s
388
- );
389
- check64.res64_16 = MpcCore.mul(
390
- castingValues.a64_s,
391
- castingValues.b16_s
392
- );
393
- check64.res32_64 = MpcCore.mul(
394
- castingValues.a32_s,
395
- castingValues.b64_s
396
- );
397
- check64.res64_32 = MpcCore.mul(
398
- castingValues.a64_s,
399
- castingValues.b32_s
400
- );
237
+ check64.res16_64 = MpcCore.mul(castingValues.a16_s, castingValues.b64_s);
238
+ check64.res64_16 = MpcCore.mul(castingValues.a64_s, castingValues.b16_s);
239
+ check64.res32_64 = MpcCore.mul(castingValues.a32_s, castingValues.b64_s);
240
+ check64.res64_32 = MpcCore.mul(castingValues.a64_s, castingValues.b32_s);
401
241
  uint64 res64 = decryptAndCompareResults64(check64);
402
- require(result16 == res64, "mulTest: cast 64 failed");
242
+ require(mulResult == res64, "mulTest: cast 64 failed");
403
243
 
404
244
  // Check the result with scalar
405
- require(
406
- result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b8_s)) &&
407
- result16 == MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, b)),
408
- "mulTest: test 8 bits with scalar failed"
409
- );
410
- require(
411
- result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b16_s)) &&
412
- result16 ==
413
- MpcCore.decrypt(MpcCore.mul(castingValues.a16_s, b)),
414
- "mulTest: test 16 bits with scalar failed"
415
- );
416
- require(
417
- result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b32_s)) &&
418
- result16 ==
419
- MpcCore.decrypt(MpcCore.mul(castingValues.a32_s, b)),
420
- "mulTest: test 32 bits with scalar failed"
421
- );
422
- require(
423
- result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b64_s)) &&
424
- result16 ==
425
- MpcCore.decrypt(MpcCore.mul(castingValues.a64_s, b)),
426
- "mulTest: test 64 bits with scalar failed"
427
- );
428
-
429
- return result16;
245
+ require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b8_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, b)),
246
+ "mulTest: test 8 bits with scalar failed");
247
+ require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b16_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a16_s, b)),
248
+ "mulTest: test 16 bits with scalar failed");
249
+ require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b32_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a32_s, b)),
250
+ "mulTest: test 32 bits with scalar failed");
251
+ require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b64_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a64_s, b)),
252
+ "mulTest: test 64 bits with scalar failed");
253
+
254
+ return mulResult;
430
255
  }
431
- }
256
+ }