@coti-io/coti-contracts 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +10780 -4962
- 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/Arithmetic128TestsContract.ts +311 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256TestsContract.ts +311 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise128TestsContract.ts +179 -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/Comparison128TestsContract.ts +278 -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/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 -8
- 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/Arithmetic128TestsContract__factory.ts +330 -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/Bitwise128TestsContract__factory.ts +184 -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/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/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/Miscellaneous1TestsContract__factory.ts +1 -1
- 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 -8
- 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 +638 -80
- package/typechain-types/index.ts +78 -16
- package/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.sol +0 -260
- package/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.sol +0 -264
- package/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.sol +0 -91
- package/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.sol +0 -91
- package/contracts/mocks/utils/mpc/Comparison128BitTestsContract.sol +0 -158
- package/contracts/mocks/utils/mpc/Comparison256BitTestsContract.sol +0 -158
- package/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.sol +0 -185
- package/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.sol +0 -190
- package/contracts/mocks/utils/mpc/README.md +0 -486
- package/test/utils/mpc/Unsigned128BitIntegers.test.ts +0 -945
- package/test/utils/mpc/Unsigned256BitIntegers.test.ts +0 -1124
- package/test/utils/mpc/helpers.ts +0 -77
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @dev Mock ERC20 token for testing
|
|
8
|
+
*/
|
|
9
|
+
contract ERC20Mock is ERC20 {
|
|
10
|
+
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}
|
|
11
|
+
|
|
12
|
+
function mint(address to, uint256 amount) external {
|
|
13
|
+
_mint(to, amount);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function burn(address from, uint256 amount) external {
|
|
17
|
+
_burn(from, amount);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/ITokenReceiverEncrypted.sol";
|
|
6
|
+
|
|
7
|
+
contract EncryptedTokenReceiverMock is ITokenReceiverEncrypted {
|
|
8
|
+
bool public accept;
|
|
9
|
+
|
|
10
|
+
constructor(bool accept_) {
|
|
11
|
+
accept = accept_;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function onPrivateTransferReceived(address, bytes calldata) external view returns (bool) {
|
|
15
|
+
return accept;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../privacyBridge/PrivacyBridgeERC20.sol";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @dev Mock contract for testing PrivacyBridgeERC20
|
|
8
|
+
*/
|
|
9
|
+
contract PrivacyBridgeERC20Mock is PrivacyBridgeERC20 {
|
|
10
|
+
constructor(address _token, address _privateToken)
|
|
11
|
+
PrivacyBridgeERC20(_token, _privateToken)
|
|
12
|
+
{}
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/PrivateERC20.sol";
|
|
6
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title PrivateERC20AuditorSupplyMock
|
|
10
|
+
* @notice Example (audit issue #5, “option 3”): keep {totalSupply} privacy-preserving (returns 0 in the
|
|
11
|
+
* base contract) while a **designated auditor** obtains **aggregate supply re-encrypted** to their key.
|
|
12
|
+
* The default product stance for #5 “option 1” is **documentation only** — see {PrivateERC20} and
|
|
13
|
+
* {IPrivateERC20} NatSpec for `totalSupply` / {supplyCap}; this contract illustrates an optional extension.
|
|
14
|
+
* @dev Flow:
|
|
15
|
+
* 1. Deploy with `auditor` = EOA (or a contract that has called `setAccountEncryptionAddress`).
|
|
16
|
+
* 2. Auditor calls `setAccountEncryptionAddress` if they use a dedicated off-chain key address.
|
|
17
|
+
* 3. Auditor calls `totalSupplyCiphertextForAuditor()` and decrypts off-chain — not plaintext on-chain.
|
|
18
|
+
* For testing mints, grant `MINTER_ROLE` to a test account or use a deploy script; this mock does not add a public minter.
|
|
19
|
+
*/
|
|
20
|
+
contract PrivateERC20AuditorSupplyMock is PrivateERC20 {
|
|
21
|
+
address public immutable auditor;
|
|
22
|
+
|
|
23
|
+
error OnlyAuditor();
|
|
24
|
+
error AuditorCannotReceiveUserCiphertext();
|
|
25
|
+
|
|
26
|
+
constructor(address auditor_) PrivateERC20("PrivateERC20AuditorSupplyMock", "PAS") {
|
|
27
|
+
if (auditor_ == address(0)) revert ERC20InvalidReceiver(address(0));
|
|
28
|
+
auditor = auditor_;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @notice Returns aggregate supply as ciphertext under the auditor’s encryption address (see {_getAccountEncryptionAddress}).
|
|
33
|
+
* @dev Reverts if `msg.sender` is not `auditor`. Contract auditors without an AES key (`encryptionAddress == 0`) cannot use this path.
|
|
34
|
+
*/
|
|
35
|
+
function totalSupplyCiphertextForAuditor() external nonReentrant returns (ctUint256 memory) {
|
|
36
|
+
if (msg.sender != auditor) revert OnlyAuditor();
|
|
37
|
+
|
|
38
|
+
address enc = _getAccountEncryptionAddress(auditor);
|
|
39
|
+
if (enc == address(0)) revert AuditorCannotReceiveUserCiphertext();
|
|
40
|
+
|
|
41
|
+
gtUint256 gtTotal = _getTotalSupplyGarbled();
|
|
42
|
+
return MpcCore.offBoardToUser(gtTotal, enc);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/PrivateERC20.sol";
|
|
6
|
+
|
|
7
|
+
/// @dev Minimal capped token for testing {supplyCap} enforcement in {_update}.
|
|
8
|
+
contract PrivateERC20CappedMock is PrivateERC20 {
|
|
9
|
+
uint256 private immutable _cap;
|
|
10
|
+
|
|
11
|
+
constructor(uint256 cap_) PrivateERC20("PrivateERC20CappedMock", "PECAP") {
|
|
12
|
+
_cap = cap_;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function decimals() public pure override returns (uint8) {
|
|
16
|
+
return 6;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function supplyCap() public view override returns (uint256) {
|
|
20
|
+
return _cap;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/IPrivateERC20.sol";
|
|
6
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @dev Helper that calls the GT overloads using `MpcCore.setPublic256(amount)` to build a gtUint256.
|
|
10
|
+
* Used to test the GT entrypoints without needing an off-chain gtUint256 constructor.
|
|
11
|
+
*/
|
|
12
|
+
contract PrivateERC20GtCallerMock {
|
|
13
|
+
function transferGT(address token, address to, uint256 amount) external {
|
|
14
|
+
IPrivateERC20(token).transferGT(to, MpcCore.setPublic256(amount));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function approveGT(address token, address spender, uint256 amount) external {
|
|
18
|
+
IPrivateERC20(token).approveGT(spender, MpcCore.setPublic256(amount));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function transferFromGT(address token, address from, address to, uint256 amount) external {
|
|
22
|
+
IPrivateERC20(token).transferFromGT(from, to, MpcCore.setPublic256(amount));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function burnGt(address token, uint256 amount) external {
|
|
26
|
+
IPrivateERC20(token).burnGt(MpcCore.setPublic256(amount));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
pragma solidity ^0.8.19;
|
|
4
4
|
|
|
5
5
|
import "../../../token/PrivateERC20/PrivateERC20.sol";
|
|
6
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
7
|
|
|
7
8
|
contract PrivateERC20Mock is PrivateERC20 {
|
|
8
9
|
constructor() PrivateERC20("PrivateERC20Mock", "PE20M") {}
|
|
9
10
|
|
|
10
|
-
function
|
|
11
|
-
|
|
11
|
+
function decimals() public pure override returns (uint8) {
|
|
12
|
+
return 6;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
function
|
|
15
|
-
|
|
15
|
+
function mint(address account, uint256 amount) public override nonReentrant {
|
|
16
|
+
_mint(account, MpcCore.setPublic256(amount));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function burn(address account, uint256 amount) public nonReentrant {
|
|
20
|
+
_burn(account, MpcCore.setPublic256(amount));
|
|
16
21
|
}
|
|
17
22
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/ITokenReceiverEncrypted.sol";
|
|
6
|
+
|
|
7
|
+
interface IPrivateERC20TransferAndCallEncrypted {
|
|
8
|
+
function transferAndCall(
|
|
9
|
+
address to,
|
|
10
|
+
bytes calldata itUint256Value,
|
|
11
|
+
bytes calldata data
|
|
12
|
+
) external;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @dev Receiver that attempts to re-enter the token during {transferAndCall} encrypted callback.
|
|
17
|
+
* Used to test {ReentrancyGuard} in PrivateERC20.
|
|
18
|
+
*/
|
|
19
|
+
contract PrivateERC20ReentrantReceiverMock is ITokenReceiverEncrypted {
|
|
20
|
+
address public token;
|
|
21
|
+
bool public tryReenter;
|
|
22
|
+
bytes public reenterCalldata;
|
|
23
|
+
|
|
24
|
+
function configure(address token_, bool tryReenter_, bytes calldata reenterCalldata_) external {
|
|
25
|
+
token = token_;
|
|
26
|
+
tryReenter = tryReenter_;
|
|
27
|
+
reenterCalldata = reenterCalldata_;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function onPrivateTransferReceived(address, bytes calldata) external returns (bool) {
|
|
31
|
+
if (tryReenter && token != address(0)) {
|
|
32
|
+
// Low-level call to avoid needing full interface/types here.
|
|
33
|
+
(bool ok, ) = token.call(reenterCalldata);
|
|
34
|
+
ok; // ignore; we only care that the outer tx reverts or not
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/ITokenReceiver.sol";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @dev Public-amount receiver that attempts to re-enter the token during `transferAndCall(uint256)` callback.
|
|
9
|
+
*/
|
|
10
|
+
contract PublicReentrantTokenReceiverMock is ITokenReceiver {
|
|
11
|
+
address public token;
|
|
12
|
+
bool public tryReenter;
|
|
13
|
+
bytes public reenterCalldata;
|
|
14
|
+
|
|
15
|
+
function configure(address token_, bool tryReenter_, bytes calldata reenterCalldata_) external {
|
|
16
|
+
token = token_;
|
|
17
|
+
tryReenter = tryReenter_;
|
|
18
|
+
reenterCalldata = reenterCalldata_;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function onTokenReceived(address, uint256, bytes calldata) external returns (bool) {
|
|
22
|
+
if (tryReenter && token != address(0)) {
|
|
23
|
+
(bool ok, ) = token.call(reenterCalldata);
|
|
24
|
+
ok;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/ITokenReceiver.sol";
|
|
6
|
+
|
|
7
|
+
contract PublicTokenReceiverBoolMock is ITokenReceiver {
|
|
8
|
+
bool public accept;
|
|
9
|
+
|
|
10
|
+
constructor(bool accept_) {
|
|
11
|
+
accept = accept_;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function onTokenReceived(address, uint256, bytes calldata) external view returns (bool) {
|
|
15
|
+
return accept;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../token/PrivateERC20/ITokenReceiver.sol";
|
|
6
|
+
|
|
7
|
+
contract PublicTokenReceiverMock is ITokenReceiver {
|
|
8
|
+
function onTokenReceived(address, uint256, bytes calldata) external pure returns (bool) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Arithmetic128TestsContract {
|
|
7
|
+
uint128 addResult;
|
|
8
|
+
uint128 subResult;
|
|
9
|
+
uint128 mulResult;
|
|
10
|
+
uint128 divResult;
|
|
11
|
+
uint128 remResult;
|
|
12
|
+
|
|
13
|
+
function getAddResult() public view returns (uint128) {
|
|
14
|
+
return addResult;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getSubResult() public view returns (uint128) {
|
|
18
|
+
return subResult;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getMulResult() public view returns (uint128) {
|
|
22
|
+
return mulResult;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getDivResult() public view returns (uint128) {
|
|
26
|
+
return divResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getRemResult() public view returns (uint128) {
|
|
30
|
+
return remResult;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function addTest(uint128 a, uint128 b) public returns (uint128) {
|
|
34
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
35
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
36
|
+
|
|
37
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.add(a128, b128)));
|
|
38
|
+
addResult = result;
|
|
39
|
+
|
|
40
|
+
// Verify with scalar operations
|
|
41
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.add(a, b128))), "addTest: scalar failed");
|
|
42
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.add(a128, b))), "addTest: scalar failed");
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function checkedAddTest(uint128 a, uint128 b) public returns (uint128) {
|
|
48
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
49
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
50
|
+
|
|
51
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.checkedAdd(a128, b128)));
|
|
52
|
+
addResult = result;
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function subTest(uint128 a, uint128 b) public returns (uint128) {
|
|
58
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
59
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
60
|
+
|
|
61
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.sub(a128, b128)));
|
|
62
|
+
subResult = result;
|
|
63
|
+
|
|
64
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.sub(a, b128))), "subTest: scalar failed");
|
|
65
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.sub(a128, b))), "subTest: scalar failed");
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function checkedSubTest(uint128 a, uint128 b) public returns (uint128) {
|
|
71
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
72
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
73
|
+
|
|
74
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.checkedSub(a128, b128)));
|
|
75
|
+
subResult = result;
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function mulTest(uint128 a, uint128 b) public returns (uint128) {
|
|
81
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
82
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
83
|
+
|
|
84
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.mul(a128, b128)));
|
|
85
|
+
mulResult = result;
|
|
86
|
+
|
|
87
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.mul(a, b128))), "mulTest: scalar failed");
|
|
88
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.mul(a128, b))), "mulTest: scalar failed");
|
|
89
|
+
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function checkedMulTest(uint128 a, uint128 b) public returns (uint128) {
|
|
94
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
95
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
96
|
+
|
|
97
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.checkedMul(a128, b128)));
|
|
98
|
+
mulResult = result;
|
|
99
|
+
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function divTest(uint128 a, uint128 b) public returns (uint128) {
|
|
104
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
105
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
106
|
+
|
|
107
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.div(a128, b128)));
|
|
108
|
+
divResult = result;
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function remTest(uint128 a, uint128 b) public returns (uint128) {
|
|
114
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
115
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
116
|
+
|
|
117
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.rem(a128, b128)));
|
|
118
|
+
remResult = result;
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Arithmetic256TestsContract {
|
|
7
|
+
uint256 addResult;
|
|
8
|
+
uint256 subResult;
|
|
9
|
+
uint256 mulResult;
|
|
10
|
+
uint256 divResult;
|
|
11
|
+
uint256 remResult;
|
|
12
|
+
|
|
13
|
+
function getAddResult() public view returns (uint256) {
|
|
14
|
+
return addResult;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getSubResult() public view returns (uint256) {
|
|
18
|
+
return subResult;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getMulResult() public view returns (uint256) {
|
|
22
|
+
return mulResult;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getDivResult() public view returns (uint256) {
|
|
26
|
+
return divResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getRemResult() public view returns (uint256) {
|
|
30
|
+
return remResult;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function addTest(uint256 a, uint256 b) public returns (uint256) {
|
|
34
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
35
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
36
|
+
|
|
37
|
+
uint256 result = MpcCore.decrypt(MpcCore.add(a256, b256));
|
|
38
|
+
addResult = result;
|
|
39
|
+
|
|
40
|
+
// Verify with scalar operations
|
|
41
|
+
require(result == MpcCore.decrypt(MpcCore.add(a, b256)), "addTest: scalar failed");
|
|
42
|
+
require(result == MpcCore.decrypt(MpcCore.add(a256, b)), "addTest: scalar failed");
|
|
43
|
+
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function checkedAddTest(uint256 a, uint256 b) public returns (uint256) {
|
|
48
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
49
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
50
|
+
|
|
51
|
+
uint256 result = MpcCore.decrypt(MpcCore.checkedAdd(a256, b256));
|
|
52
|
+
addResult = result;
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function subTest(uint256 a, uint256 b) public returns (uint256) {
|
|
58
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
59
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
60
|
+
|
|
61
|
+
uint256 result = MpcCore.decrypt(MpcCore.sub(a256, b256));
|
|
62
|
+
subResult = result;
|
|
63
|
+
|
|
64
|
+
require(result == MpcCore.decrypt(MpcCore.sub(a, b256)), "subTest: scalar failed");
|
|
65
|
+
require(result == MpcCore.decrypt(MpcCore.sub(a256, b)), "subTest: scalar failed");
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function checkedSubTest(uint256 a, uint256 b) public returns (uint256) {
|
|
71
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
72
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
73
|
+
|
|
74
|
+
uint256 result = MpcCore.decrypt(MpcCore.checkedSub(a256, b256));
|
|
75
|
+
subResult = result;
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function mulTest(uint256 a, uint256 b) public returns (uint256) {
|
|
81
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
82
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
83
|
+
|
|
84
|
+
uint256 result = MpcCore.decrypt(MpcCore.mul(a256, b256));
|
|
85
|
+
mulResult = result;
|
|
86
|
+
|
|
87
|
+
require(result == MpcCore.decrypt(MpcCore.mul(a, b256)), "mulTest: scalar failed");
|
|
88
|
+
require(result == MpcCore.decrypt(MpcCore.mul(a256, b)), "mulTest: scalar failed");
|
|
89
|
+
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function checkedMulTest(uint256 a, uint256 b) public returns (uint256) {
|
|
94
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
95
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
96
|
+
|
|
97
|
+
uint256 result = MpcCore.decrypt(MpcCore.checkedMul(a256, b256));
|
|
98
|
+
mulResult = result;
|
|
99
|
+
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function divTest(uint256 a, uint256 b) public returns (uint256) {
|
|
104
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
105
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
106
|
+
|
|
107
|
+
uint256 result = MpcCore.decrypt(MpcCore.div(a256, b256));
|
|
108
|
+
divResult = result;
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function remTest(uint256 a, uint256 b) public returns (uint256) {
|
|
114
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
115
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
116
|
+
|
|
117
|
+
uint256 result = MpcCore.decrypt(MpcCore.rem(a256, b256));
|
|
118
|
+
remResult = result;
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Bitwise128TestsContract {
|
|
7
|
+
uint128 andResult;
|
|
8
|
+
uint128 orResult;
|
|
9
|
+
uint128 xorResult;
|
|
10
|
+
|
|
11
|
+
function getAndResult() public view returns (uint128) {
|
|
12
|
+
return andResult;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getOrResult() public view returns (uint128) {
|
|
16
|
+
return orResult;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getXorResult() public view returns (uint128) {
|
|
20
|
+
return xorResult;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function andTest(uint128 a, uint128 b) public returns (uint128) {
|
|
24
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
25
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
26
|
+
|
|
27
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.and(a128, b128)));
|
|
28
|
+
andResult = result;
|
|
29
|
+
|
|
30
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.and(a, b128))), "andTest: scalar failed");
|
|
31
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.and(a128, b))), "andTest: scalar failed");
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function orTest(uint128 a, uint128 b) public returns (uint128) {
|
|
37
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
38
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
39
|
+
|
|
40
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.or(a128, b128)));
|
|
41
|
+
orResult = result;
|
|
42
|
+
|
|
43
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.or(a, b128))), "orTest: scalar failed");
|
|
44
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.or(a128, b))), "orTest: scalar failed");
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function xorTest(uint128 a, uint128 b) public returns (uint128) {
|
|
50
|
+
gtUint128 a128 = MpcCore.setPublic128(a);
|
|
51
|
+
gtUint128 b128 = MpcCore.setPublic128(b);
|
|
52
|
+
|
|
53
|
+
uint128 result = uint128(MpcCore.decrypt(MpcCore.xor(a128, b128)));
|
|
54
|
+
xorResult = result;
|
|
55
|
+
|
|
56
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.xor(a, b128))), "xorTest: scalar failed");
|
|
57
|
+
require(result == uint128(MpcCore.decrypt(MpcCore.xor(a128, b))), "xorTest: scalar failed");
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Note: NOT operation is not supported for 128-bit and 256-bit types in the MPC precompile
|
|
63
|
+
// It only supports NOT for boolean types
|
|
64
|
+
}
|
|
65
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Bitwise256TestsContract {
|
|
7
|
+
uint256 andResult;
|
|
8
|
+
uint256 orResult;
|
|
9
|
+
uint256 xorResult;
|
|
10
|
+
|
|
11
|
+
function getAndResult() public view returns (uint256) {
|
|
12
|
+
return andResult;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getOrResult() public view returns (uint256) {
|
|
16
|
+
return orResult;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getXorResult() public view returns (uint256) {
|
|
20
|
+
return xorResult;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function andTest(uint256 a, uint256 b) public returns (uint256) {
|
|
24
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
25
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
26
|
+
|
|
27
|
+
uint256 result = MpcCore.decrypt(MpcCore.and(a256, b256));
|
|
28
|
+
andResult = result;
|
|
29
|
+
|
|
30
|
+
require(result == MpcCore.decrypt(MpcCore.and(a, b256)), "andTest: scalar failed");
|
|
31
|
+
require(result == MpcCore.decrypt(MpcCore.and(a256, b)), "andTest: scalar failed");
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function orTest(uint256 a, uint256 b) public returns (uint256) {
|
|
37
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
38
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
39
|
+
|
|
40
|
+
uint256 result = MpcCore.decrypt(MpcCore.or(a256, b256));
|
|
41
|
+
orResult = result;
|
|
42
|
+
|
|
43
|
+
require(result == MpcCore.decrypt(MpcCore.or(a, b256)), "orTest: scalar failed");
|
|
44
|
+
require(result == MpcCore.decrypt(MpcCore.or(a256, b)), "orTest: scalar failed");
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function xorTest(uint256 a, uint256 b) public returns (uint256) {
|
|
50
|
+
gtUint256 a256 = MpcCore.setPublic256(a);
|
|
51
|
+
gtUint256 b256 = MpcCore.setPublic256(b);
|
|
52
|
+
|
|
53
|
+
uint256 result = MpcCore.decrypt(MpcCore.xor(a256, b256));
|
|
54
|
+
xorResult = result;
|
|
55
|
+
|
|
56
|
+
require(result == MpcCore.decrypt(MpcCore.xor(a, b256)), "xorTest: scalar failed");
|
|
57
|
+
require(result == MpcCore.decrypt(MpcCore.xor(a256, b)), "xorTest: scalar failed");
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Note: NOT operation is not supported for 128-bit and 256-bit types in the MPC precompile
|
|
63
|
+
// It only supports NOT for boolean types
|
|
64
|
+
}
|
|
65
|
+
|