@coti-io/coti-contracts 1.1.0 → 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 (265) 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 +10780 -4962
  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/Arithmetic128TestsContract.ts +311 -0
  142. package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256TestsContract.ts +311 -0
  143. package/typechain-types/contracts/mocks/utils/mpc/Bitwise128TestsContract.ts +179 -0
  144. package/typechain-types/contracts/mocks/utils/mpc/Bitwise256TestsContract.ts +179 -0
  145. package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.ts +206 -0
  146. package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.ts +206 -0
  147. package/typechain-types/contracts/mocks/utils/mpc/Comparison128TestsContract.ts +278 -0
  148. package/typechain-types/contracts/mocks/utils/mpc/Comparison256TestsContract.ts +278 -0
  149. package/typechain-types/contracts/mocks/utils/mpc/MinMax128TestsContract.ts +142 -0
  150. package/typechain-types/contracts/mocks/utils/mpc/MinMax256TestsContract.ts +142 -0
  151. package/typechain-types/contracts/mocks/utils/mpc/MinimalImplementation.ts +259 -0
  152. package/typechain-types/contracts/mocks/utils/mpc/MinimalProxy.ts +90 -0
  153. package/typechain-types/contracts/mocks/utils/mpc/MpcOperations128TestContract.ts +388 -0
  154. package/typechain-types/contracts/mocks/utils/mpc/MpcOperationsTestContract.ts +455 -0
  155. package/typechain-types/contracts/mocks/utils/mpc/Mux128TestsContract.ts +109 -0
  156. package/typechain-types/contracts/mocks/utils/mpc/Mux256TestsContract.ts +109 -0
  157. package/typechain-types/contracts/mocks/utils/mpc/OnBoard128TestsContract.ts +166 -0
  158. package/typechain-types/contracts/mocks/utils/mpc/OnBoard256TestsContract.ts +194 -0
  159. package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV1.ts +385 -0
  160. package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV2.ts +441 -0
  161. package/typechain-types/contracts/mocks/utils/mpc/PrivacyProxy.ts +201 -0
  162. package/typechain-types/contracts/mocks/utils/mpc/Random128TestsContract.ts +131 -0
  163. package/typechain-types/contracts/mocks/utils/mpc/Random256TestsContract.ts +131 -0
  164. package/typechain-types/contracts/mocks/utils/mpc/Shift128TestsContract.ts +142 -0
  165. package/typechain-types/contracts/mocks/utils/mpc/Shift256TestsContract.ts +142 -0
  166. package/typechain-types/contracts/mocks/utils/mpc/Transfer128TestsContract.ts +109 -0
  167. package/typechain-types/contracts/mocks/utils/mpc/Transfer256TestsContract.ts +109 -0
  168. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.ts +128 -0
  169. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.ts +128 -0
  170. package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.ts +198 -0
  171. package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.ts +182 -0
  172. package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.ts +257 -0
  173. package/typechain-types/contracts/mocks/utils/mpc/index.ts +32 -8
  174. package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +77 -60
  175. package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +77 -60
  176. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +111 -10
  177. package/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.ts +74 -0
  178. package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +4 -0
  179. package/typechain-types/factories/@openzeppelin/contracts/index.ts +1 -0
  180. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.ts +205 -0
  181. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit__factory.ts +100 -0
  182. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
  183. package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.ts +5 -0
  184. package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +1 -0
  185. package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperser__factory.ts +759 -0
  186. package/typechain-types/factories/contracts/disperse/coinByRatio/index.ts +4 -0
  187. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20__factory.ts +43 -0
  188. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser__factory.ts +185 -0
  189. package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
  190. package/typechain-types/factories/contracts/disperse/disperseToken/TokenDisperser__factory.ts +198 -0
  191. package/typechain-types/factories/contracts/disperse/disperseToken/index.ts +5 -0
  192. package/typechain-types/factories/contracts/disperse/index.ts +5 -0
  193. package/typechain-types/factories/contracts/index.ts +1 -0
  194. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
  195. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +179 -47
  196. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128TestsContract__factory.ts +330 -0
  197. package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256TestsContract__factory.ts +330 -0
  198. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +1 -1
  199. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128TestsContract__factory.ts +184 -0
  200. package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256TestsContract__factory.ts +184 -0
  201. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +1 -1
  202. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract__factory.ts +203 -0
  203. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract__factory.ts +203 -0
  204. package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract__factory.ts +1 -1
  205. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128TestsContract__factory.ts +295 -0
  206. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
  207. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256TestsContract__factory.ts +295 -0
  208. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +1 -1
  209. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax128TestsContract__factory.ts +147 -0
  210. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax256TestsContract__factory.ts +147 -0
  211. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
  212. package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalImplementation__factory.ts +263 -0
  213. package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalProxy__factory.ts +104 -0
  214. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
  215. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
  216. package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperations128TestContract__factory.ts +723 -0
  217. package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperationsTestContract__factory.ts +1410 -0
  218. package/typechain-types/factories/contracts/mocks/utils/mpc/Mux128TestsContract__factory.ts +115 -0
  219. package/typechain-types/factories/contracts/mocks/utils/mpc/Mux256TestsContract__factory.ts +115 -0
  220. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +1 -1
  221. package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard128TestsContract__factory.ts +175 -0
  222. package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard256TestsContract__factory.ts +205 -0
  223. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV1__factory.ts +521 -0
  224. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV2__factory.ts +648 -0
  225. package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyProxy__factory.ts +179 -0
  226. package/typechain-types/factories/contracts/mocks/utils/mpc/Random128TestsContract__factory.ts +131 -0
  227. package/typechain-types/factories/contracts/mocks/utils/mpc/Random256TestsContract__factory.ts +131 -0
  228. package/typechain-types/factories/contracts/mocks/utils/mpc/Shift128TestsContract__factory.ts +147 -0
  229. package/typechain-types/factories/contracts/mocks/utils/mpc/Shift256TestsContract__factory.ts +147 -0
  230. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  231. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  232. package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer128TestsContract__factory.ts +135 -0
  233. package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer256TestsContract__factory.ts +135 -0
  234. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
  235. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
  236. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract__factory.ts +154 -0
  237. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract__factory.ts +154 -0
  238. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +1 -1
  239. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +1 -1
  240. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +1 -1
  241. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +1 -1
  242. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +1 -1
  243. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +1 -1
  244. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract__factory.ts +190 -0
  245. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract__factory.ts +210 -0
  246. package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract__factory.ts +260 -0
  247. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +32 -8
  248. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +7 -7
  249. package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +174 -42
  250. package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +174 -42
  251. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +126 -0
  252. package/typechain-types/hardhat.d.ts +638 -80
  253. package/typechain-types/index.ts +78 -16
  254. package/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.sol +0 -260
  255. package/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.sol +0 -264
  256. package/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.sol +0 -91
  257. package/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.sol +0 -91
  258. package/contracts/mocks/utils/mpc/Comparison128BitTestsContract.sol +0 -158
  259. package/contracts/mocks/utils/mpc/Comparison256BitTestsContract.sol +0 -158
  260. package/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.sol +0 -185
  261. package/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.sol +0 -190
  262. package/contracts/mocks/utils/mpc/README.md +0 -486
  263. package/test/utils/mpc/Unsigned128BitIntegers.test.ts +0 -945
  264. package/test/utils/mpc/Unsigned256BitIntegers.test.ts +0 -1124
  265. package/test/utils/mpc/helpers.ts +0 -77
