@coti-io/coti-contracts 1.0.9 → 1.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/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.sol +260 -0
- package/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.sol +264 -0
- package/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.sol +91 -0
- package/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.sol +91 -0
- package/contracts/mocks/utils/mpc/Comparison128BitTestsContract.sol +158 -0
- package/contracts/mocks/utils/mpc/Comparison256BitTestsContract.sol +158 -0
- package/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.sol +185 -0
- package/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.sol +190 -0
- package/contracts/utils/mpc/MpcCore.sol +2804 -180
- package/package.json +1 -1
- package/test/token/PrivateERC20/PrivateERC20.test.ts +3 -3
- package/test/utils/mpc/Unsigned128BitIntegers.test.ts +945 -0
- package/test/utils/mpc/Unsigned256BitIntegers.test.ts +1124 -0
- package/test/utils/mpc/helpers.ts +77 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract.ts +341 -0
- package/typechain-types/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract.ts +347 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise128BitTestsContract.ts +186 -0
- package/typechain-types/contracts/mocks/utils/mpc/Bitwise256BitTestsContract.ts +186 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison128BitTestsContract.ts +260 -0
- package/typechain-types/contracts/mocks/utils/mpc/Comparison256BitTestsContract.ts +260 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract.ts +302 -0
- package/typechain-types/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract.ts +322 -0
- package/typechain-types/contracts/mocks/utils/mpc/index.ts +8 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic128BitTestsContract__factory.ts +349 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Arithmetic256BitTestsContract__factory.ts +364 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise128BitTestsContract__factory.ts +182 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Bitwise256BitTestsContract__factory.ts +182 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison128BitTestsContract__factory.ts +255 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Comparison256BitTestsContract__factory.ts +255 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous128BitTestsContract__factory.ts +332 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/Miscellaneous256BitTestsContract__factory.ts +380 -0
- package/typechain-types/factories/contracts/mocks/utils/mpc/index.ts +8 -0
- package/typechain-types/hardhat.d.ts +144 -0
- package/typechain-types/index.ts +16 -0
- package/contracts/package.json +0 -11
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Comparison128BitTestsContract {
|
|
7
|
+
|
|
8
|
+
bool[] public boolResults;
|
|
9
|
+
uint128[] public uintResults;
|
|
10
|
+
|
|
11
|
+
function eqTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
12
|
+
require(a.length == b.length, "Input length mismatch");
|
|
13
|
+
|
|
14
|
+
_resetBools(a.length);
|
|
15
|
+
|
|
16
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
17
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
18
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
19
|
+
|
|
20
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.eq(gtA, gtB));
|
|
21
|
+
|
|
22
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.eq(a[i], gtB)));
|
|
23
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.eq(gtA, b[i])));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function neTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
28
|
+
require(a.length == b.length, "Input length mismatch");
|
|
29
|
+
|
|
30
|
+
_resetBools(a.length);
|
|
31
|
+
|
|
32
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
33
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
34
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
35
|
+
|
|
36
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.ne(gtA, gtB));
|
|
37
|
+
|
|
38
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ne(a[i], gtB)));
|
|
39
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ne(gtA, b[i])));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function geTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
44
|
+
require(a.length == b.length, "Input length mismatch");
|
|
45
|
+
|
|
46
|
+
_resetBools(a.length);
|
|
47
|
+
|
|
48
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
49
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
50
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
51
|
+
|
|
52
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.ge(gtA, gtB));
|
|
53
|
+
|
|
54
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ge(a[i], gtB)));
|
|
55
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ge(gtA, b[i])));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function gtTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
60
|
+
require(a.length == b.length, "Input length mismatch");
|
|
61
|
+
|
|
62
|
+
_resetBools(a.length);
|
|
63
|
+
|
|
64
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
65
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
66
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
67
|
+
|
|
68
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.gt(gtA, gtB));
|
|
69
|
+
|
|
70
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.gt(a[i], gtB)));
|
|
71
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.gt(gtA, b[i])));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function leTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
76
|
+
require(a.length == b.length, "Input length mismatch");
|
|
77
|
+
|
|
78
|
+
_resetBools(a.length);
|
|
79
|
+
|
|
80
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
81
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
82
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
83
|
+
|
|
84
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.le(gtA, gtB));
|
|
85
|
+
|
|
86
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.le(a[i], gtB)));
|
|
87
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.le(gtA, b[i])));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function ltTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
92
|
+
require(a.length == b.length, "Input length mismatch");
|
|
93
|
+
|
|
94
|
+
_resetBools(a.length);
|
|
95
|
+
|
|
96
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
97
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
98
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
99
|
+
|
|
100
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.lt(gtA, gtB));
|
|
101
|
+
|
|
102
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.lt(a[i], gtB)));
|
|
103
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.lt(gtA, b[i])));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function minTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
108
|
+
require(a.length == b.length, "Input length mismatch");
|
|
109
|
+
|
|
110
|
+
_resetNumbers(a.length);
|
|
111
|
+
|
|
112
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
113
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
114
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
115
|
+
|
|
116
|
+
uintResults[i] = MpcCore.decrypt(MpcCore.min(gtA, gtB));
|
|
117
|
+
|
|
118
|
+
assert(uintResults[i] == MpcCore.decrypt(MpcCore.min(a[i], gtB)));
|
|
119
|
+
assert(uintResults[i] == MpcCore.decrypt(MpcCore.min(gtA, b[i])));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function maxTest(uint128[] calldata a, uint128[] calldata b) public {
|
|
124
|
+
require(a.length == b.length, "Input length mismatch");
|
|
125
|
+
|
|
126
|
+
_resetNumbers(a.length);
|
|
127
|
+
|
|
128
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
129
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a[i]);
|
|
130
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b[i]);
|
|
131
|
+
|
|
132
|
+
uintResults[i] = MpcCore.decrypt(MpcCore.max(gtA, gtB));
|
|
133
|
+
|
|
134
|
+
assert(uintResults[i] == MpcCore.decrypt(MpcCore.max(a[i], gtB)));
|
|
135
|
+
assert(uintResults[i] == MpcCore.decrypt(MpcCore.max(gtA, b[i])));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function _resetBools(uint256 length) internal {
|
|
140
|
+
// Reset the booleans array
|
|
141
|
+
delete boolResults;
|
|
142
|
+
|
|
143
|
+
// Resize the booleans array to match input length
|
|
144
|
+
for(uint i = 0; i < length; i++) {
|
|
145
|
+
boolResults.push(false);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function _resetNumbers(uint256 length) internal {
|
|
150
|
+
// Reset the numbers array
|
|
151
|
+
delete uintResults;
|
|
152
|
+
|
|
153
|
+
// Resize the numbers array to match input length
|
|
154
|
+
for(uint i = 0; i < length; i++) {
|
|
155
|
+
uintResults.push(0);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Comparison256BitTestsContract {
|
|
7
|
+
|
|
8
|
+
bool[] public boolResults;
|
|
9
|
+
uint256[] public uintResults2;
|
|
10
|
+
|
|
11
|
+
function eqTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
12
|
+
require(a.length == b.length, "Input length mismatch");
|
|
13
|
+
|
|
14
|
+
_resetBools(a.length);
|
|
15
|
+
|
|
16
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
17
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
18
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
19
|
+
|
|
20
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.eq(gtA, gtB));
|
|
21
|
+
|
|
22
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.eq(a[i], gtB)));
|
|
23
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.eq(gtA, b[i])));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function neTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
28
|
+
require(a.length == b.length, "Input length mismatch");
|
|
29
|
+
|
|
30
|
+
_resetBools(a.length);
|
|
31
|
+
|
|
32
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
33
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
34
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
35
|
+
|
|
36
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.ne(gtA, gtB));
|
|
37
|
+
|
|
38
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ne(a[i], gtB)));
|
|
39
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ne(gtA, b[i])));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function geTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
44
|
+
require(a.length == b.length, "Input length mismatch");
|
|
45
|
+
|
|
46
|
+
_resetBools(a.length);
|
|
47
|
+
|
|
48
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
49
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
50
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
51
|
+
|
|
52
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.ge(gtA, gtB));
|
|
53
|
+
|
|
54
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ge(a[i], gtB)));
|
|
55
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.ge(gtA, b[i])));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function gtTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
60
|
+
require(a.length == b.length, "Input length mismatch");
|
|
61
|
+
|
|
62
|
+
_resetBools(a.length);
|
|
63
|
+
|
|
64
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
65
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
66
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
67
|
+
|
|
68
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.gt(gtA, gtB));
|
|
69
|
+
|
|
70
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.gt(a[i], gtB)));
|
|
71
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.gt(gtA, b[i])));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function leTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
76
|
+
require(a.length == b.length, "Input length mismatch");
|
|
77
|
+
|
|
78
|
+
_resetBools(a.length);
|
|
79
|
+
|
|
80
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
81
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
82
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
83
|
+
|
|
84
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.le(gtA, gtB));
|
|
85
|
+
|
|
86
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.le(a[i], gtB)));
|
|
87
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.le(gtA, b[i])));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function ltTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
92
|
+
require(a.length == b.length, "Input length mismatch");
|
|
93
|
+
|
|
94
|
+
_resetBools(a.length);
|
|
95
|
+
|
|
96
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
97
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
98
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
99
|
+
|
|
100
|
+
boolResults[i] = MpcCore.decrypt(MpcCore.lt(gtA, gtB));
|
|
101
|
+
|
|
102
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.lt(a[i], gtB)));
|
|
103
|
+
assert(boolResults[i] == MpcCore.decrypt(MpcCore.lt(gtA, b[i])));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function minTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
108
|
+
require(a.length == b.length, "Input length mismatch");
|
|
109
|
+
|
|
110
|
+
_resetNumbers2(a.length);
|
|
111
|
+
|
|
112
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
113
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
114
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
115
|
+
|
|
116
|
+
uintResults2[i] = MpcCore.decrypt(MpcCore.min(gtA, gtB));
|
|
117
|
+
|
|
118
|
+
assert(uintResults2[i] == MpcCore.decrypt(MpcCore.min(a[i], gtB)));
|
|
119
|
+
assert(uintResults2[i] == MpcCore.decrypt(MpcCore.min(gtA, b[i])));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function maxTest(uint256[] calldata a, uint256[] calldata b) public {
|
|
124
|
+
require(a.length == b.length, "Input length mismatch");
|
|
125
|
+
|
|
126
|
+
_resetNumbers2(a.length);
|
|
127
|
+
|
|
128
|
+
for (uint256 i = 0; i < a.length; ++i) {
|
|
129
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a[i]);
|
|
130
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b[i]);
|
|
131
|
+
|
|
132
|
+
uintResults2[i] = MpcCore.decrypt(MpcCore.max(gtA, gtB));
|
|
133
|
+
|
|
134
|
+
assert(uintResults2[i] == MpcCore.decrypt(MpcCore.max(a[i], gtB)));
|
|
135
|
+
assert(uintResults2[i] == MpcCore.decrypt(MpcCore.max(gtA, b[i])));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function _resetBools(uint256 length) internal {
|
|
140
|
+
// Reset the booleans array
|
|
141
|
+
delete boolResults;
|
|
142
|
+
|
|
143
|
+
// Resize the booleans array to match input length
|
|
144
|
+
for(uint i = 0; i < length; i++) {
|
|
145
|
+
boolResults.push(false);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function _resetNumbers2(uint256 length) internal {
|
|
150
|
+
// Reset the numbers array
|
|
151
|
+
delete uintResults2;
|
|
152
|
+
|
|
153
|
+
// Resize the numbers array to match input length
|
|
154
|
+
for(uint i = 0; i < length; i++) {
|
|
155
|
+
uintResults2.push(0);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Miscellaneous128BitTestsContract {
|
|
7
|
+
|
|
8
|
+
uint128[] public numbers;
|
|
9
|
+
ctUint128[] public ctNumbers;
|
|
10
|
+
uint128[] public a;
|
|
11
|
+
uint128[] public b;
|
|
12
|
+
bool[] public success;
|
|
13
|
+
uint128[] public allowance;
|
|
14
|
+
|
|
15
|
+
function validateCiphertextTest(itUint128[] calldata a_) public {
|
|
16
|
+
_resetNumbers(a_.length);
|
|
17
|
+
|
|
18
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
19
|
+
gtUint128 memory gtA = MpcCore.validateCiphertext(a_[i]);
|
|
20
|
+
|
|
21
|
+
numbers[i] = MpcCore.decrypt(gtA);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setPublicTest(uint128[] calldata a_) public {
|
|
26
|
+
_resetNumbers(a_.length);
|
|
27
|
+
|
|
28
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
29
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a_[i]);
|
|
30
|
+
|
|
31
|
+
numbers[i] = MpcCore.decrypt(gtA);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function offBoardToUserTest(uint128[] calldata a_) public {
|
|
36
|
+
_resetCtNumbers(a_.length);
|
|
37
|
+
|
|
38
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
39
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a_[i]);
|
|
40
|
+
|
|
41
|
+
ctNumbers[i] = MpcCore.offBoardToUser(gtA, msg.sender);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function randTest(uint256 length) public {
|
|
46
|
+
_resetNumbers(length);
|
|
47
|
+
|
|
48
|
+
for (uint256 i = 0; i < length; ++i) {
|
|
49
|
+
numbers[i] = MpcCore.decrypt(MpcCore.rand128());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function randBoundedBitsTest(uint8[] calldata numBits) public {
|
|
54
|
+
_resetNumbers(numBits.length);
|
|
55
|
+
|
|
56
|
+
for (uint256 i = 0; i < numBits.length; ++i) {
|
|
57
|
+
numbers[i] = MpcCore.decrypt(MpcCore.randBoundedBits128(numBits[i]));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function transferTest(
|
|
62
|
+
uint128[] calldata a_,
|
|
63
|
+
uint128[] calldata b_,
|
|
64
|
+
uint128[] calldata amount_
|
|
65
|
+
)
|
|
66
|
+
public
|
|
67
|
+
{
|
|
68
|
+
require(a_.length == b_.length && a_.length == amount_.length, "Input length mismatch");
|
|
69
|
+
|
|
70
|
+
_resetA(a_.length);
|
|
71
|
+
_resetB(a_.length);
|
|
72
|
+
_resetSuccess(a_.length);
|
|
73
|
+
|
|
74
|
+
gtBool gtSuccess;
|
|
75
|
+
|
|
76
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
77
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a_[i]);
|
|
78
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b_[i]);
|
|
79
|
+
gtUint128 memory gtAmount = MpcCore.setPublic128(amount_[i]);
|
|
80
|
+
|
|
81
|
+
(gtA, gtB, gtSuccess) = MpcCore.transfer(gtA, gtB, gtAmount);
|
|
82
|
+
|
|
83
|
+
a[i] = MpcCore.decrypt(gtA);
|
|
84
|
+
b[i] = MpcCore.decrypt(gtB);
|
|
85
|
+
success[i] = MpcCore.decrypt(gtSuccess);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function transferWithAllowanceTest(
|
|
90
|
+
uint128[] calldata a_,
|
|
91
|
+
uint128[] calldata b_,
|
|
92
|
+
uint128[] calldata amount_,
|
|
93
|
+
uint128[] calldata allowance_
|
|
94
|
+
)
|
|
95
|
+
public
|
|
96
|
+
{
|
|
97
|
+
require(
|
|
98
|
+
a_.length == b_.length &&
|
|
99
|
+
a_.length == amount_.length &&
|
|
100
|
+
a_.length == allowance_.length,
|
|
101
|
+
"Input length mismatch"
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
_resetA(a_.length);
|
|
105
|
+
_resetB(a_.length);
|
|
106
|
+
_resetSuccess(a_.length);
|
|
107
|
+
_resetAllowance(a_.length);
|
|
108
|
+
|
|
109
|
+
gtBool gtSuccess;
|
|
110
|
+
|
|
111
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
112
|
+
gtUint128 memory gtA = MpcCore.setPublic128(a_[i]);
|
|
113
|
+
gtUint128 memory gtB = MpcCore.setPublic128(b_[i]);
|
|
114
|
+
gtUint128 memory gtAmount = MpcCore.setPublic128(amount_[i]);
|
|
115
|
+
gtUint128 memory gtAllowance = MpcCore.setPublic128(allowance_[i]);
|
|
116
|
+
|
|
117
|
+
(gtA, gtB, gtSuccess, gtAllowance) = MpcCore.transferWithAllowance(gtA, gtB, gtAmount, gtAllowance);
|
|
118
|
+
|
|
119
|
+
a[i] = MpcCore.decrypt(gtA);
|
|
120
|
+
b[i] = MpcCore.decrypt(gtB);
|
|
121
|
+
success[i] = MpcCore.decrypt(gtSuccess);
|
|
122
|
+
allowance[i] = MpcCore.decrypt(gtAllowance);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function _resetNumbers(uint256 length) internal {
|
|
127
|
+
// Reset the numbers array
|
|
128
|
+
delete numbers;
|
|
129
|
+
|
|
130
|
+
// Resize the numbers array to match input length
|
|
131
|
+
for(uint i = 0; i < length; i++) {
|
|
132
|
+
numbers.push(0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function _resetCtNumbers(uint256 length) internal {
|
|
137
|
+
// Reset the numbers array
|
|
138
|
+
delete ctNumbers;
|
|
139
|
+
|
|
140
|
+
// Resize the numbers array to match input length
|
|
141
|
+
for(uint i = 0; i < length; i++) {
|
|
142
|
+
ctNumbers.push(ctUint128(ctUint64.wrap(0), ctUint64.wrap(0)));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function _resetA(uint256 length) internal {
|
|
147
|
+
// Reset the numbers array
|
|
148
|
+
delete a;
|
|
149
|
+
|
|
150
|
+
// Resize the numbers array to match input length
|
|
151
|
+
for(uint i = 0; i < length; i++) {
|
|
152
|
+
a.push(0);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function _resetB(uint256 length) internal {
|
|
157
|
+
// Reset the numbers array
|
|
158
|
+
delete b;
|
|
159
|
+
|
|
160
|
+
// Resize the numbers array to match input length
|
|
161
|
+
for(uint i = 0; i < length; i++) {
|
|
162
|
+
b.push(0);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function _resetSuccess(uint256 length) internal {
|
|
167
|
+
// Reset the numbers array
|
|
168
|
+
delete success;
|
|
169
|
+
|
|
170
|
+
// Resize the numbers array to match input length
|
|
171
|
+
for(uint i = 0; i < length; i++) {
|
|
172
|
+
success.push(false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function _resetAllowance(uint256 length) internal {
|
|
177
|
+
// Reset the numbers array
|
|
178
|
+
delete allowance;
|
|
179
|
+
|
|
180
|
+
// Resize the numbers array to match input length
|
|
181
|
+
for(uint i = 0; i < length; i++) {
|
|
182
|
+
allowance.push(0);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "../../../utils/mpc/MpcCore.sol";
|
|
5
|
+
|
|
6
|
+
contract Miscellaneous256BitTestsContract {
|
|
7
|
+
|
|
8
|
+
uint256[] public numbers2;
|
|
9
|
+
ctUint256[] public ctNumbers2;
|
|
10
|
+
uint256[] public a2;
|
|
11
|
+
uint256[] public b2;
|
|
12
|
+
bool[] public success;
|
|
13
|
+
uint256[] public allowance2;
|
|
14
|
+
|
|
15
|
+
function validateCiphertextTest(itUint256[] calldata a_) public {
|
|
16
|
+
_resetNumbers2(a_.length);
|
|
17
|
+
|
|
18
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
19
|
+
gtUint256 memory gtA = MpcCore.validateCiphertext(a_[i]);
|
|
20
|
+
|
|
21
|
+
numbers2[i] = MpcCore.decrypt(gtA);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function setPublicTest(uint256[] calldata a_) public {
|
|
26
|
+
_resetNumbers2(a_.length);
|
|
27
|
+
|
|
28
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
29
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a_[i]);
|
|
30
|
+
|
|
31
|
+
numbers2[i] = MpcCore.decrypt(gtA);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function offBoardToUserTest(uint256[] calldata a_) public {
|
|
36
|
+
_resetCtNumbers2(a_.length);
|
|
37
|
+
|
|
38
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
39
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a_[i]);
|
|
40
|
+
|
|
41
|
+
ctNumbers2[i] = MpcCore.offBoardToUser(gtA, msg.sender);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function randTest2(uint256 length) public {
|
|
46
|
+
_resetNumbers2(length);
|
|
47
|
+
|
|
48
|
+
for (uint256 i = 0; i < length; ++i) {
|
|
49
|
+
numbers2[i] = MpcCore.decrypt(MpcCore.rand256());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function randBoundedBitsTest2(uint8[] calldata numBits) public {
|
|
54
|
+
_resetNumbers2(numBits.length);
|
|
55
|
+
|
|
56
|
+
for (uint256 i = 0; i < numBits.length; ++i) {
|
|
57
|
+
numbers2[i] = MpcCore.decrypt(MpcCore.randBoundedBits256(numBits[i]));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function transferTest(
|
|
62
|
+
uint256[] calldata a_,
|
|
63
|
+
uint256[] calldata b_,
|
|
64
|
+
uint256[] calldata amount_
|
|
65
|
+
)
|
|
66
|
+
public
|
|
67
|
+
{
|
|
68
|
+
require(a_.length == b_.length && a_.length == amount_.length, "Input length mismatch");
|
|
69
|
+
|
|
70
|
+
_resetA2(a_.length);
|
|
71
|
+
_resetB2(a_.length);
|
|
72
|
+
_resetSuccess(a_.length);
|
|
73
|
+
|
|
74
|
+
gtBool gtSuccess;
|
|
75
|
+
|
|
76
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
77
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a_[i]);
|
|
78
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b_[i]);
|
|
79
|
+
gtUint256 memory gtAmount = MpcCore.setPublic256(amount_[i]);
|
|
80
|
+
|
|
81
|
+
(gtA, gtB, gtSuccess) = MpcCore.transfer(gtA, gtB, gtAmount);
|
|
82
|
+
|
|
83
|
+
a2[i] = MpcCore.decrypt(gtA);
|
|
84
|
+
b2[i] = MpcCore.decrypt(gtB);
|
|
85
|
+
success[i] = MpcCore.decrypt(gtSuccess);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function transferWithAllowanceTest(
|
|
90
|
+
uint256[] calldata a_,
|
|
91
|
+
uint256[] calldata b_,
|
|
92
|
+
uint256[] calldata amount_,
|
|
93
|
+
uint256[] calldata allowance_
|
|
94
|
+
)
|
|
95
|
+
public
|
|
96
|
+
{
|
|
97
|
+
require(
|
|
98
|
+
a_.length == b_.length &&
|
|
99
|
+
a_.length == amount_.length &&
|
|
100
|
+
a_.length == allowance_.length,
|
|
101
|
+
"Input length mismatch"
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
_resetA2(a_.length);
|
|
105
|
+
_resetB2(a_.length);
|
|
106
|
+
_resetSuccess(a_.length);
|
|
107
|
+
_resetAllowance2(a_.length);
|
|
108
|
+
|
|
109
|
+
gtBool gtSuccess;
|
|
110
|
+
|
|
111
|
+
for (uint256 i = 0; i < a_.length; ++i) {
|
|
112
|
+
gtUint256 memory gtA = MpcCore.setPublic256(a_[i]);
|
|
113
|
+
gtUint256 memory gtB = MpcCore.setPublic256(b_[i]);
|
|
114
|
+
gtUint256 memory gtAmount = MpcCore.setPublic256(amount_[i]);
|
|
115
|
+
gtUint256 memory gtAllowance = MpcCore.setPublic256(allowance_[i]);
|
|
116
|
+
|
|
117
|
+
(gtA, gtB, gtSuccess, gtAllowance) = MpcCore.transferWithAllowance(gtA, gtB, gtAmount, gtAllowance);
|
|
118
|
+
|
|
119
|
+
a2[i] = MpcCore.decrypt(gtA);
|
|
120
|
+
b2[i] = MpcCore.decrypt(gtB);
|
|
121
|
+
success[i] = MpcCore.decrypt(gtSuccess);
|
|
122
|
+
allowance2[i] = MpcCore.decrypt(gtAllowance);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function _resetNumbers2(uint256 length) internal {
|
|
127
|
+
// Reset the numbers array
|
|
128
|
+
delete numbers2;
|
|
129
|
+
|
|
130
|
+
// Resize the numbers array to match input length
|
|
131
|
+
for(uint i = 0; i < length; i++) {
|
|
132
|
+
numbers2.push(0);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function _resetCtNumbers2(uint256 length) internal {
|
|
137
|
+
// Reset the numbers array
|
|
138
|
+
delete ctNumbers2;
|
|
139
|
+
|
|
140
|
+
// Resize the numbers array to match input length
|
|
141
|
+
for(uint i = 0; i < length; i++) {
|
|
142
|
+
ctNumbers2.push(
|
|
143
|
+
ctUint256(
|
|
144
|
+
ctUint128(ctUint64.wrap(0), ctUint64.wrap(0)),
|
|
145
|
+
ctUint128(ctUint64.wrap(0), ctUint64.wrap(0))
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function _resetA2(uint256 length) internal {
|
|
152
|
+
// Reset the numbers array
|
|
153
|
+
delete a2;
|
|
154
|
+
|
|
155
|
+
// Resize the numbers array to match input length
|
|
156
|
+
for(uint i = 0; i < length; i++) {
|
|
157
|
+
a2.push(0);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function _resetB2(uint256 length) internal {
|
|
162
|
+
// Reset the numbers array
|
|
163
|
+
delete b2;
|
|
164
|
+
|
|
165
|
+
// Resize the numbers array to match input length
|
|
166
|
+
for(uint i = 0; i < length; i++) {
|
|
167
|
+
b2.push(0);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function _resetSuccess(uint256 length) internal {
|
|
172
|
+
// Reset the numbers array
|
|
173
|
+
delete success;
|
|
174
|
+
|
|
175
|
+
// Resize the numbers array to match input length
|
|
176
|
+
for(uint i = 0; i < length; i++) {
|
|
177
|
+
success.push(false);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function _resetAllowance2(uint256 length) internal {
|
|
182
|
+
// Reset the numbers array
|
|
183
|
+
delete allowance2;
|
|
184
|
+
|
|
185
|
+
// Resize the numbers array to match input length
|
|
186
|
+
for(uint i = 0; i < length; i++) {
|
|
187
|
+
allowance2.push(0);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|