@coti-io/coti-contracts 1.0.9 → 1.2.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 (271) hide show
  1. package/.github/workflows/npm-publish.yml +18 -14
  2. package/README.md +3 -1
  3. package/contracts/disperse/coinByRatio/FixedRatioCoinDisperser.sol +452 -0
  4. package/contracts/disperse/coinByRatio/FixedRatioCoinDisperserLeftoverS1.sol +490 -0
  5. package/contracts/disperse/coinByRatio/FixedRatioCoinDisperserUnlimitedWindow.sol +432 -0
  6. package/contracts/disperse/disperseToken/MintDisperser.sol +120 -0
  7. package/contracts/disperse/disperseToken/TokenDisperser.sol +139 -0
  8. package/contracts/mocks/token/ERC20Mock.sol +19 -0
  9. package/contracts/mocks/token/PrivateERC20/EncryptedTokenReceiverMock.sol +18 -0
  10. package/contracts/mocks/token/PrivateERC20/PrivacyBridgeERC20Mock.sol +13 -0
  11. package/contracts/mocks/token/PrivateERC20/PrivateERC20AuditorSupplyMock.sol +44 -0
  12. package/contracts/mocks/token/PrivateERC20/PrivateERC20CappedMock.sol +23 -0
  13. package/contracts/mocks/token/PrivateERC20/PrivateERC20GtCallerMock.sol +29 -0
  14. package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +9 -4
  15. package/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol +39 -0
  16. package/contracts/mocks/token/PrivateERC20/PublicReentrantTokenReceiverMock.sol +29 -0
  17. package/contracts/mocks/token/PrivateERC20/PublicTokenReceiverBoolMock.sol +18 -0
  18. package/contracts/mocks/token/PrivateERC20/PublicTokenReceiverMock.sol +12 -0
  19. package/contracts/mocks/utils/mpc/Arithmetic128TestsContract.sol +123 -0
  20. package/contracts/mocks/utils/mpc/Arithmetic256TestsContract.sol +122 -0
  21. package/contracts/mocks/utils/mpc/Bitwise128TestsContract.sol +65 -0
  22. package/contracts/mocks/utils/mpc/Bitwise256TestsContract.sol +65 -0
  23. package/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.sol +64 -0
  24. package/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.sol +64 -0
  25. package/contracts/mocks/utils/mpc/Comparison128TestsContract.sol +98 -0
  26. package/contracts/mocks/utils/mpc/Comparison256TestsContract.sol +98 -0
  27. package/contracts/mocks/utils/mpc/MinMax128TestsContract.sol +44 -0
  28. package/contracts/mocks/utils/mpc/MinMax256TestsContract.sol +44 -0
  29. package/contracts/mocks/utils/mpc/MinimalImplementation.sol +55 -0
  30. package/contracts/mocks/utils/mpc/MinimalProxy.sol +27 -0
  31. package/contracts/mocks/utils/mpc/MpcOperations128TestContract.sol +267 -0
  32. package/contracts/mocks/utils/mpc/MpcOperationsTestContract.sol +334 -0
  33. package/contracts/mocks/utils/mpc/Mux128TestsContract.sol +24 -0
  34. package/contracts/mocks/utils/mpc/Mux256TestsContract.sol +24 -0
  35. package/contracts/mocks/utils/mpc/OnBoard128TestsContract.sol +93 -0
  36. package/contracts/mocks/utils/mpc/OnBoard256TestsContract.sol +116 -0
  37. package/contracts/mocks/utils/mpc/PrivacyImplementationV1.sol +157 -0
  38. package/contracts/mocks/utils/mpc/PrivacyImplementationV2.sol +133 -0
  39. package/contracts/mocks/utils/mpc/PrivacyProxy.sol +137 -0
  40. package/contracts/mocks/utils/mpc/Random128TestsContract.sol +32 -0
  41. package/contracts/mocks/utils/mpc/Random256TestsContract.sol +32 -0
  42. package/contracts/mocks/utils/mpc/Shift128TestsContract.sol +36 -0
  43. package/contracts/mocks/utils/mpc/Shift256TestsContract.sol +36 -0
  44. package/contracts/mocks/utils/mpc/Transfer128TestsContract.sol +29 -0
  45. package/contracts/mocks/utils/mpc/Transfer256TestsContract.sol +29 -0
  46. package/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.sol +32 -0
  47. package/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.sol +32 -0
  48. package/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.sol +59 -0
  49. package/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.sol +63 -0
  50. package/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.sol +99 -0
  51. package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +7 -6
  52. package/contracts/node/CotiNodeRewards.sol +199 -0
  53. package/contracts/node/SoulboundNodeNFT.sol +519 -0
  54. package/contracts/privacyBridge/PrivacyBridge.sol +318 -0
  55. package/contracts/privacyBridge/PrivacyBridgeCotiNative.sol +268 -0
  56. package/contracts/privacyBridge/PrivacyBridgeERC20.sol +251 -0
  57. package/contracts/privacyBridge/PrivacyBridgeUSDCe.sol +16 -0
  58. package/contracts/privacyBridge/PrivacyBridgeUSDT.sol +17 -0
  59. package/contracts/privacyBridge/PrivacyBridgeWADA.sol +17 -0
  60. package/contracts/privacyBridge/PrivacyBridgeWBTC.sol +17 -0
  61. package/contracts/privacyBridge/PrivacyBridgeWETH.sol +17 -0
  62. package/contracts/privacyBridge/PrivacyBridgegCoti.sol +17 -0
  63. package/contracts/token/PrivateERC20/IPrivateERC20.sol +273 -40
  64. package/contracts/token/PrivateERC20/ITokenReceiver.sol +17 -0
  65. package/contracts/token/PrivateERC20/ITokenReceiverEncrypted.sol +20 -0
  66. package/contracts/token/PrivateERC20/PrivateERC20.sol +861 -152
  67. package/contracts/token/PrivateERC20/tokens/PrivateBridgedUSDC.sol +17 -0
  68. package/contracts/token/PrivateERC20/tokens/PrivateCOTI.sol +13 -0
  69. package/contracts/token/PrivateERC20/tokens/PrivateCOTITreasuryGovernanceToken.sol +17 -0
  70. package/contracts/token/PrivateERC20/tokens/PrivateTetherUSD.sol +17 -0
  71. package/contracts/token/PrivateERC20/tokens/PrivateWrappedADA.sol +17 -0
  72. package/contracts/token/PrivateERC20/tokens/PrivateWrappedBTC.sol +17 -0
  73. package/contracts/token/PrivateERC20/tokens/PrivateWrappedEther.sol +13 -0
  74. package/contracts/utils/mpc/MpcCore.sol +10891 -2449
  75. package/contracts/utils/mpc/MpcInterface.sol +7 -2
  76. package/hardhat/gasPriceBump.ts +60 -0
  77. package/hardhat.config.ts +60 -12
  78. package/package.json +21 -3
  79. package/scripts/deploySoulboundNodeNFT.ts +57 -0
  80. package/test/token/PrivateERC20/PrivacyBridge.fees.test.ts +327 -0
  81. package/test/token/PrivateERC20/PrivateERC20.test.ts +1109 -268
  82. package/test/utils/mpc/Bitwise128.test.ts +92 -0
  83. package/test/utils/mpc/Bitwise256.test.ts +101 -0
  84. package/test/utils/mpc/BuildInputText128.test.ts +398 -0
  85. package/test/utils/mpc/CheckedArithmetic128.test.ts +45 -0
  86. package/test/utils/mpc/CheckedArithmetic256.test.ts +45 -0
  87. package/test/utils/mpc/Comparison128.test.ts +48 -0
  88. package/test/utils/mpc/Comparison256.test.ts +48 -0
  89. package/test/utils/mpc/InvalidCiphertext.test.ts +179 -0
  90. package/test/utils/mpc/InvalidCiphertext128.test.ts +179 -0
  91. package/test/utils/mpc/InvalidCiphertext256.test.ts +201 -0
  92. package/test/utils/mpc/InvalidTransfer128.test.ts +166 -0
  93. package/test/utils/mpc/InvalidTransfer256.test.ts +158 -0
  94. package/test/utils/mpc/MinMax128.test.ts +44 -0
  95. package/test/utils/mpc/MinMax256.test.ts +44 -0
  96. package/test/utils/mpc/MinimalProxyDemo.test.ts +280 -0
  97. package/test/utils/mpc/MpcOperations.test.ts +589 -0
  98. package/test/utils/mpc/MpcOperations128.test.ts +632 -0
  99. package/test/utils/mpc/Mux128.test.ts +41 -0
  100. package/test/utils/mpc/Mux256.test.ts +41 -0
  101. package/test/utils/mpc/NegativeCases.test.ts +478 -0
  102. package/test/utils/mpc/NegativeCases128.test.ts +237 -0
  103. package/test/utils/mpc/NegativeCases256.test.ts +236 -0
  104. package/test/utils/mpc/OnBoard128.test.ts +90 -0
  105. package/test/utils/mpc/OnBoard256.test.ts +114 -0
  106. package/test/utils/mpc/Precompile128.test.ts +51 -0
  107. package/test/utils/mpc/Precompile256.test.ts +115 -0
  108. package/test/utils/mpc/ProxyValidation.test.ts +199 -0
  109. package/test/utils/mpc/Random128.test.ts +47 -0
  110. package/test/utils/mpc/Random256.test.ts +47 -0
  111. package/test/utils/mpc/Shift128.test.ts +41 -0
  112. package/test/utils/mpc/Shift256.test.ts +41 -0
  113. package/test/utils/mpc/Transfer128.test.ts +46 -0
  114. package/test/utils/mpc/Transfer256.test.ts +46 -0
  115. package/test/utils/mpc/TransferWithAllowance128.test.ts +48 -0
  116. package/test/utils/mpc/TransferWithAllowance256.test.ts +48 -0
  117. package/test/utils/mpc/UpgradeablePrivacyProxy.test.ts +307 -0
  118. package/test/utils/mpc/ValidateCiphertext.test.ts +221 -0
  119. package/test/utils/mpc/ValidateCiphertext256.test.ts +161 -0
  120. package/test/utils/mpc/ValidateCiphertext256Decryption.test.ts +383 -0
  121. package/test/utils/mpc/WalletEncryptionFailures.test.ts +494 -0
  122. package/test/utils/privateErc20Helpers.ts +97 -0
  123. package/typechain-types/@openzeppelin/contracts/access/Ownable.ts +153 -0
  124. package/typechain-types/@openzeppelin/contracts/access/index.ts +4 -0
  125. package/typechain-types/@openzeppelin/contracts/index.ts +2 -0
  126. package/typechain-types/@openzeppelin/contracts/token/ERC20/IERC20.ts +262 -0
  127. package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.ts +143 -0
  128. package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
  129. package/typechain-types/@openzeppelin/contracts/token/ERC20/index.ts +6 -0
  130. package/typechain-types/@openzeppelin/contracts/token/index.ts +2 -0
  131. package/typechain-types/contracts/disperse/coinByRatio/FixedRatioCoinDisperser.ts +679 -0
  132. package/typechain-types/contracts/disperse/coinByRatio/index.ts +4 -0
  133. package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20.ts +97 -0
  134. package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser.ts +206 -0
  135. package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
  136. package/typechain-types/contracts/disperse/disperseToken/TokenDisperser.ts +191 -0
  137. package/typechain-types/contracts/disperse/disperseToken/index.ts +6 -0
  138. package/typechain-types/contracts/disperse/index.ts +7 -0
  139. package/typechain-types/contracts/index.ts +2 -0
  140. package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +77 -60
  141. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.ts +341 -0
  142. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128TestsContract.ts +311 -0
  143. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.ts +347 -0
  144. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256TestsContract.ts +311 -0
  145. package/typechain-types/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.ts +186 -0
  146. package/typechain-types/contracts/mocks/utils/mpc/Bitwise128TestsContract.ts +179 -0
  147. package/typechain-types/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.ts +186 -0
  148. package/typechain-types/contracts/mocks/utils/mpc/Bitwise256TestsContract.ts +179 -0
  149. package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.ts +206 -0
  150. package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.ts +206 -0
  151. package/typechain-types/contracts/mocks/utils/mpc/Comparison128BitTestsContract.ts +260 -0
  152. package/typechain-types/contracts/mocks/utils/mpc/Comparison128TestsContract.ts +278 -0
  153. package/typechain-types/contracts/mocks/utils/mpc/Comparison256BitTestsContract.ts +260 -0
  154. package/typechain-types/contracts/mocks/utils/mpc/Comparison256TestsContract.ts +278 -0
  155. package/typechain-types/contracts/mocks/utils/mpc/MinMax128TestsContract.ts +142 -0
  156. package/typechain-types/contracts/mocks/utils/mpc/MinMax256TestsContract.ts +142 -0
  157. package/typechain-types/contracts/mocks/utils/mpc/MinimalImplementation.ts +259 -0
  158. package/typechain-types/contracts/mocks/utils/mpc/MinimalProxy.ts +90 -0
  159. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.ts +302 -0
  160. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.ts +322 -0
  161. package/typechain-types/contracts/mocks/utils/mpc/MpcOperations128TestContract.ts +388 -0
  162. package/typechain-types/contracts/mocks/utils/mpc/MpcOperationsTestContract.ts +455 -0
  163. package/typechain-types/contracts/mocks/utils/mpc/Mux128TestsContract.ts +109 -0
  164. package/typechain-types/contracts/mocks/utils/mpc/Mux256TestsContract.ts +109 -0
  165. package/typechain-types/contracts/mocks/utils/mpc/OnBoard128TestsContract.ts +166 -0
  166. package/typechain-types/contracts/mocks/utils/mpc/OnBoard256TestsContract.ts +194 -0
  167. package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV1.ts +385 -0
  168. package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV2.ts +441 -0
  169. package/typechain-types/contracts/mocks/utils/mpc/PrivacyProxy.ts +201 -0
  170. package/typechain-types/contracts/mocks/utils/mpc/Random128TestsContract.ts +131 -0
  171. package/typechain-types/contracts/mocks/utils/mpc/Random256TestsContract.ts +131 -0
  172. package/typechain-types/contracts/mocks/utils/mpc/Shift128TestsContract.ts +142 -0
  173. package/typechain-types/contracts/mocks/utils/mpc/Shift256TestsContract.ts +142 -0
  174. package/typechain-types/contracts/mocks/utils/mpc/Transfer128TestsContract.ts +109 -0
  175. package/typechain-types/contracts/mocks/utils/mpc/Transfer256TestsContract.ts +109 -0
  176. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.ts +128 -0
  177. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.ts +128 -0
  178. package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.ts +198 -0
  179. package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.ts +182 -0
  180. package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.ts +257 -0
  181. package/typechain-types/contracts/mocks/utils/mpc/index.ts +32 -0
  182. package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +77 -60
  183. package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +77 -60
  184. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +111 -10
  185. package/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.ts +74 -0
  186. package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +4 -0
  187. package/typechain-types/factories/@openzeppelin/contracts/index.ts +1 -0
  188. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.ts +205 -0
  189. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit__factory.ts +100 -0
  190. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
  191. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.ts +5 -0
  192. package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +1 -0
  193. package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperser__factory.ts +759 -0
  194. package/typechain-types/factories/contracts/disperse/coinByRatio/index.ts +4 -0
  195. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20__factory.ts +43 -0
  196. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser__factory.ts +185 -0
  197. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
  198. package/typechain-types/factories/contracts/disperse/disperseToken/TokenDisperser__factory.ts +198 -0
  199. package/typechain-types/factories/contracts/disperse/disperseToken/index.ts +5 -0
  200. package/typechain-types/factories/contracts/disperse/index.ts +5 -0
  201. package/typechain-types/factories/contracts/index.ts +1 -0
  202. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
  203. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +179 -47
  204. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract__factory.ts +349 -0
  205. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128TestsContract__factory.ts +330 -0
  206. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract__factory.ts +364 -0
  207. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256TestsContract__factory.ts +330 -0
  208. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +1 -1
  209. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128BitTestsContract__factory.ts +182 -0
  210. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128TestsContract__factory.ts +184 -0
  211. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256BitTestsContract__factory.ts +182 -0
  212. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256TestsContract__factory.ts +184 -0
  213. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +1 -1
  214. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract__factory.ts +203 -0
  215. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract__factory.ts +203 -0
  216. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract__factory.ts +1 -1
  217. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128BitTestsContract__factory.ts +255 -0
  218. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128TestsContract__factory.ts +295 -0
  219. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
  220. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256BitTestsContract__factory.ts +255 -0
  221. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256TestsContract__factory.ts +295 -0
  222. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +1 -1
  223. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax128TestsContract__factory.ts +147 -0
  224. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax256TestsContract__factory.ts +147 -0
  225. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
  226. package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalImplementation__factory.ts +263 -0
  227. package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalProxy__factory.ts +104 -0
  228. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract__factory.ts +332 -0
  229. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
  230. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract__factory.ts +380 -0
  231. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
  232. package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperations128TestContract__factory.ts +723 -0
  233. package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperationsTestContract__factory.ts +1410 -0
  234. package/typechain-types/factories/contracts/mocks/utils/mpc/Mux128TestsContract__factory.ts +115 -0
  235. package/typechain-types/factories/contracts/mocks/utils/mpc/Mux256TestsContract__factory.ts +115 -0
  236. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +1 -1
  237. package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard128TestsContract__factory.ts +175 -0
  238. package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard256TestsContract__factory.ts +205 -0
  239. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV1__factory.ts +521 -0
  240. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV2__factory.ts +648 -0
  241. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyProxy__factory.ts +179 -0
  242. package/typechain-types/factories/contracts/mocks/utils/mpc/Random128TestsContract__factory.ts +131 -0
  243. package/typechain-types/factories/contracts/mocks/utils/mpc/Random256TestsContract__factory.ts +131 -0
  244. package/typechain-types/factories/contracts/mocks/utils/mpc/Shift128TestsContract__factory.ts +147 -0
  245. package/typechain-types/factories/contracts/mocks/utils/mpc/Shift256TestsContract__factory.ts +147 -0
  246. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  247. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  248. package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer128TestsContract__factory.ts +135 -0
  249. package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer256TestsContract__factory.ts +135 -0
  250. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
  251. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
  252. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract__factory.ts +154 -0
  253. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract__factory.ts +154 -0
  254. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +1 -1
  255. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +1 -1
  256. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +1 -1
  257. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +1 -1
  258. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +1 -1
  259. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +1 -1
  260. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract__factory.ts +190 -0
  261. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract__factory.ts +210 -0
  262. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract__factory.ts +260 -0
  263. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +32 -0
  264. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +7 -7
  265. package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +174 -42
  266. package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +174 -42
  267. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +126 -0
  268. package/typechain-types/hardhat.d.ts +702 -0
  269. package/typechain-types/index.ts +78 -0
  270. package/contracts/mocks/utils/mpc/README.md +0 -486
  271. package/contracts/package.json +0 -11
