@coti-io/coti-contracts 0.1.0 → 1.0.2

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.
Files changed (125) hide show
  1. package/.github/workflows/npm-publish.yml +2 -1
  2. package/CONTRIBUTING.md +2 -2
  3. package/LICENSE +1 -1
  4. package/README.md +18 -35
  5. package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +3 -115
  6. package/contracts/mocks/README.md +1 -1
  7. package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +257 -280
  8. package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +93 -187
  9. package/contracts/mocks/utils/mpc/{Comparison1Tests.Contract.sol → Comparison1TestsContract.sol} +67 -115
  10. package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +76 -116
  11. package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +69 -164
  12. package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +103 -56
  13. package/contracts/mocks/utils/mpc/MiscellaneousTestsContract.sol +270 -0
  14. package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +127 -0
  15. package/contracts/mocks/utils/mpc/README.md +12 -12
  16. package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +54 -211
  17. package/contracts/mocks/utils/mpc/TransferTestsContract.sol +165 -640
  18. package/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.sol +222 -0
  19. package/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.sol +222 -0
  20. package/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol +223 -0
  21. package/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.sol +222 -0
  22. package/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.sol +265 -0
  23. package/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol +281 -0
  24. package/contracts/onboard/AccountOnboard.sol +3 -3
  25. package/contracts/token/PrivateERC20/PrivateERC20.sol +1 -1
  26. package/contracts/token/PrivateERC721/IERC721Errors.sol +57 -0
  27. package/contracts/token/PrivateERC721/PrivateERC721.sol +1 -1
  28. package/contracts/utils/mpc/MpcCore.sol +2835 -988
  29. package/contracts/utils/mpc/MpcInterface.sol +6 -4
  30. package/hardhat.config.ts +17 -6
  31. package/package.json +20 -4
  32. package/test/token/PrivateERC20/PrivateERC20.test.ts +2 -2
  33. package/test/utils/accounts.ts +1 -1
  34. package/test/utils/mpc/Precompile.test.ts +42 -39
  35. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract.ts +374 -0
  36. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract.ts +374 -0
  37. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
  38. package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +96 -10
  39. package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +45 -5
  40. package/typechain-types/contracts/mocks/utils/mpc/Comparison1TestsContract.ts +374 -0
  41. package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +45 -5
  42. package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +25 -5
  43. package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +62 -0
  44. package/typechain-types/contracts/mocks/utils/mpc/MiscellaneousTestsContract.ts +396 -0
  45. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +251 -0
  46. package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +11 -8
  47. package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +15 -15
  48. package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +15 -15
  49. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract.ts +251 -0
  50. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract.ts +250 -0
  51. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
  52. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.ts +389 -0
  53. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.ts +391 -0
  54. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.ts +391 -0
  55. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract.ts +391 -0
  56. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract.ts +391 -0
  57. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
  58. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.ts +391 -0
  59. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.ts +391 -0
  60. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.ts +306 -0
  61. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract.ts +125 -0
  62. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract.ts +125 -0
  63. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
  64. package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.ts +296 -0
  65. package/typechain-types/contracts/mocks/utils/mpc/index.ts +9 -6
  66. package/typechain-types/contracts/onboard/AccountOnboard.ts +9 -4
  67. package/typechain-types/contracts/token/PrivateERC721/IERC721Errors.ts +69 -0
  68. package/typechain-types/contracts/token/PrivateERC721/index.ts +1 -0
  69. package/typechain-types/contracts/utils/mpc/MpcCore.ts +84 -0
  70. package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +81 -40
  71. package/typechain-types/contracts/utils/mpc/index.ts +1 -0
  72. package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
  73. package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
  74. package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
  75. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract__factory.ts +387 -0
  76. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract__factory.ts +388 -0
  77. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
  78. package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +92 -7
  79. package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +38 -2
  80. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +1 -1
  81. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +387 -0
  82. package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +38 -2
  83. package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +15 -2
  84. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +66 -1
  85. package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +1 -1
  86. package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +424 -0
  87. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +285 -0
  88. package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +19 -3
  89. package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
  90. package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
  91. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +4 -4
  92. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +4 -4
  93. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract__factory.ts +294 -0
  94. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +292 -0
  95. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
  96. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract__factory.ts +720 -0
  97. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +724 -0
  98. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +724 -0
  99. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
  100. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
  101. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
  102. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
  103. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
  104. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +507 -0
  105. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract__factory.ts +150 -0
  106. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +150 -0
  107. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
  108. package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +434 -0
  109. package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +9 -4
  110. package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
  111. package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +8 -2
  112. package/typechain-types/factories/contracts/token/PrivateERC721/IERC721Errors__factory.ts +128 -0
  113. package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +1 -0
  114. package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +77 -0
  115. package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +124 -61
  116. package/typechain-types/factories/contracts/utils/mpc/index.ts +1 -0
  117. package/typechain-types/hardhat.d.ts +152 -26
  118. package/typechain-types/index.ts +20 -8
  119. package/contracts/access/DataPrivacyFramework/README.md +0 -68
  120. package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +0 -448
  121. package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +0 -81
  122. package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +0 -311
  123. package/contracts/token/PrivateERC20/README.md +0 -104
  124. package/contracts/token/PrivateERC721/README.md +0 -282
  125. package/contracts/utils/mpc/README.md +0 -82
