@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,311 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma solidity ^0.8.19;
4
-
5
- import "../../../utils/mpc/MpcCore.sol";
6
-
7
- contract ShiftTestsContract {
8
-
9
- struct AllGTCastingValues {
10
- gtUint8 a8_s;
11
- gtUint8 b8_s;
12
- gtUint16 a16_s;
13
- gtUint16 b16_s;
14
- gtUint32 a32_s;
15
- gtUint32 b32_s;
16
- gtUint64 a64_s;
17
- gtUint64 b64_s;
18
- }
19
-
20
- struct Check16 {
21
- gtUint16 res16_16;
22
- gtUint16 res8_16;
23
- gtUint16 res16_8;
24
- }
25
-
26
- struct Check32 {
27
- gtUint32 res32_32;
28
- gtUint32 res8_32;
29
- gtUint32 res32_8;
30
- gtUint32 res16_32;
31
- gtUint32 res32_16;
32
- }
33
-
34
- struct Check64 {
35
- gtUint64 res64_64;
36
- gtUint64 res8_64;
37
- gtUint64 res64_8;
38
- gtUint64 res16_64;
39
- gtUint64 res64_16;
40
- gtUint64 res32_64;
41
- gtUint64 res64_32;
42
- }
43
-
44
- uint8 result;
45
- uint16 result16;
46
- uint32 result32;
47
- uint64 result64;
48
-
49
- function getResult() public view returns (uint8) {
50
- return result;
51
- }
52
-
53
- function getAllShiftResults()
54
- public
55
- view
56
- returns (uint8, uint16, uint32, uint64)
57
- {
58
- return (result, result16, result32, result64);
59
- }
60
-
61
- function setPublicValues(
62
- AllGTCastingValues memory castingValues,
63
- uint8 a,
64
- uint8 b
65
- ) public {
66
- castingValues.a8_s = MpcCore.setPublic8(a);
67
- castingValues.b8_s = MpcCore.setPublic8(b);
68
- castingValues.a16_s = MpcCore.setPublic16(a);
69
- castingValues.b16_s = MpcCore.setPublic16(b);
70
- castingValues.a32_s = MpcCore.setPublic32(a);
71
- castingValues.b32_s = MpcCore.setPublic32(b);
72
- castingValues.a64_s = MpcCore.setPublic64(a);
73
- castingValues.b64_s = MpcCore.setPublic64(b);
74
- }
75
-
76
- function decryptAndCompareResults16(
77
- Check16 memory check16
78
- ) public returns (uint16) {
79
- // Calculate the result
80
- uint16 result = MpcCore.decrypt(check16.res16_16);
81
-
82
- require(
83
- result == MpcCore.decrypt(check16.res8_16) &&
84
- result == MpcCore.decrypt(check16.res16_8),
85
- "decryptAndCompareAllResults: Failed to decrypt and compare all results"
86
- );
87
-
88
- return result;
89
- }
90
-
91
- function decryptAndCompareResults32(
92
- Check32 memory check32
93
- ) public returns (uint32) {
94
- // Calculate the result
95
- uint32 result = MpcCore.decrypt(check32.res32_32);
96
-
97
- require(
98
- result == MpcCore.decrypt(check32.res8_32) &&
99
- result == MpcCore.decrypt(check32.res32_8) &&
100
- result == MpcCore.decrypt(check32.res32_16) &&
101
- result == MpcCore.decrypt(check32.res16_32),
102
- "decryptAndCompareAllResults: Failed to decrypt and compare all results"
103
- );
104
-
105
- return result;
106
- }
107
-
108
- function decryptAndCompareResults64(
109
- Check64 memory check64
110
- ) public returns (uint64) {
111
- // Calculate the result
112
- uint64 result = MpcCore.decrypt(check64.res64_64);
113
-
114
- require(
115
- result == MpcCore.decrypt(check64.res8_64) &&
116
- result == MpcCore.decrypt(check64.res64_8) &&
117
- result == MpcCore.decrypt(check64.res64_16) &&
118
- result == MpcCore.decrypt(check64.res16_64) &&
119
- result == MpcCore.decrypt(check64.res64_32) &&
120
- result == MpcCore.decrypt(check64.res32_64),
121
- "decryptAndCompareAllResults: Failed to decrypt and compare all results"
122
- );
123
-
124
- return result;
125
- }
126
-
127
- function shlTest(
128
- uint8 a,
129
- uint8 b
130
- ) public returns (uint8, uint16, uint32, uint64) {
131
- AllGTCastingValues memory castingValues;
132
- Check16 memory check16;
133
- Check32 memory check32;
134
- Check64 memory check64;
135
- setPublicValues(castingValues, a, b);
136
-
137
- // Calculate the expected result
138
- result = MpcCore.decrypt(
139
- MpcCore.shl(castingValues.a8_s, castingValues.b8_s)
140
- );
141
-
142
- // Calculate the result with casting to 16
143
- check16.res16_16 = MpcCore.shl(
144
- castingValues.a16_s,
145
- castingValues.b16_s
146
- );
147
- check16.res8_16 = MpcCore.shl(castingValues.a8_s, castingValues.b16_s);
148
- check16.res16_8 = MpcCore.shl(castingValues.a16_s, castingValues.b8_s);
149
- result16 = decryptAndCompareResults16(check16);
150
-
151
- // Calculate the result with casting to 32
152
- check32.res32_32 = MpcCore.shl(
153
- castingValues.a32_s,
154
- castingValues.b32_s
155
- );
156
- check32.res8_32 = MpcCore.shl(castingValues.a8_s, castingValues.b32_s);
157
- check32.res32_8 = MpcCore.shl(castingValues.a32_s, castingValues.b8_s);
158
- check32.res16_32 = MpcCore.shl(
159
- castingValues.a16_s,
160
- castingValues.b32_s
161
- );
162
- check32.res32_16 = MpcCore.shl(
163
- castingValues.a32_s,
164
- castingValues.b16_s
165
- );
166
- result32 = decryptAndCompareResults32(check32);
167
-
168
- // Calculate the result with casting to 64
169
- check64.res64_64 = MpcCore.shl(
170
- castingValues.a64_s,
171
- castingValues.b64_s
172
- );
173
- check64.res8_64 = MpcCore.shl(castingValues.a8_s, castingValues.b64_s);
174
- check64.res64_8 = MpcCore.shl(castingValues.a64_s, castingValues.b8_s);
175
- check64.res16_64 = MpcCore.shl(
176
- castingValues.a16_s,
177
- castingValues.b64_s
178
- );
179
- check64.res64_16 = MpcCore.shl(
180
- castingValues.a64_s,
181
- castingValues.b16_s
182
- );
183
- check64.res32_64 = MpcCore.shl(
184
- castingValues.a32_s,
185
- castingValues.b64_s
186
- );
187
- check64.res64_32 = MpcCore.shl(
188
- castingValues.a64_s,
189
- castingValues.b32_s
190
- );
191
- result64 = decryptAndCompareResults64(check64);
192
-
193
- // Check the result with scalar
194
- require(
195
- result == MpcCore.decrypt(MpcCore.shl(a, castingValues.b8_s)) &&
196
- result == MpcCore.decrypt(MpcCore.shl(castingValues.a8_s, b)),
197
- "shlTest: test 8 bits with scalar failed"
198
- );
199
- require(
200
- result16 == MpcCore.decrypt(MpcCore.shl(a, castingValues.b16_s)) &&
201
- result16 ==
202
- MpcCore.decrypt(MpcCore.shl(castingValues.a16_s, b)),
203
- "shlTest: test 16 bits with scalar failed"
204
- );
205
- require(
206
- result32 == MpcCore.decrypt(MpcCore.shl(a, castingValues.b32_s)) &&
207
- result32 ==
208
- MpcCore.decrypt(MpcCore.shl(castingValues.a32_s, b)),
209
- "shlTest: test 32 bits with scalar failed"
210
- );
211
- require(
212
- result64 == MpcCore.decrypt(MpcCore.shl(a, castingValues.b64_s)) &&
213
- result64 ==
214
- MpcCore.decrypt(MpcCore.shl(castingValues.a64_s, b)),
215
- "shlTest: test 64 bits with scalar failed"
216
- );
217
-
218
- return (result, result16, result32, result64);
219
- }
220
-
221
- function shrTest(uint8 a, uint8 b) public returns (uint8) {
222
- AllGTCastingValues memory castingValues;
223
- Check16 memory check16;
224
- Check32 memory check32;
225
- Check64 memory check64;
226
- setPublicValues(castingValues, a, b);
227
-
228
- // Calculate the expected result
229
- result = MpcCore.decrypt(
230
- MpcCore.shr(castingValues.a8_s, castingValues.b8_s)
231
- );
232
-
233
- // Calculate the results with casting to 16
234
- check16.res16_16 = MpcCore.shr(
235
- castingValues.a16_s,
236
- castingValues.b16_s
237
- );
238
- check16.res8_16 = MpcCore.shr(castingValues.a8_s, castingValues.b16_s);
239
- check16.res16_8 = MpcCore.shr(castingValues.a16_s, castingValues.b8_s);
240
- uint16 res16 = decryptAndCompareResults16(check16);
241
- require(res16 == result, "shrTest: cast 16 failed");
242
-
243
- // Calculate the result with casting to 32
244
- check32.res32_32 = MpcCore.shr(
245
- castingValues.a32_s,
246
- castingValues.b32_s
247
- );
248
- check32.res8_32 = MpcCore.shr(castingValues.a8_s, castingValues.b32_s);
249
- check32.res32_8 = MpcCore.shr(castingValues.a32_s, castingValues.b8_s);
250
- check32.res16_32 = MpcCore.shr(
251
- castingValues.a16_s,
252
- castingValues.b32_s
253
- );
254
- check32.res32_16 = MpcCore.shr(
255
- castingValues.a32_s,
256
- castingValues.b16_s
257
- );
258
- uint32 res32 = decryptAndCompareResults32(check32);
259
- require(result == res32, "shrTest: cast 32 failed");
260
-
261
- // Calculate the result with casting to 64
262
- check64.res64_64 = MpcCore.shr(
263
- castingValues.a64_s,
264
- castingValues.b64_s
265
- );
266
- check64.res8_64 = MpcCore.shr(castingValues.a8_s, castingValues.b64_s);
267
- check64.res64_8 = MpcCore.shr(castingValues.a64_s, castingValues.b8_s);
268
- check64.res16_64 = MpcCore.shr(
269
- castingValues.a16_s,
270
- castingValues.b64_s
271
- );
272
- check64.res64_16 = MpcCore.shr(
273
- castingValues.a64_s,
274
- castingValues.b16_s
275
- );
276
- check64.res32_64 = MpcCore.shr(
277
- castingValues.a32_s,
278
- castingValues.b64_s
279
- );
280
- check64.res64_32 = MpcCore.shr(
281
- castingValues.a64_s,
282
- castingValues.b32_s
283
- );
284
- uint64 res64 = decryptAndCompareResults64(check64);
285
- require(result == res64, "shrTest: cast 64 failed");
286
-
287
- // Check the result with scalar
288
- require(
289
- result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b8_s)) &&
290
- result == MpcCore.decrypt(MpcCore.shr(castingValues.a8_s, b)),
291
- "shrTest: test 8 bits with scalar failed"
292
- );
293
- require(
294
- result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b16_s)) &&
295
- result == MpcCore.decrypt(MpcCore.shr(castingValues.a16_s, b)),
296
- "shrTest: test 16 bits with scalar failed"
297
- );
298
- require(
299
- result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b32_s)) &&
300
- result == MpcCore.decrypt(MpcCore.shr(castingValues.a32_s, b)),
301
- "shrTest: test 32 bits with scalar failed"
302
- );
303
- require(
304
- result == MpcCore.decrypt(MpcCore.shr(a, castingValues.b64_s)) &&
305
- result == MpcCore.decrypt(MpcCore.shr(castingValues.a64_s, b)),
306
- "shrTest: test 64 bits with scalar failed"
307
- );
308
-
309
- return result;
310
- }
311
- }
@@ -1,104 +0,0 @@
1
- # PrivateERC20
2
-
3
- ## Overview
4
-
5
- The `PrivateERC20` contract is an abstract implementation of a privacy-enhanced ERC20 token. It introduces mechanisms for handling encrypted addresses and balances, allowing for more secure and private token transfers. This contract builds on top of OpenZeppelin's `Context` and the `IPrivateERC20` interface, and it integrates with the `MpcCore` library for secure multiparty computation (MPC).
6
-
7
- ## Prerequisites
8
-
9
- - **Solidity Version**: `^0.8.19`
10
- - **License**: MIT
11
- - **Dependencies**:
12
- - OpenZeppelin's `Context` contract
13
- - Interface `IPrivateERC20`
14
- - Utility `MpcCore` for cryptographic operations.
15
-
16
- ## Table of Contents
17
- - [Constants](#constants)
18
- - [MAX_UINT_64](#max_uint_64)
19
- - [State Variables](#state-variables)
20
- - [Account Encryption Address Mapping](#account-encryption-address-mapping)
21
- - [Balance Mapping](#balance-mapping)
22
- - [Allowances Mapping](#allowances-mapping)
23
- - [Total Supply](#total-supply)
24
- - [Token Name and Symbol](#token-name-and-symbol)
25
- - [Errors](#errors)
26
- - [ERC20InvalidSender](#erc20invalidsender)
27
- - [ERC20InvalidReceiver](#erc20invalidreceiver)
28
- - [Functions](#functions)
29
- - To be documented as additional logic is discovered.
30
-
31
- ## Constants
32
-
33
- ### MAX_UINT_64
34
-
35
- ```solidity
36
- uint64 private constant MAX_UINT_64 = type(uint64).max;
37
- ```
38
-
39
- The constant `MAX_UINT_64` represents the maximum value of a 64-bit unsigned integer. This is used as a cap for various operations in the contract.
40
-
41
- ## State Variables
42
-
43
- ### Account Encryption Address Mapping
44
-
45
- ```solidity
46
- mapping(address account => address) private _accountEncryptionAddress;
47
- ```
48
-
49
- This mapping associates each account (public address) with an encryption address. The encryption address could be used for handling cryptographically secure operations involving private balances and transactions.
50
-
51
- ### Balance Mapping
52
-
53
- ```solidity
54
- mapping(address account => utUint64) private _balances;
55
- ```
56
-
57
- The `_balances` mapping keeps track of each account's token balance, but it uses a 64-bit unsigned integer (`utUint64`). This might be intended for scaling or privacy-preserving reasons.
58
-
59
- ### Allowances Mapping
60
-
61
- ```solidity
62
- mapping(address account => mapping(address spender => Allowance)) private _allowances;
63
- ```
64
-
65
- The `_allowances` mapping tracks the allowance that one account (`account`) has given to another account (`spender`). This is a standard ERC20 allowance mechanism with the added layer of the `Allowance` structure, which may handle encrypted or privacy-preserving amounts.
66
-
67
- ### Total Supply
68
-
69
- ```solidity
70
- ctUint64 private _totalSupply;
71
- ```
72
-
73
- The `_totalSupply` variable keeps track of the total number of tokens in existence. Like the `_balances` mapping, it uses a 64-bit unsigned integer (`ctUint64`).
74
-
75
- ### Token Name and Symbol
76
-
77
- ```solidity
78
- string private _name;
79
- string private _symbol;
80
- ```
81
-
82
- These variables store the name and symbol of the token, following the ERC20 standard.
83
-
84
- ## Errors
85
-
86
- ### ERC20InvalidSender
87
-
88
- ```solidity
89
- error ERC20InvalidSender(address sender);
90
- ```
91
-
92
- The `ERC20InvalidSender` error is raised when an invalid sender address attempts to perform a token transfer. It logs the `sender` address that caused the failure.
93
-
94
- ### ERC20InvalidReceiver
95
-
96
- ```solidity
97
- error ERC20InvalidReceiver(address receiver);
98
- ```
99
-
100
- The `ERC20InvalidReceiver` error is raised when a transfer fails due to an invalid receiver address. It logs the `receiver` address that caused the failure.
101
-
102
- ## Functions
103
-
104
- Functions in the contract are abstract or unimplemented in this fragment. These likely involve ERC20-style operations, such as `transfer`, `approve`, and `transferFrom`, but with privacy-preserving adjustments, including the handling of encrypted addresses and balances.
@@ -1,282 +0,0 @@
1
- # PrivateERC721
2
-
3
- ## Overview
4
-
5
- `PrivateERC721` is an abstract implementation of the [ERC721 Non-Fungible Token (NFT) Standard](https://eips.ethereum.org/EIPS/eip-721). It includes essential features of the standard, such as token ownership, approval, transfers, and safe transfers. This contract implements key components of the ERC721 standard while maintaining support for token metadata, but without fully implementing the metadata extension.
6
-
7
- ## Prerequisites
8
-
9
- - **Solidity Version**: `^0.8.19`
10
- - **License**: MIT
11
- - **Dependencies**:
12
- - OpenZeppelin’s `Context`, `ERC165`, and `IERC721` contracts.
13
- - `IERC721Receiver` for safe transfer checks.
14
- - `IERC721Errors` interface for custom errors (related to the draft standard [IERC6093](https://eips.ethereum.org/EIPS/eip-6093)).
15
-
16
- ## Table of Contents
17
- - [Events](#events)
18
- - [State Variables](#state-variables)
19
- - [Constructor](#constructor)
20
- - [Functions](#functions)
21
- - [Supports Interface](#supports-interface)
22
- - [Balance Of](#balance-of)
23
- - [Owner Of](#owner-of)
24
- - [Name](#name)
25
- - [Symbol](#symbol)
26
- - [Approve](#approve)
27
- - [Get Approved](#get-approved)
28
- - [Set Approval For All](#set-approval-for-all)
29
- - [Is Approved For All](#is-approved-for-all)
30
- - [Transfer From](#transfer-from)
31
- - [Safe Transfer From](#safe-transfer-from)
32
- - [Private/Internal Functions](#privateinternal-functions)
33
-
34
- ## Events
35
-
36
- ## Event: `Transfer`
37
-
38
- ```solidity
39
- event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
40
- ```
41
-
42
- ### Description:
43
- This event is emitted whenever an ERC-721 token is transferred from one address to another. It occurs during both direct token transfers (`transferFrom`) and safe token transfers (`safeTransferFrom`). This event helps external observers, such as dApps and explorers, to track the movement of tokens.
44
-
45
- ### Parameters:
46
- - **`from`** (`address`): The address of the current owner of the token.
47
- - **`to`** (`address`): The address that is receiving ownership of the token.
48
- - **`tokenId`** (`uint256`): The unique identifier (ID) of the token being transferred.
49
-
50
- ### Important Notes:
51
- - This event is emitted for both `transferFrom` and `safeTransferFrom` operations.
52
- - If a token is minted, `from` will be the zero address (`address(0)`).
53
- - If a token is burned, `to` will be the zero address (`address(0)`).
54
-
55
- ## Event: `Approval`
56
-
57
- ```solidity
58
- event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
59
- ```
60
-
61
- ### Description:
62
- The `Approval` event is emitted when an owner grants or revokes permission to another account (the `approved` address) to transfer a specific token. Each ERC-721 token can only have one approved address at a time. The approval is reset when the token is transferred to a new owner.
63
-
64
- ### Parameters:
65
- - **`owner`** (`address`): The current owner of the token.
66
- - **`approved`** (`address`): The address that is approved to transfer the token. This can be the zero address (`address(0)`) if no account is approved.
67
- - **`tokenId`** (`uint256`): The unique identifier (ID) of the token being approved for transfer.
68
-
69
- ### Important Notes:
70
- - This event is specific to individual tokens, meaning approvals apply to a single `tokenId`.
71
- - Approving the zero address (`address(0)`) clears the previous approval, effectively revoking approval for that token.
72
-
73
- ## Event: `ApprovalForAll`
74
-
75
- ```solidity
76
- event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
77
- ```
78
-
79
- ### Description:
80
- This event is emitted when an owner enables or disables an operator to manage all of their assets. Operators can transfer or manage any token owned by the `owner`. The event allows for bulk approval of all tokens owned by a single account.
81
-
82
- ### Parameters:
83
- - **`owner`** (`address`): The address of the token owner.
84
- - **`operator`** (`address`): The address that is granted or revoked permission to manage all of the owner's tokens.
85
- - **`approved`** (`bool`): A boolean value indicating whether the operator is approved (`true`) or approval is revoked (`false`).
86
-
87
- ### Important Notes:
88
- - This event differs from the `Approval` event because it applies to all tokens owned by the `owner`, not a single token.
89
- - This event is emitted when the `setApprovalForAll` function is called, allowing or revoking an operator’s access to all of the owner's tokens.
90
-
91
- ## State Variables
92
-
93
- - **_name** (`string`): The name of the token collection.
94
- - **_symbol** (`string`): The symbol for the token collection.
95
- - **_owners** (`mapping(uint256 => address)`): Maps a token ID to its owner address.
96
- - **_balances** (`mapping(address => uint256)`): Maps owner addresses to the number of tokens they own.
97
- - **_tokenApprovals** (`mapping(uint256 => address)`): Maps a token ID to the approved address for that token.
98
- - **_operatorApprovals** (`mapping(address => mapping(address => bool))`): Maps an owner to an operator, allowing the operator to manage all tokens owned by that owner.
99
-
100
- ## Constructor
101
-
102
- ```solidity
103
- constructor(string memory name_, string memory symbol_)
104
- ```
105
-
106
- The constructor initializes the contract by setting the name and symbol of the token collection. It accepts the following parameters:
107
-
108
- - **`name_`**: The name of the token collection.
109
- - **`symbol_`**: The symbol for the token collection.
110
-
111
- ## Functions
112
-
113
- ### Supports Interface
114
-
115
- ```solidity
116
- function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool)
117
- ```
118
-
119
- Implements the `supportsInterface` function to check if the contract implements a specific interface (e.g., `IERC721`).
120
-
121
- - **`interfaceId`**: The interface identifier to check.
122
- - **Returns**: `true` if the contract supports the interface, otherwise `false`.
123
-
124
- ### Balance Of
125
-
126
- ```solidity
127
- function balanceOf(address owner) public view virtual returns (uint256)
128
- ```
129
-
130
- Returns the number of tokens owned by the given address.
131
-
132
- - **`owner`**: The address to query.
133
- - **Returns**: The number of tokens owned by the address.
134
- - **Reverts**: `ERC721InvalidOwner` if `owner` is the zero address.
135
-
136
- ### Owner Of
137
-
138
- ```solidity
139
- function ownerOf(uint256 tokenId) public view virtual returns (address)
140
- ```
141
-
142
- Returns the owner of the given `tokenId`.
143
-
144
- - **`tokenId`**: The ID of the token.
145
- - **Returns**: The owner address of the `tokenId`.
146
- - **Reverts**: If the token does not exist.
147
-
148
- ### Name
149
-
150
- ```solidity
151
- function name() public view virtual returns (string memory)
152
- ```
153
-
154
- Returns the name of the token collection.
155
-
156
- ### Symbol
157
-
158
- ```solidity
159
- function symbol() public view virtual returns (string memory)
160
- ```
161
-
162
- Returns the symbol of the token collection.
163
-
164
- ### Approve
165
-
166
- ```solidity
167
- function approve(address to, uint256 tokenId) public virtual
168
- ```
169
-
170
- Approves the given address (`to`) to transfer the specified token on behalf of the owner.
171
-
172
- - **`to`**: The address to be approved.
173
- - **`tokenId`**: The ID of the token to approve.
174
-
175
- ### Get Approved
176
-
177
- ```solidity
178
- function getApproved(uint256 tokenId) public view virtual returns (address)
179
- ```
180
-
181
- Returns the approved address for the given `tokenId`.
182
-
183
- - **`tokenId`**: The ID of the token to check.
184
- - **Returns**: The address approved to transfer the `tokenId`.
185
-
186
- ### Set Approval For All
187
-
188
- ```solidity
189
- function setApprovalForAll(address operator, bool approved) public virtual
190
- ```
191
-
192
- Enables or disables approval for a third-party `operator` to manage all tokens owned by the sender.
193
-
194
- - **`operator`**: The address of the operator.
195
- - **`approved`**: `true` to approve, `false` to revoke approval.
196
-
197
- ### Is Approved For All
198
-
199
- ```solidity
200
- function isApprovedForAll(address owner, address operator) public view virtual returns (bool)
201
- ```
202
-
203
- Checks if the `operator` is approved to manage all tokens owned by `owner`.
204
-
205
- - **`owner`**: The address of the token owner.
206
- - **`operator`**: The address of the operator.
207
- - **Returns**: `true` if the operator is approved, otherwise `false`.
208
-
209
- ### Transfer From
210
-
211
- ```solidity
212
- function transferFrom(address from, address to, uint256 tokenId) public virtual
213
- ```
214
-
215
- Transfers ownership of the `tokenId` from one address to another.
216
-
217
- - **`from`**: The current owner of the token.
218
- - **`to`**: The address receiving the token.
219
- - **`tokenId`**: The ID of the token.
220
- - **Reverts**: `ERC721InvalidReceiver` if `to` is the zero address or if the sender is not authorized to transfer the token.
221
-
222
- ### Safe Transfer From
223
-
224
- ```solidity
225
- function safeTransferFrom(address from, address to, uint256 tokenId) public
226
- ```
227
-
228
- Safely transfers a `tokenId` from one address to another, ensuring the receiver can handle ERC721 tokens.
229
-
230
- - **`from`**: The current owner of the token.
231
- - **`to`**: The address receiving the token.
232
- - **`tokenId`**: The ID of the token.
233
-
234
- ### Private/Internal Functions
235
-
236
- #### `_ownerOf`
237
-
238
- ```solidity
239
- function _ownerOf(uint256 tokenId) internal view virtual returns (address)
240
- ```
241
-
242
- Internal function that returns the owner of the `tokenId`.
243
-
244
- #### `_isAuthorized`
245
-
246
- ```solidity
247
- function _isAuthorized(address owner, address spender, uint256 tokenId) internal view virtual returns (bool)
248
- ```
249
-
250
- Checks if `spender` is authorized to manage `owner`'s token or the specific `tokenId`.
251
-
252
- #### `_approve`
253
-
254
- ```solidity
255
- function _approve(address to, uint256 tokenId, address auth, bool emitEvent) internal virtual
256
- ```
257
-
258
- Approves the address `to` to manage the `tokenId`. Optionally emits the `Approval` event.
259
-
260
- #### `_mint`
261
-
262
- ```solidity
263
- function _mint(address to, uint256 tokenId) internal
264
- ```
265
-
266
- Mints a new token with the given `tokenId` and transfers it to the address `to`.
267
-
268
- #### `_burn`
269
-
270
- ```solidity
271
- function _burn(uint256 tokenId) internal
272
- ```
273
-
274
- Burns (destroys) the token with the given `tokenId`.
275
-
276
- #### `_checkOnERC721Received`
277
-
278
- ```solidity
279
- function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory data) private
280
- ```
281
-
282
- Private function to invoke the `IERC721Receiver.onERC721Received` on the target address if it's a contract.