@inco/lightning 0.8.0-devnet-4 → 0.8.0-devnet-5

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.
Files changed (40) hide show
  1. package/README.md +59 -1
  2. package/manifest.yaml +22 -0
  3. package/package.json +1 -1
  4. package/src/DeployUtils.sol +71 -25
  5. package/src/IncoLightning.sol +27 -7
  6. package/src/IncoVerifier.sol +18 -1
  7. package/src/Lib.alphanet.sol +390 -3
  8. package/src/Lib.demonet.sol +390 -3
  9. package/src/Lib.devnet.sol +391 -4
  10. package/src/Lib.sol +391 -4
  11. package/src/Lib.template.sol +387 -0
  12. package/src/Lib.testnet.sol +390 -3
  13. package/src/libs/incoLightning_alphanet_v0_297966649.sol +390 -3
  14. package/src/libs/incoLightning_alphanet_v1_725458969.sol +390 -3
  15. package/src/libs/incoLightning_alphanet_v2_976644394.sol +390 -3
  16. package/src/libs/incoLightning_demonet_v0_863421733.sol +390 -3
  17. package/src/libs/incoLightning_demonet_v2_467437523.sol +390 -3
  18. package/src/libs/incoLightning_devnet_v0_340846814.sol +390 -3
  19. package/src/libs/incoLightning_devnet_v1_904635675.sol +390 -3
  20. package/src/libs/incoLightning_devnet_v2_295237520.sol +390 -3
  21. package/src/libs/incoLightning_devnet_v3_976859633.sol +390 -3
  22. package/src/libs/incoLightning_devnet_v4_409204766.sol +921 -0
  23. package/src/libs/incoLightning_testnet_v0_183408998.sol +390 -3
  24. package/src/libs/incoLightning_testnet_v2_889158349.sol +390 -3
  25. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +65 -4
  26. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +71 -5
  27. package/src/lightning-parts/DecryptionAttester.sol +16 -3
  28. package/src/lightning-parts/EncryptedInput.sol +48 -2
  29. package/src/lightning-parts/EncryptedOperations.sol +134 -1
  30. package/src/lightning-parts/Fee.sol +29 -6
  31. package/src/lightning-parts/primitives/EventCounter.sol +36 -5
  32. package/src/lightning-parts/primitives/HandleGeneration.sol +38 -6
  33. package/src/lightning-parts/primitives/HandleMetadata.sol +28 -0
  34. package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
  35. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +10 -0
  36. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +0 -2
  37. package/src/periphery/IncoUtils.sol +1 -0
  38. package/src/periphery/SessionVerifier.sol +35 -7
  39. package/src/test/TestFakeInfra.t.sol +536 -1
  40. package/src/version/IncoLightningConfig.sol +2 -2
