@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,237 @@
1
+ import hre from "hardhat"
2
+ import { expect } from "chai"
3
+ import { setupAccounts } from "../accounts"
4
+
5
+ const gasLimit = 12000000
6
+
7
+ describe("Negative Test Cases - 128-bit", function () {
8
+ // Increase timeout for MPC operations, especially overflow detection
9
+ this.timeout(300000) // 5 minutes
10
+
11
+ describe("Division by Zero", function () {
12
+ it("Should handle division by zero (may revert or return special value)", async function () {
13
+ this.timeout(60000) // 1 minute timeout
14
+ const [owner] = await setupAccounts()
15
+
16
+ const factory = await hre.ethers.getContractFactory("Arithmetic128TestsContract", owner as any)
17
+ const contract = await factory.deploy({ gasLimit })
18
+ await contract.waitForDeployment()
19
+
20
+ const a = BigInt("1000000000000000000")
21
+ const b = BigInt(0)
22
+
23
+ // Division by zero - check if it reverts or returns a value
24
+ try {
25
+ const tx = await contract.divTest(a, b, { gasLimit })
26
+ const receipt = await tx.wait()
27
+
28
+ // If it doesn't revert, check what value it returns
29
+ const result = await contract.getDivResult()
30
+ console.log(`Division by zero returned: ${result}`)
31
+ // Note: MPC precompile may handle division by zero differently
32
+ // It might return 0, max value, or some other special value
33
+ } catch (error: any) {
34
+ // If it reverts, that's also valid behavior
35
+ if (error.message && error.message.includes("revert")) {
36
+ console.log("Division by zero correctly reverted")
37
+ } else {
38
+ throw error
39
+ }
40
+ }
41
+ })
42
+
43
+ it("Should handle remainder by zero (may revert or return special value)", async function () {
44
+ this.timeout(60000) // 1 minute timeout
45
+ const [owner] = await setupAccounts()
46
+
47
+ const factory = await hre.ethers.getContractFactory("Arithmetic128TestsContract", owner as any)
48
+ const contract = await factory.deploy({ gasLimit })
49
+ await contract.waitForDeployment()
50
+
51
+ const a = BigInt("1000000000000000000")
52
+ const b = BigInt(0)
53
+
54
+ // Remainder by zero - check if it reverts or returns a value
55
+ try {
56
+ const tx = await contract.remTest(a, b, { gasLimit })
57
+ const receipt = await tx.wait()
58
+
59
+ // If it doesn't revert, check what value it returns
60
+ const result = await contract.getRemResult()
61
+ console.log(`Remainder by zero returned: ${result}`)
62
+ // Note: MPC precompile may handle remainder by zero differently
63
+ } catch (error: any) {
64
+ // If it reverts, that's also valid behavior
65
+ if (error.message && error.message.includes("revert")) {
66
+ console.log("Remainder by zero correctly reverted")
67
+ } else {
68
+ throw error
69
+ }
70
+ }
71
+ })
72
+ })
73
+
74
+ describe("Arithmetic Overflow - Checked Operations", function () {
75
+ // Note: Overflow detection tests are computationally expensive due to MPC operations
76
+ // These tests may take 1-3 minutes each to complete
77
+
78
+ it("Should detect overflow in checkedAdd with max values", async function () {
79
+ this.timeout(180000) // 3 minutes for this specific test
80
+ const [owner] = await setupAccounts()
81
+
82
+ const factory = await hre.ethers.getContractFactory("CheckedArithmetic128WithOverflowBitTestsContract", owner as any)
83
+ const contract = await factory.deploy({ gasLimit })
84
+ await contract.waitForDeployment()
85
+
86
+ // Test with values that will overflow
87
+ // Using smaller values to reduce computation time while still testing overflow
88
+ const nearMax128 = (BigInt(1) << BigInt(127)) // 2^127 (half of max)
89
+ const large = (BigInt(1) << BigInt(127)) + BigInt(1) // Will overflow when added
90
+
91
+ // This should succeed but overflow bit should be set
92
+ const tx = await contract.checkedAddWithOverflowBitTest(nearMax128, large, { gasLimit })
93
+ const receipt = await tx.wait()
94
+ expect(receipt?.status).to.equal(1)
95
+
96
+ // Check overflow bit
97
+ const overflowBit = await contract.getOverflowBit()
98
+ // Note: The actual behavior depends on the MPC precompile implementation
99
+ // If overflow is detected, overflowBit should be true
100
+ console.log(`Overflow bit detected: ${overflowBit}`)
101
+ })
102
+
103
+ it("Should detect underflow in checkedSub", async function () {
104
+ this.timeout(180000) // 3 minutes for this specific test
105
+ const [owner] = await setupAccounts()
106
+
107
+ const factory = await hre.ethers.getContractFactory("CheckedArithmetic128WithOverflowBitTestsContract", owner as any)
108
+ const contract = await factory.deploy({ gasLimit })
109
+ await contract.waitForDeployment()
110
+
111
+ // Test subtraction that would underflow
112
+ const small = BigInt(5)
113
+ const large = BigInt("1000000000000000000")
114
+
115
+ // This should succeed but overflow bit should be set (indicating underflow)
116
+ const tx = await contract.checkedSubWithOverflowBitTest(small, large, { gasLimit })
117
+ const receipt = await tx.wait()
118
+ expect(receipt?.status).to.equal(1)
119
+
120
+ // Check overflow bit
121
+ const overflowBit = await contract.getOverflowBit()
122
+ // If underflow is detected, overflowBit should be true
123
+ console.log(`Underflow bit detected: ${overflowBit}`)
124
+ })
125
+
126
+ it("Should detect overflow in checkedMul with large values", async function () {
127
+ this.timeout(180000) // 3 minutes for this specific test
128
+ const [owner] = await setupAccounts()
129
+
130
+ const factory = await hre.ethers.getContractFactory("CheckedArithmetic128WithOverflowBitTestsContract", owner as any)
131
+ const contract = await factory.deploy({ gasLimit })
132
+ await contract.waitForDeployment()
133
+
134
+ // Test multiplication that will overflow
135
+ // Using smaller values to reduce computation time while still testing overflow
136
+ const large1 = BigInt(1) << BigInt(80) // 2^80
137
+ const large2 = BigInt(1) << BigInt(70) // 2^70
138
+ // 2^80 * 2^70 = 2^150 > 2^128, will overflow
139
+
140
+ const tx = await contract.checkedMulWithOverflowBitTest(large1, large2, { gasLimit })
141
+ const receipt = await tx.wait()
142
+ expect(receipt?.status).to.equal(1)
143
+
144
+ // Check overflow bit
145
+ const overflowBit = await contract.getOverflowBit()
146
+ console.log(`Multiplication overflow bit detected: ${overflowBit}`)
147
+ })
148
+ })
149
+
150
+ describe("Edge Cases - Boundary Values", function () {
151
+ it("Should handle subtraction resulting in zero", async function () {
152
+ const [owner] = await setupAccounts()
153
+
154
+ const factory = await hre.ethers.getContractFactory("Arithmetic128TestsContract", owner as any)
155
+ const contract = await factory.deploy({ gasLimit })
156
+ await contract.waitForDeployment()
157
+
158
+ const a = BigInt("1000000000000000000")
159
+ const b = a // Same value
160
+
161
+ const tx = await contract.subTest(a, b, { gasLimit })
162
+ const receipt = await tx.wait()
163
+ expect(receipt?.status).to.equal(1)
164
+
165
+ const result = await contract.getSubResult()
166
+ expect(result).to.equal(BigInt(0))
167
+ })
168
+
169
+ it("Should handle max value operations", async function () {
170
+ const [owner] = await setupAccounts()
171
+
172
+ const factory = await hre.ethers.getContractFactory("Arithmetic128TestsContract", owner as any)
173
+ const contract = await factory.deploy({ gasLimit })
174
+ await contract.waitForDeployment()
175
+
176
+ const max128 = (BigInt(1) << BigInt(128)) - BigInt(1)
177
+ const zero = BigInt(0)
178
+
179
+ // Max + 0 should work
180
+ const tx = await contract.addTest(max128, zero, { gasLimit })
181
+ const receipt = await tx.wait()
182
+ expect(receipt?.status).to.equal(1)
183
+
184
+ const result = await contract.getAddResult()
185
+ expect(result).to.equal(max128)
186
+ })
187
+ })
188
+
189
+ describe("Invalid Shift Operations", function () {
190
+ it("Should handle shift amount >= 128 bits", async function () {
191
+ const [owner] = await setupAccounts()
192
+
193
+ const factory = await hre.ethers.getContractFactory("Shift128TestsContract", owner as any)
194
+ const contract = await factory.deploy({ gasLimit })
195
+ await contract.waitForDeployment()
196
+
197
+ const a = BigInt("1000000000000000000")
198
+ const shift128 = 128 // Equal to bit size
199
+ const shift129 = 129 // Greater than bit size (but uint8 max is 255, so this is valid)
200
+
201
+ // Shift by 128 (equal to bit size) - should work but result will be 0
202
+ const tx1 = await contract.shlTest(a, shift128, { gasLimit })
203
+ const receipt1 = await tx1.wait()
204
+ expect(receipt1?.status).to.equal(1)
205
+ const result1 = await contract.getShlResult()
206
+ expect(result1).to.equal(BigInt(0)) // All bits shifted out
207
+
208
+ // Shift by 129 (greater than bit size) - behavior depends on MPC precompile
209
+ const tx2 = await contract.shlTest(a, shift129, { gasLimit })
210
+ const receipt2 = await tx2.wait()
211
+ expect(receipt2?.status).to.equal(1)
212
+ const result2 = await contract.getShlResult()
213
+ // Result should be 0 or wrapped value depending on precompile behavior
214
+ console.log(`Shift by 129 returned: ${result2}`)
215
+ expect(result2).to.equal(BigInt(0)) // All bits shifted out
216
+ })
217
+
218
+ it("Should handle right shift by >= 128 bits", async function () {
219
+ const [owner] = await setupAccounts()
220
+
221
+ const factory = await hre.ethers.getContractFactory("Shift128TestsContract", owner as any)
222
+ const contract = await factory.deploy({ gasLimit })
223
+ await contract.waitForDeployment()
224
+
225
+ const a = BigInt("1000000000000000000")
226
+ const shift128 = 128
227
+
228
+ // Right shift by 128 - should result in 0
229
+ const tx = await contract.shrTest(a, shift128, { gasLimit })
230
+ const receipt = await tx.wait()
231
+ expect(receipt?.status).to.equal(1)
232
+ const result = await contract.getShrResult()
233
+ expect(result).to.equal(BigInt(0)) // All bits shifted out
234
+ })
235
+ })
236
+ })
237
+
@@ -0,0 +1,236 @@
1
+ import hre from "hardhat"
2
+ import { expect } from "chai"
3
+ import { setupAccounts } from "../accounts"
4
+
5
+ const gasLimit = 12000000
6
+
7
+ describe("Negative Test Cases - 256-bit", function () {
8
+ // Increase timeout for MPC operations, especially overflow detection
9
+ this.timeout(300000) // 5 minutes
10
+
11
+ describe("Division by Zero", function () {
12
+ it("Should handle division by zero (may revert or return special value)", async function () {
13
+ this.timeout(60000) // 1 minute timeout
14
+ const [owner] = await setupAccounts()
15
+
16
+ const factory = await hre.ethers.getContractFactory("Arithmetic256TestsContract", owner as any)
17
+ const contract = await factory.deploy({ gasLimit })
18
+ await contract.waitForDeployment()
19
+
20
+ const a = BigInt("1000000000000000000")
21
+ const b = BigInt(0)
22
+
23
+ // Division by zero - check if it reverts or returns a value
24
+ try {
25
+ const tx = await contract.divTest(a, b, { gasLimit })
26
+ const receipt = await tx.wait()
27
+
28
+ // If it doesn't revert, check what value it returns
29
+ const result = await contract.getDivResult()
30
+ console.log(`Division by zero returned: ${result}`)
31
+ // Note: MPC precompile may handle division by zero differently
32
+ // It might return 0, max value, or some other special value
33
+ } catch (error: any) {
34
+ // If it reverts, that's also valid behavior
35
+ if (error.message && error.message.includes("revert")) {
36
+ console.log("Division by zero correctly reverted")
37
+ } else {
38
+ throw error
39
+ }
40
+ }
41
+ })
42
+
43
+ it("Should handle remainder by zero (may revert or return special value)", async function () {
44
+ this.timeout(60000) // 1 minute timeout
45
+ const [owner] = await setupAccounts()
46
+
47
+ const factory = await hre.ethers.getContractFactory("Arithmetic256TestsContract", owner as any)
48
+ const contract = await factory.deploy({ gasLimit })
49
+ await contract.waitForDeployment()
50
+
51
+ const a = BigInt("1000000000000000000")
52
+ const b = BigInt(0)
53
+
54
+ // Remainder by zero - check if it reverts or returns a value
55
+ try {
56
+ const tx = await contract.remTest(a, b, { gasLimit })
57
+ const receipt = await tx.wait()
58
+
59
+ // If it doesn't revert, check what value it returns
60
+ const result = await contract.getRemResult()
61
+ console.log(`Remainder by zero returned: ${result}`)
62
+ // Note: MPC precompile may handle remainder by zero differently
63
+ } catch (error: any) {
64
+ // If it reverts, that's also valid behavior
65
+ if (error.message && error.message.includes("revert")) {
66
+ console.log("Remainder by zero correctly reverted")
67
+ } else {
68
+ throw error
69
+ }
70
+ }
71
+ })
72
+ })
73
+
74
+ describe("Arithmetic Overflow - Checked Operations", function () {
75
+ // Note: Overflow detection tests are computationally expensive due to MPC operations
76
+ // These tests may take 1-3 minutes each to complete
77
+
78
+ it("Should detect overflow in checkedAdd with max values", async function () {
79
+ this.timeout(180000) // 3 minutes for this specific test
80
+ const [owner] = await setupAccounts()
81
+
82
+ const factory = await hre.ethers.getContractFactory("CheckedArithmetic256WithOverflowBitTestsContract", owner as any)
83
+ const contract = await factory.deploy({ gasLimit })
84
+ await contract.waitForDeployment()
85
+
86
+ // Test with values that will overflow
87
+ // Using smaller values to reduce computation time while still testing overflow
88
+ const nearMax256 = (BigInt(1) << BigInt(255)) // 2^255 (half of max)
89
+ const large = (BigInt(1) << BigInt(255)) + BigInt(1) // Will overflow when added
90
+
91
+ // This should succeed but overflow bit should be set
92
+ const tx = await contract.checkedAddWithOverflowBitTest(nearMax256, large, { gasLimit })
93
+ const receipt = await tx.wait()
94
+ expect(receipt?.status).to.equal(1)
95
+
96
+ // Check overflow bit
97
+ const overflowBit = await contract.getOverflowBit()
98
+ // Note: The actual behavior depends on the MPC precompile implementation
99
+ // If overflow is detected, overflowBit should be true
100
+ console.log(`Overflow bit detected: ${overflowBit}`)
101
+ })
102
+
103
+ it("Should detect underflow in checkedSub", async function () {
104
+ this.timeout(180000) // 3 minutes for this specific test
105
+ const [owner] = await setupAccounts()
106
+
107
+ const factory = await hre.ethers.getContractFactory("CheckedArithmetic256WithOverflowBitTestsContract", owner as any)
108
+ const contract = await factory.deploy({ gasLimit })
109
+ await contract.waitForDeployment()
110
+
111
+ // Test subtraction that would underflow
112
+ const small = BigInt(5)
113
+ const large = BigInt("1000000000000000000")
114
+
115
+ // This should succeed but overflow bit should be set (indicating underflow)
116
+ const tx = await contract.checkedSubWithOverflowBitTest(small, large, { gasLimit })
117
+ const receipt = await tx.wait()
118
+ expect(receipt?.status).to.equal(1)
119
+
120
+ // Check overflow bit
121
+ const overflowBit = await contract.getOverflowBit()
122
+ // If underflow is detected, overflowBit should be true
123
+ console.log(`Underflow bit detected: ${overflowBit}`)
124
+ })
125
+
126
+ it("Should detect overflow in checkedMul with large values", async function () {
127
+ this.timeout(180000) // 3 minutes for this specific test
128
+ const [owner] = await setupAccounts()
129
+
130
+ const factory = await hre.ethers.getContractFactory("CheckedArithmetic256WithOverflowBitTestsContract", owner as any)
131
+ const contract = await factory.deploy({ gasLimit })
132
+ await contract.waitForDeployment()
133
+
134
+ // Test multiplication that will overflow
135
+ // Using smaller values to reduce computation time while still testing overflow
136
+ const large1 = BigInt(1) << BigInt(150) // 2^150
137
+ const large2 = BigInt(1) << BigInt(150) // 2^150
138
+ // 2^150 * 2^150 = 2^300 > 2^256, will overflow
139
+
140
+ const tx = await contract.checkedMulWithOverflowBitTest(large1, large2, { gasLimit })
141
+ const receipt = await tx.wait()
142
+ expect(receipt?.status).to.equal(1)
143
+
144
+ // Check overflow bit
145
+ const overflowBit = await contract.getOverflowBit()
146
+ console.log(`Multiplication overflow bit detected: ${overflowBit}`)
147
+ })
148
+ })
149
+
150
+ describe("Edge Cases - Boundary Values", function () {
151
+ it("Should handle subtraction resulting in zero", async function () {
152
+ const [owner] = await setupAccounts()
153
+
154
+ const factory = await hre.ethers.getContractFactory("Arithmetic256TestsContract", owner as any)
155
+ const contract = await factory.deploy({ gasLimit })
156
+ await contract.waitForDeployment()
157
+
158
+ const a = BigInt("1000000000000000000")
159
+ const b = a // Same value
160
+
161
+ const tx = await contract.subTest(a, b, { gasLimit })
162
+ const receipt = await tx.wait()
163
+ expect(receipt?.status).to.equal(1)
164
+
165
+ const result = await contract.getSubResult()
166
+ expect(result).to.equal(BigInt(0))
167
+ })
168
+
169
+ it("Should handle max value operations", async function () {
170
+ const [owner] = await setupAccounts()
171
+
172
+ const factory = await hre.ethers.getContractFactory("Arithmetic256TestsContract", owner as any)
173
+ const contract = await factory.deploy({ gasLimit })
174
+ await contract.waitForDeployment()
175
+
176
+ const max256 = (BigInt(1) << BigInt(256)) - BigInt(1)
177
+ const zero = BigInt(0)
178
+
179
+ // Max + 0 should work
180
+ const tx = await contract.addTest(max256, zero, { gasLimit })
181
+ const receipt = await tx.wait()
182
+ expect(receipt?.status).to.equal(1)
183
+
184
+ const result = await contract.getAddResult()
185
+ expect(result).to.equal(max256)
186
+ })
187
+ })
188
+
189
+ describe("Invalid Shift Operations", function () {
190
+ it("Should handle shift amount >= 256 bits", async function () {
191
+ const [owner] = await setupAccounts()
192
+
193
+ const factory = await hre.ethers.getContractFactory("Shift256TestsContract", owner as any)
194
+ const contract = await factory.deploy({ gasLimit })
195
+ await contract.waitForDeployment()
196
+
197
+ const a = BigInt("1000000000000000000")
198
+ const shift256 = 255 // uint8 max is 255, so we test with max possible
199
+ const shift200 = 200 // Large shift value
200
+
201
+ // Shift by 200 - should work but most bits shifted out
202
+ const tx1 = await contract.shlTest(a, shift200, { gasLimit })
203
+ const receipt1 = await tx1.wait()
204
+ expect(receipt1?.status).to.equal(1)
205
+ const result1 = await contract.getShlResult()
206
+ console.log(`Shift by 200 returned: ${result1}`)
207
+
208
+ // Shift by 255 (max uint8) - behavior depends on MPC precompile
209
+ const tx2 = await contract.shlTest(a, shift256, { gasLimit })
210
+ const receipt2 = await tx2.wait()
211
+ expect(receipt2?.status).to.equal(1)
212
+ const result2 = await contract.getShlResult()
213
+ console.log(`Shift by 255 returned: ${result2}`)
214
+ // Result should be 0 or wrapped value depending on precompile behavior
215
+ })
216
+
217
+ it("Should handle right shift by large amounts", async function () {
218
+ const [owner] = await setupAccounts()
219
+
220
+ const factory = await hre.ethers.getContractFactory("Shift256TestsContract", owner as any)
221
+ const contract = await factory.deploy({ gasLimit })
222
+ await contract.waitForDeployment()
223
+
224
+ const a = BigInt("1000000000000000000")
225
+ const shift255 = 255 // Max uint8
226
+
227
+ // Right shift by 255 - should result in 0
228
+ const tx = await contract.shrTest(a, shift255, { gasLimit })
229
+ const receipt = await tx.wait()
230
+ expect(receipt?.status).to.equal(1)
231
+ const result = await contract.getShrResult()
232
+ expect(result).to.equal(BigInt(0)) // All bits shifted out
233
+ })
234
+ })
235
+ })
236
+
@@ -0,0 +1,90 @@
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
+ param: bigint,
12
+ expectedResult: bigint
13
+ ) {
14
+ it(`${contractName}.${func}(${param}) should return ${expectedResult}`, 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)(param, { gasLimit })
23
+ const receipt = await tx.wait()
24
+
25
+ const result = await contract.getFunction(resFunc)()
26
+ expect(result).to.equal(expectedResult)
27
+
28
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
29
+ expect(txFromChain).to.not.be.null
30
+ expect(txFromChain?.status).to.equal(1)
31
+ })
32
+ }
33
+
34
+ // Test values
35
+ const MASK_128 = (BigInt(1) << BigInt(128)) - BigInt(1)
36
+ const HALF_MAX_128 = BigInt(1) << BigInt(127)
37
+ const testValue1 = BigInt("1000000000000000000")
38
+ const testValue2 = BigInt("500000000000000000")
39
+ const testValue3 = BigInt("2000000000000000000")
40
+
41
+ describe("OnBoard 128-bit", function () {
42
+ describe("Round-trip tests (setPublic -> offBoard -> onBoard -> decrypt)", function () {
43
+ buildTest("OnBoard128TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", testValue1, testValue1)
44
+ buildTest("OnBoard128TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", testValue2, testValue2)
45
+ buildTest("OnBoard128TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", HALF_MAX_128, HALF_MAX_128)
46
+ })
47
+
48
+ describe("Multiple values test", function () {
49
+ it("OnBoard128TestsContract.testOnBoardMultipleValues should handle multiple values", async function () {
50
+ const [owner] = await setupAccounts()
51
+ const provider = owner.provider!
52
+
53
+ const factory = await hre.ethers.getContractFactory("OnBoard128TestsContract", owner as any)
54
+ const contract = await factory.deploy({ gasLimit })
55
+ await contract.waitForDeployment()
56
+
57
+ // Execute the transaction - the contract's require statements verify correctness
58
+ // If the transaction succeeds, all three values were correctly processed
59
+ const tx = await contract.testOnBoardMultipleValues(testValue1, testValue2, testValue3, { gasLimit })
60
+ const receipt = await tx.wait()
61
+ expect(receipt?.status).to.equal(1)
62
+
63
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
64
+ expect(txFromChain).to.not.be.null
65
+ expect(txFromChain?.status).to.equal(1)
66
+ })
67
+ })
68
+
69
+ describe("Edge cases (zero and max)", function () {
70
+ it("OnBoard128TestsContract.testOnBoardEdgeCases should handle zero and max values", async function () {
71
+ const [owner] = await setupAccounts()
72
+ const provider = owner.provider!
73
+
74
+ const factory = await hre.ethers.getContractFactory("OnBoard128TestsContract", owner as any)
75
+ const contract = await factory.deploy({ gasLimit })
76
+ await contract.waitForDeployment()
77
+
78
+ // Execute the transaction - the contract's require statements verify correctness
79
+ // If the transaction succeeds, both zero and max values were correctly processed
80
+ const tx = await contract.testOnBoardEdgeCases({ gasLimit })
81
+ const receipt = await tx.wait()
82
+ expect(receipt?.status).to.equal(1)
83
+
84
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
85
+ expect(txFromChain).to.not.be.null
86
+ expect(txFromChain?.status).to.equal(1)
87
+ })
88
+ })
89
+ })
90
+
@@ -0,0 +1,114 @@
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
+ param: bigint,
12
+ expectedResult: bigint
13
+ ) {
14
+ it(`${contractName}.${func}(${param}) should return ${expectedResult}`, 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)(param, { gasLimit })
23
+ const receipt = await tx.wait()
24
+
25
+ const result = await contract.getFunction(resFunc)()
26
+ expect(result).to.equal(expectedResult)
27
+
28
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
29
+ expect(txFromChain).to.not.be.null
30
+ expect(txFromChain?.status).to.equal(1)
31
+ })
32
+ }
33
+
34
+ // Test values
35
+ const MASK_256 = (BigInt(1) << BigInt(256)) - BigInt(1)
36
+ const HALF_MAX_256 = BigInt(1) << BigInt(255)
37
+ const testValue1 = BigInt("1000000000000000000")
38
+ const testValue2 = BigInt("500000000000000000")
39
+ const testValue3 = BigInt("2000000000000000000")
40
+ const valueAbove128 = BigInt(1) << BigInt(128) // 2^128
41
+ const valueBelow128 = (BigInt(1) << BigInt(127)) - BigInt(1) // 2^127 - 1
42
+
43
+ describe("OnBoard 256-bit", function () {
44
+ describe("Round-trip tests (setPublic -> offBoard -> onBoard -> decrypt)", function () {
45
+ buildTest("OnBoard256TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", testValue1, testValue1)
46
+ buildTest("OnBoard256TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", testValue2, testValue2)
47
+ buildTest("OnBoard256TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", HALF_MAX_256, HALF_MAX_256)
48
+ buildTest("OnBoard256TestsContract", "testOnBoardOffBoardRoundTrip", "getOnboardOffboardResult", valueAbove128, valueAbove128)
49
+ })
50
+
51
+ describe("Multiple values test", function () {
52
+ it("OnBoard256TestsContract.testOnBoardMultipleValues should handle multiple values", async function () {
53
+ const [owner] = await setupAccounts()
54
+ const provider = owner.provider!
55
+
56
+ const factory = await hre.ethers.getContractFactory("OnBoard256TestsContract", owner as any)
57
+ const contract = await factory.deploy({ gasLimit })
58
+ await contract.waitForDeployment()
59
+
60
+ // Execute the transaction - the contract's require statements verify correctness
61
+ // If the transaction succeeds, all three values were correctly processed
62
+ const tx = await contract.testOnBoardMultipleValues(testValue1, testValue2, testValue3, { gasLimit })
63
+ const receipt = await tx.wait()
64
+ expect(receipt?.status).to.equal(1)
65
+
66
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
67
+ expect(txFromChain).to.not.be.null
68
+ expect(txFromChain?.status).to.equal(1)
69
+ })
70
+ })
71
+
72
+ describe("Edge cases (zero and max)", function () {
73
+ it("OnBoard256TestsContract.testOnBoardEdgeCases should handle zero and max values", async function () {
74
+ const [owner] = await setupAccounts()
75
+ const provider = owner.provider!
76
+
77
+ const factory = await hre.ethers.getContractFactory("OnBoard256TestsContract", owner as any)
78
+ const contract = await factory.deploy({ gasLimit })
79
+ await contract.waitForDeployment()
80
+
81
+ // Execute the transaction - the contract's require statements verify correctness
82
+ // If the transaction succeeds, both zero and max values were correctly processed
83
+ const tx = await contract.testOnBoardEdgeCases({ gasLimit })
84
+ const receipt = await tx.wait()
85
+ expect(receipt?.status).to.equal(1)
86
+
87
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
88
+ expect(txFromChain).to.not.be.null
89
+ expect(txFromChain?.status).to.equal(1)
90
+ })
91
+ })
92
+
93
+ describe("128-bit boundary test", function () {
94
+ it("OnBoard256TestsContract.testOnBoard128BitBoundary should handle values crossing 128-bit boundary", async function () {
95
+ const [owner] = await setupAccounts()
96
+ const provider = owner.provider!
97
+
98
+ const factory = await hre.ethers.getContractFactory("OnBoard256TestsContract", owner as any)
99
+ const contract = await factory.deploy({ gasLimit })
100
+ await contract.waitForDeployment()
101
+
102
+ // Execute the transaction - the contract's require statements verify correctness
103
+ // If the transaction succeeds, both boundary values were correctly processed
104
+ const tx = await contract.testOnBoard128BitBoundary({ gasLimit })
105
+ const receipt = await tx.wait()
106
+ expect(receipt?.status).to.equal(1)
107
+
108
+ const txFromChain = await provider.getTransactionReceipt(receipt.hash)
109
+ expect(txFromChain).to.not.be.null
110
+ expect(txFromChain?.status).to.equal(1)
111
+ })
112
+ })
113
+ })
114
+