@@ -0,0 +1,589 @@
1
+ import hre from "hardhat"
2
+ import { expect } from "chai"
3
+ import { setupAccounts } from "../accounts"
4
+ import { itUint256, Wallet, ctUint256 } from "@coti-io/coti-ethers"
5
+ import { MpcOperationsTestContract } from "../../../typechain-types"
6
+
7
+ const GAS_LIMIT = 12000000
8
+
9
+ async function deploy() {
10
+ const [owner] = await setupAccounts()
11
+
12
+ const contractFactory = await hre.ethers.getContractFactory("MpcOperationsTestContract", owner as any)
13
+ const contract = await contractFactory.deploy({ gasLimit: GAS_LIMIT })
14
+ await contract.waitForDeployment()
15
+
16
+ return {
17
+ contract,
18
+ contractAddress: await contract.getAddress(),
19
+ owner
20
+ }
21
+ }
22
+
23
+ describe("MPC Operations with offBoardToUser - User Can Decrypt Results", function () {
24
+ this.timeout(180000) // 3 minutes timeout
25
+ let contract: MpcOperationsTestContract
26
+ let contractAddress: string
27
+ let owner: Wallet
28
+
29
+ before(async function () {
30
+ const deployment = await deploy()
31
+ contract = deployment.contract
32
+ contractAddress = deployment.contractAddress
33
+ owner = deployment.owner
34
+
35
+ const onboardInfo = owner.getUserOnboardInfo()
36
+ if (!onboardInfo || !onboardInfo.aesKey) {
37
+ throw new Error("User AES key not found. Please onboard the user first.")
38
+ }
39
+
40
+ console.log("\n" + "=".repeat(80))
41
+ console.log("🔐 MPC OPERATIONS TEST SETUP")
42
+ console.log("=".repeat(80))
43
+ console.log(`Contract Address: ${contractAddress}`)
44
+ console.log(`Owner Address: ${owner.address}`)
45
+ console.log(`User AES Key: ${onboardInfo.aesKey.substring(0, 8)}...${onboardInfo.aesKey.substring(onboardInfo.aesKey.length - 8)}`)
46
+ console.log("=".repeat(80) + "\n")
47
+ })
48
+
49
+ describe("Arithmetic Operations", function () {
50
+ it("Should perform addition and user can decrypt result", async function () {
51
+ // Use values > 128 bits to ensure itUint256 encryption
52
+ const a = (2n ** 130n) + 1000n
53
+ const b = (2n ** 129n) + 500n
54
+ const expected = a + b
55
+ console.log(`\n➕ Testing: ${a} + ${b} = ${expected}`)
56
+
57
+ const itA = await owner.encryptValue256(a, contractAddress, contract.add256.fragment.selector)
58
+ const itB = await owner.encryptValue256(b, contractAddress, contract.add256.fragment.selector)
59
+
60
+ console.log("📝 Performing addition on contract...")
61
+ const tx = await contract.add256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
62
+ const receipt = await tx.wait()
63
+ expect(receipt?.status).to.equal(1)
64
+
65
+ // Get the result from transaction logs
66
+ const resultEvent = receipt?.logs.find((log: any) => {
67
+ try {
68
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
69
+ } catch {
70
+ return false
71
+ }
72
+ })
73
+
74
+ if (resultEvent) {
75
+ const parsedLog = contract.interface.parseLog(resultEvent)
76
+ const ctResult: ctUint256 = parsedLog?.args.result
77
+
78
+ console.log("📝 User decrypting result...")
79
+ const decrypted = await owner.decryptValue256({
80
+ ciphertextHigh: ctResult.ciphertextHigh,
81
+ ciphertextLow: ctResult.ciphertextLow
82
+ })
83
+
84
+ console.log(`✓ Decrypted result: ${decrypted}`)
85
+ expect(decrypted).to.equal(expected)
86
+ console.log(` ✅ SUCCESS: Addition verified!\n`)
87
+ }
88
+ })
89
+
90
+ it("Should perform subtraction and user can decrypt result", async function () {
91
+ // Use values > 128 bits to ensure itUint256 encryption
92
+ const a = (2n ** 130n) + 1000n
93
+ const b = (2n ** 129n) + 300n
94
+ const expected = a - b
95
+ console.log(`\n➖ Testing: ${a} - ${b} = ${expected}`)
96
+
97
+ const itA = await owner.encryptValue256(a, contractAddress, contract.sub256.fragment.selector)
98
+ const itB = await owner.encryptValue256(b, contractAddress, contract.sub256.fragment.selector)
99
+
100
+ const tx = await contract.sub256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
101
+ const receipt = await tx.wait()
102
+ expect(receipt?.status).to.equal(1)
103
+
104
+ const resultEvent = receipt?.logs.find((log: any) => {
105
+ try {
106
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
107
+ } catch {
108
+ return false
109
+ }
110
+ })
111
+
112
+ if (resultEvent) {
113
+ const parsedLog = contract.interface.parseLog(resultEvent)
114
+ const ctResult: ctUint256 = parsedLog?.args.result
115
+
116
+ const decrypted = await owner.decryptValue256({
117
+ ciphertextHigh: ctResult.ciphertextHigh,
118
+ ciphertextLow: ctResult.ciphertextLow
119
+ })
120
+
121
+ console.log(`✓ Decrypted result: ${decrypted}`)
122
+ expect(decrypted).to.equal(expected)
123
+ console.log(` ✅ SUCCESS: Subtraction verified!\n`)
124
+ }
125
+ })
126
+
127
+ it("Should perform division and user can decrypt result", async function () {
128
+ // Use values > 128 bits to ensure itUint256 encryption
129
+ const a = (2n ** 130n) + 1000n
130
+ const b = (2n ** 129n) + 10n
131
+ const expected = a / b
132
+ console.log(`\n➗ Testing: ${a} / ${b} = ${expected}`)
133
+
134
+ const itA = await owner.encryptValue256(a, contractAddress, contract.div256.fragment.selector)
135
+ const itB = await owner.encryptValue256(b, contractAddress, contract.div256.fragment.selector)
136
+
137
+ const tx = await contract.div256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
138
+ const receipt = await tx.wait()
139
+ expect(receipt?.status).to.equal(1)
140
+
141
+ const resultEvent = receipt?.logs.find((log: any) => {
142
+ try {
143
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
144
+ } catch {
145
+ return false
146
+ }
147
+ })
148
+
149
+ if (resultEvent) {
150
+ const parsedLog = contract.interface.parseLog(resultEvent)
151
+ const ctResult: ctUint256 = parsedLog?.args.result
152
+
153
+ const decrypted = await owner.decryptValue256({
154
+ ciphertextHigh: ctResult.ciphertextHigh,
155
+ ciphertextLow: ctResult.ciphertextLow
156
+ })
157
+
158
+ console.log(`✓ Decrypted result: ${decrypted}`)
159
+ expect(decrypted).to.equal(expected)
160
+ console.log(` ✅ SUCCESS: Division verified!\n`)
161
+ }
162
+ })
163
+
164
+ it("Should perform modulo and user can decrypt result", async function () {
165
+ // Use values > 128 bits to ensure itUint256 encryption
166
+ const a = (2n ** 130n) + 1000n
167
+ const b = (2n ** 129n) + 300n
168
+ const expected = a % b
169
+ console.log(`\n🔢 Testing: ${a} % ${b} = ${expected}`)
170
+
171
+ const itA = await owner.encryptValue256(a, contractAddress, contract.rem256.fragment.selector)
172
+ const itB = await owner.encryptValue256(b, contractAddress, contract.rem256.fragment.selector)
173
+
174
+ const tx = await contract.rem256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
175
+ const receipt = await tx.wait()
176
+ expect(receipt?.status).to.equal(1)
177
+
178
+ const resultEvent = receipt?.logs.find((log: any) => {
179
+ try {
180
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
181
+ } catch {
182
+ return false
183
+ }
184
+ })
185
+
186
+ if (resultEvent) {
187
+ const parsedLog = contract.interface.parseLog(resultEvent)
188
+ const ctResult: ctUint256 = parsedLog?.args.result
189
+
190
+ const decrypted = await owner.decryptValue256({
191
+ ciphertextHigh: ctResult.ciphertextHigh,
192
+ ciphertextLow: ctResult.ciphertextLow
193
+ })
194
+
195
+ console.log(`✓ Decrypted result: ${decrypted}`)
196
+ expect(decrypted).to.equal(expected)
197
+ console.log(` ✅ SUCCESS: Modulo verified!\n`)
198
+ }
199
+ })
200
+ })
201
+
202
+ describe("Bitwise Operations", function () {
203
+ it("Should perform AND operation and user can decrypt result", async function () {
204
+ // Use values > 128 bits to ensure itUint256 encryption
205
+ const a = (2n ** 130n) + BigInt(0xFF) // > 128 bits + 255
206
+ const b = (2n ** 129n) + BigInt(0xF0) // > 128 bits + 240
207
+ const expected = a & b
208
+ console.log(`\n& Testing: ${a} & ${b} = ${expected}`)
209
+
210
+ const itA = await owner.encryptValue256(a, contractAddress, contract.and256.fragment.selector)
211
+ const itB = await owner.encryptValue256(b, contractAddress, contract.and256.fragment.selector)
212
+
213
+ const tx = await contract.and256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
214
+ const receipt = await tx.wait()
215
+ expect(receipt?.status).to.equal(1)
216
+
217
+ const resultEvent = receipt?.logs.find((log: any) => {
218
+ try {
219
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
220
+ } catch {
221
+ return false
222
+ }
223
+ })
224
+
225
+ if (resultEvent) {
226
+ const parsedLog = contract.interface.parseLog(resultEvent)
227
+ const ctResult: ctUint256 = parsedLog?.args.result
228
+
229
+ const decrypted = await owner.decryptValue256({
230
+ ciphertextHigh: ctResult.ciphertextHigh,
231
+ ciphertextLow: ctResult.ciphertextLow
232
+ })
233
+
234
+ console.log(`✓ Decrypted result: ${decrypted}`)
235
+ expect(decrypted).to.equal(expected)
236
+ console.log(` ✅ SUCCESS: AND verified!\n`)
237
+ }
238
+ })
239
+
240
+ it("Should perform OR operation and user can decrypt result", async function () {
241
+ // Use values > 128 bits to ensure itUint256 encryption
242
+ const a = (2n ** 130n) + BigInt(0xF0) // > 128 bits + 240
243
+ const b = (2n ** 129n) + BigInt(0x0F) // > 128 bits + 15
244
+ const expected = a | b
245
+ console.log(`\n| Testing: ${a} | ${b} = ${expected}`)
246
+
247
+ const itA = await owner.encryptValue256(a, contractAddress, contract.or256.fragment.selector)
248
+ const itB = await owner.encryptValue256(b, contractAddress, contract.or256.fragment.selector)
249
+
250
+ const tx = await contract.or256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
251
+ const receipt = await tx.wait()
252
+ expect(receipt?.status).to.equal(1)
253
+
254
+ const resultEvent = receipt?.logs.find((log: any) => {
255
+ try {
256
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
257
+ } catch {
258
+ return false
259
+ }
260
+ })
261
+
262
+ if (resultEvent) {
263
+ const parsedLog = contract.interface.parseLog(resultEvent)
264
+ const ctResult: ctUint256 = parsedLog?.args.result
265
+
266
+ const decrypted = await owner.decryptValue256({
267
+ ciphertextHigh: ctResult.ciphertextHigh,
268
+ ciphertextLow: ctResult.ciphertextLow
269
+ })
270
+
271
+ console.log(`✓ Decrypted result: ${decrypted}`)
272
+ expect(decrypted).to.equal(expected)
273
+ console.log(` ✅ SUCCESS: OR verified!\n`)
274
+ }
275
+ })
276
+
277
+ it("Should perform XOR operation and user can decrypt result", async function () {
278
+ // Use values > 128 bits to ensure itUint256 encryption
279
+ const a = (2n ** 130n) + BigInt(0xFF) // > 128 bits + 255
280
+ const b = (2n ** 129n) + BigInt(0xF0) // > 128 bits + 240
281
+ const expected = a ^ b
282
+ console.log(`\n^ Testing: ${a} ^ ${b} = ${expected}`)
283
+
284
+ const itA = await owner.encryptValue256(a, contractAddress, contract.xor256.fragment.selector)
285
+ const itB = await owner.encryptValue256(b, contractAddress, contract.xor256.fragment.selector)
286
+
287
+ const tx = await contract.xor256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
288
+ const receipt = await tx.wait()
289
+ expect(receipt?.status).to.equal(1)
290
+
291
+ const resultEvent = receipt?.logs.find((log: any) => {
292
+ try {
293
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
294
+ } catch {
295
+ return false
296
+ }
297
+ })
298
+
299
+ if (resultEvent) {
300
+ const parsedLog = contract.interface.parseLog(resultEvent)
301
+ const ctResult: ctUint256 = parsedLog?.args.result
302
+
303
+ const decrypted = await owner.decryptValue256({
304
+ ciphertextHigh: ctResult.ciphertextHigh,
305
+ ciphertextLow: ctResult.ciphertextLow
306
+ })
307
+
308
+ console.log(`✓ Decrypted result: ${decrypted}`)
309
+ expect(decrypted).to.equal(expected)
310
+ console.log(` ✅ SUCCESS: XOR verified!\n`)
311
+ }
312
+ })
313
+
314
+ it("Should perform shift left and user can decrypt result", async function () {
315
+ // Use value > 128 bits to ensure itUint256 encryption
316
+ const a = (2n ** 130n) + BigInt(10)
317
+ const bits = 2
318
+ const expected = a << BigInt(bits)
319
+ console.log(`\n<< Testing: ${a} << ${bits} = ${expected}`)
320
+
321
+ const itA = await owner.encryptValue256(a, contractAddress, contract.shl256.fragment.selector)
322
+
323
+ const tx = await contract.shl256(itA, bits, owner.address, { gasLimit: GAS_LIMIT })
324
+ const receipt = await tx.wait()
325
+ expect(receipt?.status).to.equal(1)
326
+
327
+ const resultEvent = receipt?.logs.find((log: any) => {
328
+ try {
329
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
330
+ } catch {
331
+ return false
332
+ }
333
+ })
334
+
335
+ if (resultEvent) {
336
+ const parsedLog = contract.interface.parseLog(resultEvent)
337
+ const ctResult: ctUint256 = parsedLog?.args.result
338
+
339
+ const decrypted = await owner.decryptValue256({
340
+ ciphertextHigh: ctResult.ciphertextHigh,
341
+ ciphertextLow: ctResult.ciphertextLow
342
+ })
343
+
344
+ console.log(`✓ Decrypted result: ${decrypted}`)
345
+ expect(decrypted).to.equal(expected)
346
+ console.log(` ✅ SUCCESS: Shift left verified!\n`)
347
+ }
348
+ })
349
+
350
+ it("Should perform shift right and user can decrypt result", async function () {
351
+ // Use value > 128 bits to ensure itUint256 encryption
352
+ const a = (2n ** 130n) + BigInt(40)
353
+ const bits = 2
354
+ const expected = a >> BigInt(bits)
355
+ console.log(`\n>> Testing: ${a} >> ${bits} = ${expected}`)
356
+
357
+ const itA = await owner.encryptValue256(a, contractAddress, contract.shr256.fragment.selector)
358
+
359
+ const tx = await contract.shr256(itA, bits, owner.address, { gasLimit: GAS_LIMIT })
360
+ const receipt = await tx.wait()
361
+ expect(receipt?.status).to.equal(1)
362
+
363
+ const resultEvent = receipt?.logs.find((log: any) => {
364
+ try {
365
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
366
+ } catch {
367
+ return false
368
+ }
369
+ })
370
+
371
+ if (resultEvent) {
372
+ const parsedLog = contract.interface.parseLog(resultEvent)
373
+ const ctResult: ctUint256 = parsedLog?.args.result
374
+
375
+ const decrypted = await owner.decryptValue256({
376
+ ciphertextHigh: ctResult.ciphertextHigh,
377
+ ciphertextLow: ctResult.ciphertextLow
378
+ })
379
+
380
+ console.log(`✓ Decrypted result: ${decrypted}`)
381
+ expect(decrypted).to.equal(expected)
382
+ console.log(` ✅ SUCCESS: Shift right verified!\n`)
383
+ }
384
+ })
385
+ })
386
+
387
+ // Note: Comparison operations (eq, gt, lt) return gtBool which requires different handling
388
+ // They are excluded from these tests but can be implemented separately if needed
389
+
390
+ describe("Big Number Operations (> 128-bit)", function () {
391
+ it("Should perform addition with 256-bit numbers and user can decrypt result", async function () {
392
+ // Use numbers larger than 128-bit
393
+ const a = BigInt("340282366920938463463374607431768211456") // 2^128 (129 bits)
394
+ const b = BigInt("340282366920938463463374607431768211457") // 2^128 + 1 (129 bits)
395
+ // Both > 128 bits ✓, a + b = 2^129 + 1 (130 bits) - safe
396
+ const expected = a + b
397
+ console.log(`\n➕ Testing BIG: ${a} + ${b}`)
398
+ console.log(` Expected: ${expected}`)
399
+
400
+ const itA = await owner.encryptValue256(a, contractAddress, contract.add256.fragment.selector)
401
+ const itB = await owner.encryptValue256(b, contractAddress, contract.add256.fragment.selector)
402
+
403
+ console.log("📝 Performing addition on contract with 256-bit numbers...")
404
+ const tx = await contract.add256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
405
+ const receipt = await tx.wait()
406
+ expect(receipt?.status).to.equal(1)
407
+
408
+ const resultEvent = receipt?.logs.find((log: any) => {
409
+ try {
410
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
411
+ } catch {
412
+ return false
413
+ }
414
+ })
415
+
416
+ if (resultEvent) {
417
+ const parsedLog = contract.interface.parseLog(resultEvent)
418
+ const ctResult: ctUint256 = parsedLog?.args.result
419
+
420
+ console.log("📝 User decrypting 256-bit result...")
421
+ const decrypted = await owner.decryptValue256({
422
+ ciphertextHigh: ctResult.ciphertextHigh,
423
+ ciphertextLow: ctResult.ciphertextLow
424
+ })
425
+
426
+ console.log(`✓ Decrypted result: ${decrypted}`)
427
+ expect(decrypted).to.equal(expected)
428
+ console.log(` ✅ SUCCESS: 256-bit addition verified!\n`)
429
+ }
430
+ })
431
+
432
+
433
+ it("Should perform subtraction with 200-bit numbers and user can decrypt result", async function () {
434
+ const a = BigInt("1606938044258990275541962092341162602522202993782792835301376") // ~200-bit
435
+ const b = BigInt("806469022129495137770981046170581301261101496891396417650688") // ~199-bit
436
+ const expected = a - b
437
+ console.log(`\n➖ Testing BIG subtraction`)
438
+ console.log(` Result should be ~199-bit number`)
439
+
440
+ const itA = await owner.encryptValue256(a, contractAddress, contract.sub256.fragment.selector)
441
+ const itB = await owner.encryptValue256(b, contractAddress, contract.sub256.fragment.selector)
442
+
443
+ const tx = await contract.sub256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
444
+ const receipt = await tx.wait()
445
+ expect(receipt?.status).to.equal(1)
446
+
447
+ const resultEvent = receipt?.logs.find((log: any) => {
448
+ try {
449
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
450
+ } catch {
451
+ return false
452
+ }
453
+ })
454
+
455
+ if (resultEvent) {
456
+ const parsedLog = contract.interface.parseLog(resultEvent)
457
+ const ctResult: ctUint256 = parsedLog?.args.result
458
+
459
+ const decrypted = await owner.decryptValue256({
460
+ ciphertextHigh: ctResult.ciphertextHigh,
461
+ ciphertextLow: ctResult.ciphertextLow
462
+ })
463
+
464
+ console.log(`✓ Decrypted result: ${decrypted}`)
465
+ expect(decrypted).to.equal(expected)
466
+ console.log(` ✅ SUCCESS: 200-bit subtraction verified!\n`)
467
+ }
468
+ })
469
+
470
+ it("Should perform max uint256 operations", async function () {
471
+ // Test with very large numbers close to max uint256
472
+ const maxUint256 = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935") // 2^256 - 1
473
+ const largeNum = maxUint256 / BigInt(2)
474
+ // Use value > 128 bits for second operand to ensure itUint256 encryption
475
+ const mask = (2n ** 130n) + BigInt(0xFFFFFFFF)
476
+ const expected = largeNum & mask
477
+
478
+ console.log(`\n& Testing with near-max uint256`)
479
+ console.log(` Using number: ${largeNum}`)
480
+
481
+ const itA = await owner.encryptValue256(largeNum, contractAddress, contract.and256.fragment.selector)
482
+ const itB = await owner.encryptValue256(mask, contractAddress, contract.and256.fragment.selector)
483
+
484
+ const tx = await contract.and256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
485
+ const receipt = await tx.wait()
486
+ expect(receipt?.status).to.equal(1)
487
+
488
+ const resultEvent = receipt?.logs.find((log: any) => {
489
+ try {
490
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
491
+ } catch {
492
+ return false
493
+ }
494
+ })
495
+
496
+ if (resultEvent) {
497
+ const parsedLog = contract.interface.parseLog(resultEvent)
498
+ const ctResult: ctUint256 = parsedLog?.args.result
499
+
500
+ const decrypted = await owner.decryptValue256({
501
+ ciphertextHigh: ctResult.ciphertextHigh,
502
+ ciphertextLow: ctResult.ciphertextLow
503
+ })
504
+
505
+ console.log(`✓ Decrypted result: ${decrypted}`)
506
+ expect(decrypted).to.equal(expected)
507
+ console.log(` ✅ SUCCESS: Near-max uint256 operation verified!\n`)
508
+ }
509
+ })
510
+ })
511
+
512
+ describe("Min/Max Operations", function () {
513
+ it("Should get minimum of two values and user can decrypt result", async function () {
514
+ // Use values > 128 bits to ensure itUint256 encryption
515
+ const a = (2n ** 130n) + 500n
516
+ const b = (2n ** 130n) + 1000n
517
+ const expected = a < b ? a : b
518
+ console.log(`\nmin Testing: min(${a}, ${b}) = ${expected}`)
519
+
520
+ const itA = await owner.encryptValue256(a, contractAddress, contract.min256.fragment.selector)
521
+ const itB = await owner.encryptValue256(b, contractAddress, contract.min256.fragment.selector)
522
+
523
+ const tx = await contract.min256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
524
+ const receipt = await tx.wait()
525
+ expect(receipt?.status).to.equal(1)
526
+
527
+ const resultEvent = receipt?.logs.find((log: any) => {
528
+ try {
529
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
530
+ } catch {
531
+ return false
532
+ }
533
+ })
534
+
535
+ if (resultEvent) {
536
+ const parsedLog = contract.interface.parseLog(resultEvent)
537
+ const ctResult: ctUint256 = parsedLog?.args.result
538
+
539
+ const decrypted = await owner.decryptValue256({
540
+ ciphertextHigh: ctResult.ciphertextHigh,
541
+ ciphertextLow: ctResult.ciphertextLow
542
+ })
543
+
544
+ console.log(`✓ Decrypted result: ${decrypted}`)
545
+ expect(decrypted).to.equal(expected)
546
+ console.log(` ✅ SUCCESS: Min verified!\n`)
547
+ }
548
+ })
549
+
550
+ it("Should get maximum of two values and user can decrypt result", async function () {
551
+ // Use values > 128 bits to ensure itUint256 encryption
552
+ const a = (2n ** 130n) + 500n
553
+ const b = (2n ** 130n) + 1000n
554
+ const expected = a > b ? a : b
555
+ console.log(`\nmax Testing: max(${a}, ${b}) = ${expected}`)
556
+
557
+ const itA = await owner.encryptValue256(a, contractAddress, contract.max256.fragment.selector)
558
+ const itB = await owner.encryptValue256(b, contractAddress, contract.max256.fragment.selector)
559
+
560
+ const tx = await contract.max256(itA, itB, owner.address, { gasLimit: GAS_LIMIT })
561
+ const receipt = await tx.wait()
562
+ expect(receipt?.status).to.equal(1)
563
+
564
+ const resultEvent = receipt?.logs.find((log: any) => {
565
+ try {
566
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
567
+ } catch {
568
+ return false
569
+ }
570
+ })
571
+
572
+ if (resultEvent) {
573
+ const parsedLog = contract.interface.parseLog(resultEvent)
574
+ const ctResult: ctUint256 = parsedLog?.args.result
575
+
576
+ const decrypted = await owner.decryptValue256({
577
+ ciphertextHigh: ctResult.ciphertextHigh,
578
+ ciphertextLow: ctResult.ciphertextLow
579
+ })
580
+
581
+ console.log(`✓ Decrypted result: ${decrypted}`)
582
+ expect(decrypted).to.equal(expected)
583
+ console.log(` ✅ SUCCESS: Max verified!\n`)
584
+ }
585
+ })
586
+ })
587
+
588
+ })
589
+