@coti-io/coti-contracts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/.github/workflows/npm-publish.yml +52 -0
  2. package/CODE_OF_CONDUCT.md +44 -0
  3. package/CONTRIBUTING.md +101 -0
  4. package/LICENSE +201 -0
  5. package/README.md +48 -0
  6. package/contracts/access/DataPrivacyFramework/DataPrivacyFramework.sol +480 -0
  7. package/contracts/access/DataPrivacyFramework/README.md +68 -0
  8. package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +1139 -0
  9. package/contracts/mocks/README.md +5 -0
  10. package/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.sol +9 -0
  11. package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +17 -0
  12. package/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.sol +34 -0
  13. package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +431 -0
  14. package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +361 -0
  15. package/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol +307 -0
  16. package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +307 -0
  17. package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +297 -0
  18. package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +185 -0
  19. package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +448 -0
  20. package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +81 -0
  21. package/contracts/mocks/utils/mpc/README.md +486 -0
  22. package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +311 -0
  23. package/contracts/mocks/utils/mpc/StringTestsContract.sol +59 -0
  24. package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +271 -0
  25. package/contracts/mocks/utils/mpc/TransferTestsContract.sol +715 -0
  26. package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +25 -0
  27. package/contracts/onboard/AccountOnboard.sol +21 -0
  28. package/contracts/onboard/README.md +65 -0
  29. package/contracts/package.json +11 -0
  30. package/contracts/token/PrivateERC20/IPrivateERC20.sol +142 -0
  31. package/contracts/token/PrivateERC20/PrivateERC20.sol +478 -0
  32. package/contracts/token/PrivateERC20/README.md +104 -0
  33. package/contracts/token/PrivateERC721/PrivateERC721.sol +458 -0
  34. package/contracts/token/PrivateERC721/README.md +282 -0
  35. package/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.sol +87 -0
  36. package/contracts/utils/mpc/MpcCore.sol +3215 -0
  37. package/contracts/utils/mpc/MpcInterface.sol +41 -0
  38. package/contracts/utils/mpc/README.md +82 -0
  39. package/hardhat.config.ts +18 -0
  40. package/package.json +14 -0
  41. package/test/access/DataPrivacyFramework/DataPrivacyFramework.test.ts +780 -0
  42. package/test/onboard/AccountOnboard.test.ts +45 -0
  43. package/test/token/PrivateERC20/PrivateERC20.test.ts +546 -0
  44. package/test/token/PrivateERC721/PrivateERC721.test.ts +223 -0
  45. package/test/utils/accounts.ts +55 -0
  46. package/test/utils/mpc/Precompile.test.ts +113 -0
  47. package/test/utils/mpc/String.test.ts +227 -0
  48. package/tsconfig.json +11 -0
  49. package/typechain-types/@openzeppelin/contracts/index.ts +9 -0
  50. package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +462 -0
  51. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +69 -0
  52. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +69 -0
  53. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +69 -0
  54. package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
  55. package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +6 -0
  56. package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +393 -0
  57. package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +110 -0
  58. package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
  59. package/typechain-types/@openzeppelin/contracts/token/index.ts +5 -0
  60. package/typechain-types/@openzeppelin/contracts/utils/index.ts +5 -0
  61. package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +94 -0
  62. package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +94 -0
  63. package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
  64. package/typechain-types/@openzeppelin/index.ts +5 -0
  65. package/typechain-types/common.ts +131 -0
  66. package/typechain-types/contracts/access/DataPrivacyFramework/DataPrivacyFramework.ts +598 -0
  67. package/typechain-types/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.ts +598 -0
  68. package/typechain-types/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
  69. package/typechain-types/contracts/access/DataPrivacyFramework/index.ts +6 -0
  70. package/typechain-types/contracts/access/index.ts +5 -0
  71. package/typechain-types/contracts/index.ts +13 -0
  72. package/typechain-types/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.ts +598 -0
  73. package/typechain-types/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
  74. package/typechain-types/contracts/mocks/access/index.ts +5 -0
  75. package/typechain-types/contracts/mocks/index.ts +11 -0
  76. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +543 -0
  77. package/typechain-types/contracts/mocks/token/PrivateERC20/index.ts +4 -0
  78. package/typechain-types/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.ts +576 -0
  79. package/typechain-types/contracts/mocks/token/PrivateERC721/index.ts +4 -0
  80. package/typechain-types/contracts/mocks/token/index.ts +7 -0
  81. package/typechain-types/contracts/mocks/utils/index.ts +5 -0
  82. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +354 -0
  83. package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +340 -0
  84. package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract.ts +340 -0
  85. package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
  86. package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +340 -0
  87. package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +321 -0
  88. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +199 -0
  89. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.ts +384 -0
  90. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +218 -0
  91. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
  92. package/typechain-types/contracts/mocks/utils/mpc/ShiftTestsContract.ts +339 -0
  93. package/typechain-types/contracts/mocks/utils/mpc/StringTestsContract.ts +211 -0
  94. package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +266 -0
  95. package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +288 -0
  96. package/typechain-types/contracts/mocks/utils/mpc/index.ts +17 -0
  97. package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.ts +173 -0
  98. package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
  99. package/typechain-types/contracts/mocks/wallet/index.ts +5 -0
  100. package/typechain-types/contracts/onboard/AccountOnboard.ts +135 -0
  101. package/typechain-types/contracts/onboard/index.ts +4 -0
  102. package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +437 -0
  103. package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +505 -0
  104. package/typechain-types/contracts/token/PrivateERC20/index.ts +5 -0
  105. package/typechain-types/contracts/token/PrivateERC721/PrivateERC721.ts +409 -0
  106. package/typechain-types/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.ts +501 -0
  107. package/typechain-types/contracts/token/PrivateERC721/extensions/index.ts +4 -0
  108. package/typechain-types/contracts/token/PrivateERC721/index.ts +6 -0
  109. package/typechain-types/contracts/token/index.ts +7 -0
  110. package/typechain-types/contracts/utils/index.ts +5 -0
  111. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +698 -0
  112. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
  113. package/typechain-types/contracts/utils/mpc/index.ts +5 -0
  114. package/typechain-types/factories/@openzeppelin/contracts/index.ts +6 -0
  115. package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +339 -0
  116. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +127 -0
  117. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +111 -0
  118. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +128 -0
  119. package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
  120. package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +5 -0
  121. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +59 -0
  122. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +307 -0
  123. package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
  124. package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +4 -0
  125. package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +4 -0
  126. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +41 -0
  127. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +41 -0
  128. package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
  129. package/typechain-types/factories/@openzeppelin/index.ts +4 -0
  130. package/typechain-types/factories/contracts/access/DataPrivacyFramework/DataPrivacyFramework__factory.ts +621 -0
  131. package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc__factory.ts +621 -0
  132. package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
  133. package/typechain-types/factories/contracts/access/DataPrivacyFramework/index.ts +5 -0
  134. package/typechain-types/factories/contracts/access/index.ts +4 -0
  135. package/typechain-types/factories/contracts/index.ts +8 -0
  136. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +670 -0
  137. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
  138. package/typechain-types/factories/contracts/mocks/access/index.ts +4 -0
  139. package/typechain-types/factories/contracts/mocks/index.ts +7 -0
  140. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +615 -0
  141. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/index.ts +4 -0
  142. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +630 -0
  143. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/index.ts +4 -0
  144. package/typechain-types/factories/contracts/mocks/token/index.ts +5 -0
  145. package/typechain-types/factories/contracts/mocks/utils/index.ts +4 -0
  146. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +374 -0
  147. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +361 -0
  148. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +361 -0
  149. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
  150. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +361 -0
  151. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +337 -0
  152. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +236 -0
  153. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +432 -0
  154. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +245 -0
  155. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
  156. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +374 -0
  157. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +264 -0
  158. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +360 -0
  159. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +441 -0
  160. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +15 -0
  161. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +194 -0
  162. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
  163. package/typechain-types/factories/contracts/mocks/wallet/index.ts +4 -0
  164. package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +104 -0
  165. package/typechain-types/factories/contracts/onboard/index.ts +4 -0
  166. package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +406 -0
  167. package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +532 -0
  168. package/typechain-types/factories/contracts/token/PrivateERC20/index.ts +5 -0
  169. package/typechain-types/factories/contracts/token/PrivateERC721/PrivateERC721__factory.ts +439 -0
  170. package/typechain-types/factories/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage__factory.ts +512 -0
  171. package/typechain-types/factories/contracts/token/PrivateERC721/extensions/index.ts +4 -0
  172. package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +5 -0
  173. package/typechain-types/factories/contracts/token/index.ts +5 -0
  174. package/typechain-types/factories/contracts/utils/index.ts +4 -0
  175. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +919 -0
  176. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
  177. package/typechain-types/factories/contracts/utils/mpc/index.ts +4 -0
  178. package/typechain-types/factories/index.ts +5 -0
  179. package/typechain-types/hardhat.d.ts +621 -0
  180. package/typechain-types/index.ts +72 -0
