@inco/lightning 0.2.14 → 0.2.15
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/package.json +1 -1
- package/src/Lib.alphanet.sol +70 -7
- package/src/Lib.demonet.sol +70 -7
- package/src/Lib.devnet.sol +70 -7
- package/src/Lib.sol +70 -7
- package/src/Lib.template.sol +89 -7
- package/src/Lib.testnet.sol +70 -7
- package/src/Types.sol +3 -2
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +70 -7
- package/src/libs/incoLightning_demonet_v0_863421733.sol +70 -7
- package/src/libs/incoLightning_devnet_v0_340846814.sol +70 -7
- package/src/libs/incoLightning_testnet_v0_183408998.sol +70 -7
- package/src/lightning-parts/EncryptedInput.gen.sol +3 -1
- package/src/lightning-parts/EncryptedInput.sol +8 -1
- package/src/lightning-parts/EncryptedOperations.gen.sol +2 -2
- package/src/lightning-parts/EncryptedOperations.sol +54 -37
- package/src/lightning-parts/TrivialEncryption.gen.sol +3 -1
- package/src/lightning-parts/TrivialEncryption.sol +6 -1
- package/src/lightning-parts/test/HandleMetadata.t.sol +13 -2
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +12 -0
- package/src/test/FakeIncoInfra/KVStore.sol +7 -1
- package/src/test/FakeIncoInfra/MockOpHandler.sol +3 -1
- package/src/test/TestFakeInfra.t.sol +6 -1
- package/src/libs/incoLightning_junknet3_v0_495844717.sol +0 -389
package/src/Lib.template.sol
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
pragma solidity ^0.8;
|
|
4
4
|
|
|
5
5
|
import "./IncoLightning.sol";
|
|
6
|
-
import {ebool, euint256, ETypes} from "./Types.sol";
|
|
6
|
+
import {ebool, euint256, eaddress, ETypes, isTypeSupported} from "./Types.sol";
|
|
7
7
|
|
|
8
8
|
IncoLightning constant inco = IncoLightning(
|
|
9
9
|
0x000000000000000000000000000000000000baBe
|
|
@@ -12,6 +12,10 @@ address constant deployedBy = 0x000000000000000000000000000000000000baBe;
|
|
|
12
12
|
|
|
13
13
|
uint256 constant defaultDecryptionDelayLimit = 2 hours;
|
|
14
14
|
|
|
15
|
+
function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
16
|
+
return ETypes(uint8(uint256(handle) >> 8));
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
library e {
|
|
16
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
17
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
@@ -27,6 +31,13 @@ library e {
|
|
|
27
31
|
return a;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
function sanitize(eaddress a) internal returns (eaddress) {
|
|
35
|
+
if (eaddress.unwrap(a) == bytes32(0)) {
|
|
36
|
+
return asEaddress(address(0));
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
function s(euint256 a) internal returns (euint256) {
|
|
31
42
|
return sanitize(a);
|
|
32
43
|
}
|
|
@@ -35,6 +46,10 @@ library e {
|
|
|
35
46
|
return sanitize(a);
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
function s(eaddress a) internal returns (eaddress) {
|
|
50
|
+
return sanitize(a);
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
39
54
|
return inco.eAdd(s(a), s(b));
|
|
40
55
|
}
|
|
@@ -249,23 +264,43 @@ library e {
|
|
|
249
264
|
}
|
|
250
265
|
|
|
251
266
|
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
252
|
-
return inco.eEq(s(a), s(b));
|
|
267
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
253
268
|
}
|
|
254
269
|
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
255
|
-
return inco.eEq(s(a), asEuint256(b));
|
|
270
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
256
271
|
}
|
|
257
272
|
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
258
|
-
return inco.eEq(asEuint256(a), s(b));
|
|
273
|
+
return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function eq(eaddress a, address b) internal returns (ebool) {
|
|
277
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
278
|
+
}
|
|
279
|
+
function eq(eaddress a, eaddress b) internal returns (ebool) {
|
|
280
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
281
|
+
}
|
|
282
|
+
function eq(address a, eaddress b) internal returns (ebool) {
|
|
283
|
+
return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
259
284
|
}
|
|
260
285
|
|
|
261
286
|
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
262
|
-
return inco.eNe(s(a), s(b));
|
|
287
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
263
288
|
}
|
|
264
289
|
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
265
|
-
return inco.eNe(s(a), asEuint256(b));
|
|
290
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
266
291
|
}
|
|
267
292
|
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
268
|
-
return inco.eNe(asEuint256(a), s(b));
|
|
293
|
+
return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function ne(eaddress a, eaddress b) internal returns (ebool) {
|
|
297
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
298
|
+
}
|
|
299
|
+
function ne(eaddress a, address b) internal returns (ebool) {
|
|
300
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
301
|
+
}
|
|
302
|
+
function ne(address a, eaddress b) internal returns (ebool) {
|
|
303
|
+
return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
269
304
|
}
|
|
270
305
|
|
|
271
306
|
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
@@ -364,6 +399,10 @@ library e {
|
|
|
364
399
|
return inco.asEbool(a);
|
|
365
400
|
}
|
|
366
401
|
|
|
402
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
403
|
+
return inco.asEaddress(a);
|
|
404
|
+
}
|
|
405
|
+
|
|
367
406
|
function asEbool(euint256 a) internal returns (ebool) {
|
|
368
407
|
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
369
408
|
}
|
|
@@ -386,6 +425,13 @@ library e {
|
|
|
386
425
|
return inco.newEbool(ciphertext, user);
|
|
387
426
|
}
|
|
388
427
|
|
|
428
|
+
function newEaddress(
|
|
429
|
+
bytes memory ciphertext,
|
|
430
|
+
address user
|
|
431
|
+
) internal returns (eaddress) {
|
|
432
|
+
return inco.newEaddress(ciphertext, user);
|
|
433
|
+
}
|
|
434
|
+
|
|
389
435
|
function allow(euint256 a, address to) internal {
|
|
390
436
|
inco.allow(euint256.unwrap(a), to);
|
|
391
437
|
}
|
|
@@ -394,6 +440,10 @@ library e {
|
|
|
394
440
|
inco.allow(ebool.unwrap(a), to);
|
|
395
441
|
}
|
|
396
442
|
|
|
443
|
+
function allow(eaddress a, address to) internal {
|
|
444
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
445
|
+
}
|
|
446
|
+
|
|
397
447
|
function allowThis(euint256 a) internal {
|
|
398
448
|
allow(a, address(this));
|
|
399
449
|
}
|
|
@@ -402,6 +452,10 @@ library e {
|
|
|
402
452
|
allow(a, address(this));
|
|
403
453
|
}
|
|
404
454
|
|
|
455
|
+
function allowThis(eaddress a) internal {
|
|
456
|
+
allow(a, address(this));
|
|
457
|
+
}
|
|
458
|
+
|
|
405
459
|
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
406
460
|
return inco.isAllowed(euint256.unwrap(a), user);
|
|
407
461
|
}
|
|
@@ -436,6 +490,21 @@ library e {
|
|
|
436
490
|
);
|
|
437
491
|
}
|
|
438
492
|
|
|
493
|
+
function select(
|
|
494
|
+
ebool control,
|
|
495
|
+
eaddress ifTrue,
|
|
496
|
+
eaddress ifFalse
|
|
497
|
+
) internal returns (eaddress) {
|
|
498
|
+
return
|
|
499
|
+
eaddress.wrap(
|
|
500
|
+
inco.eIfThenElse(
|
|
501
|
+
s(control),
|
|
502
|
+
eaddress.unwrap(s(ifTrue)),
|
|
503
|
+
eaddress.unwrap(s(ifFalse))
|
|
504
|
+
)
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
|
|
439
508
|
function requestDecryption(
|
|
440
509
|
euint256 a,
|
|
441
510
|
bytes4 callbackSelector,
|
|
@@ -461,4 +530,17 @@ library e {
|
|
|
461
530
|
callbackData
|
|
462
531
|
);
|
|
463
532
|
}
|
|
533
|
+
|
|
534
|
+
function requestDecryption(
|
|
535
|
+
eaddress a,
|
|
536
|
+
bytes4 callbackSelector,
|
|
537
|
+
bytes memory callbackData
|
|
538
|
+
) internal returns (uint256 requestId) {
|
|
539
|
+
requestId = inco.requestDecryption(
|
|
540
|
+
callbackSelector,
|
|
541
|
+
block.timestamp + defaultDecryptionDelayLimit,
|
|
542
|
+
eaddress.unwrap(s(a)),
|
|
543
|
+
callbackData
|
|
544
|
+
);
|
|
545
|
+
}
|
|
464
546
|
}
|
package/src/Lib.testnet.sol
CHANGED
|
@@ -6,12 +6,16 @@
|
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
8
|
import "./IncoLightning.sol";
|
|
9
|
-
import { ebool, euint256, ETypes } from "./Types.sol";
|
|
9
|
+
import { ebool, euint256, eaddress, ETypes, isTypeSupported } from "./Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0x63D8135aF4D393B1dB43B649010c8D3EE19FC9fd);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
13
13
|
uint256 constant defaultDecryptionDelayLimit = 2 hours;
|
|
14
14
|
|
|
15
|
+
function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
16
|
+
return ETypes(uint8(uint256(handle) >> 8));
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
library e {
|
|
16
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
17
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
@@ -27,6 +31,13 @@ library e {
|
|
|
27
31
|
return a;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
function sanitize(eaddress a) internal returns (eaddress) {
|
|
35
|
+
if (eaddress.unwrap(a) == bytes32(0)) {
|
|
36
|
+
return asEaddress(address(0));
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
function s(euint256 a) internal returns (euint256) {
|
|
31
42
|
return sanitize(a);
|
|
32
43
|
}
|
|
@@ -35,6 +46,10 @@ library e {
|
|
|
35
46
|
return sanitize(a);
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
function s(eaddress a) internal returns (eaddress) {
|
|
50
|
+
return sanitize(a);
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
39
54
|
return inco.eAdd(s(a), s(b));
|
|
40
55
|
}
|
|
@@ -216,27 +231,51 @@ library e {
|
|
|
216
231
|
}
|
|
217
232
|
|
|
218
233
|
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
219
|
-
return inco.eEq(s(a), s(b));
|
|
234
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
220
235
|
}
|
|
221
236
|
|
|
222
237
|
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
223
|
-
return inco.eEq(s(a), asEuint256(b));
|
|
238
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
224
239
|
}
|
|
225
240
|
|
|
226
241
|
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
227
|
-
return inco.eEq(asEuint256(a), s(b));
|
|
242
|
+
return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function eq(eaddress a, address b) internal returns (ebool) {
|
|
246
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function eq(eaddress a, eaddress b) internal returns (ebool) {
|
|
250
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function eq(address a, eaddress b) internal returns (ebool) {
|
|
254
|
+
return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
228
255
|
}
|
|
229
256
|
|
|
230
257
|
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
231
|
-
return inco.eNe(s(a), s(b));
|
|
258
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
232
259
|
}
|
|
233
260
|
|
|
234
261
|
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
235
|
-
return inco.eNe(s(a), asEuint256(b));
|
|
262
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
236
263
|
}
|
|
237
264
|
|
|
238
265
|
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
239
|
-
return inco.eNe(asEuint256(a), s(b));
|
|
266
|
+
return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function ne(eaddress a, eaddress b) internal returns (ebool) {
|
|
270
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function ne(eaddress a, address b) internal returns (ebool) {
|
|
274
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function ne(address a, eaddress b) internal returns (ebool) {
|
|
278
|
+
return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
240
279
|
}
|
|
241
280
|
|
|
242
281
|
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
@@ -335,6 +374,10 @@ library e {
|
|
|
335
374
|
return inco.asEbool(a);
|
|
336
375
|
}
|
|
337
376
|
|
|
377
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
378
|
+
return inco.asEaddress(a);
|
|
379
|
+
}
|
|
380
|
+
|
|
338
381
|
function asEbool(euint256 a) internal returns (ebool) {
|
|
339
382
|
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
340
383
|
}
|
|
@@ -351,6 +394,10 @@ library e {
|
|
|
351
394
|
return inco.newEbool(ciphertext, user);
|
|
352
395
|
}
|
|
353
396
|
|
|
397
|
+
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
398
|
+
return inco.newEaddress(ciphertext, user);
|
|
399
|
+
}
|
|
400
|
+
|
|
354
401
|
function allow(euint256 a, address to) internal {
|
|
355
402
|
inco.allow(euint256.unwrap(a), to);
|
|
356
403
|
}
|
|
@@ -359,6 +406,10 @@ library e {
|
|
|
359
406
|
inco.allow(ebool.unwrap(a), to);
|
|
360
407
|
}
|
|
361
408
|
|
|
409
|
+
function allow(eaddress a, address to) internal {
|
|
410
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
411
|
+
}
|
|
412
|
+
|
|
362
413
|
function allowThis(euint256 a) internal {
|
|
363
414
|
allow(a, address(this));
|
|
364
415
|
}
|
|
@@ -367,6 +418,10 @@ library e {
|
|
|
367
418
|
allow(a, address(this));
|
|
368
419
|
}
|
|
369
420
|
|
|
421
|
+
function allowThis(eaddress a) internal {
|
|
422
|
+
allow(a, address(this));
|
|
423
|
+
}
|
|
424
|
+
|
|
370
425
|
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
371
426
|
return inco.isAllowed(euint256.unwrap(a), user);
|
|
372
427
|
}
|
|
@@ -379,6 +434,10 @@ library e {
|
|
|
379
434
|
return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
|
|
380
435
|
}
|
|
381
436
|
|
|
437
|
+
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
438
|
+
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
439
|
+
}
|
|
440
|
+
|
|
382
441
|
function requestDecryption(euint256 a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
383
442
|
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, euint256.unwrap(s(a)), callbackData);
|
|
384
443
|
}
|
|
@@ -386,4 +445,8 @@ library e {
|
|
|
386
445
|
function requestDecryption(ebool a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
387
446
|
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, ebool.unwrap(s(a)), callbackData);
|
|
388
447
|
}
|
|
448
|
+
|
|
449
|
+
function requestDecryption(eaddress a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
450
|
+
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, eaddress.unwrap(s(a)), callbackData);
|
|
451
|
+
}
|
|
389
452
|
}
|
package/src/Types.sol
CHANGED
|
@@ -39,6 +39,7 @@ pragma solidity ^0.8;
|
|
|
39
39
|
|
|
40
40
|
type ebool is bytes32;
|
|
41
41
|
type euint256 is bytes32;
|
|
42
|
+
type eaddress is bytes32;
|
|
42
43
|
|
|
43
44
|
// matches Zama's ids, cf contracts/inco-fhevm/dependencies/fhevm-0.0.1/contracts/lib/TFHE.sol l24-35
|
|
44
45
|
// https://github.com/zama-ai/fhevm/blob/61c0b3593414082b2da6e591252ed3721fe922d7/lib/TFHE.sol#L26
|
|
@@ -50,7 +51,7 @@ pragma solidity ^0.8;
|
|
|
50
51
|
Uint32UNSUPPORTED,
|
|
51
52
|
Uint64UNSUPPORTED,
|
|
52
53
|
Uint128UNSUPPORTED,
|
|
53
|
-
|
|
54
|
+
AddressOrUint160OrBytes20,
|
|
54
55
|
Uint256,
|
|
55
56
|
Bytes64UNSUPPORTED,
|
|
56
57
|
Bytes128UNSUPPORTED,
|
|
@@ -63,7 +64,7 @@ pragma solidity ^0.8;
|
|
|
63
64
|
/// Checks whether the given type is a valid numeric type or a boolean.
|
|
64
65
|
/// @param t the type to check
|
|
65
66
|
function isTypeSupported(ETypes t) pure returns (bool) {
|
|
66
|
-
return t == ETypes.Uint256 || t == ETypes.Bool;
|
|
67
|
+
return t == ETypes.Uint256 || t == ETypes.Bool || t == ETypes.AddressOrUint160OrBytes20;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
error SenderNotAllowedForHandle(bytes32 handle, address sender);
|
|
@@ -6,12 +6,16 @@
|
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
8
|
import "../IncoLightning.sol";
|
|
9
|
-
import { ebool, euint256, ETypes } from "../Types.sol";
|
|
9
|
+
import { ebool, euint256, eaddress, ETypes, isTypeSupported } from "../Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0x4651DfD7729aE5568092E7351fAaD872266d4CBd);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
13
13
|
uint256 constant defaultDecryptionDelayLimit = 2 hours;
|
|
14
14
|
|
|
15
|
+
function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
16
|
+
return ETypes(uint8(uint256(handle) >> 8));
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
library e {
|
|
16
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
17
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
@@ -27,6 +31,13 @@ library e {
|
|
|
27
31
|
return a;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
function sanitize(eaddress a) internal returns (eaddress) {
|
|
35
|
+
if (eaddress.unwrap(a) == bytes32(0)) {
|
|
36
|
+
return asEaddress(address(0));
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
function s(euint256 a) internal returns (euint256) {
|
|
31
42
|
return sanitize(a);
|
|
32
43
|
}
|
|
@@ -35,6 +46,10 @@ library e {
|
|
|
35
46
|
return sanitize(a);
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
function s(eaddress a) internal returns (eaddress) {
|
|
50
|
+
return sanitize(a);
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
39
54
|
return inco.eAdd(s(a), s(b));
|
|
40
55
|
}
|
|
@@ -216,27 +231,51 @@ library e {
|
|
|
216
231
|
}
|
|
217
232
|
|
|
218
233
|
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
219
|
-
return inco.eEq(s(a), s(b));
|
|
234
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
220
235
|
}
|
|
221
236
|
|
|
222
237
|
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
223
|
-
return inco.eEq(s(a), asEuint256(b));
|
|
238
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
224
239
|
}
|
|
225
240
|
|
|
226
241
|
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
227
|
-
return inco.eEq(asEuint256(a), s(b));
|
|
242
|
+
return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function eq(eaddress a, address b) internal returns (ebool) {
|
|
246
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function eq(eaddress a, eaddress b) internal returns (ebool) {
|
|
250
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function eq(address a, eaddress b) internal returns (ebool) {
|
|
254
|
+
return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
228
255
|
}
|
|
229
256
|
|
|
230
257
|
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
231
|
-
return inco.eNe(s(a), s(b));
|
|
258
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
232
259
|
}
|
|
233
260
|
|
|
234
261
|
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
235
|
-
return inco.eNe(s(a), asEuint256(b));
|
|
262
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
236
263
|
}
|
|
237
264
|
|
|
238
265
|
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
239
|
-
return inco.eNe(asEuint256(a), s(b));
|
|
266
|
+
return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function ne(eaddress a, eaddress b) internal returns (ebool) {
|
|
270
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function ne(eaddress a, address b) internal returns (ebool) {
|
|
274
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function ne(address a, eaddress b) internal returns (ebool) {
|
|
278
|
+
return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
240
279
|
}
|
|
241
280
|
|
|
242
281
|
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
@@ -335,6 +374,10 @@ library e {
|
|
|
335
374
|
return inco.asEbool(a);
|
|
336
375
|
}
|
|
337
376
|
|
|
377
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
378
|
+
return inco.asEaddress(a);
|
|
379
|
+
}
|
|
380
|
+
|
|
338
381
|
function asEbool(euint256 a) internal returns (ebool) {
|
|
339
382
|
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
340
383
|
}
|
|
@@ -351,6 +394,10 @@ library e {
|
|
|
351
394
|
return inco.newEbool(ciphertext, user);
|
|
352
395
|
}
|
|
353
396
|
|
|
397
|
+
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
398
|
+
return inco.newEaddress(ciphertext, user);
|
|
399
|
+
}
|
|
400
|
+
|
|
354
401
|
function allow(euint256 a, address to) internal {
|
|
355
402
|
inco.allow(euint256.unwrap(a), to);
|
|
356
403
|
}
|
|
@@ -359,6 +406,10 @@ library e {
|
|
|
359
406
|
inco.allow(ebool.unwrap(a), to);
|
|
360
407
|
}
|
|
361
408
|
|
|
409
|
+
function allow(eaddress a, address to) internal {
|
|
410
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
411
|
+
}
|
|
412
|
+
|
|
362
413
|
function allowThis(euint256 a) internal {
|
|
363
414
|
allow(a, address(this));
|
|
364
415
|
}
|
|
@@ -367,6 +418,10 @@ library e {
|
|
|
367
418
|
allow(a, address(this));
|
|
368
419
|
}
|
|
369
420
|
|
|
421
|
+
function allowThis(eaddress a) internal {
|
|
422
|
+
allow(a, address(this));
|
|
423
|
+
}
|
|
424
|
+
|
|
370
425
|
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
371
426
|
return inco.isAllowed(euint256.unwrap(a), user);
|
|
372
427
|
}
|
|
@@ -379,6 +434,10 @@ library e {
|
|
|
379
434
|
return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
|
|
380
435
|
}
|
|
381
436
|
|
|
437
|
+
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
438
|
+
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
439
|
+
}
|
|
440
|
+
|
|
382
441
|
function requestDecryption(euint256 a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
383
442
|
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, euint256.unwrap(s(a)), callbackData);
|
|
384
443
|
}
|
|
@@ -386,4 +445,8 @@ library e {
|
|
|
386
445
|
function requestDecryption(ebool a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
387
446
|
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, ebool.unwrap(s(a)), callbackData);
|
|
388
447
|
}
|
|
448
|
+
|
|
449
|
+
function requestDecryption(eaddress a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
450
|
+
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, eaddress.unwrap(s(a)), callbackData);
|
|
451
|
+
}
|
|
389
452
|
}
|
|
@@ -6,12 +6,16 @@
|
|
|
6
6
|
pragma solidity ^0.8;
|
|
7
7
|
|
|
8
8
|
import "../IncoLightning.sol";
|
|
9
|
-
import { ebool, euint256, ETypes } from "../Types.sol";
|
|
9
|
+
import { ebool, euint256, eaddress, ETypes, isTypeSupported } from "../Types.sol";
|
|
10
10
|
|
|
11
11
|
IncoLightning constant inco = IncoLightning(0xeBAFF6D578733E4603b99CBdbb221482F29a78E1);
|
|
12
12
|
address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
|
|
13
13
|
uint256 constant defaultDecryptionDelayLimit = 2 hours;
|
|
14
14
|
|
|
15
|
+
function typeOf(bytes32 handle) pure returns (ETypes) {
|
|
16
|
+
return ETypes(uint8(uint256(handle) >> 8));
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
library e {
|
|
16
20
|
function sanitize(euint256 a) internal returns (euint256) {
|
|
17
21
|
if (euint256.unwrap(a) == bytes32(0)) {
|
|
@@ -27,6 +31,13 @@ library e {
|
|
|
27
31
|
return a;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
function sanitize(eaddress a) internal returns (eaddress) {
|
|
35
|
+
if (eaddress.unwrap(a) == bytes32(0)) {
|
|
36
|
+
return asEaddress(address(0));
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
function s(euint256 a) internal returns (euint256) {
|
|
31
42
|
return sanitize(a);
|
|
32
43
|
}
|
|
@@ -35,6 +46,10 @@ library e {
|
|
|
35
46
|
return sanitize(a);
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
function s(eaddress a) internal returns (eaddress) {
|
|
50
|
+
return sanitize(a);
|
|
51
|
+
}
|
|
52
|
+
|
|
38
53
|
function add(euint256 a, euint256 b) internal returns (euint256) {
|
|
39
54
|
return inco.eAdd(s(a), s(b));
|
|
40
55
|
}
|
|
@@ -216,27 +231,51 @@ library e {
|
|
|
216
231
|
}
|
|
217
232
|
|
|
218
233
|
function eq(euint256 a, euint256 b) internal returns (ebool) {
|
|
219
|
-
return inco.eEq(s(a), s(b));
|
|
234
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
220
235
|
}
|
|
221
236
|
|
|
222
237
|
function eq(euint256 a, uint256 b) internal returns (ebool) {
|
|
223
|
-
return inco.eEq(s(a), asEuint256(b));
|
|
238
|
+
return inco.eEq(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
224
239
|
}
|
|
225
240
|
|
|
226
241
|
function eq(uint256 a, euint256 b) internal returns (ebool) {
|
|
227
|
-
return inco.eEq(asEuint256(a), s(b));
|
|
242
|
+
return inco.eEq(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function eq(eaddress a, address b) internal returns (ebool) {
|
|
246
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function eq(eaddress a, eaddress b) internal returns (ebool) {
|
|
250
|
+
return inco.eEq(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function eq(address a, eaddress b) internal returns (ebool) {
|
|
254
|
+
return inco.eEq(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
228
255
|
}
|
|
229
256
|
|
|
230
257
|
function ne(euint256 a, euint256 b) internal returns (ebool) {
|
|
231
|
-
return inco.eNe(s(a), s(b));
|
|
258
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(s(b)));
|
|
232
259
|
}
|
|
233
260
|
|
|
234
261
|
function ne(euint256 a, uint256 b) internal returns (ebool) {
|
|
235
|
-
return inco.eNe(s(a), asEuint256(b));
|
|
262
|
+
return inco.eNe(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b)));
|
|
236
263
|
}
|
|
237
264
|
|
|
238
265
|
function ne(uint256 a, euint256 b) internal returns (ebool) {
|
|
239
|
-
return inco.eNe(asEuint256(a), s(b));
|
|
266
|
+
return inco.eNe(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b)));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function ne(eaddress a, eaddress b) internal returns (ebool) {
|
|
270
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(s(b)));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function ne(eaddress a, address b) internal returns (ebool) {
|
|
274
|
+
return inco.eNe(eaddress.unwrap(s(a)), eaddress.unwrap(asEaddress(b)));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function ne(address a, eaddress b) internal returns (ebool) {
|
|
278
|
+
return inco.eNe(eaddress.unwrap(asEaddress(a)), eaddress.unwrap(s(b)));
|
|
240
279
|
}
|
|
241
280
|
|
|
242
281
|
function ge(euint256 a, euint256 b) internal returns (ebool) {
|
|
@@ -335,6 +374,10 @@ library e {
|
|
|
335
374
|
return inco.asEbool(a);
|
|
336
375
|
}
|
|
337
376
|
|
|
377
|
+
function asEaddress(address a) internal returns (eaddress) {
|
|
378
|
+
return inco.asEaddress(a);
|
|
379
|
+
}
|
|
380
|
+
|
|
338
381
|
function asEbool(euint256 a) internal returns (ebool) {
|
|
339
382
|
return ebool.wrap(inco.eCast(euint256.unwrap(a), ETypes.Bool));
|
|
340
383
|
}
|
|
@@ -351,6 +394,10 @@ library e {
|
|
|
351
394
|
return inco.newEbool(ciphertext, user);
|
|
352
395
|
}
|
|
353
396
|
|
|
397
|
+
function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
|
|
398
|
+
return inco.newEaddress(ciphertext, user);
|
|
399
|
+
}
|
|
400
|
+
|
|
354
401
|
function allow(euint256 a, address to) internal {
|
|
355
402
|
inco.allow(euint256.unwrap(a), to);
|
|
356
403
|
}
|
|
@@ -359,6 +406,10 @@ library e {
|
|
|
359
406
|
inco.allow(ebool.unwrap(a), to);
|
|
360
407
|
}
|
|
361
408
|
|
|
409
|
+
function allow(eaddress a, address to) internal {
|
|
410
|
+
inco.allow(eaddress.unwrap(a), to);
|
|
411
|
+
}
|
|
412
|
+
|
|
362
413
|
function allowThis(euint256 a) internal {
|
|
363
414
|
allow(a, address(this));
|
|
364
415
|
}
|
|
@@ -367,6 +418,10 @@ library e {
|
|
|
367
418
|
allow(a, address(this));
|
|
368
419
|
}
|
|
369
420
|
|
|
421
|
+
function allowThis(eaddress a) internal {
|
|
422
|
+
allow(a, address(this));
|
|
423
|
+
}
|
|
424
|
+
|
|
370
425
|
function isAllowed(address user, euint256 a) internal view returns (bool) {
|
|
371
426
|
return inco.isAllowed(euint256.unwrap(a), user);
|
|
372
427
|
}
|
|
@@ -379,6 +434,10 @@ library e {
|
|
|
379
434
|
return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
|
|
380
435
|
}
|
|
381
436
|
|
|
437
|
+
function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
|
|
438
|
+
return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
|
|
439
|
+
}
|
|
440
|
+
|
|
382
441
|
function requestDecryption(euint256 a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
383
442
|
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, euint256.unwrap(s(a)), callbackData);
|
|
384
443
|
}
|
|
@@ -386,4 +445,8 @@ library e {
|
|
|
386
445
|
function requestDecryption(ebool a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
387
446
|
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, ebool.unwrap(s(a)), callbackData);
|
|
388
447
|
}
|
|
448
|
+
|
|
449
|
+
function requestDecryption(eaddress a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
|
|
450
|
+
requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, eaddress.unwrap(s(a)), callbackData);
|
|
451
|
+
}
|
|
389
452
|
}
|