@inco/lightning 0.8.0-devnet-9 → 0.8.0-devnet-11
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/manifest.yaml +22 -0
- package/package.json +1 -1
- package/src/IncoLightning.sol +2 -11
- package/src/Lib.alphanet.sol +261 -2
- package/src/Lib.demonet.sol +261 -2
- package/src/Lib.devnet.sol +262 -3
- package/src/Lib.sol +262 -3
- package/src/Lib.template.sol +283 -2
- package/src/Lib.testnet.sol +261 -2
- package/src/Types.sol +13 -0
- package/src/interfaces/IIncoLightning.sol +2 -12
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +261 -2
- package/src/libs/incoLightning_alphanet_v1_725458969.sol +261 -2
- package/src/libs/incoLightning_alphanet_v2_976644394.sol +261 -2
- package/src/libs/incoLightning_demonet_v0_863421733.sol +261 -2
- package/src/libs/incoLightning_demonet_v2_467437523.sol +261 -2
- package/src/libs/incoLightning_devnet_v0_340846814.sol +261 -2
- package/src/libs/incoLightning_devnet_v1_904635675.sol +261 -2
- package/src/libs/incoLightning_devnet_v2_295237520.sol +261 -2
- package/src/libs/incoLightning_devnet_v3_976859633.sol +261 -2
- package/src/libs/incoLightning_devnet_v4_409204766.sol +261 -2
- package/src/libs/incoLightning_devnet_v5_203964628.sol +261 -2
- package/src/libs/incoLightning_devnet_v6_281949651.sol +1201 -0
- package/src/libs/incoLightning_testnet_v0_183408998.sol +261 -2
- package/src/libs/incoLightning_testnet_v2_889158349.sol +261 -2
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +2 -1
- package/src/lightning-parts/DecryptionAttester.sol +38 -2
- package/src/lightning-parts/DecryptionAttester.types.sol +14 -0
- package/src/lightning-parts/EList.sol +323 -0
- package/src/lightning-parts/TrivialEncryption.sol +1 -2
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -1
- package/src/lightning-parts/interfaces/IEList.sol +35 -0
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +3 -1
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +3 -1
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +3 -1
- package/src/lightning-parts/primitives/EListHandleGeneration.sol +63 -0
- package/src/lightning-parts/primitives/EListHandleMetadata.sol +60 -0
- package/src/lightning-parts/primitives/interfaces/IEListHandleMetadata.sol +8 -0
- package/src/lightning-parts/test/Elist.t.sol +67 -0
- package/src/misc/ABIHelper.sol +15 -0
- package/src/shared/TestUtils.sol +8 -1
- package/src/test/EListTester.sol +148 -0
- package/src/version/IncoLightningConfig.sol +1 -1
|
@@ -0,0 +1,1201 @@
|
|
|
1
|
+
// AUTOGENERATED FILE. DO NOT EDIT.
|
|
2
|
+
// This file was generated by the IncoLightning library generator.
|
|
3
|
+
// The original template is located at Lib.template.sol
|
|
4
|
+
|
|
5
|
+
/// SPDX-License-Identifier: No License
|
|
6
|
+
pragma solidity ^0.8;
|
|
7
|
+
|
|
8
|
+
import { IncoLightning } from "../IncoLightning.sol";
|
|
9
|
+
import { ebool, euint256, eaddress, ETypes, elist, IndexOutOfRange, InvalidRange, SliceOutOfRange, UnsupportedListType } from "../Types.sol";
|
|
10
|
+
import { DecryptionAttestation, ElementDecryptionProof } from "../lightning-parts/DecryptionAttester.types.sol";
|
|
11
|
+
|
|
12
|
+
IncoLightning constant inco = IncoLightning(0xDF3830489208461f72Df6E45D0e6cbF9DBB74fe1);
|
|
13
|
+
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
14
|
+
|
|
15
|
+
/// @notice Returns the ETypes enum value encoded in a handle
|
|
16
|
+
/// @param handle The handle to decode
|
|
17
|
+
/// @return The ETypes value
|
|
18
|
+
function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
19
|
+
return ETypes(uint8(uint256(handle) >> 8));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
library e {
|
|
23
|
+
error CallFailedAfterFeeRefresh();
|
|
24
|
+
|
|
25
|
+
/// @dev slot to store the fee for inco operations
|
|
26
|
+
bytes32 private constant FEE_SLOT = keccak256("inco.fee");
|
|
27
|
+
|
|
28
|
+
/// @notice Returns a sanitized euint256, replacing zero with asEuint256(0)
|
|
29
|
+
/// @param a The euint256 to sanitize
|
|
30
|
+
/// @return The sanitized euint256
|
|
31
|
+
function sanitize(euint256 a) internal returns (euint256) {
|
|
32
|
+
if (euint256.unwrap(a) == bytes32(0)) {
|
|
33
|
+
return asEuint256(0);
|
|
34
|
+
}
|
|
35
|
+
return a;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// @notice Returns a sanitized ebool, replacing zero with asEbool(false)
|
|
39
|
+
/// @param a The ebool to sanitize
|
|
40
|
+
/// @return The sanitized ebool
|
|
41
|
+
function sanitize(ebool a) internal returns (ebool) {
|
|
42
|
+
if (ebool.unwrap(a) == bytes32(0)) {
|
|
43
|
+
return asEbool(false);
|
|
44
|
+
}
|
|
45
|
+
return a;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// @notice Returns a sanitized eaddress, replacing zero with asEaddress(address(0))
|
|
49
|
+
/// @param a The eaddress to sanitize
|
|
50
|
+
/// @return The sanitized eaddress
|
|
51
|
+
function sanitize(eaddress a) internal returns (eaddress) {
|
|
52
|
+
if (eaddress.unwrap(a) == bytes32(0)) {
|
|
53
|
+
return asEaddress(address(0));
|
|
54
|
+
}
|
|
55
|
+
return a;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// @notice Alias for sanitize(euint256)
|
|
59
|
+
/// @param a The euint256 to sanitize
|
|
60
|
+
/// @return The sanitized euint256
|
|
61
|
+
function s(euint256 a) internal returns (euint256) {
|
|
62
|
+
return sanitize(a);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// @notice Alias for sanitize(ebool)
|
|
66
|
+
/// @param a The ebool to sanitize
|
|
67
|
+
/// @return The sanitized ebool
|
|
68
|
+
function s(ebool a) internal returns (ebool) {
|
|
69
|
+
return sanitize(a);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// @notice Alias for sanitize(eaddress)
|
|
73
|
+
/// @param a The eaddress to sanitize
|
|
74
|
+
/// @return The sanitized eaddress
|
|
75
|
+
function s(eaddress a) internal returns (eaddress) {
|
|
76
|
+
return sanitize(a);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// @notice Adds two encrypted uint256 values
|
|
80
|
+
/// @param a First operand
|
|
81
|
+
/// @param b Second operand
|
|
82
|
+
/// @return The encrypted sum
|
|
83
|
+
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
84
|
+
return inco.eAdd(s(a), s(b));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// @notice Adds an encrypted uint256 and a plaintext uint256
|
|
88
|
+
/// @param a Encrypted operand
|
|
89
|
+
/// @param b Plaintext operand
|
|
90
|
+
/// @return The encrypted sum
|
|
91
|
+
function add(euint256 a, uint256 b) internal returns (euint256) {
|
|
92
|
+
return inco.eAdd(s(a), asEuint256(b));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/// @notice Adds a plaintext uint256 and an encrypted uint256
|
|
96
|
+
/// @param a Plaintext operand
|
|
97
|
+
/// @param b Encrypted operand
|
|
98
|
+
/// @return The encrypted sum
|
|
99
|
+
function add(uint256 a, euint256 b) internal returns (euint256) {
|
|
100
|
+
return inco.eAdd(asEuint256(a), s(b));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// @notice Subtracts two encrypted uint256 values
|
|
104
|
+
/// @param a Encrypted minuend
|
|
105
|
+
/// @param b Encrypted subtrahend
|
|
106
|
+
/// @return The encrypted difference
|
|
107
|
+
function sub(euint256 a, euint256 b) internal returns (euint256) {
|
|
108
|
+
return inco.eSub(s(a), s(b));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// @notice Subtracts a plaintext uint256 from an encrypted uint256
|
|
112
|
+
/// @param a Encrypted minuend
|
|
113
|
+
/// @param b Plaintext subtrahend
|
|
114
|
+
/// @return The encrypted difference
|
|
115
|
+
function sub(euint256 a, uint256 b) internal returns (euint256) {
|
|
116
|
+
return inco.eSub(s(a), asEuint256(b));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// @notice Subtracts an encrypted uint256 from a plaintext uint256
|
|
120
|
+
/// @param a Plaintext minuend
|
|
121
|
+
/// @param b Encrypted subtrahend
|
|
122
|
+
/// @return The encrypted difference
|
|
123
|
+
function sub(uint256 a, euint256 b) internal returns (euint256) {
|
|
124
|
+
return inco.eSub(asEuint256(a), s(b));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// @notice Multiplies two encrypted uint256 values
|
|
128
|
+
/// @param a Encrypted operand
|
|
129
|
+
/// @param b Encrypted operand
|
|
130
|
+
/// @return The encrypted product
|
|
131
|
+
function mul(euint256 a, euint256 b) internal returns (euint256) {
|
|
132
|
+
return inco.eMul(s(a), s(b));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// @notice Multiplies an encrypted uint256 and a plaintext uint256
|
|
136
|
+
/// @param a Encrypted operand
|
|
137
|
+
/// @param b Plaintext operand
|
|
138
|
+
/// @return The encrypted product
|
|
139
|
+
function mul(euint256 a, uint256 b) internal returns (euint256) {
|
|
140
|
+
return inco.eMul(s(a), asEuint256(b));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// @notice Multiplies a plaintext uint256 and an encrypted uint256
|
|
144
|
+
/// @param a Plaintext operand
|
|
145
|
+
/// @param b Encrypted operand
|
|
146
|
+
/// @return The encrypted product
|
|
147
|
+
function mul(uint256 a, euint256 b) internal returns (euint256) {
|
|
148
|
+
return inco.eMul(asEuint256(a), s(b));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// @notice Divides two encrypted uint256 values
|
|
152
|
+
/// @param a Encrypted Dividend
|
|
153
|
+
/// @param b Encrypted Divisor
|
|
154
|
+
/// @return The encrypted quotient
|
|
155
|
+
function div(euint256 a, euint256 b) internal returns (euint256) {
|
|
156
|
+
return inco.eDiv(s(a), s(b));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// @notice Divides an encrypted uint256 by a plaintext uint256
|
|
160
|
+
/// @param a Encrypted dividend
|
|
161
|
+
/// @param b Plaintext divisor
|
|
162
|
+
/// @return The encrypted quotient
|
|
163
|
+
function div(euint256 a, uint256 b) internal returns (euint256) {
|
|
164
|
+
return inco.eDiv(s(a), asEuint256(b));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// @notice Divides a plaintext uint256 by an encrypted uint256
|
|
168
|
+
/// @param a Plaintext dividend
|
|
169
|
+
/// @param b Encrypted divisor
|
|
170
|
+
/// @return The encrypted quotient
|
|
171
|
+
function div(uint256 a, euint256 b) internal returns (euint256) {
|
|
172
|
+
return inco.eDiv(asEuint256(a), s(b));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/// @notice Remainder of two encrypted uint256 values
|
|
176
|
+
/// @param a Encrypted dividend
|
|
177
|
+
/// @param b Encrypted divisor
|
|
178
|
+
/// @return The encrypted remainder
|
|
179
|
+
function rem(euint256 a, euint256 b) internal returns (euint256) {
|
|
180
|
+
return inco.eRem(s(a), s(b));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/// @notice Remainder of an encrypted uint256 and a plaintext uint256
|
|
184
|
+
/// @param a Encrypted dividend
|
|
185
|
+
/// @param b Plaintext divisor
|
|
186
|
+
/// @return The encrypted remainder
|
|
187
|
+
function rem(euint256 a, uint256 b) internal returns (euint256) {
|
|
188
|
+
return inco.eRem(s(a), asEuint256(b));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// @notice Remainder of a plaintext uint256 and an encrypted uint256
|
|
192
|
+
/// @param a Plaintext dividend
|
|
193
|
+
/// @param b Encrypted divisor
|
|
194
|
+
/// @return The encrypted remainder
|
|
195
|
+
function rem(uint256 a, euint256 b) internal returns (euint256) {
|
|
196
|
+
return inco.eRem(asEuint256(a), s(b));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/// @notice Bitwise AND of two encrypted uint256 values
|
|
200
|
+
/// @param a Encrypted operand
|
|
201
|
+
/// @param b Encrypted operand
|
|
202
|
+
/// @return The encrypted result
|
|
203
|
+
function and(euint256 a, euint256 b) internal returns (euint256) {
|
|
204
|
+
return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/// @notice Bitwise AND of an encrypted uint256 and a plaintext uint256
|
|
208
|
+
/// @param a Encrypted operand
|
|
209
|
+
/// @param b Plaintext operand
|
|
210
|
+
/// @return The encrypted result
|
|
211
|
+
function and(euint256 a, uint256 b) internal returns (euint256) {
|
|
212
|
+
return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/// @notice Bitwise AND of a plaintext uint256 and an encrypted uint256
|
|
216
|
+
/// @param a Plaintext operand
|
|
217
|
+
/// @param b Encrypted operand
|
|
218
|
+
/// @return The encrypted result
|
|
219
|
+
function and(uint256 a, euint256 b) internal returns (euint256) {
|
|
220
|
+
return euint256.wrap(inco.eBitAnd(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// @notice Bitwise AND of two encrypted bool values
|
|
224
|
+
/// @param a Encrypted operand
|
|
225
|
+
/// @param b Encrypted operand
|
|
226
|
+
/// @return The encrypted result
|
|
227
|
+
function and(ebool a, ebool b) internal returns (ebool) {
|
|
228
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/// @notice Bitwise AND of an encrypted bool and a plaintext bool
|
|
232
|
+
/// @param a Encrypted operand
|
|
233
|
+
/// @param b Plaintext operand
|
|
234
|
+
/// @return The encrypted result
|
|
235
|
+
function and(ebool a, bool b) internal returns (ebool) {
|
|
236
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// @notice Bitwise AND of a plaintext bool and an encrypted bool
|
|
240
|
+
/// @param a Plaintext operand
|
|
241
|
+
/// @param b Encrypted operand
|
|
242
|
+
/// @return The encrypted result
|
|
243
|
+
function and(bool a, ebool b) internal returns (ebool) {
|
|
244
|
+
return ebool.wrap(inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/// @notice Bitwise OR of two encrypted uint256 values
|
|
248
|
+
/// @param a Encrypted operand
|
|
249
|
+
/// @param b Encrypted operand
|
|
250
|
+
/// @return The encrypted result
|
|
251
|
+
function or(euint256 a, euint256 b) internal returns (euint256) {
|
|
252
|
+
return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/// @notice Bitwise OR of an encrypted uint256 and a plaintext uint256
|
|
256
|
+
/// @param a Encrypted operand
|
|
257
|
+
/// @param b Plaintext operand
|
|
258
|
+
/// @return The encrypted result
|
|
259
|
+
function or(euint256 a, uint256 b) internal returns (euint256) {
|
|
260
|
+
return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/// @notice Bitwise OR of a plaintext uint256 and an encrypted uint256
|
|
264
|
+
/// @param a Plaintext operand
|
|
265
|
+
/// @param b Encrypted operand
|
|
266
|
+
/// @return The encrypted result
|
|
267
|
+
function or(uint256 a, euint256 b) internal returns (euint256) {
|
|
268
|
+
return euint256.wrap(inco.eBitOr(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/// @notice Bitwise OR of two encrypted bool values
|
|
272
|
+
/// @param a Encrypted operand
|
|
273
|
+
/// @param b Encrypted operand
|
|
274
|
+
/// @return The encrypted result
|
|
275
|
+
function or(ebool a, ebool b) internal returns (ebool) {
|
|
276
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/// @notice Bitwise OR of an encrypted bool and a plaintext bool
|
|
280
|
+
/// @param a Encrypted operand
|
|
281
|
+
/// @param b Plaintext operand
|
|
282
|
+
/// @return The encrypted result
|
|
283
|
+
function or(ebool a, bool b) internal returns (ebool) {
|
|
284
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/// @notice Bitwise OR of a plaintext bool and an encrypted bool
|
|
288
|
+
/// @param a Plaintext operand
|
|
289
|
+
/// @param b Encrypted operand
|
|
290
|
+
/// @return The encrypted result
|
|
291
|
+
function or(bool a, ebool b) internal returns (ebool) {
|
|
292
|
+
return ebool.wrap(inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/// @notice Bitwise XOR of two encrypted uint256 values
|
|
296
|
+
/// @param a Encrypted operand
|
|
297
|
+
/// @param b Encrypted operand
|
|
298
|
+
/// @return The encrypted result
|
|
299
|
+
function xor(euint256 a, euint256 b) internal returns (euint256) {
|
|
300
|
+
return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/// @notice Bitwise XOR of an encrypted uint256 and a plaintext uint256
|
|
304
|
+
/// @param a Encrypted operand
|
|
305
|
+
/// @param b Plaintext operand
|
|
306
|
+
/// @return The encrypted result
|
|
307
|
+
function xor(euint256 a, uint256 b) internal returns (euint256) {
|
|
308
|
+
return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/// @notice Bitwise XOR of a plaintext uint256 and an encrypted uint256
|
|
312
|
+
/// @param a Plaintext operand
|
|
313
|
+
/// @param b Encrypted operand
|
|
314
|
+
/// @return The encrypted result
|
|
315
|
+
function xor(uint256 a, euint256 b) internal returns (euint256) {
|
|
316
|
+
return euint256.wrap(inco.eBitXor(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/// @notice Bitwise XOR of two encrypted bool values
|
|
320
|
+
/// @param a First operand
|
|
321
|
+
/// @param b Second operand
|
|
322
|
+
/// @return The encrypted result
|
|
323
|
+
function xor(ebool a, ebool b) internal returns (ebool) {
|
|
324
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/// @notice Bitwise XOR of an encrypted bool and a plaintext bool
|
|
328
|
+
/// @param a Encrypted operand
|
|
329
|
+
/// @param b Plaintext operand
|
|
330
|
+
/// @return The encrypted result
|
|
331
|
+
function xor(ebool a, bool b) internal returns (ebool) {
|
|
332
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/// @notice Bitwise XOR of a plaintext bool and an encrypted bool
|
|
336
|
+
/// @param a Plaintext operand
|
|
337
|
+
/// @param b Encrypted operand
|
|
338
|
+
/// @return The encrypted result
|
|
339
|
+
function xor(bool a, ebool b) internal returns (ebool) {
|
|
340
|
+
return ebool.wrap(inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/// @notice Left shift of two encrypted uint256 values
|
|
344
|
+
/// @param a Encrypted value to shift
|
|
345
|
+
/// @param b Encrypted shift amount
|
|
346
|
+
/// @return The encrypted result
|
|
347
|
+
function shl(euint256 a, euint256 b) internal returns (euint256) {
|
|
348
|
+
return inco.eShl(s(a), s(b));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/// @notice Left shift of an encrypted uint256 by a plaintext uint256
|
|
352
|
+
/// @param a Encrypted value to shift
|
|
353
|
+
/// @param b Plaintext shift amount
|
|
354
|
+
/// @return The encrypted result
|
|
355
|
+
function shl(euint256 a, uint256 b) internal returns (euint256) {
|
|
356
|
+
return inco.eShl(s(a), asEuint256(b));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/// @notice Left shift of a plaintext uint256 by an encrypted uint256
|
|
360
|
+
/// @param a Plaintext value to shift
|
|
361
|
+
/// @param b Encrypted shift amount
|
|
362
|
+
/// @return The encrypted result
|
|
363
|
+
function shl(uint256 a, euint256 b) internal returns (euint256) {
|
|
364
|
+
return inco.eShl(asEuint256(a), s(b));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/// @notice Right shift of two encrypted uint256 values
|
|
368
|
+
/// @param a Encrypted value to shift
|
|
369
|
+
/// @param b Encrypted shift amount
|
|
370
|
+
/// @return The encrypted result
|
|
371
|
+
function shr(euint256 a, euint256 b) internal returns (euint256) {
|
|
372
|
+
return inco.eShr(s(a), s(b));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/// @notice Right shift of an encrypted uint256 by a plaintext uint256
|
|
376
|
+
/// @param a Encrypted value to shift
|
|
377
|
+
/// @param b Plaintext shift amount
|
|
378
|
+
/// @return The encrypted result
|
|
379
|
+
function shr(euint256 a, uint256 b) internal returns (euint256) {
|
|
380
|
+
return inco.eShr(s(a), asEuint256(b));
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/// @notice Right shift of a plaintext uint256 by an encrypted uint256
|
|
384
|
+
/// @param a Plaintext value to shift
|
|
385
|
+
/// @param b Encrypted shift amount
|
|
386
|
+
/// @return The encrypted result
|
|
387
|
+
function shr(uint256 a, euint256 b) internal returns (euint256) {
|
|
388
|
+
return inco.eShr(asEuint256(a), s(b));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/// @notice Left rotate of two encrypted uint256 values
|
|
392
|
+
/// @param a Encrypted value to rotate
|
|
393
|
+
/// @param b Encrypted rotate amount
|
|
394
|
+
/// @return The encrypted result
|
|
395
|
+
function rotl(euint256 a, euint256 b) internal returns (euint256) {
|
|
396
|
+
return inco.eRotl(s(a), s(b));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/// @notice Left rotate of an encrypted uint256 by a plaintext uint256
|
|
400
|
+
/// @param a Encrypted value to rotate
|
|
401
|
+
/// @param b Plaintext rotate amount
|
|
402
|
+
/// @return The encrypted result
|
|
403
|
+
function rotl(euint256 a, uint256 b) internal returns (euint256) {
|
|
404
|
+
return inco.eRotl(s(a), asEuint256(b));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/// @notice Left rotate of a plaintext uint256 by an encrypted uint256
|
|
408
|
+
/// @param a Plaintext value to rotate
|
|
409
|
+
/// @param b Encrypted rotate amount
|
|
410
|
+
/// @return The encrypted result
|
|
411
|
+
function rotl(uint256 a, euint256 b) internal returns (euint256) {
|
|
412
|
+
return inco.eRotl(asEuint256(a), s(b));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/// @notice Right rotate of two encrypted uint256 values
|
|
416
|
+
/// @param a Encrypted value to rotate
|
|
417
|
+
/// @param b Encrypted rotate amount
|
|
418
|
+
/// @return The encrypted result
|
|
419
|
+
function rotr(euint256 a, euint256 b) internal returns (euint256) {
|
|
420
|
+
return inco.eRotr(s(a), s(b));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/// @notice Right rotate of an encrypted uint256 by a plaintext uint256
|
|
424
|
+
/// @param a Encrypted value to rotate
|
|
425
|
+
/// @param b Plaintext rotate amount
|
|
426
|
+
/// @return The encrypted result
|
|
427
|
+
function rotr(euint256 a, uint256 b) internal returns (euint256) {
|
|
428
|
+
return inco.eRotr(s(a), asEuint256(b));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/// @notice Right rotate of a plaintext uint256 by an encrypted uint256
|
|
432
|
+
/// @param a Plaintext value to rotate
|
|
433
|
+
/// @param b Encrypted rotate amount
|
|
434
|
+
/// @return The encrypted result
|
|
435
|
+
function rotr(uint256 a, euint256 b) internal returns (euint256) {
|
|
436
|
+
return inco.eRotr(asEuint256(a), s(b));
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/// @notice Checks equality of two encrypted uint256 values
|
|
440
|
+
/// @param a Encrypted operand
|
|
441
|
+
/// @param b Encrypted operand
|
|
442
|
+
/// @return The encrypted bool result
|
|
443
|
+
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
444
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/// @notice Checks equality of an encrypted uint256 and a plaintext uint256
|
|
448
|
+
/// @param a Encrypted operand
|
|
449
|
+
/// @param b Plaintext operand
|
|
450
|
+
/// @return The encrypted bool result
|
|
451
|
+
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
452
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/// @notice Checks equality of a plaintext uint256 and an encrypted uint256
|
|
456
|
+
/// @param a Plaintext operand
|
|
457
|
+
/// @param b Encrypted operand
|
|
458
|
+
/// @return The encrypted bool result
|
|
459
|
+
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
460
|
+
return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/// @notice Checks equality of an encrypted address and a plaintext address
|
|
464
|
+
/// @param a Encrypted operand
|
|
465
|
+
/// @param b Plaintext operand
|
|
466
|
+
/// @return The encrypted bool result
|
|
467
|
+
function eq(eaddress a, address b) internal returns (ebool) {
|
|
468
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/// @notice Checks equality of two encrypted addresses
|
|
472
|
+
/// @param a Encrypted operand
|
|
473
|
+
/// @param b Encrypted operand
|
|
474
|
+
/// @return The encrypted bool result
|
|
475
|
+
function eq(eaddress a, eaddress b) internal returns (ebool) {
|
|
476
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/// @notice Checks equality of a plaintext address and an encrypted address
|
|
480
|
+
/// @param a Plaintext operand
|
|
481
|
+
/// @param b Encrypted operand
|
|
482
|
+
/// @return The encrypted bool result
|
|
483
|
+
function eq(address a, eaddress b) internal returns (ebool) {
|
|
484
|
+
return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/// @notice Checks inequality of two encrypted uint256 values
|
|
488
|
+
/// @param a Encrypted operand
|
|
489
|
+
/// @param b Encrypted operand
|
|
490
|
+
/// @return The encrypted bool result
|
|
491
|
+
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
492
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/// @notice Checks inequality of an encrypted uint256 and a plaintext uint256
|
|
496
|
+
/// @param a Encrypted operand
|
|
497
|
+
/// @param b Plaintext operand
|
|
498
|
+
/// @return The encrypted bool result
|
|
499
|
+
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
500
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/// @notice Checks inequality of a plaintext uint256 and an encrypted uint256
|
|
504
|
+
/// @param a Plaintext operand
|
|
505
|
+
/// @param b Encrypted operand
|
|
506
|
+
/// @return The encrypted bool result
|
|
507
|
+
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
508
|
+
return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/// @notice Checks inequality of two encrypted addresses
|
|
512
|
+
/// @param a Encrypted operand
|
|
513
|
+
/// @param b Encrypted operand
|
|
514
|
+
/// @return The encrypted bool result
|
|
515
|
+
function ne(eaddress a, eaddress b) internal returns (ebool) {
|
|
516
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/// @notice Checks inequality of an encrypted address and a plaintext address
|
|
520
|
+
/// @param a Encrypted operand
|
|
521
|
+
/// @param b Plaintext operand
|
|
522
|
+
/// @return The encrypted bool result
|
|
523
|
+
function ne(eaddress a, address b) internal returns (ebool) {
|
|
524
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/// @notice Checks inequality of a plaintext address and an encrypted address
|
|
528
|
+
/// @param a Plaintext operand
|
|
529
|
+
/// @param b Encrypted operand
|
|
530
|
+
/// @return The encrypted bool result
|
|
531
|
+
function ne(address a, eaddress b) internal returns (ebool) {
|
|
532
|
+
return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/// @notice Checks if one encrypted uint256 is greater than or equal to another
|
|
536
|
+
/// @param a Encrypted operand
|
|
537
|
+
/// @param b Encrypted operand
|
|
538
|
+
/// @return The encrypted bool result
|
|
539
|
+
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
540
|
+
return inco.eGe(s(a), s(b));
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/// @notice Checks if an encrypted uint256 is greater than or equal to a plaintext uint256
|
|
544
|
+
/// @param a Encrypted operand
|
|
545
|
+
/// @param b Plaintext operand
|
|
546
|
+
/// @return The encrypted bool result
|
|
547
|
+
function ge(euint256 a, uint256 b) internal returns (ebool) {
|
|
548
|
+
return inco.eGe(s(a), asEuint256(b));
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/// @notice Checks if a plaintext uint256 is greater than or equal to an encrypted uint256
|
|
552
|
+
/// @param a Plaintext operand
|
|
553
|
+
/// @param b Encrypted operand
|
|
554
|
+
/// @return The encrypted bool result
|
|
555
|
+
function ge(uint256 a, euint256 b) internal returns (ebool) {
|
|
556
|
+
return inco.eGe(asEuint256(a), s(b));
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/// @notice Checks if one encrypted uint256 is greater than another
|
|
560
|
+
/// @param a Encrypted operand
|
|
561
|
+
/// @param b Encrypted operand
|
|
562
|
+
/// @return The encrypted bool result
|
|
563
|
+
function gt(euint256 a, euint256 b) internal returns (ebool) {
|
|
564
|
+
return inco.eGt(s(a), s(b));
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/// @notice Checks if an encrypted uint256 is greater than a plaintext uint256
|
|
568
|
+
/// @param a Encrypted operand
|
|
569
|
+
/// @param b Plaintext operand
|
|
570
|
+
/// @return The encrypted bool result
|
|
571
|
+
function gt(euint256 a, uint256 b) internal returns (ebool) {
|
|
572
|
+
return inco.eGt(s(a), asEuint256(b));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/// @notice Checks if a plaintext uint256 is greater than an encrypted uint256
|
|
576
|
+
/// @param a Plaintext operand
|
|
577
|
+
/// @param b Encrypted operand
|
|
578
|
+
/// @return The encrypted bool result
|
|
579
|
+
function gt(uint256 a, euint256 b) internal returns (ebool) {
|
|
580
|
+
return inco.eGt(asEuint256(a), s(b));
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/// @notice Checks if one encrypted uint256 is less than or equal to another
|
|
584
|
+
/// @param a Encrypted operand
|
|
585
|
+
/// @param b Encrypted operand
|
|
586
|
+
/// @return The encrypted bool result
|
|
587
|
+
function le(euint256 a, euint256 b) internal returns (ebool) {
|
|
588
|
+
return inco.eLe(s(a), s(b));
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/// @notice Checks if an encrypted uint256 is less than or equal to a plaintext uint256
|
|
592
|
+
/// @param a Encrypted operand
|
|
593
|
+
/// @param b Plaintext operand
|
|
594
|
+
/// @return The encrypted bool result
|
|
595
|
+
function le(euint256 a, uint256 b) internal returns (ebool) {
|
|
596
|
+
return inco.eLe(s(a), asEuint256(b));
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/// @notice Checks if a plaintext uint256 is less than or equal to an encrypted uint256
|
|
600
|
+
/// @param a Plaintext operand
|
|
601
|
+
/// @param b Encrypted operand
|
|
602
|
+
/// @return The encrypted bool result
|
|
603
|
+
function le(uint256 a, euint256 b) internal returns (ebool) {
|
|
604
|
+
return inco.eLe(asEuint256(a), s(b));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/// @notice Checks if one encrypted uint256 is less than another
|
|
608
|
+
/// @param a Encrypted operand
|
|
609
|
+
/// @param b Encrypted operand
|
|
610
|
+
/// @return The encrypted bool result
|
|
611
|
+
function lt(euint256 a, euint256 b) internal returns (ebool) {
|
|
612
|
+
return inco.eLt(s(a), s(b));
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/// @notice Checks if an encrypted uint256 is less than a plaintext uint256
|
|
616
|
+
/// @param a Encrypted operand
|
|
617
|
+
/// @param b Plaintext operand
|
|
618
|
+
/// @return The encrypted bool result
|
|
619
|
+
function lt(euint256 a, uint256 b) internal returns (ebool) {
|
|
620
|
+
return inco.eLt(s(a), asEuint256(b));
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/// @notice Checks if a plaintext uint256 is less than an encrypted uint256
|
|
624
|
+
/// @param a Plaintext operand
|
|
625
|
+
/// @param b Encrypted operand
|
|
626
|
+
/// @return The encrypted bool result
|
|
627
|
+
function lt(uint256 a, euint256 b) internal returns (ebool) {
|
|
628
|
+
return inco.eLt(asEuint256(a), s(b));
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/// @notice Returns the minimum of two encrypted uint256 values
|
|
632
|
+
/// @param a Encrypted operand
|
|
633
|
+
/// @param b Encrypted operand
|
|
634
|
+
/// @return The encrypted minimum
|
|
635
|
+
function min(euint256 a, euint256 b) internal returns (euint256) {
|
|
636
|
+
return inco.eMin(s(a), s(b));
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/// @notice Returns the minimum of an encrypted uint256 and a plaintext uint256
|
|
640
|
+
/// @param a Encrypted operand
|
|
641
|
+
/// @param b Plaintext operand
|
|
642
|
+
/// @return The encrypted minimum
|
|
643
|
+
function min(euint256 a, uint256 b) internal returns (euint256) {
|
|
644
|
+
return inco.eMin(s(a), asEuint256(b));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/// @notice Returns the minimum of a plaintext uint256 and an encrypted uint256
|
|
648
|
+
/// @param a Plaintext operand
|
|
649
|
+
/// @param b Encrypted operand
|
|
650
|
+
/// @return The encrypted minimum
|
|
651
|
+
function min(uint256 a, euint256 b) internal returns (euint256) {
|
|
652
|
+
return inco.eMin(asEuint256(a), s(b));
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/// @notice Returns the maximum of two encrypted uint256 values
|
|
656
|
+
/// @param a Encrypted operand
|
|
657
|
+
/// @param b Encrypted operand
|
|
658
|
+
/// @return The encrypted maximum
|
|
659
|
+
function max(euint256 a, euint256 b) internal returns (euint256) {
|
|
660
|
+
return inco.eMax(s(a), s(b));
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/// @notice Returns the maximum of an encrypted uint256 and a plaintext uint256
|
|
664
|
+
/// @param a Encrypted operand
|
|
665
|
+
/// @param b Plaintext operand
|
|
666
|
+
/// @return The encrypted maximum
|
|
667
|
+
function max(euint256 a, uint256 b) internal returns (euint256) {
|
|
668
|
+
return inco.eMax(s(a), asEuint256(b));
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/// @notice Returns the maximum of a plaintext uint256 and an encrypted uint256
|
|
672
|
+
/// @param a Plaintext operand
|
|
673
|
+
/// @param b Encrypted operand
|
|
674
|
+
/// @return The encrypted maximum
|
|
675
|
+
function max(uint256 a, euint256 b) internal returns (euint256) {
|
|
676
|
+
return inco.eMax(asEuint256(a), s(b));
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
/// @notice Bitwise NOT of an encrypted bool
|
|
680
|
+
/// @param a Encrypted operand
|
|
681
|
+
/// @return The encrypted result
|
|
682
|
+
function not(ebool a) internal returns (ebool) {
|
|
683
|
+
return inco.eNot(s(a));
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/// @notice Generates a random encrypted uint256 (costs the inco fee)
|
|
687
|
+
/// @dev costs the inco fee
|
|
688
|
+
/// @return The encrypted random value
|
|
689
|
+
function rand() internal returns (euint256) {
|
|
690
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.eRand.selector, ETypes.Uint256));
|
|
691
|
+
return euint256.wrap(result);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/// @notice Generates a random encrypted uint256 less than a plaintext upper bound (costs the inco fee)
|
|
695
|
+
/// @dev costs the inco fee
|
|
696
|
+
/// @param upperBound The plaintext upper bound
|
|
697
|
+
/// @return The encrypted random value
|
|
698
|
+
function randBounded(uint256 upperBound) internal returns (euint256) {
|
|
699
|
+
bytes32 boundHandle = euint256.unwrap(asEuint256(upperBound));
|
|
700
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.eRandBounded.selector, boundHandle, ETypes.Uint256));
|
|
701
|
+
return euint256.wrap(result);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
/// @notice Generates a random encrypted uint256 less than an encrypted upper bound (costs the inco fee)
|
|
705
|
+
/// @dev costs the inco fee
|
|
706
|
+
/// @param upperBound The encrypted upper bound
|
|
707
|
+
/// @return The encrypted random value
|
|
708
|
+
function randBounded(euint256 upperBound) internal returns (euint256) {
|
|
709
|
+
bytes32 boundHandle = euint256.unwrap(s(upperBound));
|
|
710
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.eRandBounded.selector, boundHandle, ETypes.Uint256));
|
|
711
|
+
return euint256.wrap(result);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/// @notice Casts a plaintext uint256 to an encrypted uint256
|
|
715
|
+
/// @param a The plaintext value
|
|
716
|
+
/// @return The encrypted value
|
|
717
|
+
function asEuint256(uint256 a) internal returns (euint256) {
|
|
718
|
+
return inco.asEuint256(a);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/// @notice Casts a plaintext bool to an encrypted bool
|
|
722
|
+
/// @param a The plaintext value
|
|
723
|
+
/// @return The encrypted value
|
|
724
|
+
function asEbool(bool a) internal returns (ebool) {
|
|
725
|
+
return inco.asEbool(a);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/// @notice Casts a plaintext address to an encrypted address
|
|
729
|
+
/// @param a The plaintext value
|
|
730
|
+
/// @return The encrypted value
|
|
731
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
732
|
+
return inco.asEaddress(a);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/// @notice Casts an encrypted uint256 to an encrypted bool
|
|
736
|
+
/// @param a The encrypted uint256 value
|
|
737
|
+
/// @return The encrypted bool value
|
|
738
|
+
function asEbool(euint256 a) internal returns (ebool) {
|
|
739
|
+
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/// @notice Casts an encrypted bool to an encrypted uint256
|
|
743
|
+
/// @param a The encrypted bool value
|
|
744
|
+
/// @return The encrypted uint256 value
|
|
745
|
+
function asEuint256(ebool a) internal returns (euint256) {
|
|
746
|
+
return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/// @notice Creates a new encrypted uint256 assuming msg.sender is the user
|
|
750
|
+
/// @dev costs the inco fee
|
|
751
|
+
function newEuint256(bytes memory ciphertext) internal returns (euint256) {
|
|
752
|
+
return newEuint256(ciphertext, msg.sender);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/// @notice Creates a new encrypted uint256 for the given user.
|
|
756
|
+
/// @dev costs the inco fee
|
|
757
|
+
function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
|
|
758
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.newEuint256.selector, ciphertext, user));
|
|
759
|
+
return euint256.wrap(result);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/// @notice Creates a new encrypted bool assuming msg.sender is the user
|
|
763
|
+
/// @dev costs the inco fee
|
|
764
|
+
function newEbool(bytes memory ciphertext) internal returns (ebool) {
|
|
765
|
+
return newEbool(ciphertext, msg.sender);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/// @notice Creates a new encrypted bool for the given user.
|
|
769
|
+
/// @dev costs the inco fee
|
|
770
|
+
function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
|
|
771
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.newEbool.selector, ciphertext, user));
|
|
772
|
+
return ebool.wrap(result);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/// @notice Creates a new encrypted address assuming msg.sender is the user
|
|
776
|
+
/// @dev costs the inco fee
|
|
777
|
+
function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
|
|
778
|
+
return newEaddress(ciphertext, msg.sender);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/// @notice Creates a new encrypted address for the given user.
|
|
782
|
+
/// @dev costs the inco fee
|
|
783
|
+
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
784
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.newEaddress.selector, ciphertext, user));
|
|
785
|
+
return eaddress.wrap(result);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
/// @notice Allows an address to access an encrypted uint256
|
|
789
|
+
/// @param a The encrypted uint256
|
|
790
|
+
/// @param to The address to allow
|
|
791
|
+
function allow(euint256 a, address to) internal {
|
|
792
|
+
inco.allow(euint256.unwrap(a), to);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/// @notice Allows an address to access an encrypted bool
|
|
796
|
+
/// @param a The encrypted bool
|
|
797
|
+
/// @param to The address to allow
|
|
798
|
+
function allow(ebool a, address to) internal {
|
|
799
|
+
inco.allow(ebool.unwrap(a), to);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/// @notice Allows an address to access an encrypted address
|
|
803
|
+
/// @param a The encrypted address
|
|
804
|
+
/// @param to The address to allow
|
|
805
|
+
function allow(eaddress a, address to) internal {
|
|
806
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/// @notice Reveals an encrypted uint256
|
|
810
|
+
/// @param a The encrypted uint256
|
|
811
|
+
function reveal(euint256 a) internal {
|
|
812
|
+
inco.reveal(euint256.unwrap(a));
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/// @notice Reveals an encrypted bool
|
|
816
|
+
/// @param a The encrypted bool
|
|
817
|
+
function reveal(ebool a) internal {
|
|
818
|
+
inco.reveal(ebool.unwrap(a));
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/// @notice Reveals an encrypted address
|
|
822
|
+
/// @param a The encrypted address
|
|
823
|
+
function reveal(eaddress a) internal {
|
|
824
|
+
inco.reveal(eaddress.unwrap(a));
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/// @notice Verifies a decryption attestation for a euint256
|
|
828
|
+
/// @param handle The encrypted handle
|
|
829
|
+
/// @param value The claimed decrypted value
|
|
830
|
+
/// @param signatures The covalidator signatures
|
|
831
|
+
/// @return True if the attestation is valid
|
|
832
|
+
function verifyDecryption(euint256 handle, uint256 value, bytes[] memory signatures) internal view returns (bool) {
|
|
833
|
+
DecryptionAttestation memory attestation = DecryptionAttestation({handle: euint256.unwrap(handle), value: bytes32(value)});
|
|
834
|
+
return inco.incoVerifier().isValidDecryptionAttestation(attestation, signatures);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/// @notice Verifies a decryption attestation for an ebool
|
|
838
|
+
/// @param handle The encrypted handle
|
|
839
|
+
/// @param value The claimed decrypted value
|
|
840
|
+
/// @param signatures The covalidator signatures
|
|
841
|
+
/// @return True if the attestation is valid
|
|
842
|
+
function verifyDecryption(ebool handle, bool value, bytes[] memory signatures) internal view returns (bool) {
|
|
843
|
+
DecryptionAttestation memory attestation = DecryptionAttestation({handle: ebool.unwrap(handle), value: value ? bytes32(uint256(1)) : bytes32(0)});
|
|
844
|
+
return inco.incoVerifier().isValidDecryptionAttestation(attestation, signatures);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/// @notice Allows this contract to access an encrypted uint256
|
|
848
|
+
/// @param a The encrypted uint256
|
|
849
|
+
function allowThis(euint256 a) internal {
|
|
850
|
+
allow(a, address(this));
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
/// @notice Allows this contract to access an encrypted bool
|
|
854
|
+
/// @param a The encrypted bool
|
|
855
|
+
function allowThis(ebool a) internal {
|
|
856
|
+
allow(a, address(this));
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/// @notice Allows this contract to access an encrypted address
|
|
860
|
+
/// @param a The encrypted address
|
|
861
|
+
function allowThis(eaddress a) internal {
|
|
862
|
+
allow(a, address(this));
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/// @notice Checks if a user is allowed to access an encrypted uint256
|
|
866
|
+
/// @param user The address to check
|
|
867
|
+
/// @param a The encrypted uint256
|
|
868
|
+
/// @return True if allowed, false otherwise
|
|
869
|
+
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
870
|
+
return inco.isAllowed(euint256.unwrap(a), user);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/// @notice Selects between two encrypted uint256 values based on an encrypted bool
|
|
874
|
+
/// @param control The encrypted bool condition
|
|
875
|
+
/// @param ifTrue Value if control is true
|
|
876
|
+
/// @param ifFalse Value if control is false
|
|
877
|
+
/// @return The selected encrypted uint256
|
|
878
|
+
function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
|
|
879
|
+
return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/// @notice Selects between two encrypted bool values based on an encrypted bool
|
|
883
|
+
/// @param control The encrypted bool condition
|
|
884
|
+
/// @param ifTrue Value if control is true
|
|
885
|
+
/// @param ifFalse Value if control is false
|
|
886
|
+
/// @return The selected encrypted bool
|
|
887
|
+
function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
|
|
888
|
+
return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/// @notice Selects between two encrypted addresses based on an encrypted bool
|
|
892
|
+
/// @param control The encrypted bool condition
|
|
893
|
+
/// @param ifTrue Value if control is true
|
|
894
|
+
/// @param ifFalse Value if control is false
|
|
895
|
+
/// @return The selected encrypted address
|
|
896
|
+
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
897
|
+
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
/// @dev Store fee in the custom slot
|
|
901
|
+
/// @param _fee The fee to store
|
|
902
|
+
function _setFee(uint256 _fee) private {
|
|
903
|
+
bytes32 slot = FEE_SLOT;
|
|
904
|
+
assembly {
|
|
905
|
+
sstore(slot, _fee)
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/// @dev Retrieve fee from the custom slot
|
|
910
|
+
/// @return fee The stored fee
|
|
911
|
+
function _getFee() private view returns (uint256 fee) {
|
|
912
|
+
bytes32 slot = FEE_SLOT;
|
|
913
|
+
assembly {
|
|
914
|
+
fee := sload(slot)
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/// @dev Get current fee with fallback to inco.getFee() if not cached
|
|
919
|
+
function getCurrentFee() private returns (uint256) {
|
|
920
|
+
uint256 cachedFee = _getFee();
|
|
921
|
+
if (cachedFee == 0) {
|
|
922
|
+
cachedFee = inco.getFee();
|
|
923
|
+
_setFee(cachedFee);
|
|
924
|
+
}
|
|
925
|
+
return cachedFee;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/// @dev Execute a call to inco with fee, retrying with fresh fee if it fails
|
|
929
|
+
/// @param callData The encoded function call (use abi.encodeWithSelector)
|
|
930
|
+
/// @return result The bytes32 result from the call
|
|
931
|
+
function _callWithFeeRetry(bytes memory callData) private returns (bytes32) {
|
|
932
|
+
uint256 fee = getCurrentFee();
|
|
933
|
+
(bool success, bytes memory result) = address(inco).call{value: fee}(callData);
|
|
934
|
+
if (!success) {
|
|
935
|
+
fee = inco.getFee();
|
|
936
|
+
_setFee(fee);
|
|
937
|
+
(success, result) = address(inco).call{value: fee}(callData);
|
|
938
|
+
require(success, CallFailedAfterFeeRefresh());
|
|
939
|
+
}
|
|
940
|
+
return abi.decode(result, (bytes32));
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
/// @notice Returns the type of the elements contained within the list.
|
|
944
|
+
/// @param handle EList handle to read container type from.
|
|
945
|
+
/// @return ret Type of each element in the list.
|
|
946
|
+
function listTypeOf(elist handle) internal pure returns (ETypes ret) {
|
|
947
|
+
return ETypes(uint8(uint256(elist.unwrap(handle)) >> 16));
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/// @notice Creates a new empty list. Type must be specified ahead of time and can not be changed.
|
|
951
|
+
/// @param listType Type of each element in the list.
|
|
952
|
+
/// @return ret A new elist handle
|
|
953
|
+
function newEList(ETypes listType) internal returns (elist ret) {
|
|
954
|
+
return inco.newEList(new bytes32[](0), listType);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/// @notice Creates a new list from existing array of handles.
|
|
958
|
+
/// @param handles An array of handles to create a new list from
|
|
959
|
+
/// @param listType Type of each element in the list.
|
|
960
|
+
/// @return ret A new elist handle
|
|
961
|
+
function newEList(bytes32[] memory handles, ETypes listType) internal returns (elist ret) {
|
|
962
|
+
return inco.newEList(handles, listType);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/// @notice Takes an array of user encrypted ciphertexts and returns a new elist handle.
|
|
966
|
+
/// @param ciphertexts An array of encrypted user inputs
|
|
967
|
+
/// @param listType Expected type of each element in the list.
|
|
968
|
+
/// @param user Address of the user encrypting the ciphertexts.
|
|
969
|
+
/// @return ret A new elist handle
|
|
970
|
+
/// @dev each ciphertext costs the inco fee
|
|
971
|
+
function newEList(bytes[] memory ciphertexts, ETypes listType, address user) internal returns (elist ret) {
|
|
972
|
+
return inco.newEList{value: inco.getFee() * ciphertexts.length}(ciphertexts, listType, user);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/// @notice Appends an ebool element at the end of a list.
|
|
976
|
+
/// @param a An elist handle to append to.
|
|
977
|
+
/// @param b Element value to be appended.
|
|
978
|
+
/// @return ret A new elist handle with length len(a)+1.
|
|
979
|
+
function append(elist a, ebool b) internal returns (elist ret) {
|
|
980
|
+
return inco.listAppend(a, ebool.unwrap(s(b)));
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/// @notice Appends an euint256 element at the end of a list.
|
|
984
|
+
/// @param a An elist handle to append to.
|
|
985
|
+
/// @param b Element value to be appended.
|
|
986
|
+
/// @return ret A new elist handle with length len(a)+1.
|
|
987
|
+
function append(elist a, euint256 b) internal returns (elist ret) {
|
|
988
|
+
return inco.listAppend(a, euint256.unwrap(s(b)));
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
/// @notice Replaces an element at some hidden index "i" (ebool variant).
|
|
992
|
+
/// @param a EList handle to modify element in.
|
|
993
|
+
/// @param i Hidden index position of an element to modify.
|
|
994
|
+
/// @param b Element value to be changed.
|
|
995
|
+
/// @return ret A new elist handle
|
|
996
|
+
function set(elist a, euint256 i, ebool b) internal returns (elist ret) {
|
|
997
|
+
return inco.listSet(a, euint256.unwrap(s(i)), ebool.unwrap(s(b)));
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/// @notice Replaces an element at some hidden index "i" (euint256 variant).
|
|
1001
|
+
/// @param a EList handle to modify element in.
|
|
1002
|
+
/// @param i Hidden index position of an element to modify.
|
|
1003
|
+
/// @param b Element value to be changed.
|
|
1004
|
+
/// @return ret A new elist handle
|
|
1005
|
+
function set(elist a, euint256 i, euint256 b) internal returns (elist ret) {
|
|
1006
|
+
return inco.listSet(a, euint256.unwrap(s(i)), euint256.unwrap(s(b)));
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/// @notice Replaces an element at plaintext index "i" (ebool variant). Reverts if out of range.
|
|
1010
|
+
/// @param a EList handle to modify element in.
|
|
1011
|
+
/// @param i Index position of element to modify.
|
|
1012
|
+
/// @param b Element value to be changed.
|
|
1013
|
+
/// @return ret A new elist handle
|
|
1014
|
+
function set(elist a, uint16 i, ebool b) internal returns (elist ret) {
|
|
1015
|
+
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
1016
|
+
return inco.listSet(a, euint256.unwrap(asEuint256(uint256(i))), ebool.unwrap(s(b)));
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
/// @notice Replaces an element at plaintext index "i" (euint256 variant). Reverts if out of range.
|
|
1020
|
+
/// @param a EList handle to modify element in.
|
|
1021
|
+
/// @param i Index position of element to modify.
|
|
1022
|
+
/// @param b Element value to be changed.
|
|
1023
|
+
/// @return ret A new elist handle
|
|
1024
|
+
function set(elist a, uint16 i, euint256 b) internal returns (elist ret) {
|
|
1025
|
+
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
1026
|
+
return inco.listSet(a, euint256.unwrap(asEuint256(uint256(i))), euint256.unwrap(s(b)));
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/// @notice Return hidden element at some hidden position (ebool variant).
|
|
1030
|
+
/// @param a EList handle to get element from.
|
|
1031
|
+
/// @param i Hidden index position to get element at.
|
|
1032
|
+
/// @param defaultValue A default element value returned if index is out of range.
|
|
1033
|
+
/// @return ret A new handle for the element or the defaultValue
|
|
1034
|
+
function getOr(elist a, euint256 i, ebool defaultValue) internal returns (ebool ret) {
|
|
1035
|
+
return ebool.wrap(inco.listGetOr(a, euint256.unwrap(s(i)), ebool.unwrap(s(defaultValue))));
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/// @notice Return hidden element at some hidden position (euint256 variant).
|
|
1039
|
+
/// @param a EList handle to get element from.
|
|
1040
|
+
/// @param i Hidden index position to get element at.
|
|
1041
|
+
/// @param defaultValue A default element value returned if index is out of range.
|
|
1042
|
+
/// @return ret A new handle for the element or the defaultValue
|
|
1043
|
+
function getOr(elist a, euint256 i, euint256 defaultValue) internal returns (euint256 ret) {
|
|
1044
|
+
return euint256.wrap(inco.listGetOr(a, euint256.unwrap(s(i)), euint256.unwrap(s(defaultValue))));
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/// @notice Return hidden element at a known position as ebool.
|
|
1048
|
+
/// @param a EList handle to get element from.
|
|
1049
|
+
/// @param i Index position to get element at.
|
|
1050
|
+
/// @return ret Returns a handle for the element.
|
|
1051
|
+
function getEbool(elist a, uint16 i) internal returns (ebool ret) {
|
|
1052
|
+
return ebool.wrap(inco.listGet(a, i));
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/// @notice Return hidden element at a known position as euint256.
|
|
1056
|
+
/// @param a EList handle to get element from.
|
|
1057
|
+
/// @param i Index position to get element at.
|
|
1058
|
+
/// @return ret Returns a handle for the element.
|
|
1059
|
+
function getEuint256(elist a, uint16 i) internal returns (euint256 ret) {
|
|
1060
|
+
return euint256.wrap(inco.listGet(a, i));
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
/// @notice Inserts a hidden element at a desired hidden position (ebool, hidden index).
|
|
1064
|
+
/// @param a An elist handle to insert into.
|
|
1065
|
+
/// @param i Hidden index position to insert at.
|
|
1066
|
+
/// @param b Element value to be inserted.
|
|
1067
|
+
/// @return ret A new elist handle with length len(a)+1.
|
|
1068
|
+
function insert(elist a, euint256 i, ebool b) internal returns (elist ret) {
|
|
1069
|
+
return inco.listInsert(a, euint256.unwrap(s(i)), ebool.unwrap(s(b)));
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/// @notice Inserts an ebool element at a known position. Reverts if out of range.
|
|
1073
|
+
/// @param a An elist handle to insert into.
|
|
1074
|
+
/// @param i Index position to insert at.
|
|
1075
|
+
/// @param b Element value to be inserted.
|
|
1076
|
+
/// @return ret A new elist handle with length len(a)+1.
|
|
1077
|
+
function insert(elist a, uint16 i, ebool b) internal returns (elist ret) {
|
|
1078
|
+
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
1079
|
+
return inco.listInsert(a, euint256.unwrap(asEuint256(uint256(i))), ebool.unwrap(s(b)));
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/// @notice Inserts a hidden element at a desired hidden position (euint256, hidden index).
|
|
1083
|
+
/// @param a An elist handle to insert into.
|
|
1084
|
+
/// @param i Hidden index position to insert at.
|
|
1085
|
+
/// @param b Element value to be inserted.
|
|
1086
|
+
/// @return ret A new elist handle with length len(a)+1.
|
|
1087
|
+
function insert(elist a, euint256 i, euint256 b) internal returns (elist ret) {
|
|
1088
|
+
return inco.listInsert(a, euint256.unwrap(s(i)), euint256.unwrap(s(b)));
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
/// @notice Inserts a euint256 element at a known position. Reverts if out of range.
|
|
1092
|
+
/// @param a An elist handle to insert into.
|
|
1093
|
+
/// @param i Index position to insert at.
|
|
1094
|
+
/// @param b Element value to be inserted.
|
|
1095
|
+
/// @return ret A new elist handle with length len(a)+1.
|
|
1096
|
+
function insert(elist a, uint16 i, euint256 b) internal returns (elist ret) {
|
|
1097
|
+
require(i < length(a), IndexOutOfRange(i, length(a)));
|
|
1098
|
+
return inco.listInsert(a, euint256.unwrap(asEuint256(uint256(i))), euint256.unwrap(s(b)));
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/// @notice Concatenates two elists into one.
|
|
1102
|
+
/// @param a EList handle to be prepended
|
|
1103
|
+
/// @param b EList handle to be appended
|
|
1104
|
+
/// @return ret A new elist handle with length len(a)+len(b).
|
|
1105
|
+
function concat(elist a, elist b) internal returns (elist ret) {
|
|
1106
|
+
return inco.listConcat(a, b);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/// @notice Slices a list from plaintext start to plaintext end.
|
|
1110
|
+
/// @param a EList handle to be sliced
|
|
1111
|
+
/// @param start Starting index (inclusive).
|
|
1112
|
+
/// @param end End index (exclusive). Must be >= start and within bounds.
|
|
1113
|
+
/// @return ret A new sliced list with length "end-start".
|
|
1114
|
+
function slice(elist a, uint16 start, uint16 end) internal returns (elist ret) {
|
|
1115
|
+
require(end >= start, InvalidRange(start, end));
|
|
1116
|
+
require(end <= length(a), SliceOutOfRange(start, end, length(a)));
|
|
1117
|
+
require(start < length(a), SliceOutOfRange(start, end, length(a)));
|
|
1118
|
+
bytes32 defaultValue;
|
|
1119
|
+
if (ETypes.Uint256 == listTypeOf(a)) {
|
|
1120
|
+
defaultValue = euint256.unwrap(asEuint256(0));
|
|
1121
|
+
} else if (ETypes.Bool == listTypeOf(a)) {
|
|
1122
|
+
defaultValue = ebool.unwrap(asEbool(false));
|
|
1123
|
+
} else {
|
|
1124
|
+
revert UnsupportedListType(listTypeOf(a));
|
|
1125
|
+
}
|
|
1126
|
+
return inco.listSlice(a, euint256.unwrap(asEuint256(start)), end - start, defaultValue);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/// @notice Slices at a hidden index with a specified length (euint256 default).
|
|
1130
|
+
/// @param a EList handle to be sliced.
|
|
1131
|
+
/// @param start Hidden starting index.
|
|
1132
|
+
/// @param len Length of the desired slice.
|
|
1133
|
+
/// @param defaultValue Default value if out of range.
|
|
1134
|
+
/// @return ret A new sliced list with length "len".
|
|
1135
|
+
function sliceLen(elist a, euint256 start, uint16 len, euint256 defaultValue) internal returns (elist ret) {
|
|
1136
|
+
return inco.listSlice(a, euint256.unwrap(s(start)), len, euint256.unwrap(s(defaultValue)));
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
/// @notice Slices at a hidden index with a specified length (ebool default).
|
|
1140
|
+
/// @param a EList handle to be sliced.
|
|
1141
|
+
/// @param start Hidden starting index.
|
|
1142
|
+
/// @param len Length of the desired slice.
|
|
1143
|
+
/// @param defaultValue Default value if out of range.
|
|
1144
|
+
/// @return ret A new sliced list with length "len".
|
|
1145
|
+
function sliceLen(elist a, euint256 start, uint16 len, ebool defaultValue) internal returns (elist ret) {
|
|
1146
|
+
return inco.listSlice(a, euint256.unwrap(s(start)), len, ebool.unwrap(s(defaultValue)));
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/// @notice Creates a new list populated with ordered values from within range.
|
|
1150
|
+
/// @param start Start value of the range, inclusive.
|
|
1151
|
+
/// @param end End of the range, exclusive. Must be >= start.
|
|
1152
|
+
/// @return ret A new elist handle with length "end-start"
|
|
1153
|
+
function range(uint16 start, uint16 end) internal returns (elist ret) {
|
|
1154
|
+
return inco.listRange(start, end);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
/// @notice Deterministically shuffles elements within a list.
|
|
1158
|
+
/// @dev costs the inco fee
|
|
1159
|
+
/// @param a elist handle to be shuffled
|
|
1160
|
+
/// @return ret A new elist handle with elements shuffled
|
|
1161
|
+
function shuffle(elist a) internal returns (elist ret) {
|
|
1162
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.listShuffle.selector, a));
|
|
1163
|
+
return elist.wrap(result);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
/// @notice A convenience function equivalent to range() followed by shuffle().
|
|
1167
|
+
/// @dev costs the inco fee
|
|
1168
|
+
/// @param start Start value of the range, inclusive.
|
|
1169
|
+
/// @param end End of the range, exclusive. Must be >= start.
|
|
1170
|
+
/// @return ret A new elist handle in random order with length "end-start".
|
|
1171
|
+
function shuffledRange(uint16 start, uint16 end) internal returns (elist ret) {
|
|
1172
|
+
elist rangeList = inco.listRange(start, end);
|
|
1173
|
+
bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.listShuffle.selector, rangeList));
|
|
1174
|
+
return elist.wrap(result);
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
/// @notice Reverses the order of elements in a list.
|
|
1178
|
+
/// @param a Elist handle to be reversed
|
|
1179
|
+
/// @return ret A new elist handle with elements in reverse order
|
|
1180
|
+
function reverse(elist a) internal returns (elist ret) {
|
|
1181
|
+
return inco.listReverse(a);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/// @notice Returns the length of the list in plaintext. Pure function, no gas cost.
|
|
1185
|
+
/// @param a EList handle to read the length from
|
|
1186
|
+
/// @return len The length of the list
|
|
1187
|
+
function length(elist a) internal pure returns (uint16 len) {
|
|
1188
|
+
return inco.lengthOf(elist.unwrap(a));
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
/// @notice verifyEListDecryption verifies elist decryption attestation and commitment proof. Each element can be either a pre-computed hash or a commitment-value pair.
|
|
1192
|
+
/// @param elistHandle The elist handle that was decrypted
|
|
1193
|
+
/// @param proofElements Array of proof elements. Each can provide either pairHash directly, or commitment+value to compute the pairHash
|
|
1194
|
+
/// @param proof The expected proof that should match keccak256 of all concatenated pair hashes
|
|
1195
|
+
/// @param signatures Array of signatures from attesters
|
|
1196
|
+
/// @return bool True if verification succeeds
|
|
1197
|
+
/// @dev For privacy, publish only pairHash. For transparency, publish commitment+value. Can mix both in the same array.
|
|
1198
|
+
function verifyEListDecryption(elist elistHandle, ElementDecryptionProof[] memory proofElements, bytes32 proof, bytes[] memory signatures) internal view returns (bool) {
|
|
1199
|
+
return inco.incoVerifier().isValidEListDecryptionAttestation(elist.unwrap(elistHandle), proofElements, proof, signatures);
|
|
1200
|
+
}
|
|
1201
|
+
}
|