@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
@@ -6,65 +6,158 @@ import "../../utils/mpc/MpcCore.sol";
6
6
 
7
7
  /**
8
8
  * @dev Interface of the COTI Private ERC-20 standard.
9
+ *
10
+ * Trust assumptions (MPC — read before deploying or integrating):
11
+ * - Confidential balances, allowances, and transfer arithmetic are executed via `MpcCore` and the
12
+ * chain’s MPC precompile. This interface does not specify a verification layer: **token accounting
13
+ * ultimately follows whatever the precompile returns.** Solidity cannot re-prove MPC soundness on-chain.
14
+ * - Deploying or holding this token means accepting **trust in the network operator**, consensus,
15
+ * precompile implementation, versioning, and any upgrade path that may replace or alter MPC behavior.
16
+ * - Operational controls on the token (e.g. pausing, roles, supply caps) **contain** misuse or
17
+ * incident response; they do **not** substitute for MPC trust and cannot roll back or audit past
18
+ * precompile outputs cryptographically.
19
+ * - Client-side encryption (ciphertext formats, AES keys, wallet/SDK behavior) must stay consistent
20
+ * with the chain’s MPC expectations; malformed or adversarial off-chain inputs are not fully
21
+ * recoverable by the contract alone.
22
+ * - **Canonical empty ciphertext:** an all-zero `ctUint256` in storage (uninitialized or cleared)
23
+ * is read as numeric **zero** using the implementation’s `_safeOnboard` shortcut (`setPublic256(0)`
24
+ * without an extra `onBoard` round-trip). Any other bit pattern is onboarded via `MpcCore.onBoard`.
25
+ * Do not rely on writing raw ciphertext to token storage outside the implementation’s normal
26
+ * `offBoard` paths unless it matches MPC encoding rules.
27
+ *
28
+ * Failure semantics: implementations are expected to use a revert-on-failure model for
29
+ * balance/supply/allowance-changing operations. If the MPC layer reports failure for a core
30
+ * update, the call reverts unless otherwise noted. View/pure reads are not token "operations"
31
+ * in that sense. Encrypted boolean (`gtBool`) is not used as a return type on this interface;
32
+ * success is indicated by the transaction completing without revert.
33
+ *
34
+ * Supply and {totalSupply} (integration rule — read before integrating):
35
+ * - {totalSupply} in the reference implementation does **not** return circulating aggregate supply.
36
+ * It is not a substitute for standard ERC-20 `totalSupply` in vaults, oracles, or pro-rata logic.
37
+ * - For the **maximum mintable** amount (ceiling), use {supplyCap} and the enforcement described in
38
+ * the implementation’s `_update` / mint path — not {totalSupply}.
39
+ * - For **actual** aggregate supply, use off-chain indexing, a privileged operational dashboard,
40
+ * or a concrete extension that exposes encrypted supply to designated parties (see project mocks
41
+ * such as `PrivateERC20AuditorSupplyMock`).
9
42
  */
