@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,311 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
|
+
|
|
7
|
+
contract StringTestsContract {
|
|
8
|
+
|
|
9
|
+
ctString private userEncryptedString;
|
|
10
|
+
|
|
11
|
+
ctString private networkEncryptedString;
|
|
12
|
+
|
|
13
|
+
string public plaintext;
|
|
14
|
+
|
|
15
|
+
bool public isEqual;
|
|
16
|
+
|
|
17
|
+
function setUserEncryptedString(itString calldata it_) public {
|
|
18
|
+
gtString memory gt_ = MpcCore.validateCiphertext(it_);
|
|
19
|
+
|
|
20
|
+
userEncryptedString = MpcCore.offBoardToUser(gt_, msg.sender);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getUserEncryptedString() public view returns (ctString memory) {
|
|
24
|
+
return userEncryptedString;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function setNetworkEncryptedString(itString calldata it_) public {
|
|
28
|
+
gtString memory gt_ = MpcCore.validateCiphertext(it_);
|
|
29
|
+
|
|
30
|
+
networkEncryptedString = MpcCore.offBoard(gt_);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function decryptNetworkEncryptedString() public {
|
|
34
|
+
gtString memory gt_ = MpcCore.onBoard(networkEncryptedString);
|
|
35
|
+
|
|
36
|
+
plaintext = MpcCore.decrypt(gt_);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function setPublicString(string calldata str) public {
|
|
40
|
+
gtString memory gt_ = MpcCore.setPublicString(str);
|
|
41
|
+
|
|
42
|
+
userEncryptedString = MpcCore.offBoardToUser(gt_, msg.sender);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function setIsEqual(itString calldata a_, itString calldata b_, bool useEq) public {
|
|
46
|
+
gtString memory a = MpcCore.validateCiphertext(a_);
|
|
47
|
+
gtString memory b = MpcCore.validateCiphertext(b_);
|
|
48
|
+
|
|
49
|
+
gtBool isEqual_;
|
|
50
|
+
|
|
51
|
+
if (useEq) {
|
|
52
|
+
isEqual_ = MpcCore.eq(a, b);
|
|
53
|
+
} else {
|
|
54
|
+
isEqual_ = MpcCore.not(MpcCore.ne(a, b));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
isEqual = MpcCore.decrypt(isEqual_);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
pragma solidity ^0.8.19;
|
|
4
|
+
|
|
5
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
6
|
+
|
|
7
|
+
contract TransferScalarTestsContract {
|
|
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
|
+
uint8 new_a;
|
|
21
|
+
uint8 new_b;
|
|
22
|
+
bool res;
|
|
23
|
+
|
|
24
|
+
function getResults() public view returns (uint8, uint8, bool) {
|
|
25
|
+
return (new_a, new_b, res);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function computeAndChekTransfer16(
|
|
29
|
+
AllGTCastingValues memory allGTCastingValues,
|
|
30
|
+
uint8 new_a,
|
|
31
|
+
uint8 new_b,
|
|
32
|
+
bool res,
|
|
33
|
+
uint8 amount
|
|
34
|
+
) public {
|
|
35
|
+
// Check all options for casting to 16 while amount is scalar
|
|
36
|
+
(gtUint16 newA_s, gtUint16 newB_s, gtBool res_s) = MpcCore.transfer(
|
|
37
|
+
allGTCastingValues.a16_s,
|
|
38
|
+
allGTCastingValues.b16_s,
|
|
39
|
+
amount
|
|
40
|
+
);
|
|
41
|
+
require(
|
|
42
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
43
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
44
|
+
res == MpcCore.decrypt(res_s),
|
|
45
|
+
"transferTest: check scalar failed"
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
49
|
+
allGTCastingValues.a8_s,
|
|
50
|
+
allGTCastingValues.b16_s,
|
|
51
|
+
amount
|
|
52
|
+
);
|
|
53
|
+
require(
|
|
54
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
55
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
56
|
+
res == MpcCore.decrypt(res_s),
|
|
57
|
+
"transferTest: check scalar failed"
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
61
|
+
allGTCastingValues.a16_s,
|
|
62
|
+
allGTCastingValues.b8_s,
|
|
63
|
+
amount
|
|
64
|
+
);
|
|
65
|
+
require(
|
|
66
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
67
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
68
|
+
res == MpcCore.decrypt(res_s),
|
|
69
|
+
"transferTest: check scalar failed"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function computeAndChekTransfer32(
|
|
74
|
+
AllGTCastingValues memory allGTCastingValues,
|
|
75
|
+
uint8 new_a,
|
|
76
|
+
uint8 new_b,
|
|
77
|
+
bool res,
|
|
78
|
+
uint8 amount
|
|
79
|
+
) public {
|
|
80
|
+
// Check all options for casting to 32 while amount is scalar
|
|
81
|
+
(gtUint32 newA_s, gtUint32 newB_s, gtBool res_s) = MpcCore.transfer(
|
|
82
|
+
allGTCastingValues.a32_s,
|
|
83
|
+
allGTCastingValues.b32_s,
|
|
84
|
+
amount
|
|
85
|
+
);
|
|
86
|
+
require(
|
|
87
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
88
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
89
|
+
res == MpcCore.decrypt(res_s),
|
|
90
|
+
"transferTest: check scalar failed"
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
94
|
+
allGTCastingValues.a8_s,
|
|
95
|
+
allGTCastingValues.b32_s,
|
|
96
|
+
amount
|
|
97
|
+
);
|
|
98
|
+
require(
|
|
99
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
100
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
101
|
+
res == MpcCore.decrypt(res_s),
|
|
102
|
+
"transferTest: check scalar failed"
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
106
|
+
allGTCastingValues.a32_s,
|
|
107
|
+
allGTCastingValues.b8_s,
|
|
108
|
+
amount
|
|
109
|
+
);
|
|
110
|
+
require(
|
|
111
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
112
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
113
|
+
res == MpcCore.decrypt(res_s),
|
|
114
|
+
"transferTest: check scalar failed"
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
118
|
+
allGTCastingValues.a16_s,
|
|
119
|
+
allGTCastingValues.b32_s,
|
|
120
|
+
amount
|
|
121
|
+
);
|
|
122
|
+
require(
|
|
123
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
124
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
125
|
+
res == MpcCore.decrypt(res_s),
|
|
126
|
+
"transferTest: check scalar failed"
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
130
|
+
allGTCastingValues.a32_s,
|
|
131
|
+
allGTCastingValues.b16_s,
|
|
132
|
+
amount
|
|
133
|
+
);
|
|
134
|
+
require(
|
|
135
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
136
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
137
|
+
res == MpcCore.decrypt(res_s),
|
|
138
|
+
"transferTest: check scalar failed"
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function computeAndChekTransfer64(
|
|
143
|
+
AllGTCastingValues memory allGTCastingValues,
|
|
144
|
+
uint8 new_a,
|
|
145
|
+
uint8 new_b,
|
|
146
|
+
bool res,
|
|
147
|
+
uint8 amount
|
|
148
|
+
) public {
|
|
149
|
+
// Check all options for casting to 64 while amount is scalar
|
|
150
|
+
(gtUint64 newA_s, gtUint64 newB_s, gtBool res_s) = MpcCore.transfer(
|
|
151
|
+
allGTCastingValues.a64_s,
|
|
152
|
+
allGTCastingValues.b64_s,
|
|
153
|
+
amount
|
|
154
|
+
);
|
|
155
|
+
require(
|
|
156
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
157
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
158
|
+
res == MpcCore.decrypt(res_s),
|
|
159
|
+
"transferTest: check scalar failed"
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
163
|
+
allGTCastingValues.a8_s,
|
|
164
|
+
allGTCastingValues.b64_s,
|
|
165
|
+
amount
|
|
166
|
+
);
|
|
167
|
+
require(
|
|
168
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
169
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
170
|
+
res == MpcCore.decrypt(res_s),
|
|
171
|
+
"transferTest: check scalar failed"
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
175
|
+
allGTCastingValues.a64_s,
|
|
176
|
+
allGTCastingValues.b8_s,
|
|
177
|
+
amount
|
|
178
|
+
);
|
|
179
|
+
require(
|
|
180
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
181
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
182
|
+
res == MpcCore.decrypt(res_s),
|
|
183
|
+
"transferTest: check scalar failed"
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
187
|
+
allGTCastingValues.a16_s,
|
|
188
|
+
allGTCastingValues.b64_s,
|
|
189
|
+
amount
|
|
190
|
+
);
|
|
191
|
+
require(
|
|
192
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
193
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
194
|
+
res == MpcCore.decrypt(res_s),
|
|
195
|
+
"transferTest: check scalar failed"
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
199
|
+
allGTCastingValues.a64_s,
|
|
200
|
+
allGTCastingValues.b16_s,
|
|
201
|
+
amount
|
|
202
|
+
);
|
|
203
|
+
require(
|
|
204
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
205
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
206
|
+
res == MpcCore.decrypt(res_s),
|
|
207
|
+
"transferTest: check scalar failed"
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
211
|
+
allGTCastingValues.a32_s,
|
|
212
|
+
allGTCastingValues.b64_s,
|
|
213
|
+
amount
|
|
214
|
+
);
|
|
215
|
+
require(
|
|
216
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
217
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
218
|
+
res == MpcCore.decrypt(res_s),
|
|
219
|
+
"transferTest: check scalar failed"
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
(newA_s, newB_s, res_s) = MpcCore.transfer(
|
|
223
|
+
allGTCastingValues.a64_s,
|
|
224
|
+
allGTCastingValues.b32_s,
|
|
225
|
+
amount
|
|
226
|
+
);
|
|
227
|
+
require(
|
|
228
|
+
new_a == MpcCore.decrypt(newA_s) &&
|
|
229
|
+
new_b == MpcCore.decrypt(newB_s) &&
|
|
230
|
+
res == MpcCore.decrypt(res_s),
|
|
231
|
+
"transferTest: check scalar failed"
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function transferScalarTest(
|
|
236
|
+
uint8 a,
|
|
237
|
+
uint8 b,
|
|
238
|
+
uint8 amount
|
|
239
|
+
) public returns (uint8, uint8, bool) {
|
|
240
|
+
AllGTCastingValues memory allGTCastingValues;
|
|
241
|
+
allGTCastingValues.a8_s = MpcCore.setPublic8(a);
|
|
242
|
+
allGTCastingValues.b8_s = MpcCore.setPublic8(b);
|
|
243
|
+
allGTCastingValues.a16_s = MpcCore.setPublic16(a);
|
|
244
|
+
allGTCastingValues.b16_s = MpcCore.setPublic16(b);
|
|
245
|
+
allGTCastingValues.a32_s = MpcCore.setPublic32(a);
|
|
246
|
+
allGTCastingValues.b32_s = MpcCore.setPublic32(b);
|
|
247
|
+
allGTCastingValues.a64_s = MpcCore.setPublic64(a);
|
|
248
|
+
allGTCastingValues.b64_s = MpcCore.setPublic64(b);
|
|
249
|
+
|
|
250
|
+
// Calculate the expected result
|
|
251
|
+
(gtUint8 newA_s, gtUint8 newB_s, gtBool res_s) = MpcCore.transfer(
|
|
252
|
+
allGTCastingValues.a8_s,
|
|
253
|
+
allGTCastingValues.b8_s,
|
|
254
|
+
amount
|
|
255
|
+
);
|
|
256
|
+
new_a = MpcCore.decrypt(newA_s);
|
|
257
|
+
new_b = MpcCore.decrypt(newB_s);
|
|
258
|
+
res = MpcCore.decrypt(res_s);
|
|
259
|
+
|
|
260
|
+
// Calculate the result with casting to 16
|
|
261
|
+
computeAndChekTransfer16(allGTCastingValues, new_a, new_b, res, amount);
|
|
262
|
+
|
|
263
|
+
// Calculate the result with casting to 32
|
|
264
|
+
computeAndChekTransfer32(allGTCastingValues, new_a, new_b, res, amount);
|
|
265
|
+
|
|
266
|
+
// Calculate the result with casting to 64
|
|
267
|
+
computeAndChekTransfer64(allGTCastingValues, new_a, new_b, res, amount);
|
|
268
|
+
|
|
269
|
+
return (new_a, new_b, res);
|
|
270
|
+
}
|
|
271
|
+
}
|