@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,51 @@
|
|
|
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
|
+
const network = await provider.getNetwork()
|
|
18
|
+
|
|
19
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
20
|
+
const contract = await factory.deploy({ gasLimit })
|
|
21
|
+
await contract.waitForDeployment()
|
|
22
|
+
|
|
23
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
24
|
+
const receipt = await tx.wait()
|
|
25
|
+
|
|
26
|
+
const result = await contract.getFunction(resFunc)()
|
|
27
|
+
expect(result).to.equal(expectedResult)
|
|
28
|
+
|
|
29
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
30
|
+
expect(txFromChain).to.not.be.null
|
|
31
|
+
expect(txFromChain?.status).to.equal(1)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const params = [
|
|
36
|
+
BigInt("1000000000000000000"), // 1e18 (fits in uint128)
|
|
37
|
+
BigInt("500000000000000000") // 0.5e18
|
|
38
|
+
]
|
|
39
|
+
const [a, b] = params
|
|
40
|
+
|
|
41
|
+
describe("Precompile 128-bit", function () {
|
|
42
|
+
buildTest("Arithmetic128TestsContract", "addTest", "getAddResult", params, a + b)
|
|
43
|
+
buildTest("Arithmetic128TestsContract", "checkedAddTest", "getAddResult", params, a + b)
|
|
44
|
+
buildTest("Arithmetic128TestsContract", "subTest", "getSubResult", params, a - b)
|
|
45
|
+
buildTest("Arithmetic128TestsContract", "checkedSubTest", "getSubResult", params, a - b)
|
|
46
|
+
buildTest("Arithmetic128TestsContract", "mulTest", "getMulResult", params, a * b)
|
|
47
|
+
buildTest("Arithmetic128TestsContract", "checkedMulTest", "getMulResult", params, a * b)
|
|
48
|
+
buildTest("Arithmetic128TestsContract", "divTest", "getDivResult", params, a / b)
|
|
49
|
+
buildTest("Arithmetic128TestsContract", "remTest", "getRemResult", params, a % b)
|
|
50
|
+
})
|
|
51
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
|
|
7
|
+
// Track if we've logged the deployment transaction
|
|
8
|
+
let deploymentLogged = false
|
|
9
|
+
|
|
10
|
+
function logTransaction(
|
|
11
|
+
txHash: string,
|
|
12
|
+
blockNumber: number,
|
|
13
|
+
contractAddress: string,
|
|
14
|
+
functionName: string,
|
|
15
|
+
networkName: string,
|
|
16
|
+
chainId: bigint,
|
|
17
|
+
gasUsed?: bigint
|
|
18
|
+
) {
|
|
19
|
+
console.log("\n" + "=".repeat(80))
|
|
20
|
+
console.log(`📝 ON-CHAIN TRANSACTION - ${functionName}`)
|
|
21
|
+
console.log("=".repeat(80))
|
|
22
|
+
console.log(`Transaction Hash: ${txHash}`)
|
|
23
|
+
console.log(`Block Number: ${blockNumber}`)
|
|
24
|
+
console.log(`Contract Address: ${contractAddress}`)
|
|
25
|
+
console.log(`Network: ${networkName}`)
|
|
26
|
+
console.log(`Chain ID: ${chainId.toString()}`)
|
|
27
|
+
if (gasUsed) {
|
|
28
|
+
console.log(`Gas Used: ${gasUsed.toString()}`)
|
|
29
|
+
}
|
|
30
|
+
console.log("=".repeat(80) + "\n")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function buildTest(
|
|
34
|
+
contractName: string,
|
|
35
|
+
func: string,
|
|
36
|
+
resFunc: string,
|
|
37
|
+
params: bigint[],
|
|
38
|
+
expectedResult: bigint
|
|
39
|
+
) {
|
|
40
|
+
it(`${contractName}.${func}(${params}) should return ${expectedResult}`, async function () {
|
|
41
|
+
const [owner] = await setupAccounts()
|
|
42
|
+
const provider = owner.provider!
|
|
43
|
+
const network = await provider.getNetwork()
|
|
44
|
+
const networkName = hre.network.name
|
|
45
|
+
|
|
46
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
47
|
+
const contract = await factory.deploy({ gasLimit })
|
|
48
|
+
await contract.waitForDeployment()
|
|
49
|
+
|
|
50
|
+
const contractAddress = await contract.getAddress()
|
|
51
|
+
|
|
52
|
+
// Log deployment transaction (first transaction only)
|
|
53
|
+
if (!deploymentLogged) {
|
|
54
|
+
const deployTx = contract.deploymentTransaction()
|
|
55
|
+
if (deployTx) {
|
|
56
|
+
const deployReceipt = await deployTx.wait()
|
|
57
|
+
if (deployReceipt) {
|
|
58
|
+
logTransaction(
|
|
59
|
+
deployReceipt.hash,
|
|
60
|
+
deployReceipt.blockNumber,
|
|
61
|
+
contractAddress,
|
|
62
|
+
"Contract Deployment",
|
|
63
|
+
networkName,
|
|
64
|
+
network.chainId,
|
|
65
|
+
deployReceipt.gasUsed
|
|
66
|
+
)
|
|
67
|
+
deploymentLogged = true
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Execute the function and log the transaction
|
|
73
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
74
|
+
const receipt = await tx.wait()
|
|
75
|
+
|
|
76
|
+
if (receipt) {
|
|
77
|
+
logTransaction(
|
|
78
|
+
receipt.hash,
|
|
79
|
+
receipt.blockNumber,
|
|
80
|
+
contractAddress,
|
|
81
|
+
`${contractName}.${func}`,
|
|
82
|
+
networkName,
|
|
83
|
+
network.chainId,
|
|
84
|
+
receipt.gasUsed
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Verify the result
|
|
89
|
+
const result = await contract.getFunction(resFunc)()
|
|
90
|
+
expect(result).to.equal(expectedResult)
|
|
91
|
+
|
|
92
|
+
// Additional verification: Check transaction exists on-chain
|
|
93
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
94
|
+
expect(txFromChain).to.not.be.null
|
|
95
|
+
expect(txFromChain?.blockNumber).to.equal(receipt.blockNumber)
|
|
96
|
+
expect(txFromChain?.status).to.equal(1) // 1 = success
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const params = [
|
|
101
|
+
BigInt("1000000000000000000"), // 1e18
|
|
102
|
+
BigInt("500000000000000000") // 0.5e18
|
|
103
|
+
]
|
|
104
|
+
const [a, b] = params
|
|
105
|
+
|
|
106
|
+
describe("Precompile 256-bit", function () {
|
|
107
|
+
buildTest("Arithmetic256TestsContract", "addTest", "getAddResult", params, a + b)
|
|
108
|
+
buildTest("Arithmetic256TestsContract", "checkedAddTest", "getAddResult", params, a + b)
|
|
109
|
+
buildTest("Arithmetic256TestsContract", "subTest", "getSubResult", params, a - b)
|
|
110
|
+
buildTest("Arithmetic256TestsContract", "checkedSubTest", "getSubResult", params, a - b)
|
|
111
|
+
buildTest("Arithmetic256TestsContract", "mulTest", "getMulResult", params, a * b)
|
|
112
|
+
buildTest("Arithmetic256TestsContract", "checkedMulTest", "getMulResult", params, a * b)
|
|
113
|
+
buildTest("Arithmetic256TestsContract", "divTest", "getDivResult", params, a / b)
|
|
114
|
+
buildTest("Arithmetic256TestsContract", "remTest", "getRemResult", params, a % b)
|
|
115
|
+
})
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
|
|
2
|
+
import { expect } from "chai";
|
|
3
|
+
import hre from "hardhat";
|
|
4
|
+
import { Wallet } from "@coti-io/coti-ethers";
|
|
5
|
+
import type { MinimalProxy, MinimalImplementation } from "../../../typechain-types";
|
|
6
|
+
|
|
7
|
+
const GAS_LIMIT = 12000000;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Test: 200-bit numbers through proxy with offBoardToUser and storage verification
|
|
11
|
+
*/
|
|
12
|
+
describe("Proxy Validation - 200-bit Numbers Test", function () {
|
|
13
|
+
let proxy: MinimalProxy;
|
|
14
|
+
let implementation: MinimalImplementation;
|
|
15
|
+
let proxyAsImpl: MinimalImplementation;
|
|
16
|
+
let owner: Wallet;
|
|
17
|
+
|
|
18
|
+
this.timeout(120000);
|
|
19
|
+
|
|
20
|
+
before(async function () {
|
|
21
|
+
// Get only the first account to avoid insufficient funds issue
|
|
22
|
+
const pks = process.env.SIGNING_KEYS ? process.env.SIGNING_KEYS.split(",") : [];
|
|
23
|
+
if (pks.length === 0) {
|
|
24
|
+
throw new Error("No signing keys found in .env");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const provider = hre.ethers.provider;
|
|
28
|
+
owner = new Wallet(pks[0], provider);
|
|
29
|
+
|
|
30
|
+
// Check if we need to onboard
|
|
31
|
+
const userKeys = process.env.USER_KEYS ? process.env.USER_KEYS.split(",") : [];
|
|
32
|
+
if (userKeys.length > 0 && userKeys[0]) {
|
|
33
|
+
owner.setAesKey(userKeys[0]);
|
|
34
|
+
} else {
|
|
35
|
+
console.log("************* Onboarding user", owner.address, "*************");
|
|
36
|
+
await owner.generateOrRecoverAes();
|
|
37
|
+
console.log("************* Onboarded! *************");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!owner.getUserOnboardInfo()?.aesKey) {
|
|
41
|
+
throw new Error("Owner AES key not found");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Deploy implementation
|
|
45
|
+
const ImplFactory = await hre.ethers.getContractFactory("MinimalImplementation", owner as any);
|
|
46
|
+
implementation = await ImplFactory.deploy({ gasLimit: GAS_LIMIT });
|
|
47
|
+
await implementation.waitForDeployment();
|
|
48
|
+
const implAddress = await implementation.getAddress();
|
|
49
|
+
|
|
50
|
+
// Deploy proxy
|
|
51
|
+
const ProxyFactory = await hre.ethers.getContractFactory("MinimalProxy", owner as any);
|
|
52
|
+
proxy = await ProxyFactory.deploy(implAddress, { gasLimit: GAS_LIMIT });
|
|
53
|
+
await proxy.waitForDeployment();
|
|
54
|
+
const proxyAddress = await proxy.getAddress();
|
|
55
|
+
|
|
56
|
+
// Create interface to call proxy as implementation
|
|
57
|
+
proxyAsImpl = await hre.ethers.getContractAt(
|
|
58
|
+
"MinimalImplementation",
|
|
59
|
+
proxyAddress,
|
|
60
|
+
owner as any
|
|
61
|
+
) as MinimalImplementation;
|
|
62
|
+
|
|
63
|
+
console.log("\n" + "=".repeat(80));
|
|
64
|
+
console.log("COMPLETE FLOW TEST: Encrypt → Validate → Add → OffBoard → Store → Decrypt");
|
|
65
|
+
console.log("=".repeat(80));
|
|
66
|
+
console.log(`Proxy: ${proxyAddress}`);
|
|
67
|
+
console.log(`Implementation: ${implAddress}`);
|
|
68
|
+
console.log("=".repeat(80) + "\n");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("✅ Full cycle with 200-bit numbers: Encrypt → Add → Store → Decrypt", async function () {
|
|
72
|
+
const proxyAddress = await proxy.getAddress();
|
|
73
|
+
const selector = proxyAsImpl.interface.getFunction("addAndStore")!.selector;
|
|
74
|
+
|
|
75
|
+
// Use 200-bit numbers (larger than 128-bit but < 256-bit)
|
|
76
|
+
const valueA = (2n ** 199n) + 123456789n; // ~200 bits
|
|
77
|
+
const valueB = (2n ** 198n) + 987654321n; // ~199 bits
|
|
78
|
+
const expected = valueA + valueB;
|
|
79
|
+
|
|
80
|
+
console.log("=" .repeat(80));
|
|
81
|
+
console.log("STEP 1: ENCRYPT OFFCHAIN");
|
|
82
|
+
console.log("=".repeat(80));
|
|
83
|
+
console.log(`Value A (200-bit): ${valueA.toString()}`);
|
|
84
|
+
console.log(`Bit length: ${valueA.toString(2).length} bits`);
|
|
85
|
+
console.log(`Value B (199-bit): ${valueB.toString()}`);
|
|
86
|
+
console.log(`Bit length: ${valueB.toString(2).length} bits`);
|
|
87
|
+
console.log(`Expected A + B: ${expected.toString()}`);
|
|
88
|
+
console.log(`Bit length: ${expected.toString(2).length} bits`);
|
|
89
|
+
console.log(`Signed for: ${proxyAddress} (PROXY)`);
|
|
90
|
+
console.log("");
|
|
91
|
+
|
|
92
|
+
// Encrypt values offchain
|
|
93
|
+
console.log("Encrypting values offchain using coti-ethers...");
|
|
94
|
+
const encA = await owner.encryptValue256(valueA, proxyAddress, selector);
|
|
95
|
+
const encB = await owner.encryptValue256(valueB, proxyAddress, selector);
|
|
96
|
+
console.log("✅ Encryption complete");
|
|
97
|
+
console.log(` encA.ciphertext.high: ${encA.ciphertext.ciphertextHigh.toString()}`);
|
|
98
|
+
console.log(` encA.ciphertext.low: ${encA.ciphertext.ciphertextLow.toString()}`);
|
|
99
|
+
console.log(` encB.ciphertext.high: ${encB.ciphertext.ciphertextHigh.toString()}`);
|
|
100
|
+
console.log(` encB.ciphertext.low: ${encB.ciphertext.ciphertextLow.toString()}`);
|
|
101
|
+
console.log("");
|
|
102
|
+
|
|
103
|
+
console.log("=".repeat(80));
|
|
104
|
+
console.log("STEP 2: SEND TRANSACTION (Validate → Add → OffBoard → Store)");
|
|
105
|
+
console.log("=".repeat(80));
|
|
106
|
+
|
|
107
|
+
// Send transaction
|
|
108
|
+
const tx = await proxyAsImpl.connect(owner).addAndStore(encA, encB, { gasLimit: GAS_LIMIT });
|
|
109
|
+
console.log(`Transaction hash: ${tx.hash}`);
|
|
110
|
+
console.log("Waiting for confirmation...");
|
|
111
|
+
|
|
112
|
+
const receipt = await tx.wait();
|
|
113
|
+
console.log(`✅ Transaction confirmed in block ${receipt?.blockNumber}`);
|
|
114
|
+
console.log(` Gas used: ${receipt?.gasUsed.toString()}`);
|
|
115
|
+
console.log("");
|
|
116
|
+
|
|
117
|
+
// Check events
|
|
118
|
+
console.log("=".repeat(80));
|
|
119
|
+
console.log("STEP 3: VERIFY EVENTS");
|
|
120
|
+
console.log("=".repeat(80));
|
|
121
|
+
|
|
122
|
+
let eventCount = 0;
|
|
123
|
+
receipt?.logs.forEach((log: any) => {
|
|
124
|
+
try {
|
|
125
|
+
const parsed = implementation.interface.parseLog({ topics: log.topics as string[], data: log.data });
|
|
126
|
+
if (parsed) {
|
|
127
|
+
eventCount++;
|
|
128
|
+
console.log(`✅ Event ${eventCount}: ${parsed.name}`);
|
|
129
|
+
console.log(` Message: ${parsed.args[1]}`);
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {}
|
|
132
|
+
});
|
|
133
|
+
console.log("");
|
|
134
|
+
|
|
135
|
+
expect(eventCount).to.be.greaterThan(0, "No events emitted - validation may have failed");
|
|
136
|
+
|
|
137
|
+
console.log("=".repeat(80));
|
|
138
|
+
console.log("STEP 4: READ FROM STORAGE");
|
|
139
|
+
console.log("=".repeat(80));
|
|
140
|
+
|
|
141
|
+
// Read the stored ctUint256 from storage
|
|
142
|
+
console.log("Reading stored result from contract storage...");
|
|
143
|
+
const storedCt = await proxyAsImpl.connect(owner).getStoredResult();
|
|
144
|
+
console.log("✅ Storage read complete");
|
|
145
|
+
console.log(` Stored CT High: ${storedCt.ciphertextHigh.toString()}`);
|
|
146
|
+
console.log(` Stored CT Low: ${storedCt.ciphertextLow.toString()}`);
|
|
147
|
+
console.log("");
|
|
148
|
+
|
|
149
|
+
console.log("=".repeat(80));
|
|
150
|
+
console.log("STEP 5: DECRYPT OFFCHAIN");
|
|
151
|
+
console.log("=".repeat(80));
|
|
152
|
+
|
|
153
|
+
// Decrypt the result offchain
|
|
154
|
+
console.log("Decrypting result offchain using coti-ethers...");
|
|
155
|
+
// Explicitly format the struct to ensure correct format
|
|
156
|
+
const decrypted = await owner.decryptValue256({
|
|
157
|
+
ciphertextHigh: storedCt.ciphertextHigh,
|
|
158
|
+
ciphertextLow: storedCt.ciphertextLow
|
|
159
|
+
});
|
|
160
|
+
console.log("✅ Decryption complete");
|
|
161
|
+
console.log(` Decrypted value: ${decrypted.toString()}`);
|
|
162
|
+
console.log("");
|
|
163
|
+
|
|
164
|
+
console.log("=".repeat(80));
|
|
165
|
+
console.log("STEP 6: VERIFY CORRECTNESS");
|
|
166
|
+
console.log("=".repeat(80));
|
|
167
|
+
console.log(`Original A: ${valueA.toString()}`);
|
|
168
|
+
console.log(`Original B: ${valueB.toString()}`);
|
|
169
|
+
console.log(`Expected A + B: ${expected.toString()}`);
|
|
170
|
+
console.log(`Decrypted result: ${decrypted.toString()}`);
|
|
171
|
+
console.log("");
|
|
172
|
+
|
|
173
|
+
expect(decrypted).to.equal(expected, "Decrypted result does not match expected");
|
|
174
|
+
|
|
175
|
+
console.log("✅ VERIFICATION PASSED!");
|
|
176
|
+
console.log("");
|
|
177
|
+
console.log("=".repeat(80));
|
|
178
|
+
console.log("SUMMARY");
|
|
179
|
+
console.log("=".repeat(80));
|
|
180
|
+
console.log("✅ 200-bit numbers encrypted offchain");
|
|
181
|
+
console.log("✅ IT-types validated through proxy");
|
|
182
|
+
console.log("✅ Addition performed on encrypted values");
|
|
183
|
+
console.log("✅ Result offBoarded to user (ctUint256)");
|
|
184
|
+
console.log("✅ Result stored in contract storage");
|
|
185
|
+
console.log("✅ Result read from storage");
|
|
186
|
+
console.log("✅ Result decrypted offchain");
|
|
187
|
+
console.log("✅ Decrypted value matches expected");
|
|
188
|
+
console.log("");
|
|
189
|
+
console.log("CONCLUSION: IT-types + proxy + large numbers = ✅ WORKS PERFECTLY!");
|
|
190
|
+
console.log("=".repeat(80) + "\n");
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Comment out other tests as requested
|
|
194
|
+
/*
|
|
195
|
+
it("❌ TEST 2: Wrong signing for implementation address", async function () {
|
|
196
|
+
// ... test code ...
|
|
197
|
+
});
|
|
198
|
+
*/
|
|
199
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
let last_random_value = BigInt(0)
|
|
7
|
+
|
|
8
|
+
function buildTest(
|
|
9
|
+
contractName: string,
|
|
10
|
+
func: string,
|
|
11
|
+
resFunc: string,
|
|
12
|
+
params: (bigint | number)[],
|
|
13
|
+
expectedResult?: bigint
|
|
14
|
+
) {
|
|
15
|
+
it(`${contractName}.${func}(${params}) should return a random value`, async function () {
|
|
16
|
+
const [owner] = await setupAccounts()
|
|
17
|
+
const provider = owner.provider!
|
|
18
|
+
|
|
19
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
20
|
+
const contract = await factory.deploy({ gasLimit })
|
|
21
|
+
await contract.waitForDeployment()
|
|
22
|
+
|
|
23
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
24
|
+
const receipt = await tx.wait()
|
|
25
|
+
|
|
26
|
+
const result = await contract.getFunction(resFunc)()
|
|
27
|
+
|
|
28
|
+
if (resFunc === "getRandom" || resFunc === "getRandomBounded") {
|
|
29
|
+
expect(result).to.not.equal(expectedResult || last_random_value)
|
|
30
|
+
last_random_value = result
|
|
31
|
+
} else {
|
|
32
|
+
expect(result).to.equal(expectedResult)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
36
|
+
expect(txFromChain).to.not.be.null
|
|
37
|
+
expect(txFromChain?.status).to.equal(1)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const numBits = 7
|
|
42
|
+
|
|
43
|
+
describe("Random 128-bit", function () {
|
|
44
|
+
buildTest("Random128TestsContract", "randomTest", "getRandom", [], last_random_value)
|
|
45
|
+
buildTest("Random128TestsContract", "randomBoundedTest", "getRandomBounded", [numBits], last_random_value)
|
|
46
|
+
})
|
|
47
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import hre from "hardhat"
|
|
2
|
+
import { expect } from "chai"
|
|
3
|
+
import { setupAccounts } from "../accounts"
|
|
4
|
+
|
|
5
|
+
const gasLimit = 12000000
|
|
6
|
+
let last_random_value = BigInt(0)
|
|
7
|
+
|
|
8
|
+
function buildTest(
|
|
9
|
+
contractName: string,
|
|
10
|
+
func: string,
|
|
11
|
+
resFunc: string,
|
|
12
|
+
params: (bigint | number)[],
|
|
13
|
+
expectedResult?: bigint
|
|
14
|
+
) {
|
|
15
|
+
it(`${contractName}.${func}(${params}) should return a random value`, async function () {
|
|
16
|
+
const [owner] = await setupAccounts()
|
|
17
|
+
const provider = owner.provider!
|
|
18
|
+
|
|
19
|
+
const factory = await hre.ethers.getContractFactory(contractName, owner as any)
|
|
20
|
+
const contract = await factory.deploy({ gasLimit })
|
|
21
|
+
await contract.waitForDeployment()
|
|
22
|
+
|
|
23
|
+
const tx = await contract.getFunction(func)(...params, { gasLimit })
|
|
24
|
+
const receipt = await tx.wait()
|
|
25
|
+
|
|
26
|
+
const result = await contract.getFunction(resFunc)()
|
|
27
|
+
|
|
28
|
+
if (resFunc === "getRandom" || resFunc === "getRandomBounded") {
|
|
29
|
+
expect(result).to.not.equal(expectedResult || last_random_value)
|
|
30
|
+
last_random_value = result
|
|
31
|
+
} else {
|
|
32
|
+
expect(result).to.equal(expectedResult)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
36
|
+
expect(txFromChain).to.not.be.null
|
|
37
|
+
expect(txFromChain?.status).to.equal(1)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const numBits = 7
|
|
42
|
+
|
|
43
|
+
describe("Random 256-bit", function () {
|
|
44
|
+
buildTest("Random256TestsContract", "randomTest", "getRandom", [], last_random_value)
|
|
45
|
+
buildTest("Random256TestsContract", "randomBoundedTest", "getRandomBounded", [numBits], last_random_value)
|
|
46
|
+
})
|
|
47
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
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 | number)[],
|
|
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 a = BigInt("1000000000000000000")
|
|
35
|
+
const shift = 2
|
|
36
|
+
|
|
37
|
+
describe("Shift 128-bit", function () {
|
|
38
|
+
buildTest("Shift128TestsContract", "shlTest", "getShlResult", [a, shift], a << BigInt(shift))
|
|
39
|
+
buildTest("Shift128TestsContract", "shrTest", "getShrResult", [a, shift], a >> BigInt(shift))
|
|
40
|
+
})
|
|
41
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
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 | number)[],
|
|
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 a = BigInt("1000000000000000000")
|
|
35
|
+
const shift = 2
|
|
36
|
+
|
|
37
|
+
describe("Shift 256-bit", function () {
|
|
38
|
+
buildTest("Shift256TestsContract", "shlTest", "getShlResult", [a, shift], a << BigInt(shift))
|
|
39
|
+
buildTest("Shift256TestsContract", "shrTest", "getShrResult", [a, shift], a >> BigInt(shift))
|
|
40
|
+
})
|
|
41
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
expectedResults: [bigint, bigint, boolean]
|
|
13
|
+
) {
|
|
14
|
+
it(`${contractName}.${func}(${params}) should return correct transfer results`, 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 results = await contract.getFunction(resFunc)()
|
|
26
|
+
expect(results[0]).to.equal(expectedResults[0])
|
|
27
|
+
expect(results[1]).to.equal(expectedResults[1])
|
|
28
|
+
expect(results[2]).to.equal(expectedResults[2])
|
|
29
|
+
|
|
30
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
31
|
+
expect(txFromChain).to.not.be.null
|
|
32
|
+
expect(txFromChain?.status).to.equal(1)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const params = [
|
|
37
|
+
BigInt("1000000000000000000"),
|
|
38
|
+
BigInt("500000000000000000"),
|
|
39
|
+
BigInt("200000000000000000")
|
|
40
|
+
]
|
|
41
|
+
const [a, b, amount] = params
|
|
42
|
+
|
|
43
|
+
describe("Transfer 128-bit", function () {
|
|
44
|
+
buildTest("Transfer128TestsContract", "transferTest", "getResults", params, [a - amount, b + amount, true])
|
|
45
|
+
})
|
|
46
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
expectedResults: [bigint, bigint, boolean]
|
|
13
|
+
) {
|
|
14
|
+
it(`${contractName}.${func}(${params}) should return correct transfer results`, 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 results = await contract.getFunction(resFunc)()
|
|
26
|
+
expect(results[0]).to.equal(expectedResults[0]) // newA
|
|
27
|
+
expect(results[1]).to.equal(expectedResults[1]) // newB
|
|
28
|
+
expect(results[2]).to.equal(expectedResults[2]) // result (success)
|
|
29
|
+
|
|
30
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
31
|
+
expect(txFromChain).to.not.be.null
|
|
32
|
+
expect(txFromChain?.status).to.equal(1)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const params = [
|
|
37
|
+
BigInt("1000000000000000000"), // a = 1e18
|
|
38
|
+
BigInt("500000000000000000"), // b = 0.5e18
|
|
39
|
+
BigInt("200000000000000000") // amount = 0.2e18
|
|
40
|
+
]
|
|
41
|
+
const [a, b, amount] = params
|
|
42
|
+
|
|
43
|
+
describe("Transfer 256-bit", function () {
|
|
44
|
+
buildTest("Transfer256TestsContract", "transferTest", "getResults", params, [a - amount, b + amount, true])
|
|
45
|
+
})
|
|
46
|
+
|
|
@@ -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
|
+
expectedResults: [bigint, bigint, boolean, bigint]
|
|
13
|
+
) {
|
|
14
|
+
it(`${contractName}.${func}(${params}) should return correct transfer results`, 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 results = await contract.getFunction(resFunc)()
|
|
26
|
+
expect(results[0]).to.equal(expectedResults[0])
|
|
27
|
+
expect(results[1]).to.equal(expectedResults[1])
|
|
28
|
+
expect(results[2]).to.equal(expectedResults[2])
|
|
29
|
+
expect(results[3]).to.equal(expectedResults[3])
|
|
30
|
+
|
|
31
|
+
const txFromChain = await provider.getTransactionReceipt(receipt.hash)
|
|
32
|
+
expect(txFromChain).to.not.be.null
|
|
33
|
+
expect(txFromChain?.status).to.equal(1)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const params = [
|
|
38
|
+
BigInt("1000000000000000000"),
|
|
39
|
+
BigInt("500000000000000000"),
|
|
40
|
+
BigInt("200000000000000000"),
|
|
41
|
+
BigInt("1000000000000000000")
|
|
42
|
+
]
|
|
43
|
+
const [a, b, amount, allowance] = params
|
|
44
|
+
|
|
45
|
+
describe("TransferWithAllowance 128-bit", function () {
|
|
46
|
+
buildTest("TransferWithAllowance128TestsContract", "transferWithAllowanceTest", "getResults", params, [a - amount, b + amount, true, allowance - amount])
|
|
47
|
+
})
|
|
48
|
+
|