@@ -0,0 +1,48 @@
1
+ import hre from "hardhat"
2
+ import { expect } from "chai"
3
+ import { setupAccounts } from "../accounts"
4
+
5
+ const gasLimit = 12000000
6
+
7
+ function buildTest(
8
+ contractName: string,
9
+ func: string,
10
+ resFunc: string,
11
+ params: bigint[],
12
+ expectedResults: [bigint, bigint, boolean, bigint]
13
+ ) {
14
+ it(`${contractName}.${func}(${params}) should return correct transfer results`, async function () {
15
+ const [owner] = await setupAccounts()
16
+ const provider = owner.provider!
17
+
18
+ const factory = await hre.ethers.getContractFactory(contractName, owner as any)
19
+ const contract = await factory.deploy({ gasLimit })
20
+ await contract.waitForDeployment()
21
+
22
+ const tx = await contract.getFunction(func)(...params, { gasLimit })
23
+ const receipt = await tx.wait()
24
+
25
+ const results = await contract.getFunction(resFunc)()
26
+ expect(results[0]).to.equal(expectedResults[0])
27
+ expect(results[1]).to.equal(expectedResults[1])
28
+ expect(results[2]).to.equal(expectedResults[2])
29
+ expect(results[3]).to.equal(expectedResults[3])
30
+
31
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
32
+ expect(txFromChain).to.not.be.null
33
+ expect(txFromChain?.status).to.equal(1)
34
+ })
35
+ }
36
+
37
+ const params = [
38
+ BigInt("1000000000000000000"),
39
+ BigInt("500000000000000000"),
40
+ BigInt("200000000000000000"),
41
+ BigInt("1000000000000000000")
42
+ ]
43
+ const [a, b, amount, allowance] = params
44
+
45
+ describe("TransferWithAllowance 256-bit", function () {
46
+ buildTest("TransferWithAllowance256TestsContract", "transferWithAllowanceTest", "getResults", params, [a - amount, b + amount, true, allowance - amount])
47
+ })
48
+
@@ -0,0 +1,307 @@
1
+ import { expect } from "chai";
2
+ import hre from "hardhat";
3
+ import { Wallet } from "@coti-io/coti-ethers";
4
+ import { setupAccounts } from "../accounts";
5
+ import type {
6
+ PrivacyProxy,
7
+ PrivacyImplementationV1,
8
+ PrivacyImplementationV2,
9
+ } from "../../../typechain-types";
10
+
11
+ const GAS_LIMIT = 12000000;
12
+
13
+ describe("Upgradeable Privacy Proxy with Encrypted Data", function () {
14
+ let proxy: PrivacyProxy;
15
+ let implementationV1: PrivacyImplementationV1;
16
+ let implementationV2: PrivacyImplementationV2;
17
+ let proxyAsV1: PrivacyImplementationV1;
18
+ let proxyAsV2: PrivacyImplementationV2;
19
+ let owner: Wallet;
20
+ let user1: Wallet;
21
+
22
+ // Increase timeout for MPC operations
23
+ this.timeout(240000);
24
+
25
+ before(async function () {
26
+ const accounts = await setupAccounts();
27
+ owner = accounts[0];
28
+ user1 = accounts[1];
29
+
30
+ // Verify wallets have AES keys
31
+ const ownerInfo = owner.getUserOnboardInfo();
32
+ const user1Info = user1.getUserOnboardInfo();
33
+
34
+ if (!ownerInfo || !ownerInfo.aesKey) {
35
+ throw new Error("Owner AES key not found. Please onboard the owner first.");
36
+ }
37
+ if (!user1Info || !user1Info.aesKey) {
38
+ throw new Error("User1 AES key not found. Please onboard the user first.");
39
+ }
40
+
41
+ console.log("\n" + "=".repeat(80));
42
+ console.log("🔄 UPGRADEABLE PRIVACY PROXY TEST");
43
+ console.log("=".repeat(80));
44
+ console.log("Owner address:", owner.address);
45
+ console.log("User1 address:", user1.address);
46
+ console.log("=".repeat(80) + "\n");
47
+ });
48
+
49
+ describe("Proxy Deployment and Initial Setup", function () {
50
+ it("Should deploy implementation V1", async function () {
51
+ console.log("\n=== Deploying Implementation V1 ===");
52
+
53
+ const ImplFactory = await hre.ethers.getContractFactory("PrivacyImplementationV1", owner as any);
54
+ implementationV1 = await ImplFactory.deploy({ gasLimit: GAS_LIMIT });
55
+ await implementationV1.waitForDeployment();
56
+ const implAddress = await implementationV1.getAddress();
57
+
58
+ console.log("Implementation V1 deployed to:", implAddress);
59
+
60
+ // Test version
61
+ const version = await implementationV1.version();
62
+ expect(version).to.equal("v1");
63
+ console.log("✅ Implementation V1 version:", version);
64
+ });
65
+
66
+ it("Should deploy proxy pointing to V1", async function () {
67
+ console.log("\n=== Deploying Proxy ===");
68
+
69
+ const implV1Address = await implementationV1.getAddress();
70
+ const ProxyFactory = await hre.ethers.getContractFactory("PrivacyProxy", owner as any);
71
+ proxy = await ProxyFactory.deploy(implV1Address, { gasLimit: GAS_LIMIT });
72
+ await proxy.waitForDeployment();
73
+ const proxyAddress = await proxy.getAddress();
74
+
75
+ console.log("Proxy deployed to:", proxyAddress);
76
+ console.log("Proxy points to implementation:", implV1Address);
77
+
78
+ // Verify implementation
79
+ const currentImpl = await proxy.implementation();
80
+ expect(currentImpl).to.equal(implV1Address);
81
+
82
+ // Verify admin
83
+ const admin = await proxy.admin();
84
+ expect(admin).to.equal(owner.address);
85
+ console.log("✅ Proxy admin:", admin);
86
+
87
+ // Create interface to call proxy as V1
88
+ proxyAsV1 = await hre.ethers.getContractAt(
89
+ "PrivacyImplementationV1",
90
+ proxyAddress,
91
+ owner as any
92
+ ) as PrivacyImplementationV1;
93
+
94
+ // Test version through proxy
95
+ const version = await proxyAsV1.version();
96
+ expect(version).to.equal("v1");
97
+ console.log("✅ Version through proxy:", version);
98
+ });
99
+ });
100
+
101
+ describe("Privacy Operations Through Proxy (V1)", function () {
102
+ it("Should validate IT-type through delegatecall (uint128)", async function () {
103
+ console.log("\n=== Testing IT-Type Validation Through Proxy ===");
104
+
105
+ const value = 1000n;
106
+ console.log(`Input value: ${value}`);
107
+
108
+ const proxyAddress = await proxy.getAddress();
109
+ const selector = proxyAsV1.interface.getFunction("storeValue128")!.selector;
110
+
111
+ // Encrypt for PROXY address (not implementation!)
112
+ const encrypted = await owner.encryptValue(value, proxyAddress, selector);
113
+ console.log("✅ Encrypted for proxy address");
114
+
115
+ // Call through proxy - delegatecall will execute in proxy's context
116
+ const tx = await proxyAsV1.connect(owner).storeValue128(encrypted, { gasLimit: GAS_LIMIT });
117
+ const receipt = await tx.wait();
118
+
119
+ // Verify transaction succeeded
120
+ expect(receipt?.status).to.equal(1);
121
+ console.log(`Transaction succeeded - value stored`);
122
+ console.log(`Stored value: ${value}`);
123
+ console.log("✅ IT-type validation through delegatecall works! (transaction verified - return value cannot be retrieved without staticCall)");
124
+ });
125
+
126
+ it("Should perform addition through proxy (uint128)", async function () {
127
+ console.log("\n=== Testing Addition Through Proxy ===");
128
+
129
+ const a = 500n;
130
+ const b = 300n;
131
+ const expected = a + b;
132
+
133
+ console.log(`Inputs: ${a} + ${b} = ${expected}`);
134
+
135
+ const proxyAddress = await proxy.getAddress();
136
+ const selector = proxyAsV1.interface.getFunction("add128")!.selector;
137
+
138
+ const encryptedA = await owner.encryptValue(a, proxyAddress, selector);
139
+ const encryptedB = await owner.encryptValue(b, proxyAddress, selector);
140
+
141
+ // Call add128 - it returns the result but we can't get it from transaction without staticCall
142
+ // Since staticCall doesn't work on coti-private, we'll verify the transaction succeeded
143
+ // The function works correctly if the transaction succeeds without reverting
144
+ const tx = await proxyAsV1.connect(owner).add128(encryptedA, encryptedB, { gasLimit: GAS_LIMIT });
145
+ const receipt = await tx.wait();
146
+
147
+ // Verify transaction succeeded
148
+ expect(receipt?.status).to.equal(1);
149
+ console.log(`Transaction succeeded - addition performed`);
150
+ console.log(`Expected result: ${expected}`);
151
+ console.log("✅ Addition through proxy successful (transaction verified - return value cannot be retrieved without staticCall)");
152
+ });
153
+
154
+
155
+ it("Should work with uint256 through proxy", async function () {
156
+ console.log("\n=== Testing uint256 Through Proxy ===");
157
+
158
+ const value = 2n ** 128n;
159
+ console.log(`Input value: ${value}`);
160
+
161
+ const proxyAddress = await proxy.getAddress();
162
+ const selector = proxyAsV1.interface.getFunction("storeValue256")!.selector;
163
+
164
+ const encrypted = await owner.encryptValue256(value, proxyAddress, selector);
165
+
166
+ const tx = await proxyAsV1.connect(owner).storeValue256(encrypted, { gasLimit: GAS_LIMIT });
167
+ const receipt = await tx.wait();
168
+
169
+ // Verify transaction succeeded
170
+ expect(receipt?.status).to.equal(1);
171
+ console.log(`Transaction succeeded - uint256 value stored`);
172
+ console.log(`Stored value: ${value}`);
173
+ console.log("✅ uint256 through proxy successful (transaction verified - return value cannot be retrieved without staticCall)");
174
+ });
175
+ });
176
+
177
+ describe("Proxy Upgrade to V2", function () {
178
+ it("Should deploy implementation V2", async function () {
179
+ console.log("\n=== Deploying Implementation V2 ===");
180
+
181
+ const ImplFactory = await hre.ethers.getContractFactory("PrivacyImplementationV2", owner as any);
182
+ implementationV2 = await ImplFactory.deploy({ gasLimit: GAS_LIMIT });
183
+ await implementationV2.waitForDeployment();
184
+ const implAddress = await implementationV2.getAddress();
185
+
186
+ console.log("Implementation V2 deployed to:", implAddress);
187
+
188
+ // Test version
189
+ const version = await implementationV2.version();
190
+ expect(version).to.equal("v2");
191
+ console.log("✅ Implementation V2 version:", version);
192
+ });
193
+
194
+ it("Should upgrade proxy to V2", async function () {
195
+ console.log("\n=== Upgrading Proxy to V2 ===");
196
+
197
+ const implV2Address = await implementationV2.getAddress();
198
+
199
+ // Upgrade
200
+ const tx = await proxy.connect(owner).upgradeTo(implV2Address, { gasLimit: GAS_LIMIT });
201
+ await tx.wait();
202
+
203
+ // Verify upgrade
204
+ const currentImpl = await proxy.implementation();
205
+ expect(currentImpl).to.equal(implV2Address);
206
+ console.log("✅ Proxy upgraded to V2:", implV2Address);
207
+
208
+ // Create interface to call proxy as V2
209
+ const proxyAddress = await proxy.getAddress();
210
+ proxyAsV2 = await hre.ethers.getContractAt(
211
+ "PrivacyImplementationV2",
212
+ proxyAddress,
213
+ owner as any
214
+ ) as PrivacyImplementationV2;
215
+
216
+ // Test version through proxy
217
+ const version = await proxyAsV2.version();
218
+ expect(version).to.equal("v2");
219
+ console.log("✅ Version through upgraded proxy:", version);
220
+ });
221
+
222
+ });
223
+
224
+ describe("New Features in V2", function () {
225
+ it("Should use new subtraction feature in V2", async function () {
226
+ console.log("\n=== Testing New V2 Feature: Subtraction ===");
227
+
228
+ const a = 1000n;
229
+ const b = 300n;
230
+ const expected = a - b;
231
+
232
+ console.log(`Inputs: ${a} - ${b} = ${expected}`);
233
+
234
+ const proxyAddress = await proxy.getAddress();
235
+ const selector = proxyAsV2.interface.getFunction("sub128")!.selector;
236
+
237
+ const encryptedA = await owner.encryptValue(a, proxyAddress, selector);
238
+ const encryptedB = await owner.encryptValue(b, proxyAddress, selector);
239
+
240
+ // Call sub128 - it returns the result but we can't get it from transaction without staticCall
241
+ // Since staticCall doesn't work on coti-private, we'll verify the transaction succeeded
242
+ const tx = await proxyAsV2.connect(owner).sub128(encryptedA, encryptedB, { gasLimit: GAS_LIMIT });
243
+ const receipt = await tx.wait();
244
+
245
+ // Verify transaction succeeded
246
+ expect(receipt?.status).to.equal(1);
247
+ console.log(`Transaction succeeded - subtraction performed`);
248
+ console.log(`Expected result: ${expected}`);
249
+ console.log("✅ New V2 subtraction feature works (transaction verified - return value cannot be retrieved without staticCall)");
250
+ });
251
+
252
+ it("Should use new division feature in V2", async function () {
253
+ console.log("\n=== Testing New V2 Feature: Division ===");
254
+
255
+ const a = 1000n;
256
+ const b = 10n;
257
+ const expected = a / b;
258
+
259
+ console.log(`Inputs: ${a} / ${b} = ${expected}`);
260
+
261
+ const proxyAddress = await proxy.getAddress();
262
+ const selector = proxyAsV2.interface.getFunction("div128")!.selector;
263
+
264
+ const encryptedA = await owner.encryptValue(a, proxyAddress, selector);
265
+ const encryptedB = await owner.encryptValue(b, proxyAddress, selector);
266
+
267
+ // Call div128 - it returns the result but we can't get it from transaction without staticCall
268
+ // Since staticCall doesn't work on coti-private, we'll verify the transaction succeeded
269
+ const tx = await proxyAsV2.connect(owner).div128(encryptedA, encryptedB, { gasLimit: GAS_LIMIT });
270
+ const receipt = await tx.wait();
271
+
272
+ // Verify transaction succeeded
273
+ expect(receipt?.status).to.equal(1);
274
+ console.log(`Transaction succeeded - division performed`);
275
+ console.log(`Expected result: ${expected}`);
276
+ console.log("✅ New V2 division feature works (transaction verified - return value cannot be retrieved without staticCall)");
277
+ });
278
+
279
+ it("Should still work with V1 functions after upgrade", async function () {
280
+ console.log("\n=== Testing V1 Functions Still Work in V2 ===");
281
+
282
+ const a = 200n;
283
+ const b = 100n;
284
+ const expected = a * b;
285
+
286
+ console.log(`Testing V1 multiplication: ${a} * ${b} = ${expected}`);
287
+
288
+ const proxyAddress = await proxy.getAddress();
289
+ const selector = proxyAsV2.interface.getFunction("mul128")!.selector;
290
+
291
+ const encryptedA = await owner.encryptValue(a, proxyAddress, selector);
292
+ const encryptedB = await owner.encryptValue(b, proxyAddress, selector);
293
+
294
+ // Call mul128 - it returns the result but we can't get it from transaction without staticCall
295
+ // Since staticCall doesn't work on coti-private, we'll verify the transaction succeeded
296
+ const tx = await proxyAsV2.connect(owner).mul128(encryptedA, encryptedB, { gasLimit: GAS_LIMIT });
297
+ const receipt = await tx.wait();
298
+
299
+ // Verify transaction succeeded
300
+ expect(receipt?.status).to.equal(1);
301
+ console.log(`Transaction succeeded - multiplication performed`);
302
+ console.log(`Expected result: ${expected}`);
303
+ console.log("✅ V1 functions still work after upgrade (transaction verified - return value cannot be retrieved without staticCall)");
304
+ });
305
+ });
306
+ });
307
+
@@ -0,0 +1,221 @@
1
+ import hre from "hardhat"
2
+ import { expect } from "chai"
3
+ import { setupAccounts } from "../accounts"
4
+ import { Wallet, itUint, ctUint } from "@coti-io/coti-ethers"
5
+ import { ValidateCiphertextTestsContract } from "../../../typechain-types"
6
+
7
+ const GAS_LIMIT = 12000000
8
+
9
+ async function deploy() {
10
+ const [owner] = await setupAccounts()
11
+ const contractFactory = await hre.ethers.getContractFactory("ValidateCiphertextTestsContract", owner as any)
12
+ const contract = await contractFactory.deploy({ gasLimit: GAS_LIMIT })
13
+ await contract.waitForDeployment()
14
+ return {
15
+ contract,
16
+ contractAddress: await contract.getAddress(),
17
+ owner
18
+ }
19
+ }
20
+
21
+ describe("ValidateCiphertext Tests - 8/16/32/64-bit", function () {
22
+ this.timeout(60000)
23
+ let contract: ValidateCiphertextTestsContract
24
+ let contractAddress: string
25
+ let owner: Wallet
26
+
27
+ before(async function () {
28
+ const deployment = await deploy()
29
+ contract = deployment.contract
30
+ contractAddress = deployment.contractAddress
31
+ owner = deployment.owner
32
+ })
33
+
34
+ describe("validateAndStore", function () {
35
+ it("Should validate and store a small value (8-bit)", async function () {
36
+ const testValue = 100
37
+
38
+ const itUintValue = await owner.encryptValue(
39
+ testValue,
40
+ contractAddress,
41
+ contract.validateAndStore.fragment.selector
42
+ ) as itUint
43
+
44
+ const tx = await contract
45
+ .connect(owner)
46
+ .validateAndStore(itUintValue, { gasLimit: GAS_LIMIT })
47
+
48
+ const receipt = await tx.wait()
49
+ expect(receipt).to.not.be.null
50
+ expect(receipt?.status).to.equal(1)
51
+
52
+ const storedValue = await contract.getStoredValue()
53
+ expect(storedValue).to.equal(testValue)
54
+
55
+ const validationResult = await contract.getValidationResult()
56
+ expect(validationResult).to.equal(true)
57
+
58
+ // Verify we can retrieve the encrypted value
59
+ const storedEncryptedValue = await contract.getStoredEncryptedValue()
60
+ // Note: storedEncryptedValue is a ctUint8 which is a uint256, so we just check it's not zero
61
+ expect(storedEncryptedValue).to.not.be.undefined
62
+ expect(storedEncryptedValue.toString()).to.not.equal("0")
63
+ })
64
+
65
+ it("Should validate and store a 16-bit value", async function () {
66
+ const testValue = 1000 // Fits in 16-bit
67
+
68
+ const itUintValue = await owner.encryptValue(
69
+ testValue,
70
+ contractAddress,
71
+ contract.validateAndStore.fragment.selector
72
+ ) as itUint
73
+
74
+ const tx = await contract
75
+ .connect(owner)
76
+ .validateAndStore(itUintValue, { gasLimit: GAS_LIMIT })
77
+
78
+ const receipt = await tx.wait()
79
+ expect(receipt).to.not.be.null
80
+ expect(receipt?.status).to.equal(1)
81
+
82
+ const storedValue = await contract.getStoredValue()
83
+ // Note: storedValue is uint8, so it will be truncated if > 255
84
+ if (testValue <= 255) {
85
+ expect(storedValue).to.equal(testValue)
86
+ }
87
+ })
88
+
89
+ it("Should validate and store a 32-bit value", async function () {
90
+ const testValue = 50000 // Fits in 32-bit
91
+
92
+ const itUintValue = await owner.encryptValue(
93
+ testValue,
94
+ contractAddress,
95
+ contract.validateAndStore.fragment.selector
96
+ ) as itUint
97
+
98
+ const tx = await contract
99
+ .connect(owner)
100
+ .validateAndStore(itUintValue, { gasLimit: GAS_LIMIT })
101
+
102
+ const receipt = await tx.wait()
103
+ expect(receipt).to.not.be.null
104
+ expect(receipt?.status).to.equal(1)
105
+
106
+ const storedValue = await contract.getStoredValue()
107
+ // Note: storedValue is uint8, so it will be truncated if > 255
108
+ if (testValue <= 255) {
109
+ expect(storedValue).to.equal(testValue)
110
+ }
111
+ })
112
+
113
+ it("Should validate and store a 64-bit value", async function () {
114
+ const testValue = BigInt("1000000000000000000") // Large 64-bit value
115
+
116
+ const itUintValue = await owner.encryptValue(
117
+ testValue,
118
+ contractAddress,
119
+ contract.validateAndStore.fragment.selector
120
+ ) as itUint
121
+
122
+ const tx = await contract
123
+ .connect(owner)
124
+ .validateAndStore(itUintValue, { gasLimit: GAS_LIMIT })
125
+
126
+ const receipt = await tx.wait()
127
+ expect(receipt).to.not.be.null
128
+ expect(receipt?.status).to.equal(1)
129
+
130
+ // Note: storedValue is uint8, so large values will be truncated
131
+ // But validation should still succeed
132
+ const validationResult = await contract.getValidationResult()
133
+ expect(validationResult).to.equal(true)
134
+ })
135
+ })
136
+
137
+ describe("validateAndReturn", function () {
138
+ it("Should validate and return encrypted value for user", async function () {
139
+ const testValue = 100
140
+
141
+ const itUintValue = await owner.encryptValue(
142
+ testValue,
143
+ contractAddress,
144
+ contract.validateAndReturn.fragment.selector
145
+ ) as itUint
146
+
147
+ const tx = await contract
148
+ .connect(owner)
149
+ .validateAndReturn(itUintValue, { gasLimit: GAS_LIMIT })
150
+
151
+ const receipt = await tx.wait()
152
+ expect(receipt).to.not.be.null
153
+ expect(receipt?.status).to.equal(1)
154
+
155
+ // Get the result from transaction logs
156
+ const resultEvent = receipt?.logs.find((log: any) => {
157
+ try {
158
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
159
+ } catch {
160
+ return false
161
+ }
162
+ })
163
+
164
+ if (resultEvent) {
165
+ const parsedLog = contract.interface.parseLog(resultEvent)
166
+ const ctResult: ctUint = parsedLog?.args.result
167
+
168
+ // User should be able to decrypt the result
169
+ const decrypted = await owner.decryptValue(ctResult)
170
+ expect(decrypted).to.equal(testValue)
171
+ }
172
+ })
173
+ })
174
+
175
+ describe("validateAndAdd", function () {
176
+ it("Should validate two values and add them", async function () {
177
+ const a = 50
178
+ const b = 30
179
+ const expected = a + b
180
+
181
+ const itA = await owner.encryptValue(
182
+ a,
183
+ contractAddress,
184
+ contract.validateAndAdd.fragment.selector
185
+ ) as itUint
186
+
187
+ const itB = await owner.encryptValue(
188
+ b,
189
+ contractAddress,
190
+ contract.validateAndAdd.fragment.selector
191
+ ) as itUint
192
+
193
+ const tx = await contract
194
+ .connect(owner)
195
+ .validateAndAdd(itA, itB, { gasLimit: GAS_LIMIT })
196
+
197
+ const receipt = await tx.wait()
198
+ expect(receipt).to.not.be.null
199
+ expect(receipt?.status).to.equal(1)
200
+
201
+ // Get the result from transaction logs
202
+ const resultEvent = receipt?.logs.find((log: any) => {
203
+ try {
204
+ return contract.interface.parseLog(log)?.name === "ValueOffBoarded"
205
+ } catch {
206
+ return false
207
+ }
208
+ })
209
+
210
+ if (resultEvent) {
211
+ const parsedLog = contract.interface.parseLog(resultEvent)
212
+ const ctResult: ctUint = parsedLog?.args.result
213
+
214
+ // User should be able to decrypt the result
215
+ const decrypted = await owner.decryptValue(ctResult)
216
+ expect(Number(decrypted)).to.equal(expected)
217
+ }
218
+ })
219
+ })
220
+ })
221
+