@@ -0,0 +1,5 @@
1
+ ## Disclaimer
2
+
3
+ The Solidity contracts in **the mocks folder** are provided **for testing purposes only**. They are not intended for use in production environments and should not be deployed without thorough review and auditing.
4
+
5
+ For additional examples, please refer to the [coti-contracts-examples repository](https://github.com/coti-io/coti-contracts-examples).
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.19;
4
+
5
+ import "../../../access/DataPrivacyFramework/DataPrivacyFramework.sol";
6
+
7
+ contract DataPrivacyFrameworkMock is DataPrivacyFramework {
8
+ constructor() DataPrivacyFramework(true, true) {}
9
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.19;
4
+
5
+ import "../../../token/PrivateERC20/PrivateERC20.sol";
6
+
7
+ contract PrivateERC20Mock is PrivateERC20 {
8
+ constructor() PrivateERC20("PrivateERC20Mock", "PE20M") {}
9
+
10
+ function mint(address account, uint64 amount) external {
11
+ _mint(account, MpcCore.setPublic64(amount));
12
+ }
13
+
14
+ function burn(address account, uint64 amount) external {
15
+ _burn(account, MpcCore.setPublic64(amount));
16
+ }
17
+ }
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.19;
4
+
5
+ import {PrivateERC721} from "../../../token/PrivateERC721/PrivateERC721.sol";
6
+ import {PrivateERC721URIStorage} from "../../../token/PrivateERC721/extensions/PrivateERC721URIStorage.sol";
7
+ import "../../../utils/mpc/MpcCore.sol";
8
+
9
+ contract PrivateERC721URIStorageMock is PrivateERC721URIStorage {
10
+ uint256 private _totalSupply;
11
+
12
+ event Minted(address indexed to, uint256 indexed tokenId);
13
+
14
+ constructor() PrivateERC721("Example", "EXL") {}
15
+
16
+ function totalSupply() public view returns (uint256) {
17
+ return _totalSupply;
18
+ }
19
+
20
+ function mint(
21
+ address to,
22
+ itString calldata itTokenURI
23
+ ) public {
24
+ uint256 tokenId = _totalSupply;
25
+
26
+ _mint(to, tokenId);
27
+
28
+ PrivateERC721URIStorage._setTokenURI(msg.sender, tokenId, itTokenURI);
29
+
30
+ _totalSupply += 1;
31
+
32
+ emit Minted(to, tokenId);
33
+ }
34
+ }
@@ -0,0 +1,431 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.19;
4
+
5
+ import "../../../utils/mpc/MpcCore.sol";
6
+
7
+ contract ArithmeticTestsContract {
8
+
9
+ struct AllGTCastingValues {
10
+ gtUint8 a8_s;
11
+ gtUint8 b8_s;
12
+ gtUint16 a16_s;
13
+ gtUint16 b16_s;
14
+ gtUint32 a32_s;
15
+ gtUint32 b32_s;
16
+ gtUint64 a64_s;
17
+ gtUint64 b64_s;
18
+ }
19
+
20
+ struct Check16 {
21
+ gtUint16 res16_16;
22
+ gtUint16 res8_16;
23
+ gtUint16 res16_8;
24
+ }
25
+
26
+ struct CheckMul16 {
27
+ gtUint32 res16_16;
28
+ gtUint32 res8_16;
29
+ gtUint32 res16_8;
30
+ }
31
+
32
+ struct Check32 {
33
+ gtUint32 res32_32;
34
+ gtUint32 res8_32;
35
+ gtUint32 res32_8;
36
+ gtUint32 res16_32;
37
+ gtUint32 res32_16;
38
+ }
39
+
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
+ struct Check64 {
49
+ gtUint64 res64_64;
50
+ gtUint64 res8_64;
51
+ gtUint64 res64_8;
52
+ gtUint64 res16_64;
53
+ gtUint64 res64_16;
54
+ gtUint64 res32_64;
55
+ gtUint64 res64_32;
56
+ }
57
+
58
+ uint8 result;
59
+ uint16 result16;
60
+
61
+ function getResult() public view returns (uint8) {
62
+ return result;
63
+ }
64
+
65
+ function getResult16() public view returns (uint16) {
66
+ return result16;
67
+ }
68
+
69
+ function setPublicValues(
70
+ AllGTCastingValues memory castingValues,
71
+ uint8 a,
72
+ uint8 b
73
+ ) public {
74
+ castingValues.a8_s = MpcCore.setPublic8(a);
75
+ 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);
82
+ }
83
+
84
+ function decryptAndCompareResults16(
85
+ Check16 memory check16
86
+ ) public returns (uint16) {
87
+ // Calculate the result
88
+ uint16 result = MpcCore.decrypt(check16.res16_16);
89
+
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
+ );
95
+ return result;
96
+ }
97
+
98
+ function decryptAndCompareResults32(
99
+ Check32 memory check32
100
+ ) public returns (uint32) {
101
+ // Calculate the result
102
+ uint32 result = MpcCore.decrypt(check32.res32_32);
103
+
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
+ );
111
+
112
+ return result;
113
+ }
114
+
115
+ function decryptAndCompareResults64(
116
+ Check64 memory check64
117
+ ) public returns (uint64) {
118
+ // Calculate the result
119
+ uint64 result = MpcCore.decrypt(check64.res64_64);
120
+
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
+ );
130
+
131
+ return result;
132
+ }
133
+
134
+ function addTest(uint8 a, uint8 b) public returns (uint8) {
135
+ AllGTCastingValues memory castingValues;
136
+ Check16 memory check16;
137
+ Check32 memory check32;
138
+ Check64 memory check64;
139
+ setPublicValues(castingValues, a, b);
140
+
141
+ // Calculate the expected result
142
+ result = MpcCore.decrypt(
143
+ MpcCore.add(castingValues.a8_s, castingValues.b8_s)
144
+ );
145
+
146
+ // Calculate the results with casting to 16
147
+ check16.res16_16 = MpcCore.add(
148
+ castingValues.a16_s,
149
+ castingValues.b16_s
150
+ );
151
+ check16.res8_16 = MpcCore.add(castingValues.a8_s, castingValues.b16_s);
152
+ check16.res16_8 = MpcCore.add(castingValues.a16_s, castingValues.b8_s);
153
+ uint16 res16 = decryptAndCompareResults16(check16);
154
+ require(res16 == result, "addTest: cast 16 failed");
155
+
156
+ // Calculate the result with casting to 32
157
+ check32.res32_32 = MpcCore.add(
158
+ castingValues.a32_s,
159
+ castingValues.b32_s
160
+ );
161
+ check32.res8_32 = MpcCore.add(castingValues.a8_s, castingValues.b32_s);
162
+ 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
+ );
171
+ uint32 res32 = decryptAndCompareResults32(check32);
172
+ require(result == res32, "addTest: cast 32 failed");
173
+
174
+ // Calculate the result with casting to 64
175
+ check64.res64_64 = MpcCore.add(
176
+ castingValues.a64_s,
177
+ castingValues.b64_s
178
+ );
179
+ check64.res8_64 = MpcCore.add(castingValues.a8_s, castingValues.b64_s);
180
+ 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
+ );
197
+ uint64 res64 = decryptAndCompareResults64(check64);
198
+ require(result == res64, "addTest: cast 64 failed");
199
+
200
+ // 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
+ );
221
+
222
+ return result;
223
+ }
224
+
225
+ function subTest(uint8 a, uint8 b) public returns (uint8) {
226
+ AllGTCastingValues memory castingValues;
227
+ Check16 memory check16;
228
+ Check32 memory check32;
229
+ Check64 memory check64;
230
+ setPublicValues(castingValues, a, b);
231
+
232
+ // Calculate the expected result
233
+ result = MpcCore.decrypt(
234
+ MpcCore.sub(castingValues.a8_s, castingValues.b8_s)
235
+ );
236
+
237
+ // Calculate the results with casting to 16
238
+ check16.res16_16 = MpcCore.sub(
239
+ castingValues.a16_s,
240
+ castingValues.b16_s
241
+ );
242
+ check16.res8_16 = MpcCore.sub(castingValues.a8_s, castingValues.b16_s);
243
+ check16.res16_8 = MpcCore.sub(castingValues.a16_s, castingValues.b8_s);
244
+ uint16 res16 = decryptAndCompareResults16(check16);
245
+ require(res16 == result, "subTest: cast 16 failed");
246
+
247
+ // Calculate the result with casting to 32
248
+ check32.res32_32 = MpcCore.sub(
249
+ castingValues.a32_s,
250
+ castingValues.b32_s
251
+ );
252
+ check32.res8_32 = MpcCore.sub(castingValues.a8_s, castingValues.b32_s);
253
+ 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
+ );
262
+ uint32 res32 = decryptAndCompareResults32(check32);
263
+ require(result == res32, "subTest: cast 32 failed");
264
+
265
+ // Calculate the result with casting to 64
266
+ check64.res64_64 = MpcCore.sub(
267
+ castingValues.a64_s,
268
+ castingValues.b64_s
269
+ );
270
+ check64.res8_64 = MpcCore.sub(castingValues.a8_s, castingValues.b64_s);
271
+ 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
+ );
288
+ uint64 res64 = decryptAndCompareResults64(check64);
289
+ require(result == res64, "subTest: cast 64 failed");
290
+
291
+ // 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
+ );
312
+
313
+ return result;
314
+ }
315
+
316
+ function mulTest(uint8 a, uint8 b) public returns (uint16) {
317
+ AllGTCastingValues memory castingValues;
318
+ CheckMul16 memory checkMul16;
319
+ CheckMul32 memory checkMul32;
320
+ Check64 memory check64;
321
+ setPublicValues(castingValues, a, b);
322
+
323
+ // Calculate the expected result
324
+ result16 = MpcCore.decrypt(
325
+ MpcCore.mul(castingValues.a8_s, castingValues.b8_s)
326
+ );
327
+
328
+ // 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
+ );
347
+
348
+ // 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
+ );
377
+
378
+ // Calculate the result with casting to 64
379
+ check64.res64_64 = MpcCore.mul(
380
+ castingValues.a64_s,
381
+ castingValues.b64_s
382
+ );
383
+ check64.res8_64 = MpcCore.mul(castingValues.a8_s, castingValues.b64_s);
384
+ 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
+ );
401
+ uint64 res64 = decryptAndCompareResults64(check64);
402
+ require(result16 == res64, "mulTest: cast 64 failed");
403
+
404
+ // 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;
430
+ }
431
+ }