10
43
  interface IPrivateERC20 {
11
44
  struct Allowance {
12
- ctUint64 ciphertext;
13
- ctUint64 ownerCiphertext;
14
- ctUint64 spenderCiphertext;
45
+ ctUint256 ciphertext;
46
+ ctUint256 ownerCiphertext;
47
+ ctUint256 spenderCiphertext;
15
48
  }
16
-
49
+
50
+ /**
51
+ * @dev Plain {approve} with a non-zero value was called while the current allowance is non-zero.
52
+ * Mitigates the ERC-20 approve race: first set allowance to zero, then set the new value.
53
+ */
54
+ error ERC20UnsafeApprove();
55
+
17
56
  /**
18
57
  * @dev Emitted when `senderValue/receiverValue` tokens are moved from one account (`from`) to
19
58
  * another (`to`).
20
59
  *
21
60
  * Note that `senderValue/receiverValue` may be zero.
22
61
  */
23
- event Transfer(address indexed from, address indexed to, ctUint64 senderValue, ctUint64 receiverValue);
62
+ event Transfer(
63
+ address indexed from,
64
+ address indexed to,
65
+ ctUint256 senderValue,
66
+ ctUint256 receiverValue
67
+ );
24
68
 
25
69
  /**
26
70
  * @dev Emitted when the allowance of a `spender` for an `owner` is set by
27
71
  * a call to {approve}. `ownerValue` and `spenderValue` are the new allowance encrypted with the respective users AES key.
28
72
  */
29
- event Approval(address indexed owner, address indexed spender, ctUint64 ownerValue, ctUint64 spenderValue);
73
+ event Approval(
74
+ address indexed owner,
75
+ address indexed spender,
76
+ ctUint256 ownerValue,
77
+ ctUint256 spenderValue
78
+ );
79
+
80
+ /**
81
+ * @dev Emitted when an allowance is re-encrypted for the owner or spender view (e.g. after key rotation).
82
+ * `isSpender` is true when the spender's ciphertext was updated; false when the owner's was updated.
83
+ */
84
+ event AllowanceReencrypted(
85
+ address indexed owner,
86
+ address indexed spender,
87
+ bool isSpender
88
+ );
30
89
 
31
90
  /**
32
- * @dev Returns the value of tokens in existence.
91
+ * @dev **Not** standard ERC-20 aggregate circulating supply in the base implementation.
92
+ *
93
+ * The reference implementation returns `0` on purpose: public aggregate supply is withheld for privacy.
94
+ * Do **not** use this value for collateral math, reward distribution, or any logic that assumes
95
+ * it reflects tokens in existence. For a mint **ceiling**, see {supplyCap}. For real supply metrics,
96
+ * integrate off-chain or via an extended contract that defines explicit semantics.
33
97
  */
34
98
  function totalSupply() external view returns (uint256);
35
99
 
36
100
  /**
37
101
  * @dev Returns the value of tokens owned by `account` encrypted with their AES key.
38
102
  */
39
- function balanceOf(address account) external view returns (ctUint64);
103
+ function balanceOf(
104
+ address account
105
+ ) external view returns (ctUint256 memory);
40
106
 
41
107
  /**
42
108
  * @dev Returns the value of tokens owned by the caller.
43
109
  */
44
- function balanceOf() external returns (gtUint64);
110
+ function balanceOf() external returns (gtUint256);
45
111
 
46
112
  /**
47
113
  * @dev Reencrypts the caller's balance using the AES key of `addr`.
48
114
  */
49
115
  function setAccountEncryptionAddress(address addr) external returns (bool);
50
116
 
117
+ /**
118
+ * @dev Returns whether clear public `uint256` operations are currently enabled
119
+ * for this token (mint, burn, transfer, transferFrom, approve, transferAndCall
120
+ * variants that take plain amounts).
121
+ */
122
+ function publicAmountsEnabled() external view returns (bool);
123
+
124
+ /**
125
+ * @dev Enables or disables operations that use clear public `uint256` amounts
126
+ * (mint, burn, transfer, transferFrom, approve, transferAndCall with uint256).
127
+ * Intended for token admins that want to disallow public value usage and
128
+ * enforce encrypted-only flows.
129
+ */
130
+ function setPublicAmountsEnabled(bool enabled) external;
131
+
51
132
  /**
52
133
  * @dev Moves a `value` amount of tokens from the caller's account to `to`.
53
134
  *
54
- * Returns an encrypted boolean value indicating whether the operation succeeded.
135
+ * Reverts if the transfer does not succeed.
55
136
  *
56
137
  * Emits a {Transfer} event.
57
138
  */
58
- function transfer(address to, itUint64 calldata value) external returns (gtBool);
139
+ function transfer(
140
+ address to,
141
+ itUint256 calldata value
142
+ ) external;
59
143
 
60
144
  /**
61
- * @dev Moves a `value` amount of tokens from the caller's account to `to`.
145
+ * @dev Moves a public `amount` of tokens from the caller's account to `to`.
62
146
  *
63
- * Returns an encrypted boolean value indicating whether the operation succeeded.
147
+ * Reverts if the transfer does not succeed.
64
148
  *
65
149
  * Emits a {Transfer} event.
66
150
  */
67
- function transfer(address to, gtUint64 value) external returns (gtBool);
151
+ function transfer(address to, uint256 amount) external;
152
+
153
+ /**
154
+ * @dev Moves a garbled-text `value` amount of tokens from the caller's account to `to`.
155
+ *
156
+ * Reverts if the transfer does not succeed.
157
+ *
158
+ * Emits a {Transfer} event.
159
+ */
160
+ function transferGT(address to, gtUint256 value) external;
68
161
 
69
162
  /**
70
163
  * @dev Returns the remaining number of tokens that `spender` will be
@@ -73,7 +166,10 @@ interface IPrivateERC20 {
73
166
  *
74
167
  * This value changes when {approve} or {transferFrom} are called.
75
168
  */
76
- function allowance(address owner, address spender) external view returns (Allowance memory);
169
+ function allowance(
170
+ address owner,
171
+ address spender
172
+ ) external view returns (Allowance memory);
77
173
 
78
174
  /**
79
175
  * @dev Returns the remaining number of tokens that `account` will be
@@ -82,61 +178,198 @@ interface IPrivateERC20 {
82
178
  *
83
179
  * This value changes when {approve} or {transferFrom} are called.
84
180
  */
85
- function allowance(address account, bool isSpender) external returns (gtUint64);
181
+ function allowance(address account, bool isSpender) external returns (gtUint256);
86
182
 
87
183
  /**
88
184
  * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
89
185
  * caller's tokens.
90
186
  *
91
- * Returns an encrypted boolean value indicating whether the operation succeeded.
187
+ * Reverts if approval cannot be completed.
92
188
  *
93
- * IMPORTANT: Beware that changing an allowance with this method brings the risk
94
- * that someone may use both the old and the new allowance by unfortunate
95
- * transaction ordering. One possible solution to mitigate this race
96
- * condition is to first reduce the spender's allowance to 0 and set the
97
- * desired value afterwards:
98
- * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
189
+ * Reverts with {ERC20UnsafeApprove} if both the current allowance and the new `value` are
190
+ * non-zero (mitigation for the ERC-20 approve race). To change a non-zero allowance, first
191
+ * approve zero, then set the new amount, **or** use {increaseAllowance}/{decreaseAllowance}.
99
192
  *
100
193
  * Emits an {Approval} event.
101
194
  */
102
- function approve(address spender, itUint64 calldata value) external returns (bool);
195
+ function approve(
196
+ address spender,
197
+ itUint256 calldata value
198
+ ) external;
103
199
 
104
200
  /**
105
- * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
201
+ * @dev Sets a public `amount` as the allowance of `spender` over the
106
202
  * caller's tokens.
107
203
  *
108
- * Returns an encrypted boolean value indicating whether the operation succeeded.
204
+ * Reverts with {ERC20UnsafeApprove} if both the current allowance and `amount` are non-zero
205
+ * (mitigation for the ERC-20 approve race). To change a non-zero allowance, first approve zero,
206
+ * then set the new amount, **or** use {increaseAllowance}/{decreaseAllowance}.
109
207
  *
110
- * IMPORTANT: Beware that changing an allowance with this method brings the risk
111
- * that someone may use both the old and the new allowance by unfortunate
112
- * transaction ordering. One possible solution to mitigate this race
113
- * condition is to first reduce the spender's allowance to 0 and set the
114
- * desired value afterwards:
115
- * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
208
+ * Emits an {Approval} event.
209
+ */
210
+ function approve(address spender, uint256 amount) external;
211
+
212
+ /**
213
+ * @dev Sets a garbled-text `value` as the allowance of `spender` over the
214
+ * caller's tokens.
215
+ *
216
+ * Reverts if approval cannot be completed.
217
+ *
218
+ * Reverts with {ERC20UnsafeApprove} if both the current allowance and the new `value` are
219
+ * non-zero (mitigation for the ERC-20 approve race). To change a non-zero allowance, first
220
+ * approve zero, then set the new amount, **or** use {increaseAllowance}/{decreaseAllowance}.
221
+ *
222
+ * Emits an {Approval} event.
223
+ */
224
+ function approveGT(address spender, gtUint256 value) external;
225
+
226
+ /**
227
+ * @dev Increases the allowance granted to `spender` by the caller by `addedValue`.
228
+ * Use this (or {decreaseAllowance}) to change a non-zero allowance without the unsafe
229
+ * “approve non-zero over non-zero” pattern. Reverts on uint256 overflow (including when the
230
+ * current allowance is already unlimited).
231
+ *
232
+ * Emits an {Approval} event.
233
+ */
234
+ function increaseAllowance(
235
+ address spender,
236
+ itUint256 calldata addedValue
237
+ ) external;
238
+
239
+ /**
240
+ * @dev Same as {increaseAllowance(address,(itUint256))} with a public `addedValue`.
241
+ * Requires {publicAmountsEnabled}.
242
+ */
243
+ function increaseAllowance(address spender, uint256 addedValue) external;
244
+
245
+ /**
246
+ * @dev Same as {increaseAllowance(address,(itUint256))} with a garbled `addedValue`.
247
+ */
248
+ function increaseAllowanceGT(address spender, gtUint256 addedValue) external;
249
+
250
+ /**
251
+ * @dev Decreases the allowance granted to `spender` by the caller by `subtractedValue`.
252
+ * Reverts if the current allowance is less than `subtractedValue`.
116
253
  *
117
254
  * Emits an {Approval} event.
118
255
  */
119
- function approve(address spender, gtUint64 value) external returns (bool);
256
+ function decreaseAllowance(
257
+ address spender,
258
+ itUint256 calldata subtractedValue
259
+ ) external;
260
+
261
+ /**
262
+ * @dev Same as {decreaseAllowance(address,(itUint256))} with a public `subtractedValue`.
263
+ * Requires {publicAmountsEnabled}.
264
+ */
265
+ function decreaseAllowance(address spender, uint256 subtractedValue) external;
266
+
267
+ /**
268
+ * @dev Same as {decreaseAllowance(address,(itUint256))} with a garbled `subtractedValue`.
269
+ */
270
+ function decreaseAllowanceGT(address spender, gtUint256 subtractedValue) external;
120
271
 
121
272
  /**
122
273
  * @dev Moves a `value` amount of tokens from `from` to `to` using the
123
274
  * allowance mechanism. `value` is then deducted from the caller's
124
275
  * allowance.
125
276
  *
126
- * Returns an encrypted boolean value indicating whether the operation succeeded.
277
+ * Reverts if the transfer fails.
127
278
  *
128
279
  * Emits a {Transfer} event.
129
280
  */
130
- function transferFrom(address from, address to, itUint64 calldata value) external returns (gtBool);
281
+ function transferFrom(
282
+ address from,
283
+ address to,
284
+ itUint256 calldata value
285
+ ) external;
131
286
 
132
287
  /**
133
- * @dev Moves a `value` amount of tokens from `from` to `to` using the
134
- * allowance mechanism. `value` is then deducted from the caller's
288
+ * @dev Moves a public `amount` of tokens from `from` to `to` using the
289
+ * allowance mechanism. `amount` is then deducted from the caller's
135
290
  * allowance.
136
291
  *
137
- * Returns an encrypted boolean value indicating whether the operation succeeded.
292
+ * Reverts if the transfer fails.
293
+ *
294
+ * Emits a {Transfer} event.
295
+ */
296
+ function transferFrom(address from, address to, uint256 amount) external;
297
+
298
+ /**
299
+ * @dev Moves a garbled-text `value` amount of tokens from `from` to `to` using the
300
+ * allowance mechanism. `value` is then deducted from the caller's allowance.
301
+ *
302
+ * Reverts if the transfer fails.
138
303
  *
139
304
  * Emits a {Transfer} event.
140
305
  */
141
- function transferFrom(address from, address to, gtUint64 value) external returns (gtBool);
142
- }
306
+ function transferFromGT(address from, address to, gtUint256 value) external;
307
+
308
+ /**
309
+ * @dev Moves a `value` amount of tokens from the caller's account to `to`, and then calls `onTokenReceived` on `to`.
310
+ * @param to The address of the recipient
311
+ * @param amount The amount of tokens to be transferred
312
+ * @param data Additional data with no specified format, sent in call to `to`
313
+ */
314
+ function transferAndCall(
315
+ address to,
316
+ uint256 amount,
317
+ bytes calldata data
318
+ ) external;
319
+
320
+ /**
321
+ * @dev Moves an input-text (encrypted) `amount` of tokens from the caller's account to `to`,
322
+ * then calls `ITokenReceiverEncrypted.onPrivateTransferReceived(sender, data)` on `to`.
323
+ * The callback has **no** plaintext amount parameter — receivers must implement {ITokenReceiverEncrypted}.
324
+ * @param to The address of the recipient (must implement {ITokenReceiverEncrypted})
325
+ * @param amount Encrypted input-text amount to be transferred
326
+ * @param data Forwarded to the callback; use for app-specific context (not a substitute for amount)
327
+ */
328
+ function transferAndCall(
329
+ address to,
330
+ itUint256 calldata amount,
331
+ bytes calldata data
332
+ ) external;
333
+
334
+ /**
335
+ * @dev Creates `amount` public tokens and assigns them to `to`, increasing the total supply.
336
+ *
337
+ * Reverts if minting does not succeed.
338
+ */
339
+ function mint(address to, uint256 amount) external;
340
+
341
+ /**
342
+ * @dev Creates `amount` input-text (encrypted) tokens and assigns them to `to`, increasing the total supply.
343
+ *
344
+ * Reverts if minting does not succeed.
345
+ */
346
+ function mint(address to, itUint256 calldata amount) external;
347
+
348
+ /**
349
+ * @dev Creates `amount` garbled-text tokens and assigns them to `to` without re-wrapping.
350
+ *
351
+ * Reverts if minting does not succeed.
352
+ */
353
+ function mintGt(address to, gtUint256 amount) external;
354
+
355
+ /**
356
+ * @dev Destroys `amount` public tokens from the caller.
357
+ *
358
+ * Reverts if burning does not succeed.
359
+ */
360
+ function burn(uint256 amount) external;
361
+
362
+ /**
363
+ * @dev Destroys `amount` input-text (encrypted) tokens from the caller.
364
+ *
365
+ * Reverts if the burn fails.
366
+ */
367
+ function burn(itUint256 calldata amount) external;
368
+
369
+ /**
370
+ * @dev Destroys `amount` garbled-text tokens from the caller without re-wrapping.
371
+ *
372
+ * Reverts if burning does not succeed.
373
+ */
374
+ function burnGt(gtUint256 amount) external;
375
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.19;
4
+
5
+ /**
6
+ * @dev Interface for receiving Private ERC-20 tokens via `transferAndCall` with a **public** `uint256` amount.
7
+ *
8
+ * For `transferAndCall` with an **encrypted** `itUint256` amount, use {ITokenReceiverEncrypted} instead —
9
+ * the amount must not be passed in plaintext in the callback.
10
+ */
11
+ interface ITokenReceiver {
12
+ function onTokenReceived(
13
+ address from,
14
+ uint256 amount,
15
+ bytes calldata data
16
+ ) external returns (bool);
17
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity ^0.8.19;
4
+
5
+ /**
6
+ * @dev Callback for the **encrypted-amount** `transferAndCall(to, itUint256, data)` overload on {PrivateERC20}.
7
+ *
8
+ * The transferred amount is intentionally **not** passed in plaintext to the callback. Receivers that
9
+ * handle private transfers must implement this interface. Do **not** use {ITokenReceiver} for that
10
+ * overload — its `amount` parameter cannot carry the real value without breaking privacy.
11
+ *
12
+ * Integrators: derive any needed amount context from `data` you control, or from off-chain decryption
13
+ * of {Transfer} events / balances — not from a callback `amount` field.
14
+ */
15
+ interface ITokenReceiverEncrypted {
16
+ function onPrivateTransferReceived(
17
+ address from,
18
+ bytes calldata data
19
+ ) external returns (bool);
20
+ }