@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.
- package/.github/workflows/npm-publish.yml +18 -14
- package/README.md +3 -1
- package/contracts/disperse/coinByRatio/FixedRatioCoinDisperser.sol +452 -0
- package/contracts/disperse/coinByRatio/FixedRatioCoinDisperserLeftoverS1.sol +490 -0
- package/contracts/disperse/coinByRatio/FixedRatioCoinDisperserUnlimitedWindow.sol +432 -0
- package/contracts/disperse/disperseToken/MintDisperser.sol +120 -0
- package/contracts/disperse/disperseToken/TokenDisperser.sol +139 -0
- package/contracts/mocks/token/ERC20Mock.sol +19 -0
- package/contracts/mocks/token/PrivateERC20/EncryptedTokenReceiverMock.sol +18 -0
- package/contracts/mocks/token/PrivateERC20/PrivacyBridgeERC20Mock.sol +13 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20AuditorSupplyMock.sol +44 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20CappedMock.sol +23 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20GtCallerMock.sol +29 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +9 -4
- package/contracts/mocks/token/PrivateERC20/PrivateERC20ReentrantReceiverMock.sol +39 -0
- package/contracts/mocks/token/PrivateERC20/PublicReentrantTokenReceiverMock.sol +29 -0
- package/contracts/mocks/token/PrivateERC20/PublicTokenReceiverBoolMock.sol +18 -0
- package/contracts/mocks/token/PrivateERC20/PublicTokenReceiverMock.sol +12 -0
- package/contracts/mocks/utils/mpc/Arithmetic128TestsContract.sol +123 -0
- package/contracts/mocks/utils/mpc/Arithmetic256TestsContract.sol +122 -0
- package/contracts/mocks/utils/mpc/Bitwise128TestsContract.sol +65 -0
- package/contracts/mocks/utils/mpc/Bitwise256TestsContract.sol +65 -0
- package/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.sol +64 -0
- package/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.sol +64 -0
- package/contracts/mocks/utils/mpc/Comparison128TestsContract.sol +98 -0
- package/contracts/mocks/utils/mpc/Comparison256TestsContract.sol +98 -0
- package/contracts/mocks/utils/mpc/MinMax128TestsContract.sol +44 -0
- package/contracts/mocks/utils/mpc/MinMax256TestsContract.sol +44 -0
- package/contracts/mocks/utils/mpc/MinimalImplementation.sol +55 -0
- package/contracts/mocks/utils/mpc/MinimalProxy.sol +27 -0
- package/contracts/mocks/utils/mpc/MpcOperations128TestContract.sol +267 -0
- package/contracts/mocks/utils/mpc/MpcOperationsTestContract.sol +334 -0
- package/contracts/mocks/utils/mpc/Mux128TestsContract.sol +24 -0
- package/contracts/mocks/utils/mpc/Mux256TestsContract.sol +24 -0
- package/contracts/mocks/utils/mpc/OnBoard128TestsContract.sol +93 -0
- package/contracts/mocks/utils/mpc/OnBoard256TestsContract.sol +116 -0
- package/contracts/mocks/utils/mpc/PrivacyImplementationV1.sol +157 -0
- package/contracts/mocks/utils/mpc/PrivacyImplementationV2.sol +133 -0
- package/contracts/mocks/utils/mpc/PrivacyProxy.sol +137 -0
- package/contracts/mocks/utils/mpc/Random128TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/Random256TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/Shift128TestsContract.sol +36 -0
- package/contracts/mocks/utils/mpc/Shift256TestsContract.sol +36 -0
- package/contracts/mocks/utils/mpc/Transfer128TestsContract.sol +29 -0
- package/contracts/mocks/utils/mpc/Transfer256TestsContract.sol +29 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.sol +32 -0
- package/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.sol +59 -0
- package/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.sol +63 -0
- package/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.sol +99 -0
- package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +7 -6
- package/contracts/node/CotiNodeRewards.sol +199 -0
- package/contracts/node/SoulboundNodeNFT.sol +519 -0
- package/contracts/privacyBridge/PrivacyBridge.sol +318 -0
- package/contracts/privacyBridge/PrivacyBridgeCotiNative.sol +268 -0
- package/contracts/privacyBridge/PrivacyBridgeERC20.sol +251 -0
- package/contracts/privacyBridge/PrivacyBridgeUSDCe.sol +16 -0
- package/contracts/privacyBridge/PrivacyBridgeUSDT.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgeWADA.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgeWBTC.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgeWETH.sol +17 -0
- package/contracts/privacyBridge/PrivacyBridgegCoti.sol +17 -0
- package/contracts/token/PrivateERC20/IPrivateERC20.sol +273 -40
- package/contracts/token/PrivateERC20/ITokenReceiver.sol +17 -0
- package/contracts/token/PrivateERC20/ITokenReceiverEncrypted.sol +20 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +861 -152
- package/contracts/token/PrivateERC20/tokens/PrivateBridgedUSDC.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateCOTI.sol +13 -0
- package/contracts/token/PrivateERC20/tokens/PrivateCOTITreasuryGovernanceToken.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateTetherUSD.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateWrappedADA.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateWrappedBTC.sol +17 -0
- package/contracts/token/PrivateERC20/tokens/PrivateWrappedEther.sol +13 -0
- package/contracts/utils/mpc/MpcCore.sol +10891 -2449
- package/contracts/utils/mpc/MpcInterface.sol +7 -2
- package/hardhat/gasPriceBump.ts +60 -0
- package/hardhat.config.ts +60 -12
- package/package.json +21 -3
- package/scripts/deploySoulboundNodeNFT.ts +57 -0
- package/test/token/PrivateERC20/PrivacyBridge.fees.test.ts +327 -0
- package/test/token/PrivateERC20/PrivateERC20.test.ts +1109 -268
- package/test/utils/mpc/Bitwise128.test.ts +92 -0
- package/test/utils/mpc/Bitwise256.test.ts +101 -0
- package/test/utils/mpc/BuildInputText128.test.ts +398 -0
- package/test/utils/mpc/CheckedArithmetic128.test.ts +45 -0
- package/test/utils/mpc/CheckedArithmetic256.test.ts +45 -0
- package/test/utils/mpc/Comparison128.test.ts +48 -0
- package/test/utils/mpc/Comparison256.test.ts +48 -0
- package/test/utils/mpc/InvalidCiphertext.test.ts +179 -0
- package/test/utils/mpc/InvalidCiphertext128.test.ts +179 -0
- package/test/utils/mpc/InvalidCiphertext256.test.ts +201 -0
- package/test/utils/mpc/InvalidTransfer128.test.ts +166 -0
- package/test/utils/mpc/InvalidTransfer256.test.ts +158 -0
- package/test/utils/mpc/MinMax128.test.ts +44 -0
- package/test/utils/mpc/MinMax256.test.ts +44 -0
- package/test/utils/mpc/MinimalProxyDemo.test.ts +280 -0
- package/test/utils/mpc/MpcOperations.test.ts +589 -0
- package/test/utils/mpc/MpcOperations128.test.ts +632 -0
- package/test/utils/mpc/Mux128.test.ts +41 -0
- package/test/utils/mpc/Mux256.test.ts +41 -0
- package/test/utils/mpc/NegativeCases.test.ts +478 -0
- package/test/utils/mpc/NegativeCases128.test.ts +237 -0
- package/test/utils/mpc/NegativeCases256.test.ts +236 -0
- package/test/utils/mpc/OnBoard128.test.ts +90 -0
- package/test/utils/mpc/OnBoard256.test.ts +114 -0
- package/test/utils/mpc/Precompile128.test.ts +51 -0
- package/test/utils/mpc/Precompile256.test.ts +115 -0
- package/test/utils/mpc/ProxyValidation.test.ts +199 -0
- package/test/utils/mpc/Random128.test.ts +47 -0
- package/test/utils/mpc/Random256.test.ts +47 -0
- package/test/utils/mpc/Shift128.test.ts +41 -0
- package/test/utils/mpc/Shift256.test.ts +41 -0
- package/test/utils/mpc/Transfer128.test.ts +46 -0
- package/test/utils/mpc/Transfer256.test.ts +46 -0
- package/test/utils/mpc/TransferWithAllowance128.test.ts +48 -0
- package/test/utils/mpc/TransferWithAllowance256.test.ts +48 -0
- package/test/utils/mpc/UpgradeablePrivacyProxy.test.ts +307 -0
- package/test/utils/mpc/ValidateCiphertext.test.ts +221 -0
- package/test/utils/mpc/ValidateCiphertext256.test.ts +161 -0
- package/test/utils/mpc/ValidateCiphertext256Decryption.test.ts +383 -0
- package/test/utils/mpc/WalletEncryptionFailures.test.ts +494 -0
- package/test/utils/privateErc20Helpers.ts +97 -0
- package/typechain-types/@openzeppelin/contracts/access/Ownable.ts +153 -0
- package/typechain-types/@openzeppelin/contracts/access/index.ts +4 -0
- package/typechain-types/@openzeppelin/contracts/index.ts +2 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/IERC20.ts +262 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.ts +143 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC20/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/token/index.ts +2 -0
- package/typechain-types/contracts/disperse/coinByRatio/FixedRatioCoinDisperser.ts +679 -0
- package/typechain-types/contracts/disperse/coinByRatio/index.ts +4 -0
- package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20.ts +97 -0
- package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser.ts +206 -0
- package/typechain-types/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
- package/typechain-types/contracts/disperse/disperseToken/TokenDisperser.ts +191 -0
- package/typechain-types/contracts/disperse/disperseToken/index.ts +6 -0
- package/typechain-types/contracts/disperse/index.ts +7 -0
- package/typechain-types/contracts/index.ts +2 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +77 -60
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.ts +341 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128TestsContract.ts +311 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.ts +347 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256TestsContract.ts +311 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.ts +186 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise128TestsContract.ts +179 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.ts +186 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise256TestsContract.ts +179 -0
- package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract.ts +206 -0
- package/typechain-types/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract.ts +206 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison128BitTestsContract.ts +260 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison128TestsContract.ts +278 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison256BitTestsContract.ts +260 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison256TestsContract.ts +278 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMax128TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMax256TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinimalImplementation.ts +259 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinimalProxy.ts +90 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.ts +302 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.ts +322 -0
- package/typechain-types/contracts/mocks/utils/mpc/MpcOperations128TestContract.ts +388 -0
- package/typechain-types/contracts/mocks/utils/mpc/MpcOperationsTestContract.ts +455 -0
- package/typechain-types/contracts/mocks/utils/mpc/Mux128TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/Mux256TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/OnBoard128TestsContract.ts +166 -0
- package/typechain-types/contracts/mocks/utils/mpc/OnBoard256TestsContract.ts +194 -0
- package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV1.ts +385 -0
- package/typechain-types/contracts/mocks/utils/mpc/PrivacyImplementationV2.ts +441 -0
- package/typechain-types/contracts/mocks/utils/mpc/PrivacyProxy.ts +201 -0
- package/typechain-types/contracts/mocks/utils/mpc/Random128TestsContract.ts +131 -0
- package/typechain-types/contracts/mocks/utils/mpc/Random256TestsContract.ts +131 -0
- package/typechain-types/contracts/mocks/utils/mpc/Shift128TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/Shift256TestsContract.ts +142 -0
- package/typechain-types/contracts/mocks/utils/mpc/Transfer128TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/Transfer256TestsContract.ts +109 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract.ts +128 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract.ts +128 -0
- package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract.ts +198 -0
- package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract.ts +182 -0
- package/typechain-types/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract.ts +257 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +32 -0
- package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +77 -60
- package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +77 -60
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +111 -10
- package/typechain-types/factories/@openzeppelin/contracts/access/Ownable__factory.ts +74 -0
- package/typechain-types/factories/@openzeppelin/contracts/access/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/index.ts +1 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.ts +205 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit__factory.ts +100 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/extensions/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC20/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +1 -0
- package/typechain-types/factories/contracts/disperse/coinByRatio/FixedRatioCoinDisperser__factory.ts +759 -0
- package/typechain-types/factories/contracts/disperse/coinByRatio/index.ts +4 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/IMintableERC20__factory.ts +43 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/MintDisperser__factory.ts +185 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/MintDisperser.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/TokenDisperser__factory.ts +198 -0
- package/typechain-types/factories/contracts/disperse/disperseToken/index.ts +5 -0
- package/typechain-types/factories/contracts/disperse/index.ts +5 -0
- package/typechain-types/factories/contracts/index.ts +1 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +179 -47
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract__factory.ts +349 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128TestsContract__factory.ts +330 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract__factory.ts +364 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256TestsContract__factory.ts +330 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128BitTestsContract__factory.ts +182 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128TestsContract__factory.ts +184 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256BitTestsContract__factory.ts +182 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256TestsContract__factory.ts +184 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic128WithOverflowBitTestsContract__factory.ts +203 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmetic256WithOverflowBitTestsContract__factory.ts +203 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/CheckedArithmeticWIthOverflowBitTestsContract.sol/CheckedArithmeticWithOverflowBitTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128BitTestsContract__factory.ts +255 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128TestsContract__factory.ts +295 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256BitTestsContract__factory.ts +255 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256TestsContract__factory.ts +295 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax128TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMax256TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalImplementation__factory.ts +263 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinimalProxy__factory.ts +104 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract__factory.ts +332 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract__factory.ts +380 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperations128TestContract__factory.ts +723 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MpcOperationsTestContract__factory.ts +1410 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Mux128TestsContract__factory.ts +115 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Mux256TestsContract__factory.ts +115 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard128TestsContract__factory.ts +175 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OnBoard256TestsContract__factory.ts +205 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV1__factory.ts +521 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyImplementationV2__factory.ts +648 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/PrivacyProxy__factory.ts +179 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Random128TestsContract__factory.ts +131 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Random256TestsContract__factory.ts +131 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Shift128TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Shift256TestsContract__factory.ts +147 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer128TestsContract__factory.ts +135 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Transfer256TestsContract__factory.ts +135 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance128TestsContract__factory.ts +154 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance256TestsContract__factory.ts +154 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext128TestsContract__factory.ts +190 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertext256TestsContract__factory.ts +210 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ValidateCiphertextTestsContract__factory.ts +260 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +32 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +7 -7
- package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +174 -42
- package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +174 -42
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +126 -0
- package/typechain-types/hardhat.d.ts +702 -0
- package/typechain-types/index.ts +78 -0
- package/contracts/mocks/utils/mpc/README.md +0 -486
- package/contracts/package.json +0 -11
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title MpcOperations128TestContract
|
|
8
|
+
* @dev Contract to test uint128 MPC operations with offBoardToUser functionality
|
|
9
|
+
* This allows users to decrypt the results of operations performed on encrypted uint128 values
|
|
10
|
+
*/
|
|
11
|
+
contract MpcOperations128TestContract {
|
|
12
|
+
|
|
13
|
+
// Events for tracking operations
|
|
14
|
+
event OperationPerformed(string operation, address indexed user);
|
|
15
|
+
event ValueOffBoarded128(address indexed user, ctUint128 result);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @dev Add two encrypted 128-bit values and return result encrypted for user
|
|
19
|
+
* @param a First encrypted value (itUint128)
|
|
20
|
+
* @param b Second encrypted value (itUint128)
|
|
21
|
+
* @param user Address to encrypt result for
|
|
22
|
+
* @return Result encrypted for the user (ctUint128)
|
|
23
|
+
*/
|
|
24
|
+
function add128(itUint128 memory a, itUint128 memory b, address user) public returns (ctUint128) {
|
|
25
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
26
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
27
|
+
|
|
28
|
+
gtUint128 result = MpcCore.add(gtA, gtB);
|
|
29
|
+
|
|
30
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
31
|
+
|
|
32
|
+
emit OperationPerformed("add128", user);
|
|
33
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
34
|
+
|
|
35
|
+
return ctResult;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @dev Subtract two encrypted 128-bit values and return result encrypted for user
|
|
40
|
+
* @param a First encrypted value (itUint128)
|
|
41
|
+
* @param b Second encrypted value (itUint128)
|
|
42
|
+
* @param user Address to encrypt result for
|
|
43
|
+
* @return Result encrypted for the user (ctUint128)
|
|
44
|
+
*/
|
|
45
|
+
function sub128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
46
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
47
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
48
|
+
|
|
49
|
+
gtUint128 result = MpcCore.sub(gtA, gtB);
|
|
50
|
+
|
|
51
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
52
|
+
|
|
53
|
+
emit OperationPerformed("sub128", user);
|
|
54
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
55
|
+
|
|
56
|
+
return ctResult;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @dev Multiply two encrypted 128-bit values and return result encrypted for user
|
|
61
|
+
* @param a First encrypted value (itUint128)
|
|
62
|
+
* @param b Second encrypted value (itUint128)
|
|
63
|
+
* @param user Address to encrypt result for
|
|
64
|
+
* @return Result encrypted for the user (ctUint128)
|
|
65
|
+
*/
|
|
66
|
+
function mul128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
67
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
68
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
69
|
+
|
|
70
|
+
gtUint128 result = MpcCore.mul(gtA, gtB);
|
|
71
|
+
|
|
72
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
73
|
+
|
|
74
|
+
emit OperationPerformed("mul128", user);
|
|
75
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
76
|
+
|
|
77
|
+
return ctResult;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @dev Divide two encrypted 128-bit values and return result encrypted for user
|
|
82
|
+
* @param a First encrypted value (itUint128)
|
|
83
|
+
* @param b Second encrypted value (itUint128)
|
|
84
|
+
* @param user Address to encrypt result for
|
|
85
|
+
* @return Result encrypted for the user (ctUint128)
|
|
86
|
+
*/
|
|
87
|
+
function div128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
88
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
89
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
90
|
+
|
|
91
|
+
gtUint128 result = MpcCore.div(gtA, gtB);
|
|
92
|
+
|
|
93
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
94
|
+
|
|
95
|
+
emit OperationPerformed("div128", user);
|
|
96
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
97
|
+
|
|
98
|
+
return ctResult;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @dev Get remainder of division and return result encrypted for user
|
|
103
|
+
* @param a First encrypted value (itUint128)
|
|
104
|
+
* @param b Second encrypted value (itUint128)
|
|
105
|
+
* @param user Address to encrypt result for
|
|
106
|
+
* @return Result encrypted for the user (ctUint128)
|
|
107
|
+
*/
|
|
108
|
+
function rem128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
109
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
110
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
111
|
+
|
|
112
|
+
gtUint128 result = MpcCore.rem(gtA, gtB);
|
|
113
|
+
|
|
114
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
115
|
+
|
|
116
|
+
emit OperationPerformed("rem128", user);
|
|
117
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
118
|
+
|
|
119
|
+
return ctResult;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @dev Perform AND operation on two encrypted 128-bit values
|
|
124
|
+
* @param a First encrypted value (itUint128)
|
|
125
|
+
* @param b Second encrypted value (itUint128)
|
|
126
|
+
* @param user Address to encrypt result for
|
|
127
|
+
* @return Result encrypted for the user (ctUint128)
|
|
128
|
+
*/
|
|
129
|
+
function and128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
130
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
131
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
132
|
+
|
|
133
|
+
gtUint128 result = MpcCore.and(gtA, gtB);
|
|
134
|
+
|
|
135
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
136
|
+
|
|
137
|
+
emit OperationPerformed("and128", user);
|
|
138
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
139
|
+
|
|
140
|
+
return ctResult;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @dev Perform OR operation on two encrypted 128-bit values
|
|
145
|
+
* @param a First encrypted value (itUint128)
|
|
146
|
+
* @param b Second encrypted value (itUint128)
|
|
147
|
+
* @param user Address to encrypt result for
|
|
148
|
+
* @return Result encrypted for the user (ctUint128)
|
|
149
|
+
*/
|
|
150
|
+
function or128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
151
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
152
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
153
|
+
|
|
154
|
+
gtUint128 result = MpcCore.or(gtA, gtB);
|
|
155
|
+
|
|
156
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
157
|
+
|
|
158
|
+
emit OperationPerformed("or128", user);
|
|
159
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
160
|
+
|
|
161
|
+
return ctResult;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @dev Perform XOR operation on two encrypted 128-bit values
|
|
166
|
+
* @param a First encrypted value (itUint128)
|
|
167
|
+
* @param b Second encrypted value (itUint128)
|
|
168
|
+
* @param user Address to encrypt result for
|
|
169
|
+
* @return Result encrypted for the user (ctUint128)
|
|
170
|
+
*/
|
|
171
|
+
function xor128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
172
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
173
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
174
|
+
|
|
175
|
+
gtUint128 result = MpcCore.xor(gtA, gtB);
|
|
176
|
+
|
|
177
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
178
|
+
|
|
179
|
+
emit OperationPerformed("xor128", user);
|
|
180
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
181
|
+
|
|
182
|
+
return ctResult;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @dev Shift left operation on encrypted 128-bit value
|
|
187
|
+
* @param a Encrypted value to shift (itUint128)
|
|
188
|
+
* @param bits Number of bits to shift (plain, must be uint8)
|
|
189
|
+
* @param user Address to encrypt result for
|
|
190
|
+
* @return Result encrypted for the user (ctUint128)
|
|
191
|
+
*/
|
|
192
|
+
function shl128(itUint128 calldata a, uint8 bits, address user) public returns (ctUint128) {
|
|
193
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
194
|
+
|
|
195
|
+
gtUint128 result = MpcCore.shl(gtA, bits);
|
|
196
|
+
|
|
197
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
198
|
+
|
|
199
|
+
emit OperationPerformed("shl128", user);
|
|
200
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
201
|
+
|
|
202
|
+
return ctResult;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @dev Shift right operation on encrypted 128-bit value
|
|
207
|
+
* @param a Encrypted value to shift (itUint128)
|
|
208
|
+
* @param bits Number of bits to shift (plain, must be uint8)
|
|
209
|
+
* @param user Address to encrypt result for
|
|
210
|
+
* @return Result encrypted for the user (ctUint128)
|
|
211
|
+
*/
|
|
212
|
+
function shr128(itUint128 calldata a, uint8 bits, address user) public returns (ctUint128) {
|
|
213
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
214
|
+
|
|
215
|
+
gtUint128 result = MpcCore.shr(gtA, bits);
|
|
216
|
+
|
|
217
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
218
|
+
|
|
219
|
+
emit OperationPerformed("shr128", user);
|
|
220
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
221
|
+
|
|
222
|
+
return ctResult;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @dev Get minimum of two encrypted values
|
|
227
|
+
* @param a First encrypted value (itUint128)
|
|
228
|
+
* @param b Second encrypted value (itUint128)
|
|
229
|
+
* @param user Address to encrypt result for
|
|
230
|
+
* @return Result encrypted for the user (ctUint128)
|
|
231
|
+
*/
|
|
232
|
+
function min128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
233
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
234
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
235
|
+
|
|
236
|
+
gtUint128 result = MpcCore.min(gtA, gtB);
|
|
237
|
+
|
|
238
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
239
|
+
|
|
240
|
+
emit OperationPerformed("min128", user);
|
|
241
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
242
|
+
|
|
243
|
+
return ctResult;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @dev Get maximum of two encrypted values
|
|
248
|
+
* @param a First encrypted value (itUint128)
|
|
249
|
+
* @param b Second encrypted value (itUint128)
|
|
250
|
+
* @param user Address to encrypt result for
|
|
251
|
+
* @return Result encrypted for the user (ctUint128)
|
|
252
|
+
*/
|
|
253
|
+
function max128(itUint128 calldata a, itUint128 calldata b, address user) public returns (ctUint128) {
|
|
254
|
+
gtUint128 gtA = MpcCore.validateCiphertext(a);
|
|
255
|
+
gtUint128 gtB = MpcCore.validateCiphertext(b);
|
|
256
|
+
|
|
257
|
+
gtUint128 result = MpcCore.max(gtA, gtB);
|
|
258
|
+
|
|
259
|
+
ctUint128 ctResult = MpcCore.offBoardToUser(result, user);
|
|
260
|
+
|
|
261
|
+
emit OperationPerformed("max128", user);
|
|
262
|
+
emit ValueOffBoarded128(user, ctResult);
|
|
263
|
+
|
|
264
|
+
return ctResult;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @title MpcOperationsTestContract
|
|
8
|
+
* @dev Contract to test various MPC operations with offBoardToUser functionality
|
|
9
|
+
* This allows users to decrypt the results of operations performed on encrypted values
|
|
10
|
+
*/
|
|
11
|
+
contract MpcOperationsTestContract {
|
|
12
|
+
|
|
13
|
+
// Events for tracking operations
|
|
14
|
+
event OperationPerformed(string operation, address indexed user);
|
|
15
|
+
event ValueOffBoarded(address indexed user, ctUint256 result);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @dev Add two encrypted 256-bit values and return result encrypted for user
|
|
19
|
+
* @param a First encrypted value (itUint256)
|
|
20
|
+
* @param b Second encrypted value (itUint256)
|
|
21
|
+
* @param user Address to encrypt result for
|
|
22
|
+
* @return Result encrypted for the user (ctUint256)
|
|
23
|
+
*/
|
|
24
|
+
function add256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
25
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
26
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
27
|
+
|
|
28
|
+
gtUint256 result = MpcCore.add(gtA, gtB);
|
|
29
|
+
|
|
30
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
31
|
+
|
|
32
|
+
emit OperationPerformed("add256", user);
|
|
33
|
+
emit ValueOffBoarded(user, ctResult);
|
|
34
|
+
|
|
35
|
+
return ctResult;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @dev Subtract two encrypted 256-bit values and return result encrypted for user
|
|
40
|
+
* @param a First encrypted value (itUint256)
|
|
41
|
+
* @param b Second encrypted value (itUint256)
|
|
42
|
+
* @param user Address to encrypt result for
|
|
43
|
+
* @return Result encrypted for the user (ctUint256)
|
|
44
|
+
*/
|
|
45
|
+
function sub256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
46
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
47
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
48
|
+
|
|
49
|
+
gtUint256 result = MpcCore.sub(gtA, gtB);
|
|
50
|
+
|
|
51
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
52
|
+
|
|
53
|
+
emit OperationPerformed("sub256", user);
|
|
54
|
+
emit ValueOffBoarded(user, ctResult);
|
|
55
|
+
|
|
56
|
+
return ctResult;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @dev Multiply two encrypted 256-bit values and return result encrypted for user
|
|
61
|
+
* @param a First encrypted value (itUint256)
|
|
62
|
+
* @param b Second encrypted value (itUint256)
|
|
63
|
+
* @param user Address to encrypt result for
|
|
64
|
+
* @return Result encrypted for the user (ctUint256)
|
|
65
|
+
*/
|
|
66
|
+
function mul256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
67
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
68
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
69
|
+
|
|
70
|
+
gtUint256 result = MpcCore.mul(gtA, gtB);
|
|
71
|
+
|
|
72
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
73
|
+
|
|
74
|
+
emit OperationPerformed("mul256", user);
|
|
75
|
+
emit ValueOffBoarded(user, ctResult);
|
|
76
|
+
|
|
77
|
+
return ctResult;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @dev Divide two encrypted 256-bit values and return result encrypted for user
|
|
82
|
+
* @param a First encrypted value (itUint256)
|
|
83
|
+
* @param b Second encrypted value (itUint256)
|
|
84
|
+
* @param user Address to encrypt result for
|
|
85
|
+
* @return Result encrypted for the user (ctUint256)
|
|
86
|
+
*/
|
|
87
|
+
function div256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
88
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
89
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
90
|
+
|
|
91
|
+
gtUint256 result = MpcCore.div(gtA, gtB);
|
|
92
|
+
|
|
93
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
94
|
+
|
|
95
|
+
emit OperationPerformed("div256", user);
|
|
96
|
+
emit ValueOffBoarded(user, ctResult);
|
|
97
|
+
|
|
98
|
+
return ctResult;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @dev Get remainder of division and return result encrypted for user
|
|
103
|
+
* @param a First encrypted value (itUint256)
|
|
104
|
+
* @param b Second encrypted value (itUint256)
|
|
105
|
+
* @param user Address to encrypt result for
|
|
106
|
+
* @return Result encrypted for the user (ctUint256)
|
|
107
|
+
*/
|
|
108
|
+
function rem256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
109
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
110
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
111
|
+
|
|
112
|
+
gtUint256 result = MpcCore.rem(gtA, gtB);
|
|
113
|
+
|
|
114
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
115
|
+
|
|
116
|
+
emit OperationPerformed("rem256", user);
|
|
117
|
+
emit ValueOffBoarded(user, ctResult);
|
|
118
|
+
|
|
119
|
+
return ctResult;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @dev Perform AND operation on two encrypted 256-bit values
|
|
124
|
+
* @param a First encrypted value (itUint256)
|
|
125
|
+
* @param b Second encrypted value (itUint256)
|
|
126
|
+
* @param user Address to encrypt result for
|
|
127
|
+
* @return Result encrypted for the user (ctUint256)
|
|
128
|
+
*/
|
|
129
|
+
function and256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
130
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
131
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
132
|
+
|
|
133
|
+
gtUint256 result = MpcCore.and(gtA, gtB);
|
|
134
|
+
|
|
135
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
136
|
+
|
|
137
|
+
emit OperationPerformed("and256", user);
|
|
138
|
+
emit ValueOffBoarded(user, ctResult);
|
|
139
|
+
|
|
140
|
+
return ctResult;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @dev Perform OR operation on two encrypted 256-bit values
|
|
145
|
+
* @param a First encrypted value (itUint256)
|
|
146
|
+
* @param b Second encrypted value (itUint256)
|
|
147
|
+
* @param user Address to encrypt result for
|
|
148
|
+
* @return Result encrypted for the user (ctUint256)
|
|
149
|
+
*/
|
|
150
|
+
function or256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
151
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
152
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
153
|
+
|
|
154
|
+
gtUint256 result = MpcCore.or(gtA, gtB);
|
|
155
|
+
|
|
156
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
157
|
+
|
|
158
|
+
emit OperationPerformed("or256", user);
|
|
159
|
+
emit ValueOffBoarded(user, ctResult);
|
|
160
|
+
|
|
161
|
+
return ctResult;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @dev Perform XOR operation on two encrypted 256-bit values
|
|
166
|
+
* @param a First encrypted value (itUint256)
|
|
167
|
+
* @param b Second encrypted value (itUint256)
|
|
168
|
+
* @param user Address to encrypt result for
|
|
169
|
+
* @return Result encrypted for the user (ctUint256)
|
|
170
|
+
*/
|
|
171
|
+
function xor256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
172
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
173
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
174
|
+
|
|
175
|
+
gtUint256 result = MpcCore.xor(gtA, gtB);
|
|
176
|
+
|
|
177
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
178
|
+
|
|
179
|
+
emit OperationPerformed("xor256", user);
|
|
180
|
+
emit ValueOffBoarded(user, ctResult);
|
|
181
|
+
|
|
182
|
+
return ctResult;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @dev Shift left operation on encrypted 256-bit value
|
|
187
|
+
* @param a Encrypted value to shift (itUint256)
|
|
188
|
+
* @param bits Number of bits to shift (plain, must be uint8)
|
|
189
|
+
* @param user Address to encrypt result for
|
|
190
|
+
* @return Result encrypted for the user (ctUint256)
|
|
191
|
+
*/
|
|
192
|
+
function shl256(itUint256 memory a, uint8 bits, address user) public returns (ctUint256 memory) {
|
|
193
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
194
|
+
|
|
195
|
+
gtUint256 result = MpcCore.shl(gtA, bits);
|
|
196
|
+
|
|
197
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
198
|
+
|
|
199
|
+
emit OperationPerformed("shl256", user);
|
|
200
|
+
emit ValueOffBoarded(user, ctResult);
|
|
201
|
+
|
|
202
|
+
return ctResult;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @dev Shift right operation on encrypted 256-bit value
|
|
207
|
+
* @param a Encrypted value to shift (itUint256)
|
|
208
|
+
* @param bits Number of bits to shift (plain, must be uint8)
|
|
209
|
+
* @param user Address to encrypt result for
|
|
210
|
+
* @return Result encrypted for the user (ctUint256)
|
|
211
|
+
*/
|
|
212
|
+
function shr256(itUint256 memory a, uint8 bits, address user) public returns (ctUint256 memory) {
|
|
213
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
214
|
+
|
|
215
|
+
gtUint256 result = MpcCore.shr(gtA, bits);
|
|
216
|
+
|
|
217
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
218
|
+
|
|
219
|
+
emit OperationPerformed("shr256", user);
|
|
220
|
+
emit ValueOffBoarded(user, ctResult);
|
|
221
|
+
|
|
222
|
+
return ctResult;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @dev Check if two encrypted values are equal
|
|
227
|
+
* @param a First encrypted value (itUint256)
|
|
228
|
+
* @param b Second encrypted value (itUint256)
|
|
229
|
+
* @param user Address to encrypt result for
|
|
230
|
+
* @return Result encrypted for the user (ctUint256) - 1 if equal, 0 otherwise
|
|
231
|
+
*/
|
|
232
|
+
function eq256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
233
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
234
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
235
|
+
|
|
236
|
+
gtBool result = MpcCore.eq(gtA, gtB);
|
|
237
|
+
gtUint256 resultAsUint = MpcCore.mux(result, MpcCore.setPublic256(1), MpcCore.setPublic256(0));
|
|
238
|
+
|
|
239
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(resultAsUint, user);
|
|
240
|
+
|
|
241
|
+
emit OperationPerformed("eq256", user);
|
|
242
|
+
emit ValueOffBoarded(user, ctResult);
|
|
243
|
+
|
|
244
|
+
return ctResult;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @dev Check if first value is greater than second
|
|
249
|
+
* @param a First encrypted value (itUint256)
|
|
250
|
+
* @param b Second encrypted value (itUint256)
|
|
251
|
+
* @param user Address to encrypt result for
|
|
252
|
+
* @return Result encrypted for the user (ctUint256) - 1 if a > b, 0 otherwise
|
|
253
|
+
*/
|
|
254
|
+
function gt256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
255
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
256
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
257
|
+
|
|
258
|
+
gtBool result = MpcCore.gt(gtA, gtB);
|
|
259
|
+
gtUint256 resultAsUint = MpcCore.mux(result, MpcCore.setPublic256(1), MpcCore.setPublic256(0));
|
|
260
|
+
|
|
261
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(resultAsUint, user);
|
|
262
|
+
|
|
263
|
+
emit OperationPerformed("gt256", user);
|
|
264
|
+
emit ValueOffBoarded(user, ctResult);
|
|
265
|
+
|
|
266
|
+
return ctResult;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @dev Check if first value is less than second
|
|
271
|
+
* @param a First encrypted value (itUint256)
|
|
272
|
+
* @param b Second encrypted value (itUint256)
|
|
273
|
+
* @param user Address to encrypt result for
|
|
274
|
+
* @return Result encrypted for the user (ctUint256) - 1 if a < b, 0 otherwise
|
|
275
|
+
*/
|
|
276
|
+
function lt256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
277
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
278
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
279
|
+
|
|
280
|
+
gtBool result = MpcCore.lt(gtA, gtB);
|
|
281
|
+
gtUint256 resultAsUint = MpcCore.mux(result, MpcCore.setPublic256(1), MpcCore.setPublic256(0));
|
|
282
|
+
|
|
283
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(resultAsUint, user);
|
|
284
|
+
|
|
285
|
+
emit OperationPerformed("lt256", user);
|
|
286
|
+
emit ValueOffBoarded(user, ctResult);
|
|
287
|
+
|
|
288
|
+
return ctResult;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* @dev Get minimum of two encrypted values
|
|
293
|
+
* @param a First encrypted value (itUint256)
|
|
294
|
+
* @param b Second encrypted value (itUint256)
|
|
295
|
+
* @param user Address to encrypt result for
|
|
296
|
+
* @return Result encrypted for the user (ctUint256)
|
|
297
|
+
*/
|
|
298
|
+
function min256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
299
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
300
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
301
|
+
|
|
302
|
+
gtUint256 result = MpcCore.min(gtA, gtB);
|
|
303
|
+
|
|
304
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
305
|
+
|
|
306
|
+
emit OperationPerformed("min256", user);
|
|
307
|
+
emit ValueOffBoarded(user, ctResult);
|
|
308
|
+
|
|
309
|
+
return ctResult;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @dev Get maximum of two encrypted values
|
|
314
|
+
* @param a First encrypted value (itUint256)
|
|
315
|
+
* @param b Second encrypted value (itUint256)
|
|
316
|
+
* @param user Address to encrypt result for
|
|
317
|
+
* @return Result encrypted for the user (ctUint256)
|
|
318
|
+
*/
|
|
319
|
+
function max256(itUint256 memory a, itUint256 memory b, address user) public returns (ctUint256 memory) {
|
|
320
|
+
gtUint256 gtA = MpcCore.validateCiphertext(a);
|
|
321
|
+
gtUint256 gtB = MpcCore.validateCiphertext(b);
|
|
322
|
+
|
|
323
|
+
gtUint256 result = MpcCore.max(gtA, gtB);
|
|
324
|
+
|
|
325
|
+
ctUint256 memory ctResult = MpcCore.offBoardToUser(result, user);
|
|
326
|
+
|
|
327
|
+
emit OperationPerformed("max256", user);
|
|
328
|
+
emit ValueOffBoarded(user, ctResult);
|
|
329
|
+
|
|
330
|
+
return ctResult;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
}
|
|
334
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Mux128TestsContract {
|
|
7
|
+
uint128 muxResult;
|
|
8
|
+
|
|
9
|
+
function getMuxResult() public view returns (uint128) {
|
|
10
|
+
return muxResult;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function muxTest(bool bit, uint128 a, uint128 b) public returns (uint128) {
|
|
14
|
+
gtBool bitBool = MpcCore.setPublic(bit);
|
|
15
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
16
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
17
|
+
|
|
18
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.mux(bitBool, a128, b128)));
|
|
19
|
+
muxResult = result;
|
|
20
|
+
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Mux256TestsContract {
|
|
7
|
+
uint256 muxResult;
|
|
8
|
+
|
|
9
|
+
function getMuxResult() public view returns (uint256) {
|
|
10
|
+
return muxResult;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function muxTest(bool bit, uint256 a, uint256 b) public returns (uint256) {
|
|
14
|
+
gtBool bitBool = MpcCore.setPublic(bit);
|
|
15
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
16
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
17
|
+
|
|
18
|
+
uint256 result = MpcCore.decrypt(MpcCore.mux(bitBool, a256, b256));
|
|
19
|
+
muxResult = result;
|
|
20
|
+
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|