@coti-io/coti-contracts 1.0.4 → 1.0.6

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 (85) hide show
  1. package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +6 -6
  2. package/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol +309 -0
  3. package/contracts/utils/mpc/MpcCore.sol +527 -18
  4. package/contracts/utils/mpc/MpcInterface.sol +1 -2
  5. package/package.json +1 -1
  6. package/test/utils/mpc/CheckedArithmetic.test.ts +41 -0
  7. package/typechain-types/contracts/mocks/utils/mpc/{ArithmeticTestsContract.sol → ArithmeticWithOverflowBitTestsContract.sol}/ArithmeticTestsContract.ts +52 -43
  8. package/typechain-types/contracts/mocks/utils/mpc/{ArithmeticTestsContract.sol → ArithmeticWithOverflowBitTestsContract.sol}/index.ts +0 -1
  9. package/typechain-types/contracts/mocks/utils/mpc/{ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract.ts → CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract.ts} +73 -60
  10. package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/index.ts +4 -0
  11. package/typechain-types/contracts/mocks/utils/mpc/index.ts +4 -0
  12. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +43 -18
  13. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
  14. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
  15. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +1 -1
  16. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticWithOverflowBitTestsContract.sol/ArithmeticTestsContract__factory.ts +387 -0
  17. package/typechain-types/factories/contracts/mocks/utils/mpc/{ArithmeticTestsContract.sol → ArithmeticWithOverflowBitTestsContract.sol}/index.ts +0 -1
  18. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +1 -1
  19. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract__factory.ts +397 -0
  20. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/index.ts +4 -0
  21. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
  22. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +1 -1
  23. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
  24. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
  25. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
  26. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +1 -1
  27. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  28. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  29. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
  30. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
  31. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +1 -1
  32. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +1 -1
  33. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +1 -1
  34. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +1 -1
  35. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +1 -1
  36. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +1 -1
  37. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +2 -0
  38. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
  39. package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +1 -1
  40. package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +1 -1
  41. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +44 -19
  42. package/typechain-types/hardhat.d.ts +36 -0
  43. package/typechain-types/index.ts +2 -0
  44. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +0 -69
  45. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +0 -69
  46. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +0 -69
  47. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +0 -6
  48. package/typechain-types/contracts/GasTest.ts +0 -91
  49. package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract.ts +0 -340
  50. package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +0 -4
  51. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.ts +0 -384
  52. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +0 -221
  53. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +0 -4
  54. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract.ts +0 -251
  55. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract.ts +0 -250
  56. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +0 -5
  57. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.ts +0 -389
  58. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract.ts +0 -391
  59. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract.ts +0 -391
  60. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +0 -5
  61. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract.ts +0 -125
  62. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract.ts +0 -125
  63. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +0 -5
  64. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +0 -127
  65. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +0 -111
  66. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +0 -128
  67. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +0 -6
  68. package/typechain-types/factories/contracts/GasTest__factory.ts +0 -75
  69. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract__factory.ts +0 -387
  70. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract__factory.ts +0 -388
  71. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +0 -361
  72. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +0 -4
  73. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +0 -432
  74. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +0 -261
  75. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +0 -4
  76. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract__factory.ts +0 -294
  77. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +0 -292
  78. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +0 -5
  79. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract__factory.ts +0 -720
  80. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract__factory.ts +0 -724
  81. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract__factory.ts +0 -724
  82. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +0 -5
  83. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract__factory.ts +0 -150
  84. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +0 -150
  85. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +0 -5
