@coti-io/coti-contracts 0.1.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 +52 -0
- package/CODE_OF_CONDUCT.md +44 -0
- package/CONTRIBUTING.md +101 -0
- package/LICENSE +201 -0
- package/README.md +48 -0
- package/contracts/access/DataPrivacyFramework/DataPrivacyFramework.sol +480 -0
- package/contracts/access/DataPrivacyFramework/README.md +68 -0
- package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +1139 -0
- package/contracts/mocks/README.md +5 -0
- package/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.sol +9 -0
- package/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.sol +17 -0
- package/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.sol +34 -0
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +431 -0
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +361 -0
- package/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol +307 -0
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +307 -0
- package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +297 -0
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +185 -0
- package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +448 -0
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +81 -0
- package/contracts/mocks/utils/mpc/README.md +486 -0
- package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +311 -0
- package/contracts/mocks/utils/mpc/StringTestsContract.sol +59 -0
- package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +271 -0
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +715 -0
- package/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.sol +25 -0
- package/contracts/onboard/AccountOnboard.sol +21 -0
- package/contracts/onboard/README.md +65 -0
- package/contracts/package.json +11 -0
- package/contracts/token/PrivateERC20/IPrivateERC20.sol +142 -0
- package/contracts/token/PrivateERC20/PrivateERC20.sol +478 -0
- package/contracts/token/PrivateERC20/README.md +104 -0
- package/contracts/token/PrivateERC721/PrivateERC721.sol +458 -0
- package/contracts/token/PrivateERC721/README.md +282 -0
- package/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.sol +87 -0
- package/contracts/utils/mpc/MpcCore.sol +3215 -0
- package/contracts/utils/mpc/MpcInterface.sol +41 -0
- package/contracts/utils/mpc/README.md +82 -0
- package/hardhat.config.ts +18 -0
- package/package.json +14 -0
- package/test/access/DataPrivacyFramework/DataPrivacyFramework.test.ts +780 -0
- package/test/onboard/AccountOnboard.test.ts +45 -0
- package/test/token/PrivateERC20/PrivateERC20.test.ts +546 -0
- package/test/token/PrivateERC721/PrivateERC721.test.ts +223 -0
- package/test/utils/accounts.ts +55 -0
- package/test/utils/mpc/Precompile.test.ts +113 -0
- package/test/utils/mpc/String.test.ts +227 -0
- package/tsconfig.json +11 -0
- package/typechain-types/@openzeppelin/contracts/index.ts +9 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/IERC4906.ts +462 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors.ts +69 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/interfaces/index.ts +6 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721.ts +393 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/IERC721Receiver.ts +110 -0
- package/typechain-types/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/token/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/index.ts +5 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/ERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/IERC165.ts +94 -0
- package/typechain-types/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/@openzeppelin/index.ts +5 -0
- package/typechain-types/common.ts +131 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/DataPrivacyFramework.ts +598 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.ts +598 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
- package/typechain-types/contracts/access/DataPrivacyFramework/index.ts +6 -0
- package/typechain-types/contracts/access/index.ts +5 -0
- package/typechain-types/contracts/index.ts +13 -0
- package/typechain-types/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock.ts +598 -0
- package/typechain-types/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
- package/typechain-types/contracts/mocks/access/index.ts +5 -0
- package/typechain-types/contracts/mocks/index.ts +11 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/PrivateERC20Mock.ts +543 -0
- package/typechain-types/contracts/mocks/token/PrivateERC20/index.ts +4 -0
- package/typechain-types/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock.ts +576 -0
- package/typechain-types/contracts/mocks/token/PrivateERC721/index.ts +4 -0
- package/typechain-types/contracts/mocks/token/index.ts +7 -0
- package/typechain-types/contracts/mocks/utils/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +354 -0
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +340 -0
- package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +321 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +199 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.ts +384 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +218 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
- package/typechain-types/contracts/mocks/utils/mpc/ShiftTestsContract.ts +339 -0
- package/typechain-types/contracts/mocks/utils/mpc/StringTestsContract.ts +211 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +266 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +288 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +17 -0
- package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock.ts +173 -0
- package/typechain-types/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
- package/typechain-types/contracts/mocks/wallet/index.ts +5 -0
- package/typechain-types/contracts/onboard/AccountOnboard.ts +135 -0
- package/typechain-types/contracts/onboard/index.ts +4 -0
- package/typechain-types/contracts/token/PrivateERC20/IPrivateERC20.ts +437 -0
- package/typechain-types/contracts/token/PrivateERC20/PrivateERC20.ts +505 -0
- package/typechain-types/contracts/token/PrivateERC20/index.ts +5 -0
- package/typechain-types/contracts/token/PrivateERC721/PrivateERC721.ts +409 -0
- package/typechain-types/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage.ts +501 -0
- package/typechain-types/contracts/token/PrivateERC721/extensions/index.ts +4 -0
- package/typechain-types/contracts/token/PrivateERC721/index.ts +6 -0
- package/typechain-types/contracts/token/index.ts +7 -0
- package/typechain-types/contracts/utils/index.ts +5 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +698 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
- package/typechain-types/contracts/utils/mpc/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/IERC4906__factory.ts +339 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC1155Errors__factory.ts +127 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC20Errors__factory.ts +111 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/draft-IERC6093.sol/index.ts +6 -0
- package/typechain-types/factories/@openzeppelin/contracts/interfaces/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.ts +59 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.ts +307 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/ERC721/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/contracts/token/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +4 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/ERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.ts +41 -0
- package/typechain-types/factories/@openzeppelin/contracts/utils/introspection/index.ts +5 -0
- package/typechain-types/factories/@openzeppelin/index.ts +4 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/DataPrivacyFramework__factory.ts +621 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc__factory.ts +621 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/extensions/index.ts +4 -0
- package/typechain-types/factories/contracts/access/DataPrivacyFramework/index.ts +5 -0
- package/typechain-types/factories/contracts/access/index.ts +4 -0
- package/typechain-types/factories/contracts/index.ts +8 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +670 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/access/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/index.ts +7 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +615 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +630 -0
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/token/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +374 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +361 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +337 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +236 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +432 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +245 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +374 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +264 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +360 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +441 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +15 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +194 -0
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/index.ts +4 -0
- package/typechain-types/factories/contracts/mocks/wallet/index.ts +4 -0
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +104 -0
- package/typechain-types/factories/contracts/onboard/index.ts +4 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/IPrivateERC20__factory.ts +406 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/PrivateERC20__factory.ts +532 -0
- package/typechain-types/factories/contracts/token/PrivateERC20/index.ts +5 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/PrivateERC721__factory.ts +439 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/extensions/PrivateERC721URIStorage__factory.ts +512 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/extensions/index.ts +4 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +5 -0
- package/typechain-types/factories/contracts/token/index.ts +5 -0
- package/typechain-types/factories/contracts/utils/index.ts +4 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +919 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/index.ts +4 -0
- package/typechain-types/factories/contracts/utils/mpc/index.ts +4 -0
- package/typechain-types/factories/index.ts +5 -0
- package/typechain-types/hardhat.d.ts +621 -0
- package/typechain-types/index.ts +72 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
|
+
|
|
7
|
+
contract Miscellaneous1TestsContract {
|
|
8
|
+
|
|
9
|
+
uint64 random = 0;
|
|
10
|
+
bool andRes;
|
|
11
|
+
bool orRes;
|
|
12
|
+
bool xorRes;
|
|
13
|
+
bool notRes;
|
|
14
|
+
bool eqRes;
|
|
15
|
+
bool neqRes;
|
|
16
|
+
bool muxRes;
|
|
17
|
+
bool onboardRes;
|
|
18
|
+
|
|
19
|
+
function getRandom() public view returns (uint64) {
|
|
20
|
+
return random;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getBooleanResults()
|
|
24
|
+
public
|
|
25
|
+
view
|
|
26
|
+
returns (bool, bool, bool, bool, bool, bool, bool, bool)
|
|
27
|
+
{
|
|
28
|
+
return (
|
|
29
|
+
andRes,
|
|
30
|
+
orRes,
|
|
31
|
+
xorRes,
|
|
32
|
+
notRes,
|
|
33
|
+
eqRes,
|
|
34
|
+
neqRes,
|
|
35
|
+
muxRes,
|
|
36
|
+
onboardRes
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
uint constant MAX_SIZE_8_BITS = 10;
|
|
41
|
+
uint constant MAX_SIZE_16_BITS = 3;
|
|
42
|
+
uint constant MAX_SIZE_32_BITS = 3;
|
|
43
|
+
uint constant MAX_SIZE_64_BITS = 2;
|
|
44
|
+
uint constant MAX_BOOL_SIZE = 40;
|
|
45
|
+
|
|
46
|
+
function checkNotAllEqual(
|
|
47
|
+
uint64[MAX_SIZE_8_BITS] memory randoms,
|
|
48
|
+
uint size
|
|
49
|
+
) private {
|
|
50
|
+
// Count how many randoms are equal
|
|
51
|
+
uint numEqual = 1;
|
|
52
|
+
for (uint i = 1; i < size; i++) {
|
|
53
|
+
if (randoms[0] == randoms[i]) {
|
|
54
|
+
numEqual++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
require(
|
|
58
|
+
numEqual != size,
|
|
59
|
+
"randomTest: random failed, all values are the same"
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function randomTest() public returns (uint64) {
|
|
64
|
+
return randTest_(false, 0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function checkBound(
|
|
68
|
+
uint64[MAX_SIZE_8_BITS] memory randoms,
|
|
69
|
+
uint size,
|
|
70
|
+
uint8 numBits
|
|
71
|
+
) public {
|
|
72
|
+
for (uint i = 0; i < size; i++) {
|
|
73
|
+
require(
|
|
74
|
+
randoms[i] < (1 << numBits),
|
|
75
|
+
"randomTest: random failed, out of bounds"
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function randomBoundedTest(uint8 numBits) public returns (uint64) {
|
|
81
|
+
return randTest_(true, numBits);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function randTest_(bool isBounded, uint8 numBits) public returns (uint64) {
|
|
85
|
+
uint size = MAX_SIZE_8_BITS;
|
|
86
|
+
uint64[MAX_SIZE_8_BITS] memory randoms;
|
|
87
|
+
// Generate gtUint8 randoms
|
|
88
|
+
for (uint i = 0; i < size; i++) {
|
|
89
|
+
if (!isBounded) {
|
|
90
|
+
randoms[i] = MpcCore.decrypt(MpcCore.rand8());
|
|
91
|
+
} else {
|
|
92
|
+
randoms[i] = MpcCore.decrypt(MpcCore.randBoundedBits8(numBits));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
random = randoms[0];
|
|
96
|
+
if (isBounded) {
|
|
97
|
+
// Check that all randoms are in bounds
|
|
98
|
+
checkBound(randoms, size, numBits);
|
|
99
|
+
}
|
|
100
|
+
// Check that not all the generated random values are the same
|
|
101
|
+
checkNotAllEqual(randoms, size);
|
|
102
|
+
|
|
103
|
+
// In case of bounded random, the bit size does not matter because the bounded bits can be small.
|
|
104
|
+
// So the max size remain as in 8 bits.
|
|
105
|
+
// In case of unbounded random, max size can be reduced.
|
|
106
|
+
if (!isBounded) {
|
|
107
|
+
size = MAX_SIZE_16_BITS;
|
|
108
|
+
}
|
|
109
|
+
// Generate gtUint16 randoms
|
|
110
|
+
for (uint i = 0; i < size; i++) {
|
|
111
|
+
if (!isBounded) {
|
|
112
|
+
randoms[i] = MpcCore.decrypt(MpcCore.rand16());
|
|
113
|
+
} else {
|
|
114
|
+
randoms[i] = MpcCore.decrypt(
|
|
115
|
+
MpcCore.randBoundedBits16(numBits)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (isBounded) {
|
|
120
|
+
// Check that all randoms are in bounds
|
|
121
|
+
checkBound(randoms, size, numBits);
|
|
122
|
+
}
|
|
123
|
+
// Check that not all the generated random values are the same
|
|
124
|
+
checkNotAllEqual(randoms, size);
|
|
125
|
+
|
|
126
|
+
// Generate gtUint32 randoms
|
|
127
|
+
if (!isBounded) {
|
|
128
|
+
size = MAX_SIZE_32_BITS;
|
|
129
|
+
}
|
|
130
|
+
for (uint i = 0; i < size; i++) {
|
|
131
|
+
if (!isBounded) {
|
|
132
|
+
randoms[i] = MpcCore.decrypt(MpcCore.rand32());
|
|
133
|
+
} else {
|
|
134
|
+
randoms[i] = MpcCore.decrypt(
|
|
135
|
+
MpcCore.randBoundedBits32(numBits)
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (isBounded) {
|
|
140
|
+
// Check that all randoms are in bounds
|
|
141
|
+
checkBound(randoms, size, numBits);
|
|
142
|
+
}
|
|
143
|
+
// Check that not all the generated random values are the same
|
|
144
|
+
checkNotAllEqual(randoms, size);
|
|
145
|
+
|
|
146
|
+
// Generate gtUint64 randoms
|
|
147
|
+
if (!isBounded) {
|
|
148
|
+
size = MAX_SIZE_64_BITS;
|
|
149
|
+
}
|
|
150
|
+
for (uint i = 0; i < size; i++) {
|
|
151
|
+
if (!isBounded) {
|
|
152
|
+
randoms[i] = MpcCore.decrypt(MpcCore.rand64());
|
|
153
|
+
} else {
|
|
154
|
+
randoms[i] = MpcCore.decrypt(
|
|
155
|
+
MpcCore.randBoundedBits64(numBits)
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (isBounded) {
|
|
160
|
+
// Check that all randoms are in bounds
|
|
161
|
+
checkBound(randoms, size, numBits);
|
|
162
|
+
}
|
|
163
|
+
// Check that not all the generated random values are the same
|
|
164
|
+
checkNotAllEqual(randoms, size);
|
|
165
|
+
|
|
166
|
+
return random;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function booleanTest(bool a, bool b, bool bit) public {
|
|
170
|
+
gtBool aGT = MpcCore.setPublic(a);
|
|
171
|
+
gtBool bGT = MpcCore.setPublic(b);
|
|
172
|
+
gtBool bitGT = MpcCore.setPublic(bit);
|
|
173
|
+
|
|
174
|
+
andRes = MpcCore.decrypt(MpcCore.and(aGT, bGT));
|
|
175
|
+
orRes = MpcCore.decrypt(MpcCore.or(aGT, bGT));
|
|
176
|
+
xorRes = MpcCore.decrypt(MpcCore.xor(aGT, bGT));
|
|
177
|
+
notRes = MpcCore.decrypt(MpcCore.not(aGT));
|
|
178
|
+
eqRes = MpcCore.decrypt(MpcCore.eq(aGT, bGT));
|
|
179
|
+
neqRes = MpcCore.decrypt(MpcCore.ne(aGT, bGT));
|
|
180
|
+
muxRes = MpcCore.decrypt(MpcCore.mux(bitGT, aGT, bGT));
|
|
181
|
+
|
|
182
|
+
ctBool cipher = MpcCore.offBoard(aGT);
|
|
183
|
+
onboardRes = MpcCore.decrypt(MpcCore.onBoard(cipher));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
|
+
|
|
7
|
+
contract Miscellaneous2TestsContract {
|
|
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
|
+
function setPublicValues(
|
|
45
|
+
AllGTCastingValues memory castingValues,
|
|
46
|
+
uint8 a,
|
|
47
|
+
uint8 b
|
|
48
|
+
) public {
|
|
49
|
+
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
50
|
+
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
51
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
52
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
53
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
54
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
55
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
56
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
uint8 result;
|
|
60
|
+
bool boolResult;
|
|
61
|
+
|
|
62
|
+
function getResult() public view returns (uint8) {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getBoolResult() public view returns (bool) {
|
|
67
|
+
return boolResult;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function decryptAndCompareResults16(
|
|
71
|
+
Check16 memory check16
|
|
72
|
+
) public returns (uint16) {
|
|
73
|
+
// Calculate the result
|
|
74
|
+
uint16 result = MpcCore.decrypt(check16.res16_16);
|
|
75
|
+
|
|
76
|
+
require(
|
|
77
|
+
result == MpcCore.decrypt(check16.res8_16) &&
|
|
78
|
+
result == MpcCore.decrypt(check16.res16_8),
|
|
79
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function decryptAndCompareResults32(
|
|
86
|
+
Check32 memory check32
|
|
87
|
+
) public returns (uint32) {
|
|
88
|
+
// Calculate the result
|
|
89
|
+
uint32 result = MpcCore.decrypt(check32.res32_32);
|
|
90
|
+
|
|
91
|
+
require(
|
|
92
|
+
result == MpcCore.decrypt(check32.res8_32) &&
|
|
93
|
+
result == MpcCore.decrypt(check32.res32_8) &&
|
|
94
|
+
result == MpcCore.decrypt(check32.res32_16) &&
|
|
95
|
+
result == MpcCore.decrypt(check32.res16_32),
|
|
96
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function decryptAndCompareResults64(
|
|
103
|
+
Check64 memory check64
|
|
104
|
+
) public returns (uint64) {
|
|
105
|
+
// Calculate the result
|
|
106
|
+
uint64 result = MpcCore.decrypt(check64.res64_64);
|
|
107
|
+
|
|
108
|
+
require(
|
|
109
|
+
result == MpcCore.decrypt(check64.res8_64) &&
|
|
110
|
+
result == MpcCore.decrypt(check64.res64_8) &&
|
|
111
|
+
result == MpcCore.decrypt(check64.res64_16) &&
|
|
112
|
+
result == MpcCore.decrypt(check64.res16_64) &&
|
|
113
|
+
result == MpcCore.decrypt(check64.res64_32) &&
|
|
114
|
+
result == MpcCore.decrypt(check64.res32_64),
|
|
115
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function divTest(uint8 a, uint8 b) public returns (uint8) {
|
|
122
|
+
AllGTCastingValues memory castingValues;
|
|
123
|
+
Check16 memory check16;
|
|
124
|
+
Check32 memory check32;
|
|
125
|
+
Check64 memory check64;
|
|
126
|
+
setPublicValues(castingValues, a, b);
|
|
127
|
+
|
|
128
|
+
// Calculate the expected result
|
|
129
|
+
result = MpcCore.decrypt(
|
|
130
|
+
MpcCore.div(castingValues.a8_s, castingValues.b8_s)
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
// Calculate the results with casting to 16
|
|
134
|
+
check16.res16_16 = MpcCore.div(
|
|
135
|
+
castingValues.a16_s,
|
|
136
|
+
castingValues.b16_s
|
|
137
|
+
);
|
|
138
|
+
check16.res8_16 = MpcCore.div(castingValues.a8_s, castingValues.b16_s);
|
|
139
|
+
check16.res16_8 = MpcCore.div(castingValues.a16_s, castingValues.b8_s);
|
|
140
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
141
|
+
require(res16 == result, "divTest: cast 16 failed");
|
|
142
|
+
|
|
143
|
+
// Calculate the result with casting to 32
|
|
144
|
+
check32.res32_32 = MpcCore.div(
|
|
145
|
+
castingValues.a32_s,
|
|
146
|
+
castingValues.b32_s
|
|
147
|
+
);
|
|
148
|
+
check32.res8_32 = MpcCore.div(castingValues.a8_s, castingValues.b32_s);
|
|
149
|
+
check32.res32_8 = MpcCore.div(castingValues.a32_s, castingValues.b8_s);
|
|
150
|
+
check32.res16_32 = MpcCore.div(
|
|
151
|
+
castingValues.a16_s,
|
|
152
|
+
castingValues.b32_s
|
|
153
|
+
);
|
|
154
|
+
check32.res32_16 = MpcCore.div(
|
|
155
|
+
castingValues.a32_s,
|
|
156
|
+
castingValues.b16_s
|
|
157
|
+
);
|
|
158
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
159
|
+
require(result == res32, "divTest: cast 32 failed");
|
|
160
|
+
|
|
161
|
+
// Calculate the result with casting to 64
|
|
162
|
+
check64.res64_64 = MpcCore.div(
|
|
163
|
+
castingValues.a64_s,
|
|
164
|
+
castingValues.b64_s
|
|
165
|
+
);
|
|
166
|
+
check64.res8_64 = MpcCore.div(castingValues.a8_s, castingValues.b64_s);
|
|
167
|
+
check64.res64_8 = MpcCore.div(castingValues.a64_s, castingValues.b8_s);
|
|
168
|
+
check64.res16_64 = MpcCore.div(
|
|
169
|
+
castingValues.a16_s,
|
|
170
|
+
castingValues.b64_s
|
|
171
|
+
);
|
|
172
|
+
check64.res64_16 = MpcCore.div(
|
|
173
|
+
castingValues.a64_s,
|
|
174
|
+
castingValues.b16_s
|
|
175
|
+
);
|
|
176
|
+
check64.res32_64 = MpcCore.div(
|
|
177
|
+
castingValues.a32_s,
|
|
178
|
+
castingValues.b64_s
|
|
179
|
+
);
|
|
180
|
+
check64.res64_32 = MpcCore.div(
|
|
181
|
+
castingValues.a64_s,
|
|
182
|
+
castingValues.b32_s
|
|
183
|
+
);
|
|
184
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
185
|
+
require(result == res64, "divTest: cast 64 failed");
|
|
186
|
+
|
|
187
|
+
// Check the result with scalar
|
|
188
|
+
require(
|
|
189
|
+
result == MpcCore.decrypt(MpcCore.div(a, castingValues.b8_s)) &&
|
|
190
|
+
result == MpcCore.decrypt(MpcCore.div(castingValues.a8_s, b)),
|
|
191
|
+
"divTest: test 8 bits with scalar failed"
|
|
192
|
+
);
|
|
193
|
+
require(
|
|
194
|
+
result == MpcCore.decrypt(MpcCore.div(a, castingValues.b16_s)) &&
|
|
195
|
+
result == MpcCore.decrypt(MpcCore.div(castingValues.a16_s, b)),
|
|
196
|
+
"divTest: test 16 bits with scalar failed"
|
|
197
|
+
);
|
|
198
|
+
require(
|
|
199
|
+
result == MpcCore.decrypt(MpcCore.div(a, castingValues.b32_s)) &&
|
|
200
|
+
result == MpcCore.decrypt(MpcCore.div(castingValues.a32_s, b)),
|
|
201
|
+
"divTest: test 32 bits with scalar failed"
|
|
202
|
+
);
|
|
203
|
+
require(
|
|
204
|
+
result == MpcCore.decrypt(MpcCore.div(a, castingValues.b64_s)) &&
|
|
205
|
+
result == MpcCore.decrypt(MpcCore.div(castingValues.a64_s, b)),
|
|
206
|
+
"divTest: test 64 bits with scalar failed"
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function remTest(uint8 a, uint8 b) public returns (uint8) {
|
|
213
|
+
AllGTCastingValues memory castingValues;
|
|
214
|
+
Check16 memory check16;
|
|
215
|
+
Check32 memory check32;
|
|
216
|
+
Check64 memory check64;
|
|
217
|
+
setPublicValues(castingValues, a, b);
|
|
218
|
+
|
|
219
|
+
// Calculate the expected result
|
|
220
|
+
result = MpcCore.decrypt(
|
|
221
|
+
MpcCore.rem(castingValues.a8_s, castingValues.b8_s)
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
// Calculate the results with casting to 16
|
|
225
|
+
check16.res16_16 = MpcCore.rem(
|
|
226
|
+
castingValues.a16_s,
|
|
227
|
+
castingValues.b16_s
|
|
228
|
+
);
|
|
229
|
+
check16.res8_16 = MpcCore.rem(castingValues.a8_s, castingValues.b16_s);
|
|
230
|
+
check16.res16_8 = MpcCore.rem(castingValues.a16_s, castingValues.b8_s);
|
|
231
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
232
|
+
require(res16 == result, "remTest: cast 16 failed");
|
|
233
|
+
|
|
234
|
+
// Calculate the result with casting to 32
|
|
235
|
+
check32.res32_32 = MpcCore.rem(
|
|
236
|
+
castingValues.a32_s,
|
|
237
|
+
castingValues.b32_s
|
|
238
|
+
);
|
|
239
|
+
check32.res8_32 = MpcCore.rem(castingValues.a8_s, castingValues.b32_s);
|
|
240
|
+
check32.res32_8 = MpcCore.rem(castingValues.a32_s, castingValues.b8_s);
|
|
241
|
+
check32.res16_32 = MpcCore.rem(
|
|
242
|
+
castingValues.a16_s,
|
|
243
|
+
castingValues.b32_s
|
|
244
|
+
);
|
|
245
|
+
check32.res32_16 = MpcCore.rem(
|
|
246
|
+
castingValues.a32_s,
|
|
247
|
+
castingValues.b16_s
|
|
248
|
+
);
|
|
249
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
250
|
+
require(result == res32, "remTest: cast 32 failed");
|
|
251
|
+
|
|
252
|
+
// Calculate the result with casting to 64
|
|
253
|
+
check64.res64_64 = MpcCore.rem(
|
|
254
|
+
castingValues.a64_s,
|
|
255
|
+
castingValues.b64_s
|
|
256
|
+
);
|
|
257
|
+
check64.res8_64 = MpcCore.rem(castingValues.a8_s, castingValues.b64_s);
|
|
258
|
+
check64.res64_8 = MpcCore.rem(castingValues.a64_s, castingValues.b8_s);
|
|
259
|
+
check64.res16_64 = MpcCore.rem(
|
|
260
|
+
castingValues.a16_s,
|
|
261
|
+
castingValues.b64_s
|
|
262
|
+
);
|
|
263
|
+
check64.res64_16 = MpcCore.rem(
|
|
264
|
+
castingValues.a64_s,
|
|
265
|
+
castingValues.b16_s
|
|
266
|
+
);
|
|
267
|
+
check64.res32_64 = MpcCore.rem(
|
|
268
|
+
castingValues.a32_s,
|
|
269
|
+
castingValues.b64_s
|
|
270
|
+
);
|
|
271
|
+
check64.res64_32 = MpcCore.rem(
|
|
272
|
+
castingValues.a64_s,
|
|
273
|
+
castingValues.b32_s
|
|
274
|
+
);
|
|
275
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
276
|
+
require(result == res64, "remTest: cast 64 failed");
|
|
277
|
+
|
|
278
|
+
// Check the result with scalar
|
|
279
|
+
require(
|
|
280
|
+
result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b8_s)) &&
|
|
281
|
+
result == MpcCore.decrypt(MpcCore.rem(castingValues.a8_s, b)),
|
|
282
|
+
"remTest: test 8 bits with scalar failed"
|
|
283
|
+
);
|
|
284
|
+
require(
|
|
285
|
+
result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b16_s)) &&
|
|
286
|
+
result == MpcCore.decrypt(MpcCore.rem(castingValues.a16_s, b)),
|
|
287
|
+
"remTest: test 16 bits with scalar failed"
|
|
288
|
+
);
|
|
289
|
+
require(
|
|
290
|
+
result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b32_s)) &&
|
|
291
|
+
result == MpcCore.decrypt(MpcCore.rem(castingValues.a32_s, b)),
|
|
292
|
+
"remTest: test 32 bits with scalar failed"
|
|
293
|
+
);
|
|
294
|
+
require(
|
|
295
|
+
result == MpcCore.decrypt(MpcCore.rem(a, castingValues.b64_s)) &&
|
|
296
|
+
result == MpcCore.decrypt(MpcCore.rem(castingValues.a64_s, b)),
|
|
297
|
+
"remTest: test 64 bits with scalar failed"
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
return result;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function muxTest(
|
|
304
|
+
bool selectionBit,
|
|
305
|
+
uint8 a,
|
|
306
|
+
uint8 b
|
|
307
|
+
) public returns (uint8) {
|
|
308
|
+
AllGTCastingValues memory castingValues;
|
|
309
|
+
Check16 memory check16;
|
|
310
|
+
Check32 memory check32;
|
|
311
|
+
Check64 memory check64;
|
|
312
|
+
setPublicValues(castingValues, a, b);
|
|
313
|
+
gtBool selectionBit_s = MpcCore.setPublic(selectionBit);
|
|
314
|
+
|
|
315
|
+
// Calculate the expected result
|
|
316
|
+
result = MpcCore.decrypt(
|
|
317
|
+
MpcCore.mux(selectionBit_s, castingValues.a8_s, castingValues.b8_s)
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
// Calculate the result with casting to 16
|
|
321
|
+
check16.res16_16 = MpcCore.mux(
|
|
322
|
+
selectionBit_s,
|
|
323
|
+
castingValues.a16_s,
|
|
324
|
+
castingValues.b16_s
|
|
325
|
+
);
|
|
326
|
+
check16.res8_16 = MpcCore.mux(
|
|
327
|
+
selectionBit_s,
|
|
328
|
+
castingValues.a8_s,
|
|
329
|
+
castingValues.b16_s
|
|
330
|
+
);
|
|
331
|
+
check16.res16_8 = MpcCore.mux(
|
|
332
|
+
selectionBit_s,
|
|
333
|
+
castingValues.a16_s,
|
|
334
|
+
castingValues.b8_s
|
|
335
|
+
);
|
|
336
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
337
|
+
require(res16 == result, "muxTest: cast 16 failed");
|
|
338
|
+
|
|
339
|
+
// Calculate the result with casting to 32
|
|
340
|
+
check32.res32_32 = MpcCore.mux(
|
|
341
|
+
selectionBit_s,
|
|
342
|
+
castingValues.a32_s,
|
|
343
|
+
castingValues.b32_s
|
|
344
|
+
);
|
|
345
|
+
check32.res8_32 = MpcCore.mux(
|
|
346
|
+
selectionBit_s,
|
|
347
|
+
castingValues.a8_s,
|
|
348
|
+
castingValues.b32_s
|
|
349
|
+
);
|
|
350
|
+
check32.res32_8 = MpcCore.mux(
|
|
351
|
+
selectionBit_s,
|
|
352
|
+
castingValues.a32_s,
|
|
353
|
+
castingValues.b8_s
|
|
354
|
+
);
|
|
355
|
+
check32.res16_32 = MpcCore.mux(
|
|
356
|
+
selectionBit_s,
|
|
357
|
+
castingValues.a16_s,
|
|
358
|
+
castingValues.b32_s
|
|
359
|
+
);
|
|
360
|
+
check32.res32_16 = MpcCore.mux(
|
|
361
|
+
selectionBit_s,
|
|
362
|
+
castingValues.a32_s,
|
|
363
|
+
castingValues.b16_s
|
|
364
|
+
);
|
|
365
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
366
|
+
require(result == res32, "muxTest: cast 32 failed");
|
|
367
|
+
|
|
368
|
+
// Calculate the result with casting to 64
|
|
369
|
+
check64.res64_64 = MpcCore.mux(
|
|
370
|
+
selectionBit_s,
|
|
371
|
+
castingValues.a64_s,
|
|
372
|
+
castingValues.b64_s
|
|
373
|
+
);
|
|
374
|
+
check64.res8_64 = MpcCore.mux(
|
|
375
|
+
selectionBit_s,
|
|
376
|
+
castingValues.a8_s,
|
|
377
|
+
castingValues.b64_s
|
|
378
|
+
);
|
|
379
|
+
check64.res64_8 = MpcCore.mux(
|
|
380
|
+
selectionBit_s,
|
|
381
|
+
castingValues.a64_s,
|
|
382
|
+
castingValues.b8_s
|
|
383
|
+
);
|
|
384
|
+
check64.res16_64 = MpcCore.mux(
|
|
385
|
+
selectionBit_s,
|
|
386
|
+
castingValues.a16_s,
|
|
387
|
+
castingValues.b64_s
|
|
388
|
+
);
|
|
389
|
+
check64.res64_16 = MpcCore.mux(
|
|
390
|
+
selectionBit_s,
|
|
391
|
+
castingValues.a64_s,
|
|
392
|
+
castingValues.b16_s
|
|
393
|
+
);
|
|
394
|
+
check64.res32_64 = MpcCore.mux(
|
|
395
|
+
selectionBit_s,
|
|
396
|
+
castingValues.a32_s,
|
|
397
|
+
castingValues.b64_s
|
|
398
|
+
);
|
|
399
|
+
check64.res64_32 = MpcCore.mux(
|
|
400
|
+
selectionBit_s,
|
|
401
|
+
castingValues.a64_s,
|
|
402
|
+
castingValues.b32_s
|
|
403
|
+
);
|
|
404
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
405
|
+
require(result == res64, "muxTest: cast 64 failed");
|
|
406
|
+
|
|
407
|
+
return result;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function offboardOnboardTest(
|
|
411
|
+
uint8 a8,
|
|
412
|
+
uint16 a16,
|
|
413
|
+
uint32 a32,
|
|
414
|
+
uint32 a64
|
|
415
|
+
) public returns (uint8) {
|
|
416
|
+
gtUint8 a8_s = MpcCore.setPublic8(a8);
|
|
417
|
+
gtUint16 a16_s = MpcCore.setPublic16(a16);
|
|
418
|
+
gtUint32 a32_s = MpcCore.setPublic32(a32);
|
|
419
|
+
gtUint64 a64_s = MpcCore.setPublic64(a64);
|
|
420
|
+
|
|
421
|
+
ctUint8 cipher8 = MpcCore.offBoard(a8_s);
|
|
422
|
+
result = MpcCore.decrypt(MpcCore.onBoard(cipher8));
|
|
423
|
+
|
|
424
|
+
ctUint16 cipher16 = MpcCore.offBoard(a16_s);
|
|
425
|
+
uint16 result16 = MpcCore.decrypt(MpcCore.onBoard(cipher16));
|
|
426
|
+
|
|
427
|
+
ctUint32 cipher32 = MpcCore.offBoard(a32_s);
|
|
428
|
+
uint32 result32 = MpcCore.decrypt(MpcCore.onBoard(cipher32));
|
|
429
|
+
|
|
430
|
+
ctUint64 cipher64 = MpcCore.offBoard(a64_s);
|
|
431
|
+
uint64 result64 = MpcCore.decrypt(MpcCore.onBoard(cipher64));
|
|
432
|
+
|
|
433
|
+
require(
|
|
434
|
+
result == result16 && result == result32 && result == result64,
|
|
435
|
+
"Failed to offboard and onboard all values"
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
return result;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function notTest(bool a) public returns (bool) {
|
|
442
|
+
gtBool a_s = MpcCore.setPublic(a);
|
|
443
|
+
gtBool not = MpcCore.not(a_s);
|
|
444
|
+
boolResult = MpcCore.decrypt(not);
|
|
445
|
+
|
|
446
|
+
return boolResult;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
pragma solidity ^0.8.19;
|
|
5
|
+
|
|
6
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
7
|
+
|
|
8
|
+
contract OffboardToUserKeyTestContract {
|
|
9
|
+
|
|
10
|
+
bytes userKey;
|
|
11
|
+
uint8 x;
|
|
12
|
+
ctUint8 ctUserKey;
|
|
13
|
+
|
|
14
|
+
uint256 ct8;
|
|
15
|
+
uint256 ct16;
|
|
16
|
+
uint256 ct32;
|
|
17
|
+
uint256 ct64;
|
|
18
|
+
|
|
19
|
+
event AccountOnboarded(address indexed _from, bytes userKey);
|
|
20
|
+
|
|
21
|
+
function getCTs() public view returns (uint256, uint256, uint256, uint256) {
|
|
22
|
+
return (ct8, ct16, ct32, ct64);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getUserKeyTest(
|
|
26
|
+
bytes calldata signedEK,
|
|
27
|
+
bytes calldata signature,
|
|
28
|
+
address addr
|
|
29
|
+
) public returns (uint8) {
|
|
30
|
+
gtUint8 a = MpcCore.setPublic8(uint8(5));
|
|
31
|
+
gtUint8 c = MpcCore.add(a, uint8(5)); // 10
|
|
32
|
+
userKey = MpcCore.getUserKey(signedEK, signature);
|
|
33
|
+
ctUserKey = MpcCore.offBoardToUser(c, addr);
|
|
34
|
+
ctUint8 ctSystemKey = MpcCore.offBoard(c);
|
|
35
|
+
gtUint8 c1 = MpcCore.onBoard(ctSystemKey);
|
|
36
|
+
x = MpcCore.decrypt(c1);
|
|
37
|
+
return x;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getX() public view returns (uint8) {
|
|
41
|
+
return x;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getUserKey() public view returns (bytes memory) {
|
|
45
|
+
return userKey;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getCt() public view returns (ctUint8) {
|
|
49
|
+
return ctUserKey;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function userKeyTest(
|
|
53
|
+
bytes calldata signedEK,
|
|
54
|
+
bytes calldata signature
|
|
55
|
+
) public {
|
|
56
|
+
bytes memory encryptedKey = MpcCore.getUserKey(signedEK, signature);
|
|
57
|
+
emit AccountOnboarded(msg.sender, encryptedKey);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function offboardToUserTest(
|
|
61
|
+
uint8 a,
|
|
62
|
+
address addr
|
|
63
|
+
) public returns (uint256, uint256, uint256, uint256) {
|
|
64
|
+
gtUint8 a8_s = MpcCore.setPublic8(a);
|
|
65
|
+
gtUint16 a16_s = MpcCore.setPublic16(a);
|
|
66
|
+
gtUint32 a32_s = MpcCore.setPublic32(a);
|
|
67
|
+
gtUint64 a64_s = MpcCore.setPublic64(a);
|
|
68
|
+
|
|
69
|
+
ctUint8 cipher8 = MpcCore.offBoardToUser(a8_s, addr);
|
|
70
|
+
ctUint16 cipher16 = MpcCore.offBoardToUser(a16_s, addr);
|
|
71
|
+
ctUint32 cipher32 = MpcCore.offBoardToUser(a32_s, addr);
|
|
72
|
+
ctUint64 cipher64 = MpcCore.offBoardToUser(a64_s, addr);
|
|
73
|
+
|
|
74
|
+
ct8 = ctUint8.unwrap(cipher8);
|
|
75
|
+
ct16 = ctUint16.unwrap(cipher16);
|
|
76
|
+
ct32 = ctUint32.unwrap(cipher32);
|
|
77
|
+
ct64 = ctUint64.unwrap(cipher64);
|
|
78
|
+
|
|
79
|
+
return (ct8, ct16, ct32, ct64);
|
|
80
|
+
}
|
|
81
|
+
}
|