@@ -1,82 +0,0 @@
1
- # MpcCore.sol
2
-
3
- This Solidity library, `MpcCore`, provides core functionalities for secure multi-party computation (MPC) using the COTI protocol. Below is an overview of its components and functions:
4
-
5
- ## Legend
6
-
7
- - it = input text. This structure contains text that was encrypted by user and provided a signature to authenticate it.
8
- - gc = garbled text
9
- - ct = cipher text
10
- - ut = user text. This structure contains 2 types of cipher texts: one by the network and one by the user key. Convenient for operations that require some times to decipher one or another.
11
-
12
- ## Types
13
- The library defines several custom types using `uint256` as the base type:
14
- - `gtBool`, `gtUint8`, `gtUint16`, `gtUint32`, `gtUint64`
15
- - `ctBool`, `ctUint8`, `ctUint16`, `ctUint32`, `ctUint64`
16
- - `lenghts`, use to differentiate the length
17
-
18
- ## Structures
19
- The library defines multiple structures for handling encrypted and signed data:
20
- - `itBool`, `itUint8`, `itUint16`, `itUint32`, `itUint64`: Each structure contains a inputtext (`ctBool`, `ctUint8`, etc.) and a signature (`bytes`).
21
- - `utBool`, `utUint8`, `utUint16`, `utUint32`, `utUint64`: Each structure contains two usertext (`ctBool`, `ctUint8`, etc.) for user and regular data.
22
-
23
- ## Enums
24
- - `MPC_TYPE`: Enum to represent different MPC data types (`SBOOL_T`, `SUINT8_T`, `SUINT16_T`, `SUINT32_T`, `SUINT64_T`).
25
- - `ARGS`: Enum to represent different argument types (`BOTH_SECRET`, `LHS_PUBLIC`, `RHS_PUBLIC`).
26
-
27
- ## Functions
28
- ### Enum Combination Functions
29
- These functions combine enum values into bytes for efficient storage and transfer:
30
- - `combineEnumsToBytes2(MPC_TYPE mpcType, ARGS argsType)`: Combines an `MPC_TYPE` and `ARGS` into a `bytes2` value.
31
- - `combineEnumsToBytes3(MPC_TYPE mpcType1, MPC_TYPE mpcType2, ARGS argsType)`: Combines two `MPC_TYPE` values and an `ARGS` value into a `bytes3` value.
32
- - `combineEnumsToBytes4(MPC_TYPE mpcType1, MPC_TYPE mpcType2, MPC_TYPE mpcType3, ARGS argsType)`: Combines three `MPC_TYPE` values and an `ARGS` value into a `bytes4` value.
33
-
34
- ### Key Management Functions
35
- - `getUserKey(bytes calldata signedEK, bytes calldata signature)`: Retrieves the user's AES encryption key in encrypted format, by using the provided public key to encrypt it - signature is used to validate the account ownership.
36
-
37
- This library is designed to be used as part of a secure multi-party computation framework, facilitating the handling and combination of encrypted and signed data types.
38
-
39
- # MpcInterface.sol
40
-
41
- This Solidity interface, `ExtendedOperations`, defines a set of functions for performing various operations that are essential for secure multi-party computation (MPC) on the COTI network. Below is an overview of its components and functions:
42
-
43
- ## Functions
44
-
45
- ### Onboarding and Offboarding Functions
46
- - `OnBoard(bytes1 metaData, uint256 ct)`: Onboards a new EOA. Metadata is used to define what is the data type being used (8 , 16, 32 , 64). This function is not directly called by others in MpcCore.
47
- - `OffBoard(bytes1 metaData, uint256 ct)`: Offboards an EOA. Metadata is used to define what is the data type being used (8 , 16, 32 , 64). This function is not directly called by others in MpcCore.
48
- - `OffBoardToUser(bytes1 metaData, uint256 ct, bytes calldata addr)`: Offboards an EOA to a user-specified address. Metadata is used to define what is the data type being used (8 , 16, 32 , 64). This function is not directly called by others in MpcCore.
49
- - `SetPublic(bytes1 metaData, uint256 ct)`: Sets the data as public with the given metadata and ciphertext.
50
-
51
- ### Randomness Functions
52
- - `Rand(bytes1 metaData)`: Generates a random value with the given metadata.
53
- - `RandBoundedBits(bytes1 metaData, uint8 numBits)`: Generates a random value with a specified number of bits.
54
-
55
- ### Arithmetic Functions
56
- - `Add(bytes3 metaData, uint256 lhs, uint256 rhs)`: Adds two values.
57
- - `Sub(bytes3 metaData, uint256 lhs, uint256 rhs)`: Subtracts the second value from the first.
58
- - `Mul(bytes3 metaData, uint256 lhs, uint256 rhs)`: Multiplies two values.
59
- - `Div(bytes3 metaData, uint256 lhs, uint256 rhs)`: Divides the first value by the second.
60
- - `Rem(bytes3 metaData, uint256 lhs, uint256 rhs)`: Computes the remainder of the division of two values.
61
-
62
- ### Bitwise Functions
63
- - `And(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise AND operation.
64
- - `Or(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise OR operation.
65
- - `Xor(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise XOR operation.
66
- - `Shl(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise shift left operation.
67
- - `Shr(bytes3 metaData, uint256 lhs, uint256 rhs)`: Performs a bitwise shift right operation.
68
-
69
- ### Comparison Functions
70
- - `Eq(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if two values are equal.
71
- - `Ne(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if two values are not equal.
72
- - `Ge(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is greater than or equal to the second.
73
- - `Gt(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is greater than the second.
74
- - `Le(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is less than or equal to the second.
75
- - `Lt(bytes3 metaData, uint256 lhs, uint256 rhs)`: Checks if the first value is less than the second.
76
-
77
- ### Validation and Transfer Functions
78
- - `ValidateCiphertext(bytes calldata ciphertext, bytes calldata signature)`: Validates the given ciphertext and signature.
79
- - If the input is not valid, the call will revert with no return data and no additional gas will be consumed.
80
- - `TransferWithAllowance(address from, address to, uint256 amount, bytes calldata signature)`: Transfers the specified amount from one address to another with the provided signature.
81
-
82
- This interface is designed to be implemented by a contract that performs secure multi-party computation, providing essential operations such as arithmetic, bitwise, and comparison functions, as well as onboarding and offboarding participants or data.