@@ -407,7 +407,7 @@ abstract contract DataPrivacyFrameworkMpc is DataPrivacyFramework {
407
407
 
408
408
  function shl(
409
409
  gtUint16 a,
410
- uint16 b,
410
+ uint8 b,
411
411
  uint256 uintParameter,
412
412
  address addressParameter,
413
413
  string calldata stringParameter
@@ -421,7 +421,7 @@ abstract contract DataPrivacyFrameworkMpc is DataPrivacyFramework {
421
421
 
422
422
  function shr(
423
423
  gtUint16 a,
424
- uint16 b,
424
+ uint8 b,
425
425
  uint256 uintParameter,
426
426
  address addressParameter,
427
427
  string calldata stringParameter
@@ -689,7 +689,7 @@ abstract contract DataPrivacyFrameworkMpc is DataPrivacyFramework {
689
689
 
690
690
  function shl(
691
691
  gtUint32 a,
692
- uint32 b,
692
+ uint8 b,
693
693
  uint256 uintParameter,
694
694
  address addressParameter,
695
695
  string calldata stringParameter
@@ -703,7 +703,7 @@ abstract contract DataPrivacyFrameworkMpc is DataPrivacyFramework {
703
703
 
704
704
  function shr(
705
705
  gtUint32 a,
706
- uint32 b,
706
+ uint8 b,
707
707
  uint256 uintParameter,
708
708
  address addressParameter,
709
709
  string calldata stringParameter
@@ -971,7 +971,7 @@ abstract contract DataPrivacyFrameworkMpc is DataPrivacyFramework {
971
971
 
972
972
  function shl(
973
973
  gtUint64 a,
974
- uint64 b,
974
+ uint8 b,
975
975
  uint256 uintParameter,
976
976
  address addressParameter,
977
977
  string calldata stringParameter
@@ -985,7 +985,7 @@ abstract contract DataPrivacyFrameworkMpc is DataPrivacyFramework {
985
985
 
986
986
  function shr(
987
987
  gtUint64 a,
988
- uint64 b,
988
+ uint8 b,
989
989
  uint256 uintParameter,
990
990
  address addressParameter,
991
991
  string calldata stringParameter
@@ -0,0 +1,309 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.19;
3
+
4
+ import "../../../utils/mpc/MpcCore.sol";
5
+
6
+ contract CheckedArithmeticWithOverflowBitTestsContract {
7
+
8
+ struct AllGTCastingValues {
9
+ gtUint8 a8_s;
10
+ gtUint8 b8_s;
11
+ gtUint16 a16_s;
12
+ gtUint16 b16_s;
13
+ gtUint32 a32_s;
14
+ gtUint32 b32_s;
15
+ gtUint64 a64_s;
16
+ gtUint64 b64_s;
17
+ }
18
+
19
+ struct Check16 {
20
+ gtUint16 res16_16;
21
+ gtUint16 res8_16;
22
+ gtUint16 res16_8;
23
+ }
24
+
25
+ struct Check32 {
26
+ gtUint32 res32_32;
27
+ gtUint32 res8_32;
28
+ gtUint32 res32_8;
29
+ gtUint32 res16_32;
30
+ gtUint32 res32_16;
31
+ }
32
+
33
+ struct Check64 {
34
+ gtUint64 res64_64;
35
+ gtUint64 res8_64;
36
+ gtUint64 res64_8;
37
+ gtUint64 res16_64;
38
+ gtUint64 res64_16;
39
+ gtUint64 res32_64;
40
+ gtUint64 res64_32;
41
+ }
42
+
43
+ uint8 addResult;
44
+ uint8 subResult;
45
+ uint8 mulResult;
46
+
47
+ function getAddResult() public view returns (uint8) {
48
+ return addResult;
49
+ }
50
+
51
+ function getSubResult() public view returns (uint8) {
52
+ return subResult;
53
+ }
54
+
55
+ function getMulResult() public view returns (uint8) {
56
+ return mulResult;
57
+ }
58
+
59
+ function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
60
+ castingValues.a8_s = MpcCore.setPublic8(a);
61
+ castingValues.b8_s = MpcCore.setPublic8(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);
68
+ }
69
+
70
+ function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){
71
+
72
+ // Calculate the result
73
+ uint16 result = MpcCore.decrypt(check16.res16_16);
74
+
75
+ require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
76
+ "decryptAndCompareAllResults: Failed to decrypt and compare all results");
77
+ return result;
78
+ }
79
+
80
+ function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){
81
+
82
+ // Calculate the result
83
+ uint32 result = MpcCore.decrypt(check32.res32_32);
84
+
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");
88
+
89
+ return result;
90
+ }
91
+
92
+ function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){
93
+
94
+ // Calculate the result
95
+ uint64 result = MpcCore.decrypt(check64.res64_64);
96
+
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");
101
+
102
+ return result;
103
+ }
104
+
105
+ function checkedAddWithOverflowBitTest(uint8 a, uint8 b) public returns (uint8) {
106
+ AllGTCastingValues memory castingValues;
107
+ Check16 memory check16;
108
+ Check32 memory check32;
109
+ Check64 memory check64;
110
+ setPublicValues(castingValues, a, b);
111
+
112
+ // Calculate the expected result
113
+ (gtBool overflow, gtUint8 gtResult) = MpcCore.checkedAddWithOverflowBit(castingValues.a8_s, castingValues.b8_s);
114
+ uint8 result = MpcCore.decrypt(gtResult);
115
+ addResult = result;
116
+
117
+ // Calculate the results with casting to 16
118
+ (, check16.res16_16) = MpcCore.checkedAddWithOverflowBit(castingValues.a16_s, castingValues.b16_s);
119
+ (, check16.res8_16) = MpcCore.checkedAddWithOverflowBit(castingValues.a8_s, castingValues.b16_s);
120
+ (, check16.res16_8) = MpcCore.checkedAddWithOverflowBit(castingValues.a16_s, castingValues.b8_s);
121
+ uint16 res16 = decryptAndCompareResults16(check16);
122
+ require(res16 == result, "addTest: cast 16 failed");
123
+
124
+ // Calculate the result with casting to 32
125
+ (, check32.res32_32) = MpcCore.checkedAddWithOverflowBit(castingValues.a32_s, castingValues.b32_s);
126
+ (, check32.res8_32) = MpcCore.checkedAddWithOverflowBit(castingValues.a8_s, castingValues.b32_s);
127
+ (, check32.res32_8) = MpcCore.checkedAddWithOverflowBit(castingValues.a32_s, castingValues.b8_s);
128
+ (, check32.res16_32) = MpcCore.checkedAddWithOverflowBit(castingValues.a16_s, castingValues.b32_s);
129
+ (, check32.res32_16) = MpcCore.checkedAddWithOverflowBit(castingValues.a32_s, castingValues.b16_s);
130
+ uint32 res32 = decryptAndCompareResults32(check32);
131
+ require(result == res32, "addTest: cast 32 failed");
132
+
133
+ // Calculate the result with casting to 64
134
+ (, check64.res64_64) = MpcCore.checkedAddWithOverflowBit(castingValues.a64_s, castingValues.b64_s);
135
+ (, check64.res8_64) = MpcCore.checkedAddWithOverflowBit(castingValues.a8_s, castingValues.b64_s);
136
+ (, check64.res64_8) = MpcCore.checkedAddWithOverflowBit(castingValues.a64_s, castingValues.b8_s);
137
+ (, check64.res16_64) = MpcCore.checkedAddWithOverflowBit(castingValues.a16_s, castingValues.b64_s);
138
+ (, check64.res64_16) = MpcCore.checkedAddWithOverflowBit(castingValues.a64_s, castingValues.b16_s);
139
+ (, check64.res32_64) = MpcCore.checkedAddWithOverflowBit(castingValues.a32_s, castingValues.b64_s);
140
+ (, check64.res64_32) = MpcCore.checkedAddWithOverflowBit(castingValues.a64_s, castingValues.b32_s);
141
+ uint64 res64 = decryptAndCompareResults64(check64);
142
+ require(result == res64, "addTest: cast 64 failed");
143
+
144
+ // Check the result with scalar
145
+ {
146
+ (, gtUint8 gtResult8_1) = MpcCore.checkedAddWithOverflowBit(a, castingValues.b8_s);
147
+ (, gtUint8 gtResult8_2) = MpcCore.checkedAddWithOverflowBit(castingValues.a8_s, b);
148
+ require(result == MpcCore.decrypt(gtResult8_1) && result == MpcCore.decrypt(gtResult8_2),
149
+ "addTest: test 8 bits with scalar failed");
150
+ }
151
+ {
152
+
153
+ (, gtUint16 gtResult16_1) = MpcCore.checkedAddWithOverflowBit(a, castingValues.b16_s);
154
+ (, gtUint16 gtResult16_2) = MpcCore.checkedAddWithOverflowBit(castingValues.a16_s, b);
155
+ require(result == MpcCore.decrypt(gtResult16_1) && result == MpcCore.decrypt(gtResult16_2),
156
+ "addTest: test 16 bits with scalar failed");
157
+ }
158
+ {
159
+ (, gtUint32 gtResult32_1) = MpcCore.checkedAddWithOverflowBit(a, castingValues.b32_s);
160
+ (, gtUint32 gtResult32_2) = MpcCore.checkedAddWithOverflowBit(castingValues.a32_s, b);
161
+ require(result == MpcCore.decrypt(gtResult32_1) && result == MpcCore.decrypt(gtResult32_2),
162
+ "addTest: test 32 bits with scalar failed");
163
+ }
164
+ {
165
+ (, gtUint64 gtResult64_1) = MpcCore.checkedAddWithOverflowBit(a, castingValues.b64_s);
166
+ (, gtUint64 gtResult64_2) = MpcCore.checkedAddWithOverflowBit(castingValues.a64_s, b);
167
+ require(result == MpcCore.decrypt(gtResult64_1) && result == MpcCore.decrypt(gtResult64_2),
168
+ "addTest: test 64 bits with scalar failed");
169
+ }
170
+
171
+ return result;
172
+ }
173
+
174
+ function checkedSubWithOverflowBitTest(uint8 a, uint8 b) public returns (uint8) {
175
+ AllGTCastingValues memory castingValues;
176
+ Check16 memory check16;
177
+ Check32 memory check32;
178
+ Check64 memory check64;
179
+ setPublicValues(castingValues, a, b);
180
+
181
+ // Calculate the expected result
182
+ (gtBool overflow, gtUint8 gtResult) = MpcCore.checkedSubWithOverflowBit(castingValues.a8_s, castingValues.b8_s);
183
+ uint8 result = MpcCore.decrypt(gtResult);
184
+ subResult = result;
185
+
186
+ // Calculate the results with casting to 16
187
+ (, check16.res16_16) = MpcCore.checkedSubWithOverflowBit(castingValues.a16_s, castingValues.b16_s);
188
+ (, check16.res8_16) = MpcCore.checkedSubWithOverflowBit(castingValues.a8_s, castingValues.b16_s);
189
+ (, check16.res16_8) = MpcCore.checkedSubWithOverflowBit(castingValues.a16_s, castingValues.b8_s);
190
+ uint16 res16 = decryptAndCompareResults16(check16);
191
+ require(res16 == result, "subTest: cast 16 failed");
192
+
193
+ // Calculate the result with casting to 32
194
+ (, check32.res32_32) = MpcCore.checkedSubWithOverflowBit(castingValues.a32_s, castingValues.b32_s);
195
+ (, check32.res8_32) = MpcCore.checkedSubWithOverflowBit(castingValues.a8_s, castingValues.b32_s);
196
+ (, check32.res32_8) = MpcCore.checkedSubWithOverflowBit(castingValues.a32_s, castingValues.b8_s);
197
+ (, check32.res16_32) = MpcCore.checkedSubWithOverflowBit(castingValues.a16_s, castingValues.b32_s);
198
+ (, check32.res32_16) = MpcCore.checkedSubWithOverflowBit(castingValues.a32_s, castingValues.b16_s);
199
+ uint32 res32 = decryptAndCompareResults32(check32);
200
+ require(result == res32, "subTest: cast 32 failed");
201
+
202
+ // Calculate the result with casting to 64
203
+ (, check64.res64_64) = MpcCore.checkedSubWithOverflowBit(castingValues.a64_s, castingValues.b64_s);
204
+ (, check64.res8_64) = MpcCore.checkedSubWithOverflowBit(castingValues.a8_s, castingValues.b64_s);
205
+ (, check64.res64_8) = MpcCore.checkedSubWithOverflowBit(castingValues.a64_s, castingValues.b8_s);
206
+ (, check64.res16_64) = MpcCore.checkedSubWithOverflowBit(castingValues.a16_s, castingValues.b64_s);
207
+ (, check64.res64_16) = MpcCore.checkedSubWithOverflowBit(castingValues.a64_s, castingValues.b16_s);
208
+ (, check64.res32_64) = MpcCore.checkedSubWithOverflowBit(castingValues.a32_s, castingValues.b64_s);
209
+ (, check64.res64_32) = MpcCore.checkedSubWithOverflowBit(castingValues.a64_s, castingValues.b32_s);
210
+ uint64 res64 = decryptAndCompareResults64(check64);
211
+ require(result == res64, "subTest: cast 64 failed");
212
+
213
+ // Check the result with scalar
214
+ {
215
+ (, gtUint8 gtResult8_1) = MpcCore.checkedSubWithOverflowBit(a, castingValues.b8_s);
216
+ (, gtUint8 gtResult8_2) = MpcCore.checkedSubWithOverflowBit(castingValues.a8_s, b);
217
+ require(result == MpcCore.decrypt(gtResult8_1) && result == MpcCore.decrypt(gtResult8_2),
218
+ "subTest: test 8 bits with scalar failed");
219
+ }
220
+ {
221
+ (, gtUint16 gtResult16_1) = MpcCore.checkedSubWithOverflowBit(a, castingValues.b16_s);
222
+ (, gtUint16 gtResult16_2) = MpcCore.checkedSubWithOverflowBit(castingValues.a16_s, b);
223
+ require(result == MpcCore.decrypt(gtResult16_1) && result == MpcCore.decrypt(gtResult16_2),
224
+ "subTest: test 16 bits with scalar failed");
225
+ }
226
+ {
227
+ (, gtUint32 gtResult32_1) = MpcCore.checkedSubWithOverflowBit(a, castingValues.b32_s);
228
+ (, gtUint32 gtResult32_2) = MpcCore.checkedSubWithOverflowBit(castingValues.a32_s, b);
229
+ require(result == MpcCore.decrypt(gtResult32_1) && result == MpcCore.decrypt(gtResult32_2),
230
+ "subTest: test 32 bits with scalar failed");
231
+ }
232
+ {
233
+ (, gtUint64 gtResult64_1) = MpcCore.checkedSubWithOverflowBit(a, castingValues.b64_s);
234
+ (, gtUint64 gtResult64_2) = MpcCore.checkedSubWithOverflowBit(castingValues.a64_s, b);
235
+ require(result == MpcCore.decrypt(gtResult64_1) && result == MpcCore.decrypt(gtResult64_2),
236
+ "subTest: test 64 bits with scalar failed");
237
+ }
238
+
239
+ return result;
240
+ }
241
+
242
+ function checkedMulWithOverflowBitTest(uint8 a, uint8 b) public returns (uint8) {
243
+ AllGTCastingValues memory castingValues;
244
+ Check16 memory check16;
245
+ Check32 memory check32;
246
+ Check64 memory check64;
247
+ setPublicValues(castingValues, a, b);
248
+
249
+ // Calculate the expected result
250
+ (gtBool overflow, gtUint8 gtResult) = MpcCore.checkedMulWithOverflowBit(castingValues.a8_s, castingValues.b8_s);
251
+ uint8 result = MpcCore.decrypt(gtResult);
252
+ mulResult = result;
253
+
254
+ // Calculate the results with casting to 16
255
+ (, check16.res16_16) = MpcCore.checkedMulWithOverflowBit(castingValues.a16_s, castingValues.b16_s);
256
+ (, check16.res8_16) = MpcCore.checkedMulWithOverflowBit(castingValues.a8_s, castingValues.b16_s);
257
+ (, check16.res16_8) = MpcCore.checkedMulWithOverflowBit(castingValues.a16_s, castingValues.b8_s);
258
+ uint16 res16 = decryptAndCompareResults16(check16);
259
+ require(result == res16, "mulTest: cast 16 failed");
260
+
261
+ // Calculate the result with casting to 32
262
+ (, check32.res32_32) = MpcCore.checkedMulWithOverflowBit(castingValues.a32_s, castingValues.b32_s);
263
+ (, check32.res8_32) = MpcCore.checkedMulWithOverflowBit(castingValues.a8_s, castingValues.b32_s);
264
+ (, check32.res32_8) = MpcCore.checkedMulWithOverflowBit(castingValues.a32_s, castingValues.b8_s);
265
+ (, check32.res16_32) = MpcCore.checkedMulWithOverflowBit(castingValues.a16_s, castingValues.b32_s);
266
+ (, check32.res32_16) = MpcCore.checkedMulWithOverflowBit(castingValues.a32_s, castingValues.b16_s);
267
+ uint32 res32 = decryptAndCompareResults32(check32);
268
+ require(result == res32, "mulTest: cast 32 failed");
269
+
270
+ // Calculate the result with casting to 64
271
+ (, check64.res64_64) = MpcCore.checkedMulWithOverflowBit(castingValues.a64_s, castingValues.b64_s);
272
+ (, check64.res8_64) = MpcCore.checkedMulWithOverflowBit(castingValues.a8_s, castingValues.b64_s);
273
+ (, check64.res64_8) = MpcCore.checkedMulWithOverflowBit(castingValues.a64_s, castingValues.b8_s);
274
+ (, check64.res16_64) = MpcCore.checkedMulWithOverflowBit(castingValues.a16_s, castingValues.b64_s);
275
+ (, check64.res64_16) = MpcCore.checkedMulWithOverflowBit(castingValues.a64_s, castingValues.b16_s);
276
+ (, check64.res32_64) = MpcCore.checkedMulWithOverflowBit(castingValues.a32_s, castingValues.b64_s);
277
+ (, check64.res64_32) = MpcCore.checkedMulWithOverflowBit(castingValues.a64_s, castingValues.b32_s);
278
+ uint64 res64 = decryptAndCompareResults64(check64);
279
+ require(result == res64, "mulTest: cast 64 failed");
280
+
281
+ // Check the result with scalar
282
+ {
283
+ (, gtUint8 gtResult8_1) = MpcCore.checkedMulWithOverflowBit(a, castingValues.b8_s);
284
+ (, gtUint8 gtResult8_2) = MpcCore.checkedMulWithOverflowBit(castingValues.a8_s, b);
285
+ require(result == MpcCore.decrypt(gtResult8_1) && result == MpcCore.decrypt(gtResult8_2),
286
+ "mulTest: test 8 bits with scalar failed");
287
+ }
288
+ {
289
+ (, gtUint16 gtResult16_1) = MpcCore.checkedMulWithOverflowBit(a, castingValues.b16_s);
290
+ (, gtUint16 gtResult16_2) = MpcCore.checkedMulWithOverflowBit(castingValues.a16_s, b);
291
+ require(result == MpcCore.decrypt(gtResult16_1) && result == MpcCore.decrypt(gtResult16_2),
292
+ "mulTest: test 16 bits with scalar failed");
293
+ }
294
+ {
295
+ (, gtUint32 gtResult32_1) = MpcCore.checkedMulWithOverflowBit(a, castingValues.b32_s);
296
+ (, gtUint32 gtResult32_2) = MpcCore.checkedMulWithOverflowBit(castingValues.a32_s, b);
297
+ require(result == MpcCore.decrypt(gtResult32_1) && result == MpcCore.decrypt(gtResult32_2),
298
+ "mulTest: test 32 bits with scalar failed");
299
+ }
300
+ {
301
+ (, gtUint64 gtResult64_1) = MpcCore.checkedMulWithOverflowBit(a, castingValues.b64_s);
302
+ (, gtUint64 gtResult64_2) = MpcCore.checkedMulWithOverflowBit(castingValues.a64_s, b);
303
+ require(result == MpcCore.decrypt(gtResult64_1) && result == MpcCore.decrypt(gtResult64_2),
304
+ "mulTest: test 64 bits with scalar failed");
305
+ }
306
+
307
+ return result;
308
+ }
309
+ }