@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,201 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { Buffer } from "buffer"
|
|
4
|
+
import { setupAccounts } from "../accounts"
|
|
5
|
+
import { Wallet, itUint256 } from "@coti-io/coti-ethers"
|
|
6
|
+
import { ValidateCiphertext256TestsContract } 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("ValidateCiphertext256TestsContract", 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 - 256-bit", function () {
|
|
23
|
+
this.timeout(120000) // 2 minutes
|
|
24
|
+
let contract: ValidateCiphertext256TestsContract
|
|
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 = (2n ** 128n) + BigInt("1000000000000000000") // > 128 bits
|
|
39
|
+
const validItUint = await owner.encryptValue256(
|
|
40
|
+
testValue,
|
|
41
|
+
contractAddress,
|
|
42
|
+
contract.validateAndStore.fragment.selector
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
// Corrupt the signature - convert to Buffer
|
|
46
|
+
const invalidSignature = Buffer.from("00".repeat(64), "hex")
|
|
47
|
+
|
|
48
|
+
const invalidItUint: itUint256 = {
|
|
49
|
+
ciphertext: validItUint.ciphertext,
|
|
50
|
+
signature: invalidSignature
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Should revert or return false
|
|
54
|
+
try {
|
|
55
|
+
const tx = await contract.validateAndStore(invalidItUint, { gasLimit: GAS_LIMIT })
|
|
56
|
+
const receipt = await tx.wait()
|
|
57
|
+
|
|
58
|
+
// Check validation result
|
|
59
|
+
const validationResult = await contract.getValidationResult()
|
|
60
|
+
expect(validationResult).to.equal(false, "Invalid signature should fail validation")
|
|
61
|
+
console.log("✅ Invalid signature correctly failed validation")
|
|
62
|
+
} catch (error: any) {
|
|
63
|
+
// Reverting is also acceptable behavior
|
|
64
|
+
if (error.message && error.message.includes("revert")) {
|
|
65
|
+
console.log("✅ Invalid signature correctly caused revert")
|
|
66
|
+
} else {
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it("Should reject ciphertext with wrong contract address signature", async function () {
|
|
73
|
+
// Create ciphertext signed for different contract
|
|
74
|
+
const wrongAddress = "0x" + "11".repeat(20) // Different address
|
|
75
|
+
const testValue = (2n ** 128n) + BigInt("1000000000000000000")
|
|
76
|
+
|
|
77
|
+
// This should fail because signature is for wrong address
|
|
78
|
+
const itUint = await owner.encryptValue256(
|
|
79
|
+
testValue,
|
|
80
|
+
wrongAddress, // Wrong address
|
|
81
|
+
contract.validateAndStore.fragment.selector
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
// Try to validate with correct contract address
|
|
85
|
+
try {
|
|
86
|
+
const tx = await contract.validateAndStore(itUint, { gasLimit: GAS_LIMIT })
|
|
87
|
+
const receipt = await tx.wait()
|
|
88
|
+
|
|
89
|
+
// Check validation result
|
|
90
|
+
const validationResult = await contract.getValidationResult()
|
|
91
|
+
expect(validationResult).to.equal(false, "Wrong address signature should fail")
|
|
92
|
+
console.log("✅ Wrong address signature correctly failed validation")
|
|
93
|
+
} catch (error: any) {
|
|
94
|
+
if (error.message && error.message.includes("revert")) {
|
|
95
|
+
console.log("✅ Wrong address signature correctly caused revert")
|
|
96
|
+
} else {
|
|
97
|
+
throw error
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it("Should reject ciphertext with corrupted signature", async function () {
|
|
103
|
+
const testValue = (2n ** 128n) + BigInt("1000000000000000000")
|
|
104
|
+
const validItUint = await owner.encryptValue256(
|
|
105
|
+
testValue,
|
|
106
|
+
contractAddress,
|
|
107
|
+
contract.validateAndStore.fragment.selector
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
// Convert signature to Buffer, corrupt it
|
|
111
|
+
const sigBuffer = Buffer.isBuffer(validItUint.signature)
|
|
112
|
+
? Buffer.from(validItUint.signature)
|
|
113
|
+
: Buffer.from(validItUint.signature)
|
|
114
|
+
|
|
115
|
+
// Flip first byte
|
|
116
|
+
sigBuffer[0] = sigBuffer[0] ^ 0xFF
|
|
117
|
+
|
|
118
|
+
const corruptedItUint: itUint256 = {
|
|
119
|
+
ciphertext: validItUint.ciphertext,
|
|
120
|
+
signature: sigBuffer
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const tx = await contract.validateAndStore(corruptedItUint, { gasLimit: GAS_LIMIT })
|
|
125
|
+
const receipt = await tx.wait()
|
|
126
|
+
|
|
127
|
+
const validationResult = await contract.getValidationResult()
|
|
128
|
+
expect(validationResult).to.equal(false, "Corrupted signature should fail")
|
|
129
|
+
console.log("✅ Corrupted signature correctly failed validation")
|
|
130
|
+
} catch (error: any) {
|
|
131
|
+
if (error.message && error.message.includes("revert")) {
|
|
132
|
+
console.log("✅ Corrupted signature correctly caused revert")
|
|
133
|
+
} else {
|
|
134
|
+
throw error
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe("Corrupted Ciphertext Tests", function () {
|
|
141
|
+
it("Should handle corrupted ciphertext data", async function () {
|
|
142
|
+
const testValue = (2n ** 128n) + BigInt("1000000000000000000")
|
|
143
|
+
const validItUint = await owner.encryptValue256(
|
|
144
|
+
testValue,
|
|
145
|
+
contractAddress,
|
|
146
|
+
contract.validateAndStore.fragment.selector
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
// Corrupt the ciphertext by modifying high or low parts
|
|
150
|
+
const corruptedItUint: itUint256 = {
|
|
151
|
+
ciphertext: {
|
|
152
|
+
ciphertextHigh: (BigInt(validItUint.ciphertext.ciphertextHigh) ^ BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")).toString(),
|
|
153
|
+
ciphertextLow: validItUint.ciphertext.ciphertextLow
|
|
154
|
+
},
|
|
155
|
+
signature: validItUint.signature
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Should fail validation
|
|
159
|
+
try {
|
|
160
|
+
const tx = await contract.validateAndStore(corruptedItUint, { gasLimit: GAS_LIMIT })
|
|
161
|
+
const receipt = await tx.wait()
|
|
162
|
+
|
|
163
|
+
const validationResult = await contract.getValidationResult()
|
|
164
|
+
expect(validationResult).to.equal(false, "Corrupted ciphertext should fail validation")
|
|
165
|
+
console.log("✅ Corrupted ciphertext correctly failed validation")
|
|
166
|
+
} catch (error: any) {
|
|
167
|
+
if (error.message && error.message.includes("revert")) {
|
|
168
|
+
console.log("✅ Corrupted ciphertext correctly caused revert")
|
|
169
|
+
} else {
|
|
170
|
+
throw error
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it("Should handle empty ciphertext", async function () {
|
|
176
|
+
const emptyItUint: itUint256 = {
|
|
177
|
+
ciphertext: {
|
|
178
|
+
ciphertextHigh: "0",
|
|
179
|
+
ciphertextLow: "0"
|
|
180
|
+
},
|
|
181
|
+
signature: Buffer.from("00".repeat(64), "hex")
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const tx = await contract.validateAndStore(emptyItUint, { gasLimit: GAS_LIMIT })
|
|
186
|
+
const receipt = await tx.wait()
|
|
187
|
+
|
|
188
|
+
const validationResult = await contract.getValidationResult()
|
|
189
|
+
expect(validationResult).to.equal(false, "Empty ciphertext should fail validation")
|
|
190
|
+
console.log("✅ Empty ciphertext correctly failed validation")
|
|
191
|
+
} catch (error: any) {
|
|
192
|
+
if (error.message && error.message.includes("revert")) {
|
|
193
|
+
console.log("✅ Empty ciphertext correctly caused revert")
|
|
194
|
+
} else {
|
|
195
|
+
throw error
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
|
|
7
|
+
describe("Invalid Transfer Operations - 128-bit", function () {
|
|
8
|
+
this.timeout(120000) // 2 minutes
|
|
9
|
+
|
|
10
|
+
describe("Transfer with Insufficient Balance", function () {
|
|
11
|
+
it("Should handle transfer when balance < amount", async function () {
|
|
12
|
+
const [owner] = await setupAccounts()
|
|
13
|
+
|
|
14
|
+
const factory = await hre.ethers.getContractFactory("Transfer128TestsContract", owner as any)
|
|
15
|
+
const contract = await factory.deploy({ gasLimit })
|
|
16
|
+
await contract.waitForDeployment()
|
|
17
|
+
|
|
18
|
+
const smallBalance = BigInt("100000000000000000") // 0.1
|
|
19
|
+
const largeAmount = BigInt("1000000000000000000") // 1.0 (10x balance)
|
|
20
|
+
|
|
21
|
+
// Transfer more than available balance
|
|
22
|
+
// Note: MPC precompile may handle this differently - it might:
|
|
23
|
+
// 1. Revert the transaction
|
|
24
|
+
// 2. Return a failure flag (result = false)
|
|
25
|
+
// 3. Allow underflow (result in wrapped value)
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const tx = await contract.transferTest(smallBalance, BigInt(0), largeAmount, { gasLimit })
|
|
29
|
+
const receipt = await tx.wait()
|
|
30
|
+
expect(receipt?.status).to.equal(1)
|
|
31
|
+
|
|
32
|
+
// Check the result flag
|
|
33
|
+
const results = await contract.getResults()
|
|
34
|
+
console.log(`Transfer result: new_a=${results[0]}, new_b=${results[1]}, success=${results[2]}`)
|
|
35
|
+
|
|
36
|
+
// The behavior depends on MPC precompile implementation
|
|
37
|
+
// If transfer fails, success flag should be false
|
|
38
|
+
// Or the new balance might be wrapped/underflowed
|
|
39
|
+
if (results[2] === false) {
|
|
40
|
+
console.log("✅ Transfer correctly returned failure flag for insufficient balance")
|
|
41
|
+
} else {
|
|
42
|
+
console.log("⚠️ Transfer succeeded despite insufficient balance - may allow underflow")
|
|
43
|
+
}
|
|
44
|
+
} catch (error: any) {
|
|
45
|
+
// Reverting is acceptable behavior for insufficient balance
|
|
46
|
+
if (error.message && error.message.includes("revert")) {
|
|
47
|
+
console.log("✅ Insufficient balance correctly caused revert")
|
|
48
|
+
} else {
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it("Should handle transfer with zero balance", async function () {
|
|
55
|
+
const [owner] = await setupAccounts()
|
|
56
|
+
|
|
57
|
+
const factory = await hre.ethers.getContractFactory("Transfer128TestsContract", owner as any)
|
|
58
|
+
const contract = await factory.deploy({ gasLimit })
|
|
59
|
+
await contract.waitForDeployment()
|
|
60
|
+
|
|
61
|
+
const zeroBalance = BigInt(0)
|
|
62
|
+
const amount = BigInt("100000000000000000")
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const tx = await contract.transferTest(zeroBalance, BigInt(0), amount, { gasLimit })
|
|
66
|
+
const receipt = await tx.wait()
|
|
67
|
+
expect(receipt?.status).to.equal(1)
|
|
68
|
+
|
|
69
|
+
const results = await contract.getResults()
|
|
70
|
+
console.log(`Transfer from zero balance: new_a=${results[0]}, new_b=${results[1]}, success=${results[2]}`)
|
|
71
|
+
|
|
72
|
+
if (results[2] === false) {
|
|
73
|
+
console.log("✅ Transfer correctly returned failure flag for zero balance")
|
|
74
|
+
}
|
|
75
|
+
} catch (error: any) {
|
|
76
|
+
if (error.message && error.message.includes("revert")) {
|
|
77
|
+
console.log("✅ Zero balance transfer correctly caused revert")
|
|
78
|
+
} else {
|
|
79
|
+
throw error
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe("Transfer with Insufficient Allowance", function () {
|
|
86
|
+
it("Should handle transferWithAllowance when allowance < amount", async function () {
|
|
87
|
+
const [owner] = await setupAccounts()
|
|
88
|
+
|
|
89
|
+
const factory = await hre.ethers.getContractFactory("TransferWithAllowance128TestsContract", owner as any)
|
|
90
|
+
const contract = await factory.deploy({ gasLimit })
|
|
91
|
+
await contract.waitForDeployment()
|
|
92
|
+
|
|
93
|
+
const balance = BigInt("1000000000000000000")
|
|
94
|
+
const smallAllowance = BigInt("100000000000000000") // 0.1
|
|
95
|
+
const largeAmount = BigInt("1000000000000000000") // 1.0 (10x allowance)
|
|
96
|
+
|
|
97
|
+
// Transfer more than allowance
|
|
98
|
+
try {
|
|
99
|
+
const tx = await contract.transferWithAllowanceTest(
|
|
100
|
+
balance,
|
|
101
|
+
BigInt(0),
|
|
102
|
+
largeAmount,
|
|
103
|
+
smallAllowance,
|
|
104
|
+
{ gasLimit }
|
|
105
|
+
)
|
|
106
|
+
const receipt = await tx.wait()
|
|
107
|
+
expect(receipt?.status).to.equal(1)
|
|
108
|
+
|
|
109
|
+
const results = await contract.getResults()
|
|
110
|
+
console.log(`TransferWithAllowance result: new_a=${results[0]}, new_b=${results[1]}, success=${results[2]}, new_allowance=${results[3]}`)
|
|
111
|
+
|
|
112
|
+
// Check if allowance was properly enforced
|
|
113
|
+
// The new_allowance should not be negative if enforcement works
|
|
114
|
+
if (results[2] === false) {
|
|
115
|
+
console.log("✅ TransferWithAllowance correctly returned failure flag for insufficient allowance")
|
|
116
|
+
} else {
|
|
117
|
+
console.log("⚠️ TransferWithAllowance succeeded despite insufficient allowance")
|
|
118
|
+
}
|
|
119
|
+
} catch (error: any) {
|
|
120
|
+
if (error.message && error.message.includes("revert")) {
|
|
121
|
+
console.log("✅ Insufficient allowance correctly caused revert")
|
|
122
|
+
} else {
|
|
123
|
+
throw error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it("Should handle transferWithAllowance with zero allowance", async function () {
|
|
129
|
+
const [owner] = await setupAccounts()
|
|
130
|
+
|
|
131
|
+
const factory = await hre.ethers.getContractFactory("TransferWithAllowance128TestsContract", owner as any)
|
|
132
|
+
const contract = await factory.deploy({ gasLimit })
|
|
133
|
+
await contract.waitForDeployment()
|
|
134
|
+
|
|
135
|
+
const balance = BigInt("1000000000000000000")
|
|
136
|
+
const zeroAllowance = BigInt(0)
|
|
137
|
+
const amount = BigInt("100000000000000000")
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
const tx = await contract.transferWithAllowanceTest(
|
|
141
|
+
balance,
|
|
142
|
+
BigInt(0),
|
|
143
|
+
amount,
|
|
144
|
+
zeroAllowance,
|
|
145
|
+
{ gasLimit }
|
|
146
|
+
)
|
|
147
|
+
const receipt = await tx.wait()
|
|
148
|
+
expect(receipt?.status).to.equal(1)
|
|
149
|
+
|
|
150
|
+
const results = await contract.getResults()
|
|
151
|
+
console.log(`TransferWithAllowance with zero allowance: success=${results[2]}, new_allowance=${results[3]}`)
|
|
152
|
+
|
|
153
|
+
if (results[2] === false) {
|
|
154
|
+
console.log("✅ TransferWithAllowance correctly returned failure flag for zero allowance")
|
|
155
|
+
}
|
|
156
|
+
} catch (error: any) {
|
|
157
|
+
if (error.message && error.message.includes("revert")) {
|
|
158
|
+
console.log("✅ Zero allowance transfer correctly caused revert")
|
|
159
|
+
} else {
|
|
160
|
+
throw error
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
})
|
|
166
|
+
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
|
|
7
|
+
describe("Invalid Transfer Operations - 256-bit", function () {
|
|
8
|
+
this.timeout(120000) // 2 minutes
|
|
9
|
+
|
|
10
|
+
describe("Transfer with Insufficient Balance", function () {
|
|
11
|
+
it("Should handle transfer when balance < amount", async function () {
|
|
12
|
+
const [owner] = await setupAccounts()
|
|
13
|
+
|
|
14
|
+
const factory = await hre.ethers.getContractFactory("Transfer256TestsContract", owner as any)
|
|
15
|
+
const contract = await factory.deploy({ gasLimit })
|
|
16
|
+
await contract.waitForDeployment()
|
|
17
|
+
|
|
18
|
+
const smallBalance = BigInt("100000000000000000") // 0.1
|
|
19
|
+
const largeAmount = BigInt("1000000000000000000") // 1.0 (10x balance)
|
|
20
|
+
|
|
21
|
+
// Transfer more than available balance
|
|
22
|
+
try {
|
|
23
|
+
const tx = await contract.transferTest(smallBalance, BigInt(0), largeAmount, { gasLimit })
|
|
24
|
+
const receipt = await tx.wait()
|
|
25
|
+
expect(receipt?.status).to.equal(1)
|
|
26
|
+
|
|
27
|
+
// Check the result flag
|
|
28
|
+
const results = await contract.getResults()
|
|
29
|
+
console.log(`Transfer result: new_a=${results[0]}, new_b=${results[1]}, success=${results[2]}`)
|
|
30
|
+
|
|
31
|
+
// The behavior depends on MPC precompile implementation
|
|
32
|
+
if (results[2] === false) {
|
|
33
|
+
console.log("✅ Transfer correctly returned failure flag for insufficient balance")
|
|
34
|
+
} else {
|
|
35
|
+
console.log("⚠️ Transfer succeeded despite insufficient balance - may allow underflow")
|
|
36
|
+
}
|
|
37
|
+
} catch (error: any) {
|
|
38
|
+
// Reverting is acceptable behavior for insufficient balance
|
|
39
|
+
if (error.message && error.message.includes("revert")) {
|
|
40
|
+
console.log("✅ Insufficient balance correctly caused revert")
|
|
41
|
+
} else {
|
|
42
|
+
throw error
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it("Should handle transfer with zero balance", async function () {
|
|
48
|
+
const [owner] = await setupAccounts()
|
|
49
|
+
|
|
50
|
+
const factory = await hre.ethers.getContractFactory("Transfer256TestsContract", owner as any)
|
|
51
|
+
const contract = await factory.deploy({ gasLimit })
|
|
52
|
+
await contract.waitForDeployment()
|
|
53
|
+
|
|
54
|
+
const zeroBalance = BigInt(0)
|
|
55
|
+
const amount = BigInt("100000000000000000")
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
const tx = await contract.transferTest(zeroBalance, BigInt(0), amount, { gasLimit })
|
|
59
|
+
const receipt = await tx.wait()
|
|
60
|
+
expect(receipt?.status).to.equal(1)
|
|
61
|
+
|
|
62
|
+
const results = await contract.getResults()
|
|
63
|
+
console.log(`Transfer from zero balance: new_a=${results[0]}, new_b=${results[1]}, success=${results[2]}`)
|
|
64
|
+
|
|
65
|
+
if (results[2] === false) {
|
|
66
|
+
console.log("✅ Transfer correctly returned failure flag for zero balance")
|
|
67
|
+
}
|
|
68
|
+
} catch (error: any) {
|
|
69
|
+
if (error.message && error.message.includes("revert")) {
|
|
70
|
+
console.log("✅ Zero balance transfer correctly caused revert")
|
|
71
|
+
} else {
|
|
72
|
+
throw error
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe("Transfer with Insufficient Allowance", function () {
|
|
79
|
+
it("Should handle transferWithAllowance when allowance < amount", async function () {
|
|
80
|
+
const [owner] = await setupAccounts()
|
|
81
|
+
|
|
82
|
+
const factory = await hre.ethers.getContractFactory("TransferWithAllowance256TestsContract", owner as any)
|
|
83
|
+
const contract = await factory.deploy({ gasLimit })
|
|
84
|
+
await contract.waitForDeployment()
|
|
85
|
+
|
|
86
|
+
const balance = BigInt("1000000000000000000")
|
|
87
|
+
const smallAllowance = BigInt("100000000000000000") // 0.1
|
|
88
|
+
const largeAmount = BigInt("1000000000000000000") // 1.0 (10x allowance)
|
|
89
|
+
|
|
90
|
+
// Transfer more than allowance
|
|
91
|
+
try {
|
|
92
|
+
const tx = await contract.transferWithAllowanceTest(
|
|
93
|
+
balance,
|
|
94
|
+
BigInt(0),
|
|
95
|
+
largeAmount,
|
|
96
|
+
smallAllowance,
|
|
97
|
+
{ gasLimit }
|
|
98
|
+
)
|
|
99
|
+
const receipt = await tx.wait()
|
|
100
|
+
expect(receipt?.status).to.equal(1)
|
|
101
|
+
|
|
102
|
+
const results = await contract.getResults()
|
|
103
|
+
console.log(`TransferWithAllowance result: new_a=${results[0]}, new_b=${results[1]}, success=${results[2]}, new_allowance=${results[3]}`)
|
|
104
|
+
|
|
105
|
+
// Check if allowance was properly enforced
|
|
106
|
+
if (results[2] === false) {
|
|
107
|
+
console.log("✅ TransferWithAllowance correctly returned failure flag for insufficient allowance")
|
|
108
|
+
} else {
|
|
109
|
+
console.log("⚠️ TransferWithAllowance succeeded despite insufficient allowance")
|
|
110
|
+
}
|
|
111
|
+
} catch (error: any) {
|
|
112
|
+
if (error.message && error.message.includes("revert")) {
|
|
113
|
+
console.log("✅ Insufficient allowance correctly caused revert")
|
|
114
|
+
} else {
|
|
115
|
+
throw error
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
it("Should handle transferWithAllowance with zero allowance", async function () {
|
|
121
|
+
const [owner] = await setupAccounts()
|
|
122
|
+
|
|
123
|
+
const factory = await hre.ethers.getContractFactory("TransferWithAllowance256TestsContract", owner as any)
|
|
124
|
+
const contract = await factory.deploy({ gasLimit })
|
|
125
|
+
await contract.waitForDeployment()
|
|
126
|
+
|
|
127
|
+
const balance = BigInt("1000000000000000000")
|
|
128
|
+
const zeroAllowance = BigInt(0)
|
|
129
|
+
const amount = BigInt("100000000000000000")
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const tx = await contract.transferWithAllowanceTest(
|
|
133
|
+
balance,
|
|
134
|
+
BigInt(0),
|
|
135
|
+
amount,
|
|
136
|
+
zeroAllowance,
|
|
137
|
+
{ gasLimit }
|
|
138
|
+
)
|
|
139
|
+
const receipt = await tx.wait()
|
|
140
|
+
expect(receipt?.status).to.equal(1)
|
|
141
|
+
|
|
142
|
+
const results = await contract.getResults()
|
|
143
|
+
console.log(`TransferWithAllowance with zero allowance: success=${results[2]}, new_allowance=${results[3]}`)
|
|
144
|
+
|
|
145
|
+
if (results[2] === false) {
|
|
146
|
+
console.log("✅ TransferWithAllowance correctly returned failure flag for zero allowance")
|
|
147
|
+
}
|
|
148
|
+
} catch (error: any) {
|
|
149
|
+
if (error.message && error.message.includes("revert")) {
|
|
150
|
+
console.log("✅ Zero allowance transfer correctly caused revert")
|
|
151
|
+
} else {
|
|
152
|
+
throw error
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
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"),
|
|
36
|
+
BigInt("500000000000000000")
|
|
37
|
+
]
|
|
38
|
+
const [a, b] = params
|
|
39
|
+
|
|
40
|
+
describe("MinMax 128-bit", function () {
|
|
41
|
+
buildTest("MinMax128TestsContract", "minTest", "getMinResult", params, a < b ? a : b)
|
|
42
|
+
buildTest("MinMax128TestsContract", "maxTest", "getMaxResult", params, a > b ? a : b)
|
|
43
|
+
})
|
|
44
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
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("MinMax 256-bit", function () {
|
|
41
|
+
buildTest("MinMax256TestsContract", "minTest", "getMinResult", params, a < b ? a : b)
|
|
42
|
+
buildTest("MinMax256TestsContract", "maxTest", "getMaxResult", params, a > b ? a : b)
|
|
43
|
+
})
|
|
44
|
+
|