@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.
- package/.github/workflows/npm-publish.yml +2 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +1 -1
- package/README.md +18 -35
- package/contracts/access/DataPrivacyFramework/extensions/DataPrivacyFrameworkMpc.sol +3 -115
- package/contracts/mocks/README.md +1 -1
- package/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol +257 -280
- package/contracts/mocks/utils/mpc/BitwiseTestsContract.sol +93 -187
- package/contracts/mocks/utils/mpc/{Comparison1Tests.Contract.sol → Comparison1TestsContract.sol} +67 -115
- package/contracts/mocks/utils/mpc/Comparison2TestsContract.sol +76 -116
- package/contracts/mocks/utils/mpc/MinMaxTestsContract.sol +69 -164
- package/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.sol +103 -56
- package/contracts/mocks/utils/mpc/MiscellaneousTestsContract.sol +270 -0
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.sol +127 -0
- package/contracts/mocks/utils/mpc/README.md +12 -12
- package/contracts/mocks/utils/mpc/TransferScalarTestsContract.sol +54 -211
- package/contracts/mocks/utils/mpc/TransferTestsContract.sol +165 -640
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol +223 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.sol +222 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.sol +265 -0
- package/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol +281 -0
- package/contracts/onboard/AccountOnboard.sol +3 -3
- package/contracts/token/PrivateERC20/PrivateERC20.sol +1 -1
- package/contracts/token/PrivateERC721/IERC721Errors.sol +57 -0
- package/contracts/token/PrivateERC721/PrivateERC721.sol +1 -1
- package/contracts/utils/mpc/MpcCore.sol +2835 -988
- package/contracts/utils/mpc/MpcInterface.sol +6 -4
- package/hardhat.config.ts +17 -6
- package/package.json +20 -4
- package/test/token/PrivateERC20/PrivateERC20.test.ts +2 -2
- package/test/utils/accounts.ts +1 -1
- package/test/utils/mpc/Precompile.test.ts +42 -39
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract.ts +374 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract.ts +374 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/ArithmeticTestsContract.ts +96 -10
- package/typechain-types/contracts/mocks/utils/mpc/BitwiseTestsContract.ts +45 -5
- package/typechain-types/contracts/mocks/utils/mpc/Comparison1TestsContract.ts +374 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison2TestsContract.ts +45 -5
- package/typechain-types/contracts/mocks/utils/mpc/MinMaxTestsContract.ts +25 -5
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous1TestsContract.ts +62 -0
- package/typechain-types/contracts/mocks/utils/mpc/MiscellaneousTestsContract.ts +396 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract.ts +251 -0
- package/typechain-types/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract.ts +11 -8
- package/typechain-types/contracts/mocks/utils/mpc/TransferScalarTestsContract.ts +15 -15
- package/typechain-types/contracts/mocks/utils/mpc/TransferTestsContract.ts +15 -15
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract.ts +251 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract.ts +250 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.ts +389 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract.ts +391 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract.ts +306 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract.ts +125 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract.ts +125 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
- package/typechain-types/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.ts +296 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +9 -6
- package/typechain-types/contracts/onboard/AccountOnboard.ts +9 -4
- package/typechain-types/contracts/token/PrivateERC721/IERC721Errors.ts +69 -0
- package/typechain-types/contracts/token/PrivateERC721/index.ts +1 -0
- package/typechain-types/contracts/utils/mpc/MpcCore.ts +84 -0
- package/typechain-types/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations.ts +81 -40
- package/typechain-types/contracts/utils/mpc/index.ts +1 -0
- package/typechain-types/factories/contracts/mocks/access/DataPrivacyFramework/DataPrivacyFrameworkMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC20/PrivateERC20Mock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/token/PrivateERC721/PrivateERC721URIStorageMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/ArithmeticTestsContract__factory.ts +387 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/PrecompilesArythmeticTestsContract__factory.ts +388 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/ArithmeticTestsContract__factory.ts +92 -7
- package/typechain-types/factories/contracts/mocks/utils/mpc/BitwiseTestsContract__factory.ts +38 -2
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1Tests.Contract.sol/Comparison1TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison1TestsContract__factory.ts +387 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison2TestsContract__factory.ts +38 -2
- package/typechain-types/factories/contracts/mocks/utils/mpc/MinMaxTestsContract__factory.ts +15 -2
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous1TestsContract__factory.ts +66 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous2TestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/MiscellaneousTestsContract__factory.ts +424 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestContract__factory.ts +285 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol/OffboardToUserKeyTestContract__factory.ts +19 -3
- package/typechain-types/factories/contracts/mocks/utils/mpc/ShiftTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/StringTestsContract__factory.ts +1 -1
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferScalarTestsContract__factory.ts +4 -4
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferTestsContract__factory.ts +4 -4
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowance64TestsContract__factory.ts +294 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +292 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64TestsContract__factory.ts +720 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_16TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_32TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_64TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowance64_8TestsContract__factory.ts +724 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceScalarTestsContract__factory.ts +507 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferTestsContract__factory.ts +150 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/TransferWithAllowanceTestsContract__factory.ts +150 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract.sol/index.ts +5 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/TransferWithAllowanceTestsContract__factory.ts +434 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +9 -4
- package/typechain-types/factories/contracts/mocks/wallet/PrivateERC20Wallet/PrivateERC20WalletMock__factory.ts +1 -1
- package/typechain-types/factories/contracts/onboard/AccountOnboard__factory.ts +8 -2
- package/typechain-types/factories/contracts/token/PrivateERC721/IERC721Errors__factory.ts +128 -0
- package/typechain-types/factories/contracts/token/PrivateERC721/index.ts +1 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcCore__factory.ts +77 -0
- package/typechain-types/factories/contracts/utils/mpc/MpcInterface.sol/ExtendedOperations__factory.ts +124 -61
- package/typechain-types/factories/contracts/utils/mpc/index.ts +1 -0
- package/typechain-types/hardhat.d.ts +152 -26
- package/typechain-types/index.ts +20 -8
- package/contracts/access/DataPrivacyFramework/README.md +0 -68
- package/contracts/mocks/utils/mpc/Miscellaneous2TestsContract.sol +0 -448
- package/contracts/mocks/utils/mpc/OffboardToUserKeyTestsContract.sol +0 -81
- package/contracts/mocks/utils/mpc/ShiftTestsContract.sol +0 -311
- package/contracts/token/PrivateERC20/README.md +0 -104
- package/contracts/token/PrivateERC721/README.md +0 -282
- package/contracts/utils/mpc/README.md +0 -82
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
2
|
pragma solidity ^0.8.19;
|
|
4
3
|
|
|
5
4
|
import "../../../utils/mpc/MpcCore.sol";
|
|
6
5
|
|
|
7
6
|
contract ArithmeticTestsContract {
|
|
8
|
-
|
|
7
|
+
|
|
9
8
|
struct AllGTCastingValues {
|
|
10
9
|
gtUint8 a8_s;
|
|
11
10
|
gtUint8 b8_s;
|
|
@@ -23,12 +22,6 @@ contract ArithmeticTestsContract {
|
|
|
23
22
|
gtUint16 res16_8;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
struct CheckMul16 {
|
|
27
|
-
gtUint32 res16_16;
|
|
28
|
-
gtUint32 res8_16;
|
|
29
|
-
gtUint32 res16_8;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
25
|
struct Check32 {
|
|
33
26
|
gtUint32 res32_32;
|
|
34
27
|
gtUint32 res8_32;
|
|
@@ -37,14 +30,6 @@ contract ArithmeticTestsContract {
|
|
|
37
30
|
gtUint32 res32_16;
|
|
38
31
|
}
|
|
39
32
|
|
|
40
|
-
struct CheckMul32 {
|
|
41
|
-
gtUint64 res32_32;
|
|
42
|
-
gtUint64 res8_32;
|
|
43
|
-
gtUint64 res32_8;
|
|
44
|
-
gtUint64 res16_32;
|
|
45
|
-
gtUint64 res32_16;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
33
|
struct Check64 {
|
|
49
34
|
gtUint64 res64_64;
|
|
50
35
|
gtUint64 res8_64;
|
|
@@ -55,78 +40,64 @@ contract ArithmeticTestsContract {
|
|
|
55
40
|
gtUint64 res64_32;
|
|
56
41
|
}
|
|
57
42
|
|
|
58
|
-
uint8
|
|
59
|
-
|
|
43
|
+
uint8 addResult;
|
|
44
|
+
uint8 subResult;
|
|
45
|
+
uint8 mulResult;
|
|
60
46
|
|
|
61
|
-
function
|
|
62
|
-
return
|
|
47
|
+
function getAddResult() public view returns (uint8) {
|
|
48
|
+
return addResult;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getSubResult() public view returns (uint8) {
|
|
52
|
+
return subResult;
|
|
63
53
|
}
|
|
64
54
|
|
|
65
|
-
function
|
|
66
|
-
return
|
|
55
|
+
function getMulResult() public view returns (uint8) {
|
|
56
|
+
return mulResult;
|
|
67
57
|
}
|
|
68
58
|
|
|
69
|
-
function setPublicValues(
|
|
70
|
-
AllGTCastingValues memory castingValues,
|
|
71
|
-
uint8 a,
|
|
72
|
-
uint8 b
|
|
73
|
-
) public {
|
|
59
|
+
function setPublicValues(AllGTCastingValues memory castingValues, uint8 a, uint8 b) public{
|
|
74
60
|
castingValues.a8_s = MpcCore.setPublic8(a);
|
|
75
61
|
castingValues.b8_s = MpcCore.setPublic8(b);
|
|
76
|
-
castingValues.a16_s =
|
|
77
|
-
castingValues.b16_s =
|
|
78
|
-
castingValues.a32_s =
|
|
79
|
-
castingValues.b32_s =
|
|
80
|
-
castingValues.a64_s =
|
|
81
|
-
castingValues.b64_s =
|
|
62
|
+
castingValues.a16_s = MpcCore.setPublic16(a);
|
|
63
|
+
castingValues.b16_s = MpcCore.setPublic16(b);
|
|
64
|
+
castingValues.a32_s = MpcCore.setPublic32(a);
|
|
65
|
+
castingValues.b32_s = MpcCore.setPublic32(b);
|
|
66
|
+
castingValues.a64_s = MpcCore.setPublic64(a);
|
|
67
|
+
castingValues.b64_s = MpcCore.setPublic64(b);
|
|
82
68
|
}
|
|
83
69
|
|
|
84
|
-
function decryptAndCompareResults16(
|
|
85
|
-
|
|
86
|
-
) public returns (uint16) {
|
|
70
|
+
function decryptAndCompareResults16(Check16 memory check16) public returns (uint16){
|
|
71
|
+
|
|
87
72
|
// Calculate the result
|
|
88
73
|
uint16 result = MpcCore.decrypt(check16.res16_16);
|
|
89
74
|
|
|
90
|
-
require(
|
|
91
|
-
|
|
92
|
-
result == MpcCore.decrypt(check16.res16_8),
|
|
93
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
94
|
-
);
|
|
75
|
+
require(result == MpcCore.decrypt(check16.res8_16) && result == MpcCore.decrypt(check16.res16_8),
|
|
76
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
95
77
|
return result;
|
|
96
78
|
}
|
|
97
79
|
|
|
98
|
-
function decryptAndCompareResults32(
|
|
99
|
-
|
|
100
|
-
) public returns (uint32) {
|
|
80
|
+
function decryptAndCompareResults32(Check32 memory check32) public returns (uint32){
|
|
81
|
+
|
|
101
82
|
// Calculate the result
|
|
102
83
|
uint32 result = MpcCore.decrypt(check32.res32_32);
|
|
103
84
|
|
|
104
|
-
require(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
result == MpcCore.decrypt(check32.res32_16) &&
|
|
108
|
-
result == MpcCore.decrypt(check32.res16_32),
|
|
109
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
110
|
-
);
|
|
85
|
+
require(result == MpcCore.decrypt(check32.res8_32) && result == MpcCore.decrypt(check32.res32_8)
|
|
86
|
+
&& result == MpcCore.decrypt(check32.res32_16) && result == MpcCore.decrypt(check32.res16_32),
|
|
87
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
111
88
|
|
|
112
89
|
return result;
|
|
113
90
|
}
|
|
114
91
|
|
|
115
|
-
function decryptAndCompareResults64(
|
|
116
|
-
|
|
117
|
-
) public returns (uint64) {
|
|
92
|
+
function decryptAndCompareResults64(Check64 memory check64) public returns (uint64){
|
|
93
|
+
|
|
118
94
|
// Calculate the result
|
|
119
95
|
uint64 result = MpcCore.decrypt(check64.res64_64);
|
|
120
96
|
|
|
121
|
-
require(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
result == MpcCore.decrypt(check64.res16_64) &&
|
|
126
|
-
result == MpcCore.decrypt(check64.res64_32) &&
|
|
127
|
-
result == MpcCore.decrypt(check64.res32_64),
|
|
128
|
-
"decryptAndCompareAllResults: Failed to decrypt and compare all results"
|
|
129
|
-
);
|
|
97
|
+
require(result == MpcCore.decrypt(check64.res8_64) && result == MpcCore.decrypt(check64.res64_8)
|
|
98
|
+
&& result == MpcCore.decrypt(check64.res64_16) && result == MpcCore.decrypt(check64.res16_64)
|
|
99
|
+
&& result == MpcCore.decrypt(check64.res64_32) && result == MpcCore.decrypt(check64.res32_64),
|
|
100
|
+
"decryptAndCompareAllResults: Failed to decrypt and compare all results");
|
|
130
101
|
|
|
131
102
|
return result;
|
|
132
103
|
}
|
|
@@ -139,85 +110,96 @@ contract ArithmeticTestsContract {
|
|
|
139
110
|
setPublicValues(castingValues, a, b);
|
|
140
111
|
|
|
141
112
|
// Calculate the expected result
|
|
142
|
-
result =
|
|
143
|
-
|
|
144
|
-
);
|
|
113
|
+
uint8 result = MpcCore.decrypt(MpcCore.add(castingValues.a8_s, castingValues.b8_s));
|
|
114
|
+
addResult = result;
|
|
145
115
|
|
|
146
116
|
// Calculate the results with casting to 16
|
|
147
|
-
check16.res16_16 = MpcCore.add(
|
|
148
|
-
castingValues.a16_s,
|
|
149
|
-
castingValues.b16_s
|
|
150
|
-
);
|
|
117
|
+
check16.res16_16 = MpcCore.add(castingValues.a16_s, castingValues.b16_s);
|
|
151
118
|
check16.res8_16 = MpcCore.add(castingValues.a8_s, castingValues.b16_s);
|
|
152
119
|
check16.res16_8 = MpcCore.add(castingValues.a16_s, castingValues.b8_s);
|
|
153
120
|
uint16 res16 = decryptAndCompareResults16(check16);
|
|
154
121
|
require(res16 == result, "addTest: cast 16 failed");
|
|
155
122
|
|
|
156
123
|
// Calculate the result with casting to 32
|
|
157
|
-
check32.res32_32 = MpcCore.add(
|
|
158
|
-
castingValues.a32_s,
|
|
159
|
-
castingValues.b32_s
|
|
160
|
-
);
|
|
124
|
+
check32.res32_32 = MpcCore.add(castingValues.a32_s, castingValues.b32_s);
|
|
161
125
|
check32.res8_32 = MpcCore.add(castingValues.a8_s, castingValues.b32_s);
|
|
162
126
|
check32.res32_8 = MpcCore.add(castingValues.a32_s, castingValues.b8_s);
|
|
163
|
-
check32.res16_32 = MpcCore.add(
|
|
164
|
-
|
|
165
|
-
castingValues.b32_s
|
|
166
|
-
);
|
|
167
|
-
check32.res32_16 = MpcCore.add(
|
|
168
|
-
castingValues.a32_s,
|
|
169
|
-
castingValues.b16_s
|
|
170
|
-
);
|
|
127
|
+
check32.res16_32 = MpcCore.add(castingValues.a16_s, castingValues.b32_s);
|
|
128
|
+
check32.res32_16 = MpcCore.add(castingValues.a32_s, castingValues.b16_s);
|
|
171
129
|
uint32 res32 = decryptAndCompareResults32(check32);
|
|
172
130
|
require(result == res32, "addTest: cast 32 failed");
|
|
173
131
|
|
|
174
132
|
// Calculate the result with casting to 64
|
|
175
|
-
check64.res64_64 = MpcCore.add(
|
|
176
|
-
castingValues.a64_s,
|
|
177
|
-
castingValues.b64_s
|
|
178
|
-
);
|
|
133
|
+
check64.res64_64 = MpcCore.add(castingValues.a64_s, castingValues.b64_s);
|
|
179
134
|
check64.res8_64 = MpcCore.add(castingValues.a8_s, castingValues.b64_s);
|
|
180
135
|
check64.res64_8 = MpcCore.add(castingValues.a64_s, castingValues.b8_s);
|
|
181
|
-
check64.res16_64 = MpcCore.add(
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
);
|
|
185
|
-
check64.res64_16 = MpcCore.add(
|
|
186
|
-
castingValues.a64_s,
|
|
187
|
-
castingValues.b16_s
|
|
188
|
-
);
|
|
189
|
-
check64.res32_64 = MpcCore.add(
|
|
190
|
-
castingValues.a32_s,
|
|
191
|
-
castingValues.b64_s
|
|
192
|
-
);
|
|
193
|
-
check64.res64_32 = MpcCore.add(
|
|
194
|
-
castingValues.a64_s,
|
|
195
|
-
castingValues.b32_s
|
|
196
|
-
);
|
|
136
|
+
check64.res16_64 = MpcCore.add(castingValues.a16_s, castingValues.b64_s);
|
|
137
|
+
check64.res64_16 = MpcCore.add(castingValues.a64_s, castingValues.b16_s);
|
|
138
|
+
check64.res32_64 = MpcCore.add(castingValues.a32_s, castingValues.b64_s);
|
|
139
|
+
check64.res64_32 = MpcCore.add(castingValues.a64_s, castingValues.b32_s);
|
|
197
140
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
198
141
|
require(result == res64, "addTest: cast 64 failed");
|
|
199
142
|
|
|
200
143
|
// Check the result with scalar
|
|
201
|
-
require(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
"addTest: test
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
144
|
+
require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a8_s, b)),
|
|
145
|
+
"addTest: test 8 bits with scalar failed");
|
|
146
|
+
require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a16_s, b)),
|
|
147
|
+
"addTest: test 16 bits with scalar failed");
|
|
148
|
+
require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a32_s, b)),
|
|
149
|
+
"addTest: test 32 bits with scalar failed");
|
|
150
|
+
require(result == MpcCore.decrypt(MpcCore.add(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.add(castingValues.a64_s, b)),
|
|
151
|
+
"addTest: test 64 bits with scalar failed");
|
|
152
|
+
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function checkedAddTest(uint8 a, uint8 b) public returns (uint8) {
|
|
157
|
+
AllGTCastingValues memory castingValues;
|
|
158
|
+
Check16 memory check16;
|
|
159
|
+
Check32 memory check32;
|
|
160
|
+
Check64 memory check64;
|
|
161
|
+
setPublicValues(castingValues, a, b);
|
|
162
|
+
|
|
163
|
+
// Calculate the expected result
|
|
164
|
+
uint8 result = MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a8_s, castingValues.b8_s));
|
|
165
|
+
addResult = result;
|
|
166
|
+
|
|
167
|
+
// Calculate the results with casting to 16
|
|
168
|
+
check16.res16_16 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b16_s);
|
|
169
|
+
check16.res8_16 = MpcCore.checkedAdd(castingValues.a8_s, castingValues.b16_s);
|
|
170
|
+
check16.res16_8 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b8_s);
|
|
171
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
172
|
+
require(res16 == result, "addTest: cast 16 failed");
|
|
173
|
+
|
|
174
|
+
// Calculate the result with casting to 32
|
|
175
|
+
check32.res32_32 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b32_s);
|
|
176
|
+
check32.res8_32 = MpcCore.checkedAdd(castingValues.a8_s, castingValues.b32_s);
|
|
177
|
+
check32.res32_8 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b8_s);
|
|
178
|
+
check32.res16_32 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b32_s);
|
|
179
|
+
check32.res32_16 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b16_s);
|
|
180
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
181
|
+
require(result == res32, "addTest: cast 32 failed");
|
|
182
|
+
|
|
183
|
+
// Calculate the result with casting to 64
|
|
184
|
+
check64.res64_64 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b64_s);
|
|
185
|
+
check64.res8_64 = MpcCore.checkedAdd(castingValues.a8_s, castingValues.b64_s);
|
|
186
|
+
check64.res64_8 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b8_s);
|
|
187
|
+
check64.res16_64 = MpcCore.checkedAdd(castingValues.a16_s, castingValues.b64_s);
|
|
188
|
+
check64.res64_16 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b16_s);
|
|
189
|
+
check64.res32_64 = MpcCore.checkedAdd(castingValues.a32_s, castingValues.b64_s);
|
|
190
|
+
check64.res64_32 = MpcCore.checkedAdd(castingValues.a64_s, castingValues.b32_s);
|
|
191
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
192
|
+
require(result == res64, "addTest: cast 64 failed");
|
|
193
|
+
|
|
194
|
+
// Check the result with scalar
|
|
195
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a8_s, b)),
|
|
196
|
+
"addTest: test 8 bits with scalar failed");
|
|
197
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a16_s, b)),
|
|
198
|
+
"addTest: test 16 bits with scalar failed");
|
|
199
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a32_s, b)),
|
|
200
|
+
"addTest: test 32 bits with scalar failed");
|
|
201
|
+
require(result == MpcCore.decrypt(MpcCore.checkedAdd(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.checkedAdd(castingValues.a64_s, b)),
|
|
202
|
+
"addTest: test 64 bits with scalar failed");
|
|
221
203
|
|
|
222
204
|
return result;
|
|
223
205
|
}
|
|
@@ -230,202 +212,197 @@ contract ArithmeticTestsContract {
|
|
|
230
212
|
setPublicValues(castingValues, a, b);
|
|
231
213
|
|
|
232
214
|
// Calculate the expected result
|
|
233
|
-
result =
|
|
234
|
-
|
|
235
|
-
);
|
|
215
|
+
uint8 result = MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, castingValues.b8_s));
|
|
216
|
+
subResult = result;
|
|
236
217
|
|
|
237
218
|
// Calculate the results with casting to 16
|
|
238
|
-
check16.res16_16 = MpcCore.sub(
|
|
239
|
-
castingValues.a16_s,
|
|
240
|
-
castingValues.b16_s
|
|
241
|
-
);
|
|
219
|
+
check16.res16_16 = MpcCore.sub(castingValues.a16_s, castingValues.b16_s);
|
|
242
220
|
check16.res8_16 = MpcCore.sub(castingValues.a8_s, castingValues.b16_s);
|
|
243
221
|
check16.res16_8 = MpcCore.sub(castingValues.a16_s, castingValues.b8_s);
|
|
244
222
|
uint16 res16 = decryptAndCompareResults16(check16);
|
|
245
223
|
require(res16 == result, "subTest: cast 16 failed");
|
|
246
224
|
|
|
247
225
|
// Calculate the result with casting to 32
|
|
248
|
-
check32.res32_32 = MpcCore.sub(
|
|
249
|
-
castingValues.a32_s,
|
|
250
|
-
castingValues.b32_s
|
|
251
|
-
);
|
|
226
|
+
check32.res32_32 = MpcCore.sub(castingValues.a32_s, castingValues.b32_s);
|
|
252
227
|
check32.res8_32 = MpcCore.sub(castingValues.a8_s, castingValues.b32_s);
|
|
253
228
|
check32.res32_8 = MpcCore.sub(castingValues.a32_s, castingValues.b8_s);
|
|
254
|
-
check32.res16_32 = MpcCore.sub(
|
|
255
|
-
|
|
256
|
-
castingValues.b32_s
|
|
257
|
-
);
|
|
258
|
-
check32.res32_16 = MpcCore.sub(
|
|
259
|
-
castingValues.a32_s,
|
|
260
|
-
castingValues.b16_s
|
|
261
|
-
);
|
|
229
|
+
check32.res16_32 = MpcCore.sub(castingValues.a16_s, castingValues.b32_s);
|
|
230
|
+
check32.res32_16 = MpcCore.sub(castingValues.a32_s, castingValues.b16_s);
|
|
262
231
|
uint32 res32 = decryptAndCompareResults32(check32);
|
|
263
232
|
require(result == res32, "subTest: cast 32 failed");
|
|
264
233
|
|
|
265
234
|
// Calculate the result with casting to 64
|
|
266
|
-
check64.res64_64 = MpcCore.sub(
|
|
267
|
-
castingValues.a64_s,
|
|
268
|
-
castingValues.b64_s
|
|
269
|
-
);
|
|
235
|
+
check64.res64_64 = MpcCore.sub(castingValues.a64_s, castingValues.b64_s);
|
|
270
236
|
check64.res8_64 = MpcCore.sub(castingValues.a8_s, castingValues.b64_s);
|
|
271
237
|
check64.res64_8 = MpcCore.sub(castingValues.a64_s, castingValues.b8_s);
|
|
272
|
-
check64.res16_64 = MpcCore.sub(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
238
|
+
check64.res16_64 = MpcCore.sub(castingValues.a16_s, castingValues.b64_s);
|
|
239
|
+
check64.res64_16 = MpcCore.sub(castingValues.a64_s, castingValues.b16_s);
|
|
240
|
+
check64.res32_64 = MpcCore.sub(castingValues.a32_s, castingValues.b64_s);
|
|
241
|
+
check64.res64_32 = MpcCore.sub(castingValues.a64_s, castingValues.b32_s);
|
|
242
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
243
|
+
require(result == res64, "subTest: cast 64 failed");
|
|
244
|
+
|
|
245
|
+
// Check the result with scalar
|
|
246
|
+
require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a8_s, b)),
|
|
247
|
+
"subTest: test 8 bits with scalar failed");
|
|
248
|
+
require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a16_s, b)),
|
|
249
|
+
"subTest: test 16 bits with scalar failed");
|
|
250
|
+
require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a32_s, b)),
|
|
251
|
+
"subTest: test 32 bits with scalar failed");
|
|
252
|
+
require(result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.sub(castingValues.a64_s, b)),
|
|
253
|
+
"subTest: test 64 bits with scalar failed");
|
|
254
|
+
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function checkedSubTest(uint8 a, uint8 b) public returns (uint8) {
|
|
259
|
+
AllGTCastingValues memory castingValues;
|
|
260
|
+
Check16 memory check16;
|
|
261
|
+
Check32 memory check32;
|
|
262
|
+
Check64 memory check64;
|
|
263
|
+
setPublicValues(castingValues, a, b);
|
|
264
|
+
|
|
265
|
+
// Calculate the expected result
|
|
266
|
+
uint8 result = MpcCore.decrypt(MpcCore.checkedSub(castingValues.a8_s, castingValues.b8_s));
|
|
267
|
+
subResult = result;
|
|
268
|
+
|
|
269
|
+
// Calculate the results with casting to 16
|
|
270
|
+
check16.res16_16 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b16_s);
|
|
271
|
+
check16.res8_16 = MpcCore.checkedSub(castingValues.a8_s, castingValues.b16_s);
|
|
272
|
+
check16.res16_8 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b8_s);
|
|
273
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
274
|
+
require(res16 == result, "subTest: cast 16 failed");
|
|
275
|
+
|
|
276
|
+
// Calculate the result with casting to 32
|
|
277
|
+
check32.res32_32 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b32_s);
|
|
278
|
+
check32.res8_32 = MpcCore.checkedSub(castingValues.a8_s, castingValues.b32_s);
|
|
279
|
+
check32.res32_8 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b8_s);
|
|
280
|
+
check32.res16_32 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b32_s);
|
|
281
|
+
check32.res32_16 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b16_s);
|
|
282
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
283
|
+
require(result == res32, "subTest: cast 32 failed");
|
|
284
|
+
|
|
285
|
+
// Calculate the result with casting to 64
|
|
286
|
+
check64.res64_64 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b64_s);
|
|
287
|
+
check64.res8_64 = MpcCore.checkedSub(castingValues.a8_s, castingValues.b64_s);
|
|
288
|
+
check64.res64_8 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b8_s);
|
|
289
|
+
check64.res16_64 = MpcCore.checkedSub(castingValues.a16_s, castingValues.b64_s);
|
|
290
|
+
check64.res64_16 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b16_s);
|
|
291
|
+
check64.res32_64 = MpcCore.checkedSub(castingValues.a32_s, castingValues.b64_s);
|
|
292
|
+
check64.res64_32 = MpcCore.checkedSub(castingValues.a64_s, castingValues.b32_s);
|
|
288
293
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
289
294
|
require(result == res64, "subTest: cast 64 failed");
|
|
290
295
|
|
|
291
296
|
// Check the result with scalar
|
|
292
|
-
require(
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
"subTest: test
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
"subTest: test 16 bits with scalar failed"
|
|
301
|
-
);
|
|
302
|
-
require(
|
|
303
|
-
result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b32_s)) &&
|
|
304
|
-
result == MpcCore.decrypt(MpcCore.sub(castingValues.a32_s, b)),
|
|
305
|
-
"subTest: test 32 bits with scalar failed"
|
|
306
|
-
);
|
|
307
|
-
require(
|
|
308
|
-
result == MpcCore.decrypt(MpcCore.sub(a, castingValues.b64_s)) &&
|
|
309
|
-
result == MpcCore.decrypt(MpcCore.sub(castingValues.a64_s, b)),
|
|
310
|
-
"subTest: test 64 bits with scalar failed"
|
|
311
|
-
);
|
|
297
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b8_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a8_s, b)),
|
|
298
|
+
"subTest: test 8 bits with scalar failed");
|
|
299
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b16_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a16_s, b)),
|
|
300
|
+
"subTest: test 16 bits with scalar failed");
|
|
301
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b32_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a32_s, b)),
|
|
302
|
+
"subTest: test 32 bits with scalar failed");
|
|
303
|
+
require(result == MpcCore.decrypt(MpcCore.checkedSub(a, castingValues.b64_s)) && result == MpcCore.decrypt(MpcCore.checkedSub(castingValues.a64_s, b)),
|
|
304
|
+
"subTest: test 64 bits with scalar failed");
|
|
312
305
|
|
|
313
306
|
return result;
|
|
314
307
|
}
|
|
315
308
|
|
|
316
|
-
function mulTest(uint8 a, uint8 b) public returns (
|
|
309
|
+
function mulTest(uint8 a, uint8 b) public returns (uint8) {
|
|
317
310
|
AllGTCastingValues memory castingValues;
|
|
318
|
-
|
|
319
|
-
|
|
311
|
+
Check16 memory check16;
|
|
312
|
+
Check32 memory check32;
|
|
320
313
|
Check64 memory check64;
|
|
321
314
|
setPublicValues(castingValues, a, b);
|
|
322
315
|
|
|
323
316
|
// Calculate the expected result
|
|
324
|
-
|
|
325
|
-
MpcCore.mul(castingValues.a8_s, castingValues.b8_s)
|
|
326
|
-
);
|
|
317
|
+
mulResult = MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, castingValues.b8_s));
|
|
327
318
|
|
|
328
319
|
// Calculate the result with casting to 16
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
);
|
|
333
|
-
|
|
334
|
-
castingValues.a8_s,
|
|
335
|
-
castingValues.b16_s
|
|
336
|
-
);
|
|
337
|
-
checkMul16.res16_8 = MpcCore.mul(
|
|
338
|
-
castingValues.a16_s,
|
|
339
|
-
castingValues.b8_s
|
|
340
|
-
);
|
|
341
|
-
require(
|
|
342
|
-
result16 == MpcCore.decrypt(checkMul16.res16_16) &&
|
|
343
|
-
result16 == MpcCore.decrypt(checkMul16.res8_16) &&
|
|
344
|
-
result16 == MpcCore.decrypt(checkMul16.res16_8),
|
|
345
|
-
"mulTest: cast 16 failed"
|
|
346
|
-
);
|
|
320
|
+
check16.res16_16 = MpcCore.mul(castingValues.a16_s, castingValues.b16_s);
|
|
321
|
+
check16.res8_16 = MpcCore.mul(castingValues.a8_s, castingValues.b16_s);
|
|
322
|
+
check16.res16_8 = MpcCore.mul(castingValues.a16_s, castingValues.b8_s);
|
|
323
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
324
|
+
require(mulResult == res16, "mulTest: cast 16 failed");
|
|
347
325
|
|
|
348
326
|
// Calculate the result with casting to 32
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
);
|
|
357
|
-
checkMul32.res32_8 = MpcCore.mul(
|
|
358
|
-
castingValues.a32_s,
|
|
359
|
-
castingValues.b8_s
|
|
360
|
-
);
|
|
361
|
-
checkMul32.res16_32 = MpcCore.mul(
|
|
362
|
-
castingValues.a16_s,
|
|
363
|
-
castingValues.b32_s
|
|
364
|
-
);
|
|
365
|
-
checkMul32.res32_16 = MpcCore.mul(
|
|
366
|
-
castingValues.a32_s,
|
|
367
|
-
castingValues.b16_s
|
|
368
|
-
);
|
|
369
|
-
require(
|
|
370
|
-
result16 == MpcCore.decrypt(checkMul32.res32_32) &&
|
|
371
|
-
result16 == MpcCore.decrypt(checkMul32.res8_32) &&
|
|
372
|
-
result16 == MpcCore.decrypt(checkMul32.res32_8) &&
|
|
373
|
-
result16 == MpcCore.decrypt(checkMul32.res32_16) &&
|
|
374
|
-
result16 == MpcCore.decrypt(checkMul32.res16_32),
|
|
375
|
-
"mulTest: cast 32 failed"
|
|
376
|
-
);
|
|
327
|
+
check32.res32_32 = MpcCore.mul(castingValues.a32_s, castingValues.b32_s);
|
|
328
|
+
check32.res8_32 = MpcCore.mul(castingValues.a8_s, castingValues.b32_s);
|
|
329
|
+
check32.res32_8 = MpcCore.mul(castingValues.a32_s, castingValues.b8_s);
|
|
330
|
+
check32.res16_32 = MpcCore.mul(castingValues.a16_s, castingValues.b32_s);
|
|
331
|
+
check32.res32_16 = MpcCore.mul(castingValues.a32_s, castingValues.b16_s);
|
|
332
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
333
|
+
require(mulResult == res32, "mulTest: cast 32 failed");
|
|
377
334
|
|
|
378
335
|
// Calculate the result with casting to 64
|
|
379
|
-
check64.res64_64 = MpcCore.mul(
|
|
380
|
-
castingValues.a64_s,
|
|
381
|
-
castingValues.b64_s
|
|
382
|
-
);
|
|
336
|
+
check64.res64_64 = MpcCore.mul(castingValues.a64_s, castingValues.b64_s);
|
|
383
337
|
check64.res8_64 = MpcCore.mul(castingValues.a8_s, castingValues.b64_s);
|
|
384
338
|
check64.res64_8 = MpcCore.mul(castingValues.a64_s, castingValues.b8_s);
|
|
385
|
-
check64.res16_64 = MpcCore.mul(
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
339
|
+
check64.res16_64 = MpcCore.mul(castingValues.a16_s, castingValues.b64_s);
|
|
340
|
+
check64.res64_16 = MpcCore.mul(castingValues.a64_s, castingValues.b16_s);
|
|
341
|
+
check64.res32_64 = MpcCore.mul(castingValues.a32_s, castingValues.b64_s);
|
|
342
|
+
check64.res64_32 = MpcCore.mul(castingValues.a64_s, castingValues.b32_s);
|
|
343
|
+
uint64 res64 = decryptAndCompareResults64(check64);
|
|
344
|
+
require(mulResult == res64, "mulTest: cast 64 failed");
|
|
345
|
+
|
|
346
|
+
// Check the result with scalar
|
|
347
|
+
require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b8_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a8_s, b)),
|
|
348
|
+
"mulTest: test 8 bits with scalar failed");
|
|
349
|
+
require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b16_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a16_s, b)),
|
|
350
|
+
"mulTest: test 16 bits with scalar failed");
|
|
351
|
+
require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b32_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a32_s, b)),
|
|
352
|
+
"mulTest: test 32 bits with scalar failed");
|
|
353
|
+
require(mulResult == MpcCore.decrypt(MpcCore.mul(a, castingValues.b64_s)) && mulResult == MpcCore.decrypt(MpcCore.mul(castingValues.a64_s, b)),
|
|
354
|
+
"mulTest: test 64 bits with scalar failed");
|
|
355
|
+
|
|
356
|
+
return mulResult;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function checkedMulTest(uint8 a, uint8 b) public returns (uint8) {
|
|
360
|
+
AllGTCastingValues memory castingValues;
|
|
361
|
+
Check16 memory check16;
|
|
362
|
+
Check32 memory check32;
|
|
363
|
+
Check64 memory check64;
|
|
364
|
+
setPublicValues(castingValues, a, b);
|
|
365
|
+
|
|
366
|
+
// Calculate the expected result
|
|
367
|
+
mulResult = MpcCore.decrypt(MpcCore.checkedMul(castingValues.a8_s, castingValues.b8_s));
|
|
368
|
+
|
|
369
|
+
// Calculate the result with casting to 16
|
|
370
|
+
check16.res16_16 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b16_s);
|
|
371
|
+
check16.res8_16 = MpcCore.checkedMul(castingValues.a8_s, castingValues.b16_s);
|
|
372
|
+
check16.res16_8 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b8_s);
|
|
373
|
+
uint16 res16 = decryptAndCompareResults16(check16);
|
|
374
|
+
require(mulResult == res16, "mulTest: cast 16 failed");
|
|
375
|
+
|
|
376
|
+
// Calculate the result with casting to 32
|
|
377
|
+
check32.res32_32 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b32_s);
|
|
378
|
+
check32.res8_32 = MpcCore.checkedMul(castingValues.a8_s, castingValues.b32_s);
|
|
379
|
+
check32.res32_8 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b8_s);
|
|
380
|
+
check32.res16_32 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b32_s);
|
|
381
|
+
check32.res32_16 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b16_s);
|
|
382
|
+
uint32 res32 = decryptAndCompareResults32(check32);
|
|
383
|
+
require(mulResult == res32, "mulTest: cast 32 failed");
|
|
384
|
+
|
|
385
|
+
// Calculate the result with casting to 64
|
|
386
|
+
check64.res64_64 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b64_s);
|
|
387
|
+
check64.res8_64 = MpcCore.checkedMul(castingValues.a8_s, castingValues.b64_s);
|
|
388
|
+
check64.res64_8 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b8_s);
|
|
389
|
+
check64.res16_64 = MpcCore.checkedMul(castingValues.a16_s, castingValues.b64_s);
|
|
390
|
+
check64.res64_16 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b16_s);
|
|
391
|
+
check64.res32_64 = MpcCore.checkedMul(castingValues.a32_s, castingValues.b64_s);
|
|
392
|
+
check64.res64_32 = MpcCore.checkedMul(castingValues.a64_s, castingValues.b32_s);
|
|
401
393
|
uint64 res64 = decryptAndCompareResults64(check64);
|
|
402
|
-
require(
|
|
394
|
+
require(mulResult == res64, "mulTest: cast 64 failed");
|
|
403
395
|
|
|
404
396
|
// Check the result with scalar
|
|
405
|
-
require(
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
"mulTest: test
|
|
409
|
-
)
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
);
|
|
416
|
-
require(
|
|
417
|
-
result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b32_s)) &&
|
|
418
|
-
result16 ==
|
|
419
|
-
MpcCore.decrypt(MpcCore.mul(castingValues.a32_s, b)),
|
|
420
|
-
"mulTest: test 32 bits with scalar failed"
|
|
421
|
-
);
|
|
422
|
-
require(
|
|
423
|
-
result16 == MpcCore.decrypt(MpcCore.mul(a, castingValues.b64_s)) &&
|
|
424
|
-
result16 ==
|
|
425
|
-
MpcCore.decrypt(MpcCore.mul(castingValues.a64_s, b)),
|
|
426
|
-
"mulTest: test 64 bits with scalar failed"
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
return result16;
|
|
397
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b8_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a8_s, b)),
|
|
398
|
+
"mulTest: test 8 bits with scalar failed");
|
|
399
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b16_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a16_s, b)),
|
|
400
|
+
"mulTest: test 16 bits with scalar failed");
|
|
401
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b32_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a32_s, b)),
|
|
402
|
+
"mulTest: test 32 bits with scalar failed");
|
|
403
|
+
require(mulResult == MpcCore.decrypt(MpcCore.checkedMul(a, castingValues.b64_s)) && mulResult == MpcCore.decrypt(MpcCore.checkedMul(castingValues.a64_s, b)),
|
|
404
|
+
"mulTest: test 64 bits with scalar failed");
|
|
405
|
+
|
|
406
|
+
return mulResult;
|
|
430
407
|
}
|
|
431
|
-
}
|
|
408
|
+
}
|