@@ -0,0 +1,921 @@
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 } from "../Types.sol";
10
+
11
+ IncoLightning constant inco = IncoLightning(0x4046b737B454b0430FBF29cea070e3337AdE95aD);
12
+ address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
13
+
14
+ /// @notice Returns the ETypes enum value encoded in a handle
15
+ /// @param handle The handle to decode
16
+ /// @return The ETypes value
17
+ function typeOf(bytes32 handle) pure returns (ETypes) {
18
+ return ETypes(uint8(uint256(handle) >> 8));
19
+ }
20
+
21
+ library e {
22
+ error CallFailedAfterFeeRefresh();
23
+
24
+ /// @dev slot to store the fee for inco operations
25
+ bytes32 private constant FEE_SLOT = keccak256("inco.fee");
26
+
27
+ /// @notice Returns a sanitized euint256, replacing zero with asEuint256(0)
28
+ /// @param a The euint256 to sanitize
29
+ /// @return The sanitized euint256
30
+ function sanitize(euint256 a) internal returns (euint256) {
31
+ if (euint256.unwrap(a) == bytes32(0)) {
32
+ return asEuint256(0);
33
+ }
34
+ return a;
35
+ }
36
+
37
+ /// @notice Returns a sanitized ebool, replacing zero with asEbool(false)
38
+ /// @param a The ebool to sanitize
39
+ /// @return The sanitized ebool
40
+ function sanitize(ebool a) internal returns (ebool) {
41
+ if (ebool.unwrap(a) == bytes32(0)) {
42
+ return asEbool(false);
43
+ }
44
+ return a;
45
+ }
46
+
47
+ /// @notice Returns a sanitized eaddress, replacing zero with asEaddress(address(0))
48
+ /// @param a The eaddress to sanitize
49
+ /// @return The sanitized eaddress
50
+ function sanitize(eaddress a) internal returns (eaddress) {
51
+ if (eaddress.unwrap(a) == bytes32(0)) {
52
+ return asEaddress(address(0));
53
+ }
54
+ return a;
55
+ }
56
+
57
+ /// @notice Alias for sanitize(euint256)
58
+ /// @param a The euint256 to sanitize
59
+ /// @return The sanitized euint256
60
+ function s(euint256 a) internal returns (euint256) {
61
+ return sanitize(a);
62
+ }
63
+
64
+ /// @notice Alias for sanitize(ebool)
65
+ /// @param a The ebool to sanitize
66
+ /// @return The sanitized ebool
67
+ function s(ebool a) internal returns (ebool) {
68
+ return sanitize(a);
69
+ }
70
+
71
+ /// @notice Alias for sanitize(eaddress)
72
+ /// @param a The eaddress to sanitize
73
+ /// @return The sanitized eaddress
74
+ function s(eaddress a) internal returns (eaddress) {
75
+ return sanitize(a);
76
+ }
77
+
78
+ /// @notice Adds two encrypted uint256 values
79
+ /// @param a First operand
80
+ /// @param b Second operand
81
+ /// @return The encrypted sum
82
+ function add(euint256 a, euint256 b) internal returns (euint256) {
83
+ return inco.eAdd(s(a), s(b));
84
+ }
85
+
86
+ /// @notice Adds an encrypted uint256 and a plaintext uint256
87
+ /// @param a Encrypted operand
88
+ /// @param b Plaintext operand
89
+ /// @return The encrypted sum
90
+ function add(euint256 a, uint256 b) internal returns (euint256) {
91
+ return inco.eAdd(s(a), asEuint256(b));
92
+ }
93
+
94
+ /// @notice Adds a plaintext uint256 and an encrypted uint256
95
+ /// @param a Plaintext operand
96
+ /// @param b Encrypted operand
97
+ /// @return The encrypted sum
98
+ function add(uint256 a, euint256 b) internal returns (euint256) {
99
+ return inco.eAdd(asEuint256(a), s(b));
100
+ }
101
+
102
+ /// @notice Subtracts two encrypted uint256 values
103
+ /// @param a Encrypted minuend
104
+ /// @param b Encrypted subtrahend
105
+ /// @return The encrypted difference
106
+ function sub(euint256 a, euint256 b) internal returns (euint256) {
107
+ return inco.eSub(s(a), s(b));
108
+ }
109
+
110
+ /// @notice Subtracts a plaintext uint256 from an encrypted uint256
111
+ /// @param a Encrypted minuend
112
+ /// @param b Plaintext subtrahend
113
+ /// @return The encrypted difference
114
+ function sub(euint256 a, uint256 b) internal returns (euint256) {
115
+ return inco.eSub(s(a), asEuint256(b));
116
+ }
117
+
118
+ /// @notice Subtracts an encrypted uint256 from a plaintext uint256
119
+ /// @param a Plaintext minuend
120
+ /// @param b Encrypted subtrahend
121
+ /// @return The encrypted difference
122
+ function sub(uint256 a, euint256 b) internal returns (euint256) {
123
+ return inco.eSub(asEuint256(a), s(b));
124
+ }
125
+
126
+ /// @notice Multiplies two encrypted uint256 values
127
+ /// @param a Encrypted operand
128
+ /// @param b Encrypted operand
129
+ /// @return The encrypted product
130
+ function mul(euint256 a, euint256 b) internal returns (euint256) {
131
+ return inco.eMul(s(a), s(b));
132
+ }
133
+
134
+ /// @notice Multiplies an encrypted uint256 and a plaintext uint256
135
+ /// @param a Encrypted operand
136
+ /// @param b Plaintext operand
137
+ /// @return The encrypted product
138
+ function mul(euint256 a, uint256 b) internal returns (euint256) {
139
+ return inco.eMul(s(a), asEuint256(b));
140
+ }
141
+
142
+ /// @notice Multiplies a plaintext uint256 and an encrypted uint256
143
+ /// @param a Plaintext operand
144
+ /// @param b Encrypted operand
145
+ /// @return The encrypted product
146
+ function mul(uint256 a, euint256 b) internal returns (euint256) {
147
+ return inco.eMul(asEuint256(a), s(b));
148
+ }
149
+
150
+ /// @notice Divides two encrypted uint256 values
151
+ /// @param a Encrypted Dividend
152
+ /// @param b Encrypted Divisor
153
+ /// @return The encrypted quotient
154
+ function div(euint256 a, euint256 b) internal returns (euint256) {
155
+ return inco.eDiv(s(a), s(b));
156
+ }
157
+
158
+ /// @notice Divides an encrypted uint256 by a plaintext uint256
159
+ /// @param a Encrypted dividend
160
+ /// @param b Plaintext divisor
161
+ /// @return The encrypted quotient
162
+ function div(euint256 a, uint256 b) internal returns (euint256) {
163
+ return inco.eDiv(s(a), asEuint256(b));
164
+ }
165
+
166
+ /// @notice Divides a plaintext uint256 by an encrypted uint256
167
+ /// @param a Plaintext dividend
168
+ /// @param b Encrypted divisor
169
+ /// @return The encrypted quotient
170
+ function div(uint256 a, euint256 b) internal returns (euint256) {
171
+ return inco.eDiv(asEuint256(a), s(b));
172
+ }
173
+
174
+ /// @notice Remainder of two encrypted uint256 values
175
+ /// @param a Encrypted dividend
176
+ /// @param b Encrypted divisor
177
+ /// @return The encrypted remainder
178
+ function rem(euint256 a, euint256 b) internal returns (euint256) {
179
+ return inco.eRem(s(a), s(b));
180
+ }
181
+
182
+ /// @notice Remainder of an encrypted uint256 and a plaintext uint256
183
+ /// @param a Encrypted dividend
184
+ /// @param b Plaintext divisor
185
+ /// @return The encrypted remainder
186
+ function rem(euint256 a, uint256 b) internal returns (euint256) {
187
+ return inco.eRem(s(a), asEuint256(b));
188
+ }
189
+
190
+ /// @notice Remainder of a plaintext uint256 and an encrypted uint256
191
+ /// @param a Plaintext dividend
192
+ /// @param b Encrypted divisor
193
+ /// @return The encrypted remainder
194
+ function rem(uint256 a, euint256 b) internal returns (euint256) {
195
+ return inco.eRem(asEuint256(a), s(b));
196
+ }
197
+
198
+ /// @notice Bitwise AND of two encrypted uint256 values
199
+ /// @param a Encrypted operand
200
+ /// @param b Encrypted operand
201
+ /// @return The encrypted result
202
+ function and(euint256 a, euint256 b) internal returns (euint256) {
203
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
204
+ }
205
+
206
+ /// @notice Bitwise AND of an encrypted uint256 and a plaintext uint256
207
+ /// @param a Encrypted operand
208
+ /// @param b Plaintext operand
209
+ /// @return The encrypted result
210
+ function and(euint256 a, uint256 b) internal returns (euint256) {
211
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
212
+ }
213
+
214
+ /// @notice Bitwise AND of a plaintext uint256 and an encrypted uint256
215
+ /// @param a Plaintext operand
216
+ /// @param b Encrypted operand
217
+ /// @return The encrypted result
218
+ function and(uint256 a, euint256 b) internal returns (euint256) {
219
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
220
+ }
221
+
222
+ /// @notice Bitwise AND of two encrypted bool values
223
+ /// @param a Encrypted operand
224
+ /// @param b Encrypted operand
225
+ /// @return The encrypted result
226
+ function and(ebool a, ebool b) internal returns (ebool) {
227
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
228
+ }
229
+
230
+ /// @notice Bitwise AND of an encrypted bool and a plaintext bool
231
+ /// @param a Encrypted operand
232
+ /// @param b Plaintext operand
233
+ /// @return The encrypted result
234
+ function and(ebool a, bool b) internal returns (ebool) {
235
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
236
+ }
237
+
238
+ /// @notice Bitwise AND of a plaintext bool and an encrypted bool
239
+ /// @param a Plaintext operand
240
+ /// @param b Encrypted operand
241
+ /// @return The encrypted result
242
+ function and(bool a, ebool b) internal returns (ebool) {
243
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
244
+ }
245
+
246
+ /// @notice Bitwise OR of two encrypted uint256 values
247
+ /// @param a Encrypted operand
248
+ /// @param b Encrypted operand
249
+ /// @return The encrypted result
250
+ function or(euint256 a, euint256 b) internal returns (euint256) {
251
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
252
+ }
253
+
254
+ /// @notice Bitwise OR of an encrypted uint256 and a plaintext uint256
255
+ /// @param a Encrypted operand
256
+ /// @param b Plaintext operand
257
+ /// @return The encrypted result
258
+ function or(euint256 a, uint256 b) internal returns (euint256) {
259
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
260
+ }
261
+
262
+ /// @notice Bitwise OR of a plaintext uint256 and an encrypted uint256
263
+ /// @param a Plaintext operand
264
+ /// @param b Encrypted operand
265
+ /// @return The encrypted result
266
+ function or(uint256 a, euint256 b) internal returns (euint256) {
267
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
268
+ }
269
+
270
+ /// @notice Bitwise OR of two encrypted bool values
271
+ /// @param a Encrypted operand
272
+ /// @param b Encrypted operand
273
+ /// @return The encrypted result
274
+ function or(ebool a, ebool b) internal returns (ebool) {
275
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
276
+ }
277
+
278
+ /// @notice Bitwise OR of an encrypted bool and a plaintext bool
279
+ /// @param a Encrypted operand
280
+ /// @param b Plaintext operand
281
+ /// @return The encrypted result
282
+ function or(ebool a, bool b) internal returns (ebool) {
283
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
284
+ }
285
+
286
+ /// @notice Bitwise OR of a plaintext bool and an encrypted bool
287
+ /// @param a Plaintext operand
288
+ /// @param b Encrypted operand
289
+ /// @return The encrypted result
290
+ function or(bool a, ebool b) internal returns (ebool) {
291
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
292
+ }
293
+
294
+ /// @notice Bitwise XOR of two encrypted uint256 values
295
+ /// @param a Encrypted operand
296
+ /// @param b Encrypted operand
297
+ /// @return The encrypted result
298
+ function xor(euint256 a, euint256 b) internal returns (euint256) {
299
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
300
+ }
301
+
302
+ /// @notice Bitwise XOR of an encrypted uint256 and a plaintext uint256
303
+ /// @param a Encrypted operand
304
+ /// @param b Plaintext operand
305
+ /// @return The encrypted result
306
+ function xor(euint256 a, uint256 b) internal returns (euint256) {
307
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
308
+ }
309
+
310
+ /// @notice Bitwise XOR of a plaintext uint256 and an encrypted uint256
311
+ /// @param a Plaintext operand
312
+ /// @param b Encrypted operand
313
+ /// @return The encrypted result
314
+ function xor(uint256 a, euint256 b) internal returns (euint256) {
315
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
316
+ }
317
+
318
+ /// @notice Bitwise XOR of two encrypted bool values
319
+ /// @param a First operand
320
+ /// @param b Second operand
321
+ /// @return The encrypted result
322
+ function xor(ebool a, ebool b) internal returns (ebool) {
323
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(s(b))));
324
+ }
325
+
326
+ /// @notice Bitwise XOR of an encrypted bool and a plaintext bool
327
+ /// @param a Encrypted operand
328
+ /// @param b Plaintext operand
329
+ /// @return The encrypted result
330
+ function xor(ebool a, bool b) internal returns (ebool) {
331
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
332
+ }
333
+
334
+ /// @notice Bitwise XOR of a plaintext bool and an encrypted bool
335
+ /// @param a Plaintext operand
336
+ /// @param b Encrypted operand
337
+ /// @return The encrypted result
338
+ function xor(bool a, ebool b) internal returns (ebool) {
339
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
340
+ }
341
+
342
+ /// @notice Left shift of two encrypted uint256 values
343
+ /// @param a Encrypted value to shift
344
+ /// @param b Encrypted shift amount
345
+ /// @return The encrypted result
346
+ function shl(euint256 a, euint256 b) internal returns (euint256) {
347
+ return inco.eShl(s(a), s(b));
348
+ }
349
+
350
+ /// @notice Left shift of an encrypted uint256 by a plaintext uint256
351
+ /// @param a Encrypted value to shift
352
+ /// @param b Plaintext shift amount
353
+ /// @return The encrypted result
354
+ function shl(euint256 a, uint256 b) internal returns (euint256) {
355
+ return inco.eShl(s(a), asEuint256(b));
356
+ }
357
+
358
+ /// @notice Left shift of a plaintext uint256 by an encrypted uint256
359
+ /// @param a Plaintext value to shift
360
+ /// @param b Encrypted shift amount
361
+ /// @return The encrypted result
362
+ function shl(uint256 a, euint256 b) internal returns (euint256) {
363
+ return inco.eShl(asEuint256(a), s(b));
364
+ }
365
+
366
+ /// @notice Right shift of two encrypted uint256 values
367
+ /// @param a Encrypted value to shift
368
+ /// @param b Encrypted shift amount
369
+ /// @return The encrypted result
370
+ function shr(euint256 a, euint256 b) internal returns (euint256) {
371
+ return inco.eShr(s(a), s(b));
372
+ }
373
+
374
+ /// @notice Right shift of an encrypted uint256 by a plaintext uint256
375
+ /// @param a Encrypted value to shift
376
+ /// @param b Plaintext shift amount
377
+ /// @return The encrypted result
378
+ function shr(euint256 a, uint256 b) internal returns (euint256) {
379
+ return inco.eShr(s(a), asEuint256(b));
380
+ }
381
+
382
+ /// @notice Right shift of a plaintext uint256 by an encrypted uint256
383
+ /// @param a Plaintext value to shift
384
+ /// @param b Encrypted shift amount
385
+ /// @return The encrypted result
386
+ function shr(uint256 a, euint256 b) internal returns (euint256) {
387
+ return inco.eShr(asEuint256(a), s(b));
388
+ }
389
+
390
+ /// @notice Left rotate of two encrypted uint256 values
391
+ /// @param a Encrypted value to rotate
392
+ /// @param b Encrypted rotate amount
393
+ /// @return The encrypted result
394
+ function rotl(euint256 a, euint256 b) internal returns (euint256) {
395
+ return inco.eRotl(s(a), s(b));
396
+ }
397
+
398
+ /// @notice Left rotate of an encrypted uint256 by a plaintext uint256
399
+ /// @param a Encrypted value to rotate
400
+ /// @param b Plaintext rotate amount
401
+ /// @return The encrypted result
402
+ function rotl(euint256 a, uint256 b) internal returns (euint256) {
403
+ return inco.eRotl(s(a), asEuint256(b));
404
+ }
405
+
406
+ /// @notice Left rotate of a plaintext uint256 by an encrypted uint256
407
+ /// @param a Plaintext value to rotate
408
+ /// @param b Encrypted rotate amount
409
+ /// @return The encrypted result
410
+ function rotl(uint256 a, euint256 b) internal returns (euint256) {
411
+ return inco.eRotl(asEuint256(a), s(b));
412
+ }
413
+
414
+ /// @notice Right rotate of two encrypted uint256 values
415
+ /// @param a Encrypted value to rotate
416
+ /// @param b Encrypted rotate amount
417
+ /// @return The encrypted result
418
+ function rotr(euint256 a, euint256 b) internal returns (euint256) {
419
+ return inco.eRotr(s(a), s(b));
420
+ }
421
+
422
+ /// @notice Right rotate of an encrypted uint256 by a plaintext uint256
423
+ /// @param a Encrypted value to rotate
424
+ /// @param b Plaintext rotate amount
425
+ /// @return The encrypted result
426
+ function rotr(euint256 a, uint256 b) internal returns (euint256) {
427
+ return inco.eRotr(s(a), asEuint256(b));
428
+ }
429
+
430
+ /// @notice Right rotate of a plaintext uint256 by an encrypted uint256
431
+ /// @param a Plaintext value to rotate
432
+ /// @param b Encrypted rotate amount
433
+ /// @return The encrypted result
434
+ function rotr(uint256 a, euint256 b) internal returns (euint256) {
435
+ return inco.eRotr(asEuint256(a), s(b));
436
+ }
437
+
438
+ /// @notice Checks equality of two encrypted uint256 values
439
+ /// @param a Encrypted operand
440
+ /// @param b Encrypted operand
441
+ /// @return The encrypted bool result
442
+ function eq(euint256 a, euint256 b) internal returns (ebool) {
443
+ return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
444
+ }
445
+
446
+ /// @notice Checks equality of an encrypted uint256 and a plaintext uint256
447
+ /// @param a Encrypted operand
448
+ /// @param b Plaintext operand
449
+ /// @return The encrypted bool result
450
+ function eq(euint256 a, uint256 b) internal returns (ebool) {
451
+ return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
452
+ }
453
+
454
+ /// @notice Checks equality of a plaintext uint256 and an encrypted uint256
455
+ /// @param a Plaintext operand
456
+ /// @param b Encrypted operand
457
+ /// @return The encrypted bool result
458
+ function eq(uint256 a, euint256 b) internal returns (ebool) {
459
+ return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
460
+ }
461
+
462
+ /// @notice Checks equality of an encrypted address and a plaintext address
463
+ /// @param a Encrypted operand
464
+ /// @param b Plaintext operand
465
+ /// @return The encrypted bool result
466
+ function eq(eaddress a, address b) internal returns (ebool) {
467
+ return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
468
+ }
469
+
470
+ /// @notice Checks equality of two encrypted addresses
471
+ /// @param a Encrypted operand
472
+ /// @param b Encrypted operand
473
+ /// @return The encrypted bool result
474
+ function eq(eaddress a, eaddress b) internal returns (ebool) {
475
+ return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
476
+ }
477
+
478
+ /// @notice Checks equality of a plaintext address and an encrypted address
479
+ /// @param a Plaintext operand
480
+ /// @param b Encrypted operand
481
+ /// @return The encrypted bool result
482
+ function eq(address a, eaddress b) internal returns (ebool) {
483
+ return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
484
+ }
485
+
486
+ /// @notice Checks inequality of two encrypted uint256 values
487
+ /// @param a Encrypted operand
488
+ /// @param b Encrypted operand
489
+ /// @return The encrypted bool result
490
+ function ne(euint256 a, euint256 b) internal returns (ebool) {
491
+ return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
492
+ }
493
+
494
+ /// @notice Checks inequality of an encrypted uint256 and a plaintext uint256
495
+ /// @param a Encrypted operand
496
+ /// @param b Plaintext operand
497
+ /// @return The encrypted bool result
498
+ function ne(euint256 a, uint256 b) internal returns (ebool) {
499
+ return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
500
+ }
501
+
502
+ /// @notice Checks inequality of a plaintext uint256 and an encrypted uint256
503
+ /// @param a Plaintext operand
504
+ /// @param b Encrypted operand
505
+ /// @return The encrypted bool result
506
+ function ne(uint256 a, euint256 b) internal returns (ebool) {
507
+ return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
508
+ }
509
+
510
+ /// @notice Checks inequality of two encrypted addresses
511
+ /// @param a Encrypted operand
512
+ /// @param b Encrypted operand
513
+ /// @return The encrypted bool result
514
+ function ne(eaddress a, eaddress b) internal returns (ebool) {
515
+ return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
516
+ }
517
+
518
+ /// @notice Checks inequality of an encrypted address and a plaintext address
519
+ /// @param a Encrypted operand
520
+ /// @param b Plaintext operand
521
+ /// @return The encrypted bool result
522
+ function ne(eaddress a, address b) internal returns (ebool) {
523
+ return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
524
+ }
525
+
526
+ /// @notice Checks inequality of a plaintext address and an encrypted address
527
+ /// @param a Plaintext operand
528
+ /// @param b Encrypted operand
529
+ /// @return The encrypted bool result
530
+ function ne(address a, eaddress b) internal returns (ebool) {
531
+ return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
532
+ }
533
+
534
+ /// @notice Checks if one encrypted uint256 is greater than or equal to another
535
+ /// @param a Encrypted operand
536
+ /// @param b Encrypted operand
537
+ /// @return The encrypted bool result
538
+ function ge(euint256 a, euint256 b) internal returns (ebool) {
539
+ return inco.eGe(s(a), s(b));
540
+ }
541
+
542
+ /// @notice Checks if an encrypted uint256 is greater than or equal to a plaintext uint256
543
+ /// @param a Encrypted operand
544
+ /// @param b Plaintext operand
545
+ /// @return The encrypted bool result
546
+ function ge(euint256 a, uint256 b) internal returns (ebool) {
547
+ return inco.eGe(s(a), asEuint256(b));
548
+ }
549
+
550
+ /// @notice Checks if a plaintext uint256 is greater than or equal to an encrypted uint256
551
+ /// @param a Plaintext operand
552
+ /// @param b Encrypted operand
553
+ /// @return The encrypted bool result
554
+ function ge(uint256 a, euint256 b) internal returns (ebool) {
555
+ return inco.eGe(asEuint256(a), s(b));
556
+ }
557
+
558
+ /// @notice Checks if one encrypted uint256 is greater than another
559
+ /// @param a Encrypted operand
560
+ /// @param b Encrypted operand
561
+ /// @return The encrypted bool result
562
+ function gt(euint256 a, euint256 b) internal returns (ebool) {
563
+ return inco.eGt(s(a), s(b));
564
+ }
565
+
566
+ /// @notice Checks if an encrypted uint256 is greater than a plaintext uint256
567
+ /// @param a Encrypted operand
568
+ /// @param b Plaintext operand
569
+ /// @return The encrypted bool result
570
+ function gt(euint256 a, uint256 b) internal returns (ebool) {
571
+ return inco.eGt(s(a), asEuint256(b));
572
+ }
573
+
574
+ /// @notice Checks if a plaintext uint256 is greater than an encrypted uint256
575
+ /// @param a Plaintext operand
576
+ /// @param b Encrypted operand
577
+ /// @return The encrypted bool result
578
+ function gt(uint256 a, euint256 b) internal returns (ebool) {
579
+ return inco.eGt(asEuint256(a), s(b));
580
+ }
581
+
582
+ /// @notice Checks if one encrypted uint256 is less than or equal to another
583
+ /// @param a Encrypted operand
584
+ /// @param b Encrypted operand
585
+ /// @return The encrypted bool result
586
+ function le(euint256 a, euint256 b) internal returns (ebool) {
587
+ return inco.eLe(s(a), s(b));
588
+ }
589
+
590
+ /// @notice Checks if an encrypted uint256 is less than or equal to a plaintext uint256
591
+ /// @param a Encrypted operand
592
+ /// @param b Plaintext operand
593
+ /// @return The encrypted bool result
594
+ function le(euint256 a, uint256 b) internal returns (ebool) {
595
+ return inco.eLe(s(a), asEuint256(b));
596
+ }
597
+
598
+ /// @notice Checks if a plaintext uint256 is less than or equal to an encrypted uint256
599
+ /// @param a Plaintext operand
600
+ /// @param b Encrypted operand
601
+ /// @return The encrypted bool result
602
+ function le(uint256 a, euint256 b) internal returns (ebool) {
603
+ return inco.eLe(asEuint256(a), s(b));
604
+ }
605
+
606
+ /// @notice Checks if one encrypted uint256 is less than another
607
+ /// @param a Encrypted operand
608
+ /// @param b Encrypted operand
609
+ /// @return The encrypted bool result
610
+ function lt(euint256 a, euint256 b) internal returns (ebool) {
611
+ return inco.eLt(s(a), s(b));
612
+ }
613
+
614
+ /// @notice Checks if an encrypted uint256 is less than a plaintext uint256
615
+ /// @param a Encrypted operand
616
+ /// @param b Plaintext operand
617
+ /// @return The encrypted bool result
618
+ function lt(euint256 a, uint256 b) internal returns (ebool) {
619
+ return inco.eLt(s(a), asEuint256(b));
620
+ }
621
+
622
+ /// @notice Checks if a plaintext uint256 is less than an encrypted uint256
623
+ /// @param a Plaintext operand
624
+ /// @param b Encrypted operand
625
+ /// @return The encrypted bool result
626
+ function lt(uint256 a, euint256 b) internal returns (ebool) {
627
+ return inco.eLt(asEuint256(a), s(b));
628
+ }
629
+
630
+ /// @notice Returns the minimum of two encrypted uint256 values
631
+ /// @param a Encrypted operand
632
+ /// @param b Encrypted operand
633
+ /// @return The encrypted minimum
634
+ function min(euint256 a, euint256 b) internal returns (euint256) {
635
+ return inco.eMin(s(a), s(b));
636
+ }
637
+
638
+ /// @notice Returns the minimum of an encrypted uint256 and a plaintext uint256
639
+ /// @param a Encrypted operand
640
+ /// @param b Plaintext operand
641
+ /// @return The encrypted minimum
642
+ function min(euint256 a, uint256 b) internal returns (euint256) {
643
+ return inco.eMin(s(a), asEuint256(b));
644
+ }
645
+
646
+ /// @notice Returns the minimum of a plaintext uint256 and an encrypted uint256
647
+ /// @param a Plaintext operand
648
+ /// @param b Encrypted operand
649
+ /// @return The encrypted minimum
650
+ function min(uint256 a, euint256 b) internal returns (euint256) {
651
+ return inco.eMin(asEuint256(a), s(b));
652
+ }
653
+
654
+ /// @notice Returns the maximum of two encrypted uint256 values
655
+ /// @param a Encrypted operand
656
+ /// @param b Encrypted operand
657
+ /// @return The encrypted maximum
658
+ function max(euint256 a, euint256 b) internal returns (euint256) {
659
+ return inco.eMax(s(a), s(b));
660
+ }
661
+
662
+ /// @notice Returns the maximum of an encrypted uint256 and a plaintext uint256
663
+ /// @param a Encrypted operand
664
+ /// @param b Plaintext operand
665
+ /// @return The encrypted maximum
666
+ function max(euint256 a, uint256 b) internal returns (euint256) {
667
+ return inco.eMax(s(a), asEuint256(b));
668
+ }
669
+
670
+ /// @notice Returns the maximum of a plaintext uint256 and an encrypted uint256
671
+ /// @param a Plaintext operand
672
+ /// @param b Encrypted operand
673
+ /// @return The encrypted maximum
674
+ function max(uint256 a, euint256 b) internal returns (euint256) {
675
+ return inco.eMax(asEuint256(a), s(b));
676
+ }
677
+
678
+ /// @notice Bitwise NOT of an encrypted bool
679
+ /// @param a Encrypted operand
680
+ /// @return The encrypted result
681
+ function not(ebool a) internal returns (ebool) {
682
+ return inco.eNot(s(a));
683
+ }
684
+
685
+ /// @notice Generates a random encrypted uint256 (costs the inco fee)
686
+ /// @dev costs the inco fee
687
+ /// @return The encrypted random value
688
+ function rand() internal returns (euint256) {
689
+ bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.eRand.selector, ETypes.Uint256));
690
+ return euint256.wrap(result);
691
+ }
692
+
693
+ /// @notice Generates a random encrypted uint256 less than a plaintext upper bound (costs the inco fee)
694
+ /// @dev costs the inco fee
695
+ /// @param upperBound The plaintext upper bound
696
+ /// @return The encrypted random value
697
+ function randBounded(uint256 upperBound) internal returns (euint256) {
698
+ bytes32 boundHandle = euint256.unwrap(asEuint256(upperBound));
699
+ bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.eRandBounded.selector, boundHandle, ETypes.Uint256));
700
+ return euint256.wrap(result);
701
+ }
702
+
703
+ /// @notice Generates a random encrypted uint256 less than an encrypted upper bound (costs the inco fee)
704
+ /// @dev costs the inco fee
705
+ /// @param upperBound The encrypted upper bound
706
+ /// @return The encrypted random value
707
+ function randBounded(euint256 upperBound) internal returns (euint256) {
708
+ bytes32 boundHandle = euint256.unwrap(s(upperBound));
709
+ bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.eRandBounded.selector, boundHandle, ETypes.Uint256));
710
+ return euint256.wrap(result);
711
+ }
712
+
713
+ /// @notice Casts a plaintext uint256 to an encrypted uint256
714
+ /// @param a The plaintext value
715
+ /// @return The encrypted value
716
+ function asEuint256(uint256 a) internal returns (euint256) {
717
+ return inco.asEuint256(a);
718
+ }
719
+
720
+ /// @notice Casts a plaintext bool to an encrypted bool
721
+ /// @param a The plaintext value
722
+ /// @return The encrypted value
723
+ function asEbool(bool a) internal returns (ebool) {
724
+ return inco.asEbool(a);
725
+ }
726
+
727
+ /// @notice Casts a plaintext address to an encrypted address
728
+ /// @param a The plaintext value
729
+ /// @return The encrypted value
730
+ function asEaddress(address a) internal returns (eaddress) {
731
+ return inco.asEaddress(a);
732
+ }
733
+
734
+ /// @notice Casts an encrypted uint256 to an encrypted bool
735
+ /// @param a The encrypted uint256 value
736
+ /// @return The encrypted bool value
737
+ function asEbool(euint256 a) internal returns (ebool) {
738
+ return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
739
+ }
740
+
741
+ /// @notice Casts an encrypted bool to an encrypted uint256
742
+ /// @param a The encrypted bool value
743
+ /// @return The encrypted uint256 value
744
+ function asEuint256(ebool a) internal returns (euint256) {
745
+ return euint256.wrap(inco.eCast(ebool.unwrap(a), ETypes.Uint256));
746
+ }
747
+
748
+ /// @notice Creates a new encrypted uint256 assuming msg.sender is the user
749
+ /// @dev costs the inco fee
750
+ function newEuint256(bytes memory ciphertext) internal returns (euint256) {
751
+ return newEuint256(ciphertext, msg.sender);
752
+ }
753
+
754
+ /// @notice Creates a new encrypted uint256 for the given user.
755
+ /// @dev costs the inco fee
756
+ function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
757
+ bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.newEuint256.selector, ciphertext, user));
758
+ return euint256.wrap(result);
759
+ }
760
+
761
+ /// @notice Creates a new encrypted bool assuming msg.sender is the user
762
+ /// @dev costs the inco fee
763
+ function newEbool(bytes memory ciphertext) internal returns (ebool) {
764
+ return newEbool(ciphertext, msg.sender);
765
+ }
766
+
767
+ /// @notice Creates a new encrypted bool for the given user.
768
+ /// @dev costs the inco fee
769
+ function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
770
+ bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.newEbool.selector, ciphertext, user));
771
+ return ebool.wrap(result);
772
+ }
773
+
774
+ /// @notice Creates a new encrypted address assuming msg.sender is the user
775
+ /// @dev costs the inco fee
776
+ function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
777
+ return newEaddress(ciphertext, msg.sender);
778
+ }
779
+
780
+ /// @notice Creates a new encrypted address for the given user.
781
+ /// @dev costs the inco fee
782
+ function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
783
+ bytes32 result = _callWithFeeRetry(abi.encodeWithSelector(inco.newEaddress.selector, ciphertext, user));
784
+ return eaddress.wrap(result);
785
+ }
786
+
787
+ /// @notice Allows an address to access an encrypted uint256
788
+ /// @param a The encrypted uint256
789
+ /// @param to The address to allow
790
+ function allow(euint256 a, address to) internal {
791
+ inco.allow(euint256.unwrap(a), to);
792
+ }
793
+
794
+ /// @notice Allows an address to access an encrypted bool
795
+ /// @param a The encrypted bool
796
+ /// @param to The address to allow
797
+ function allow(ebool a, address to) internal {
798
+ inco.allow(ebool.unwrap(a), to);
799
+ }
800
+
801
+ /// @notice Allows an address to access an encrypted address
802
+ /// @param a The encrypted address
803
+ /// @param to The address to allow
804
+ function allow(eaddress a, address to) internal {
805
+ inco.allow(eaddress.unwrap(a), to);
806
+ }
807
+
808
+ /// @notice Reveals an encrypted uint256
809
+ /// @param a The encrypted uint256
810
+ function reveal(euint256 a) internal {
811
+ inco.reveal(euint256.unwrap(a));
812
+ }
813
+
814
+ /// @notice Reveals an encrypted bool
815
+ /// @param a The encrypted bool
816
+ function reveal(ebool a) internal {
817
+ inco.reveal(ebool.unwrap(a));
818
+ }
819
+
820
+ /// @notice Reveals an encrypted address
821
+ /// @param a The encrypted address
822
+ function reveal(eaddress a) internal {
823
+ inco.reveal(eaddress.unwrap(a));
824
+ }
825
+
826
+ /// @notice Allows this contract to access an encrypted uint256
827
+ /// @param a The encrypted uint256
828
+ function allowThis(euint256 a) internal {
829
+ allow(a, address(this));
830
+ }
831
+
832
+ /// @notice Allows this contract to access an encrypted bool
833
+ /// @param a The encrypted bool
834
+ function allowThis(ebool a) internal {
835
+ allow(a, address(this));
836
+ }
837
+
838
+ /// @notice Allows this contract to access an encrypted address
839
+ /// @param a The encrypted address
840
+ function allowThis(eaddress a) internal {
841
+ allow(a, address(this));
842
+ }
843
+
844
+ /// @notice Checks if a user is allowed to access an encrypted uint256
845
+ /// @param user The address to check
846
+ /// @param a The encrypted uint256
847
+ /// @return True if allowed, false otherwise
848
+ function isAllowed(address user, euint256 a) internal view returns (bool) {
849
+ return inco.isAllowed(euint256.unwrap(a), user);
850
+ }
851
+
852
+ /// @notice Selects between two encrypted uint256 values based on an encrypted bool
853
+ /// @param control The encrypted bool condition
854
+ /// @param ifTrue Value if control is true
855
+ /// @param ifFalse Value if control is false
856
+ /// @return The selected encrypted uint256
857
+ function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
858
+ return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
859
+ }
860
+
861
+ /// @notice Selects between two encrypted bool values based on an encrypted bool
862
+ /// @param control The encrypted bool condition
863
+ /// @param ifTrue Value if control is true
864
+ /// @param ifFalse Value if control is false
865
+ /// @return The selected encrypted bool
866
+ function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
867
+ return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
868
+ }
869
+
870
+ /// @notice Selects between two encrypted addresses based on an encrypted bool
871
+ /// @param control The encrypted bool condition
872
+ /// @param ifTrue Value if control is true
873
+ /// @param ifFalse Value if control is false
874
+ /// @return The selected encrypted address
875
+ function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
876
+ return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
877
+ }
878
+
879
+ /// @dev Store fee in the custom slot
880
+ /// @param _fee The fee to store
881
+ function _setFee(uint256 _fee) private {
882
+ bytes32 slot = FEE_SLOT;
883
+ assembly {
884
+ sstore(slot, _fee)
885
+ }
886
+ }
887
+
888
+ /// @dev Retrieve fee from the custom slot
889
+ /// @return fee The stored fee
890
+ function _getFee() private view returns (uint256 fee) {
891
+ bytes32 slot = FEE_SLOT;
892
+ assembly {
893
+ fee := sload(slot)
894
+ }
895
+ }
896
+
897
+ /// @dev Get current fee with fallback to inco.getFee() if not cached
898
+ function getCurrentFee() private returns (uint256) {
899
+ uint256 cachedFee = _getFee();
900
+ if (cachedFee == 0) {
901
+ cachedFee = inco.getFee();
902
+ _setFee(cachedFee);
903
+ }
904
+ return cachedFee;
905
+ }
906
+
907
+ /// @dev Execute a call to inco with fee, retrying with fresh fee if it fails
908
+ /// @param callData The encoded function call (use abi.encodeWithSelector)
909
+ /// @return result The bytes32 result from the call
910
+ function _callWithFeeRetry(bytes memory callData) private returns (bytes32) {
911
+ uint256 fee = getCurrentFee();
912
+ (bool success, bytes memory result) = address(inco).call{value: fee}(callData);
913
+ if (!success) {
914
+ fee = inco.getFee();
915
+ _setFee(fee);
916
+ (success, result) = address(inco).call{value: fee}(callData);
917
+ require(success, CallFailedAfterFeeRefresh());
918
+ }
919
+ return abi.decode(result, (bytes32));
920
+ }
921
+ }