@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,45 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
|
|
7
|
+
function buildTest(
|
|
8
|
+
contractName: string,
|
|
9
|
+
func: string,
|
|
10
|
+
resFunc: string,
|
|
11
|
+
params: bigint[],
|
|
12
|
+
expectedResult: bigint
|
|
13
|
+
) {
|
|
14
|
+
it(`${contractName}.${func}(${params}) should return ${expectedResult}`, async function () {
|
|
15
|
+
const [owner] = await setupAccounts()
|
|
16
|
+
const provider = owner.provider!
|
|
17
|
+
|
|
18
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
19
|
+
const contract = await factory.deploy({ gasLimit })
|
|
20
|
+
await contract.waitForDeployment()
|
|
21
|
+
|
|
22
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
23
|
+
const receipt = await tx.wait()
|
|
24
|
+
|
|
25
|
+
const result = await contract.getFunction(resFunc)()
|
|
26
|
+
expect(result).to.equal(expectedResult)
|
|
27
|
+
|
|
28
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
29
|
+
expect(txFromChain).to.not.be.null
|
|
30
|
+
expect(txFromChain?.status).to.equal(1)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const params = [
|
|
35
|
+
BigInt("1000000000000000000"), // 1e18
|
|
36
|
+
BigInt("500000000000000000") // 0.5e18
|
|
37
|
+
]
|
|
38
|
+
const [a, b] = params
|
|
39
|
+
|
|
40
|
+
describe("Checked Arithmetic 256-bit with Overflow Bit", function () {
|
|
41
|
+
buildTest("CheckedArithmetic256WithOverflowBitTestsContract", "checkedAddWithOverflowBitTest", "getAddResult", params, a + b)
|
|
42
|
+
buildTest("CheckedArithmetic256WithOverflowBitTestsContract", "checkedSubWithOverflowBitTest", "getSubResult", params, a - b)
|
|
43
|
+
buildTest("CheckedArithmetic256WithOverflowBitTestsContract", "checkedMulWithOverflowBitTest", "getMulResult", params, a * b)
|
|
44
|
+
})
|
|
45
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
|
|
7
|
+
function buildTest(
|
|
8
|
+
contractName: string,
|
|
9
|
+
func: string,
|
|
10
|
+
resFunc: string,
|
|
11
|
+
params: bigint[],
|
|
12
|
+
expectedResult: boolean
|
|
13
|
+
) {
|
|
14
|
+
it(`${contractName}.${func}(${params}) should return ${expectedResult}`, async function () {
|
|
15
|
+
const [owner] = await setupAccounts()
|
|
16
|
+
const provider = owner.provider!
|
|
17
|
+
|
|
18
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
19
|
+
const contract = await factory.deploy({ gasLimit })
|
|
20
|
+
await contract.waitForDeployment()
|
|
21
|
+
|
|
22
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
23
|
+
const receipt = await tx.wait()
|
|
24
|
+
|
|
25
|
+
const result = await contract.getFunction(resFunc)()
|
|
26
|
+
expect(result).to.equal(expectedResult)
|
|
27
|
+
|
|
28
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
29
|
+
expect(txFromChain).to.not.be.null
|
|
30
|
+
expect(txFromChain?.status).to.equal(1)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const params = [
|
|
35
|
+
BigInt("1000000000000000000"),
|
|
36
|
+
BigInt("500000000000000000")
|
|
37
|
+
]
|
|
38
|
+
const [a, b] = params
|
|
39
|
+
|
|
40
|
+
describe("Comparison 128-bit", function () {
|
|
41
|
+
buildTest("Comparison128TestsContract", "eqTest", "getEqResult", params, a == b)
|
|
42
|
+
buildTest("Comparison128TestsContract", "neTest", "getNeResult", params, a != b)
|
|
43
|
+
buildTest("Comparison128TestsContract", "geTest", "getGeResult", params, a >= b)
|
|
44
|
+
buildTest("Comparison128TestsContract", "gtTest", "getGtResult", params, a > b)
|
|
45
|
+
buildTest("Comparison128TestsContract", "leTest", "getLeResult", params, a <= b)
|
|
46
|
+
buildTest("Comparison128TestsContract", "ltTest", "getLtResult", params, a < b)
|
|
47
|
+
})
|
|
48
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
|
|
7
|
+
function buildTest(
|
|
8
|
+
contractName: string,
|
|
9
|
+
func: string,
|
|
10
|
+
resFunc: string,
|
|
11
|
+
params: bigint[],
|
|
12
|
+
expectedResult: boolean
|
|
13
|
+
) {
|
|
14
|
+
it(`${contractName}.${func}(${params}) should return ${expectedResult}`, async function () {
|
|
15
|
+
const [owner] = await setupAccounts()
|
|
16
|
+
const provider = owner.provider!
|
|
17
|
+
|
|
18
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
19
|
+
const contract = await factory.deploy({ gasLimit })
|
|
20
|
+
await contract.waitForDeployment()
|
|
21
|
+
|
|
22
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
23
|
+
const receipt = await tx.wait()
|
|
24
|
+
|
|
25
|
+
const result = await contract.getFunction(resFunc)()
|
|
26
|
+
expect(result).to.equal(expectedResult)
|
|
27
|
+
|
|
28
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
29
|
+
expect(txFromChain).to.not.be.null
|
|
30
|
+
expect(txFromChain?.status).to.equal(1)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const params = [
|
|
35
|
+
BigInt("1000000000000000000"), // 1e18
|
|
36
|
+
BigInt("500000000000000000") // 0.5e18
|
|
37
|
+
]
|
|
38
|
+
const [a, b] = params
|
|
39
|
+
|
|
40
|
+
describe("Comparison 256-bit", function () {
|
|
41
|
+
buildTest("Comparison256TestsContract", "eqTest", "getEqResult", params, a == b)
|
|
42
|
+
buildTest("Comparison256TestsContract", "neTest", "getNeResult", params, a != b)
|
|
43
|
+
buildTest("Comparison256TestsContract", "geTest", "getGeResult", params, a >= b)
|
|
44
|
+
buildTest("Comparison256TestsContract", "gtTest", "getGtResult", params, a > b)
|
|
45
|
+
buildTest("Comparison256TestsContract", "leTest", "getLeResult", params, a <= b)
|
|
46
|
+
buildTest("Comparison256TestsContract", "ltTest", "getLtResult", params, a < b)
|
|
47
|
+
})
|
|
48
|
+
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { Buffer } from "buffer"
|
|
4
|
+
import { setupAccounts } from "../accounts"
|
|
5
|
+
import { Wallet, itUint } from "@coti-io/coti-ethers"
|
|
6
|
+
import { ValidateCiphertextTestsContract } from "../../../typechain-types"
|
|
7
|
+
|
|
8
|
+
const GAS_LIMIT = 12000000
|
|
9
|
+
|
|
10
|
+
async function deploy() {
|
|
11
|
+
const [owner] = await setupAccounts()
|
|
12
|
+
const contractFactory = await hre.ethers.getContractFactory("ValidateCiphertextTestsContract", owner as any)
|
|
13
|
+
const contract = await contractFactory.deploy({ gasLimit: GAS_LIMIT })
|
|
14
|
+
await contract.waitForDeployment()
|
|
15
|
+
return {
|
|
16
|
+
contract,
|
|
17
|
+
contractAddress: await contract.getAddress(),
|
|
18
|
+
owner
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("Invalid Ciphertext Validation - 8/16/32/64-bit", function () {
|
|
23
|
+
this.timeout(120000) // 2 minutes
|
|
24
|
+
let contract: ValidateCiphertextTestsContract
|
|
25
|
+
let contractAddress: string
|
|
26
|
+
let owner: Wallet
|
|
27
|
+
|
|
28
|
+
before(async function () {
|
|
29
|
+
const deployment = await deploy()
|
|
30
|
+
contract = deployment.contract
|
|
31
|
+
contractAddress = deployment.contractAddress
|
|
32
|
+
owner = deployment.owner
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe("Invalid Signature Tests", function () {
|
|
36
|
+
it("Should reject ciphertext with invalid signature (all zeros)", async function () {
|
|
37
|
+
// Create valid ciphertext
|
|
38
|
+
const testValue = 100
|
|
39
|
+
const validItUint = await owner.encryptValue(
|
|
40
|
+
testValue,
|
|
41
|
+
contractAddress,
|
|
42
|
+
contract.validateAndReturn.fragment.selector
|
|
43
|
+
) as itUint
|
|
44
|
+
|
|
45
|
+
// Corrupt the signature - convert to Buffer
|
|
46
|
+
const invalidSignature = Buffer.from("00".repeat(64), "hex")
|
|
47
|
+
|
|
48
|
+
const invalidItUint: itUint = {
|
|
49
|
+
ciphertext: validItUint.ciphertext,
|
|
50
|
+
signature: invalidSignature
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Try the transaction - it might not revert, so check behavior
|
|
54
|
+
try {
|
|
55
|
+
const tx = await contract.validateAndReturn(invalidItUint, { gasLimit: GAS_LIMIT })
|
|
56
|
+
const receipt = await tx.wait()
|
|
57
|
+
// If it doesn't revert, that's unexpected but we log it
|
|
58
|
+
console.log("⚠️ Invalid signature did not cause revert - validation may be lenient")
|
|
59
|
+
} catch (error: any) {
|
|
60
|
+
if (error.message && error.message.includes("revert")) {
|
|
61
|
+
console.log("✅ Invalid signature correctly caused revert")
|
|
62
|
+
} else {
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("Should reject ciphertext with wrong contract address signature", async function () {
|
|
69
|
+
// Create ciphertext signed for different contract
|
|
70
|
+
const wrongAddress = "0x" + "11".repeat(20) // Different address
|
|
71
|
+
const testValue = 100
|
|
72
|
+
|
|
73
|
+
// This should fail because signature is for wrong address
|
|
74
|
+
const itUint = await owner.encryptValue(
|
|
75
|
+
testValue,
|
|
76
|
+
wrongAddress, // Wrong address
|
|
77
|
+
contract.validateAndReturn.fragment.selector
|
|
78
|
+
) as itUint
|
|
79
|
+
|
|
80
|
+
// Try to validate - might not revert
|
|
81
|
+
try {
|
|
82
|
+
const tx = await contract.validateAndReturn(itUint, { gasLimit: GAS_LIMIT })
|
|
83
|
+
const receipt = await tx.wait()
|
|
84
|
+
console.log("⚠️ Wrong address signature did not cause revert")
|
|
85
|
+
} catch (error: any) {
|
|
86
|
+
if (error.message && error.message.includes("revert")) {
|
|
87
|
+
console.log("✅ Wrong address signature correctly caused revert")
|
|
88
|
+
} else {
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it("Should reject ciphertext with corrupted signature", async function () {
|
|
95
|
+
const testValue = 100
|
|
96
|
+
const validItUint = await owner.encryptValue(
|
|
97
|
+
testValue,
|
|
98
|
+
contractAddress,
|
|
99
|
+
contract.validateAndReturn.fragment.selector
|
|
100
|
+
) as itUint
|
|
101
|
+
|
|
102
|
+
// Convert signature to Buffer, corrupt it
|
|
103
|
+
const sigBuffer = Buffer.isBuffer(validItUint.signature)
|
|
104
|
+
? Buffer.from(validItUint.signature)
|
|
105
|
+
: Buffer.from(validItUint.signature)
|
|
106
|
+
|
|
107
|
+
// Flip first byte
|
|
108
|
+
sigBuffer[0] = sigBuffer[0] ^ 0xFF
|
|
109
|
+
|
|
110
|
+
const corruptedItUint: itUint = {
|
|
111
|
+
ciphertext: validItUint.ciphertext,
|
|
112
|
+
signature: sigBuffer
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const tx = await contract.validateAndReturn(corruptedItUint, { gasLimit: GAS_LIMIT })
|
|
117
|
+
const receipt = await tx.wait()
|
|
118
|
+
console.log("⚠️ Corrupted signature did not cause revert")
|
|
119
|
+
} catch (error: any) {
|
|
120
|
+
if (error.message && error.message.includes("revert")) {
|
|
121
|
+
console.log("✅ Corrupted signature correctly caused revert")
|
|
122
|
+
} else {
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
describe("Corrupted Ciphertext Tests", function () {
|
|
130
|
+
it("Should handle corrupted ciphertext data", async function () {
|
|
131
|
+
const testValue = 100
|
|
132
|
+
const validItUint = await owner.encryptValue(
|
|
133
|
+
testValue,
|
|
134
|
+
contractAddress,
|
|
135
|
+
contract.validateAndReturn.fragment.selector
|
|
136
|
+
) as itUint
|
|
137
|
+
|
|
138
|
+
// For 8/16/32/64-bit, ciphertext is a direct string value
|
|
139
|
+
const corruptedCiphertext = (BigInt(validItUint.ciphertext.toString()) ^ BigInt("0xFFFFFFFFFFFFFFFF")).toString()
|
|
140
|
+
|
|
141
|
+
const corruptedItUint: itUint = {
|
|
142
|
+
ciphertext: corruptedCiphertext,
|
|
143
|
+
signature: validItUint.signature
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const tx = await contract.validateAndReturn(corruptedItUint, { gasLimit: GAS_LIMIT })
|
|
148
|
+
const receipt = await tx.wait()
|
|
149
|
+
console.log("⚠️ Corrupted ciphertext did not cause revert")
|
|
150
|
+
} catch (error: any) {
|
|
151
|
+
if (error.message && error.message.includes("revert")) {
|
|
152
|
+
console.log("✅ Corrupted ciphertext correctly caused revert")
|
|
153
|
+
} else {
|
|
154
|
+
throw error
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it("Should handle empty ciphertext", async function () {
|
|
160
|
+
const emptyItUint: itUint = {
|
|
161
|
+
ciphertext: "0",
|
|
162
|
+
signature: Buffer.from("00".repeat(64), "hex")
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const tx = await contract.validateAndReturn(emptyItUint, { gasLimit: GAS_LIMIT })
|
|
167
|
+
const receipt = await tx.wait()
|
|
168
|
+
console.log("⚠️ Empty ciphertext did not cause revert")
|
|
169
|
+
} catch (error: any) {
|
|
170
|
+
if (error.message && error.message.includes("revert")) {
|
|
171
|
+
console.log("✅ Empty ciphertext correctly caused revert")
|
|
172
|
+
} else {
|
|
173
|
+
throw error
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { Buffer } from "buffer"
|
|
4
|
+
import { setupAccounts } from "../accounts"
|
|
5
|
+
import { Wallet, itUint128 } from "@coti-io/coti-ethers"
|
|
6
|
+
import { ValidateCiphertext128TestsContract } from "../../../typechain-types"
|
|
7
|
+
|
|
8
|
+
const GAS_LIMIT = 12000000
|
|
9
|
+
|
|
10
|
+
async function deploy() {
|
|
11
|
+
const [owner] = await setupAccounts()
|
|
12
|
+
const contractFactory = await hre.ethers.getContractFactory("ValidateCiphertext128TestsContract", owner as any)
|
|
13
|
+
const contract = await contractFactory.deploy({ gasLimit: GAS_LIMIT })
|
|
14
|
+
await contract.waitForDeployment()
|
|
15
|
+
return {
|
|
16
|
+
contract,
|
|
17
|
+
contractAddress: await contract.getAddress(),
|
|
18
|
+
owner
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("Invalid Ciphertext Validation - 128-bit", function () {
|
|
23
|
+
this.timeout(120000) // 2 minutes
|
|
24
|
+
let contract: ValidateCiphertext128TestsContract
|
|
25
|
+
let contractAddress: string
|
|
26
|
+
let owner: Wallet
|
|
27
|
+
|
|
28
|
+
before(async function () {
|
|
29
|
+
const deployment = await deploy()
|
|
30
|
+
contract = deployment.contract
|
|
31
|
+
contractAddress = deployment.contractAddress
|
|
32
|
+
owner = deployment.owner
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe("Invalid Signature Tests", function () {
|
|
36
|
+
it("Should reject ciphertext with invalid signature (all zeros)", async function () {
|
|
37
|
+
// Create valid ciphertext
|
|
38
|
+
const testValue = BigInt("1000000000000000000")
|
|
39
|
+
const validItUint = await owner.encryptValue(
|
|
40
|
+
testValue,
|
|
41
|
+
contractAddress,
|
|
42
|
+
contract.validateAndReturn.fragment.selector
|
|
43
|
+
) as any
|
|
44
|
+
|
|
45
|
+
// Corrupt the signature - convert to Buffer
|
|
46
|
+
const invalidSignature = Buffer.from("00".repeat(64), "hex")
|
|
47
|
+
|
|
48
|
+
const invalidItUint: itUint128 = {
|
|
49
|
+
ciphertext: validItUint.ciphertext,
|
|
50
|
+
signature: invalidSignature
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Try the transaction - it might not revert, so check behavior
|
|
54
|
+
try {
|
|
55
|
+
const tx = await contract.validateAndReturn(invalidItUint, { gasLimit: GAS_LIMIT })
|
|
56
|
+
const receipt = await tx.wait()
|
|
57
|
+
// If it doesn't revert, that's unexpected but we log it
|
|
58
|
+
console.log("⚠️ Invalid signature did not cause revert - validation may be lenient")
|
|
59
|
+
} catch (error: any) {
|
|
60
|
+
if (error.message && error.message.includes("revert")) {
|
|
61
|
+
console.log("✅ Invalid signature correctly caused revert")
|
|
62
|
+
} else {
|
|
63
|
+
throw error
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("Should reject ciphertext with wrong contract address signature", async function () {
|
|
69
|
+
// Create ciphertext signed for different contract
|
|
70
|
+
const wrongAddress = "0x" + "11".repeat(20) // Different address
|
|
71
|
+
const testValue = BigInt("1000000000000000000")
|
|
72
|
+
|
|
73
|
+
// This should fail because signature is for wrong address
|
|
74
|
+
const itUint = await owner.encryptValue(
|
|
75
|
+
testValue,
|
|
76
|
+
wrongAddress, // Wrong address
|
|
77
|
+
contract.validateAndReturn.fragment.selector
|
|
78
|
+
) as any
|
|
79
|
+
|
|
80
|
+
// Try to validate - might not revert
|
|
81
|
+
try {
|
|
82
|
+
const tx = await contract.validateAndReturn(itUint, { gasLimit: GAS_LIMIT })
|
|
83
|
+
const receipt = await tx.wait()
|
|
84
|
+
console.log("⚠️ Wrong address signature did not cause revert")
|
|
85
|
+
} catch (error: any) {
|
|
86
|
+
if (error.message && error.message.includes("revert")) {
|
|
87
|
+
console.log("✅ Wrong address signature correctly caused revert")
|
|
88
|
+
} else {
|
|
89
|
+
throw error
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it("Should reject ciphertext with corrupted signature", async function () {
|
|
95
|
+
const testValue = BigInt("1000000000000000000")
|
|
96
|
+
const validItUint = await owner.encryptValue(
|
|
97
|
+
testValue,
|
|
98
|
+
contractAddress,
|
|
99
|
+
contract.validateAndReturn.fragment.selector
|
|
100
|
+
) as any
|
|
101
|
+
|
|
102
|
+
// Convert signature to Buffer, corrupt it, convert back
|
|
103
|
+
const sigBuffer = Buffer.isBuffer(validItUint.signature)
|
|
104
|
+
? Buffer.from(validItUint.signature)
|
|
105
|
+
: Buffer.from(validItUint.signature)
|
|
106
|
+
|
|
107
|
+
// Flip first byte
|
|
108
|
+
sigBuffer[0] = sigBuffer[0] ^ 0xFF
|
|
109
|
+
|
|
110
|
+
const corruptedItUint: itUint128 = {
|
|
111
|
+
ciphertext: validItUint.ciphertext,
|
|
112
|
+
signature: sigBuffer
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const tx = await contract.validateAndReturn(corruptedItUint, { gasLimit: GAS_LIMIT })
|
|
117
|
+
const receipt = await tx.wait()
|
|
118
|
+
console.log("⚠️ Corrupted signature did not cause revert")
|
|
119
|
+
} catch (error: any) {
|
|
120
|
+
if (error.message && error.message.includes("revert")) {
|
|
121
|
+
console.log("✅ Corrupted signature correctly caused revert")
|
|
122
|
+
} else {
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
describe("Corrupted Ciphertext Tests", function () {
|
|
130
|
+
it("Should handle corrupted ciphertext data", async function () {
|
|
131
|
+
const testValue = BigInt("1000000000000000000")
|
|
132
|
+
const validItUint = await owner.encryptValue(
|
|
133
|
+
testValue,
|
|
134
|
+
contractAddress,
|
|
135
|
+
contract.validateAndReturn.fragment.selector
|
|
136
|
+
) as any
|
|
137
|
+
|
|
138
|
+
// For 128-bit, ciphertext is a direct BigInt value, not an object
|
|
139
|
+
const corruptedCiphertext = (BigInt(validItUint.ciphertext.toString()) ^ BigInt("0xFFFFFFFFFFFFFFFF")).toString()
|
|
140
|
+
|
|
141
|
+
const corruptedItUint: itUint128 = {
|
|
142
|
+
ciphertext: corruptedCiphertext, // Direct value for 128-bit
|
|
143
|
+
signature: validItUint.signature
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const tx = await contract.validateAndReturn(corruptedItUint, { gasLimit: GAS_LIMIT })
|
|
148
|
+
const receipt = await tx.wait()
|
|
149
|
+
console.log("⚠️ Corrupted ciphertext did not cause revert")
|
|
150
|
+
} catch (error: any) {
|
|
151
|
+
if (error.message && error.message.includes("revert")) {
|
|
152
|
+
console.log("✅ Corrupted ciphertext correctly caused revert")
|
|
153
|
+
} else {
|
|
154
|
+
throw error
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it("Should handle empty ciphertext", async function () {
|
|
160
|
+
const emptyItUint: itUint128 = {
|
|
161
|
+
ciphertext: "0", // Direct value for 128-bit
|
|
162
|
+
signature: Buffer.from("00".repeat(64), "hex")
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const tx = await contract.validateAndReturn(emptyItUint, { gasLimit: GAS_LIMIT })
|
|
167
|
+
const receipt = await tx.wait()
|
|
168
|
+
console.log("⚠️ Empty ciphertext did not cause revert")
|
|
169
|
+
} catch (error: any) {
|
|
170
|
+
if (error.message && error.message.includes("revert")) {
|
|
171
|
+
console.log("✅ Empty ciphertext correctly caused revert")
|
|
172
|
+
} else {
|
|
173
|
+
throw error
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|