@inco/lightning 0.2.13 → 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
|
@@ -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(0x3B22be60Ae699933959CA3cE147C96caa88Ccd3D);
|
|
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(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
|
}
|
|
@@ -4,10 +4,12 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
|
|
5
5
|
import { EventCounter } from "./primitives/EventCounter.sol";
|
|
6
6
|
import { HandleGeneration } from "./primitives/HandleGeneration.sol";
|
|
7
|
-
import { euint256, ebool, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX } from "../Types.sol";
|
|
7
|
+
import { euint256, ebool, eaddress, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX } from "../Types.sol";
|
|
8
8
|
|
|
9
9
|
interface IEncryptedInputGen {
|
|
10
10
|
function newEuint256(bytes memory ciphertext, address user) external returns (euint256 newValue);
|
|
11
11
|
|
|
12
12
|
function newEbool(bytes memory ciphertext, address user) external returns (ebool newValue);
|
|
13
|
+
|
|
14
|
+
function newEaddress(bytes memory ciphertext, address user) external returns (eaddress newValue);
|
|
13
15
|
}
|
|
@@ -4,7 +4,7 @@ pragma solidity ^0.8;
|
|
|
4
4
|
import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
|
|
5
5
|
import {EventCounter} from "./primitives/EventCounter.sol";
|
|
6
6
|
import {HandleGeneration} from "./primitives/HandleGeneration.sol";
|
|
7
|
-
import {euint256, ebool, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX} from "../Types.sol";
|
|
7
|
+
import {euint256, ebool, eaddress, ETypes, EVM_HOST_CHAIN_PREFIX, HANDLE_VERSION, HANDLE_INDEX} from "../Types.sol";
|
|
8
8
|
import {IEncryptedInputGen} from "./EncryptedInput.gen.sol";
|
|
9
9
|
|
|
10
10
|
abstract contract EncryptedInput is
|
|
@@ -38,6 +38,13 @@ abstract contract EncryptedInput is
|
|
|
38
38
|
return ebool.wrap(newInput(ciphertext, user, ETypes.Bool));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
function newEaddress(
|
|
42
|
+
bytes memory ciphertext,
|
|
43
|
+
address user
|
|
44
|
+
) external returns (eaddress newValue) {
|
|
45
|
+
return eaddress.wrap(newInput(ciphertext, user, ETypes.AddressOrUint160OrBytes20));
|
|
46
|
+
}
|
|
47
|
+
|
|
41
48
|
function newInput(
|
|
42
49
|
bytes memory ciphertext,
|
|
43
50
|
address user,
|
|
@@ -31,9 +31,9 @@ interface IEncryptedOperationsGen {
|
|
|
31
31
|
|
|
32
32
|
function eRotr(euint256 lhs, euint256 rhs) external returns (euint256 result);
|
|
33
33
|
|
|
34
|
-
function eEq(
|
|
34
|
+
function eEq(bytes32 lhs, bytes32 rhs) external returns (ebool result);
|
|
35
35
|
|
|
36
|
-
function eNe(
|
|
36
|
+
function eNe(bytes32 lhs, bytes32 rhs) external returns (ebool result);
|
|
37
37
|
|
|
38
38
|
function eGe(euint256 lhs, euint256 rhs) external returns (ebool result);
|
|
39
39
|
|
|
@@ -13,11 +13,20 @@ abstract contract EncryptedOperations is
|
|
|
13
13
|
EventCounter,
|
|
14
14
|
HandleGeneration
|
|
15
15
|
{
|
|
16
|
-
error UnexpectedType(ETypes actual,
|
|
16
|
+
error UnexpectedType(ETypes actual, bytes32 expectedTypes);
|
|
17
17
|
error UnsupportedType(ETypes actual);
|
|
18
18
|
|
|
19
19
|
uint256 private randCounter;
|
|
20
20
|
|
|
21
|
+
bytes32 constant EBOOL = bytes32(1 << uint256(ETypes.Bool));
|
|
22
|
+
bytes32 constant EUINT160 = bytes32(1 << uint256(ETypes.AddressOrUint160OrBytes20));
|
|
23
|
+
bytes32 constant EUINT256 = bytes32(1 << uint256(ETypes.Uint256));
|
|
24
|
+
|
|
25
|
+
bytes32 constant SUPPORTED_TYPES_MASK =
|
|
26
|
+
EBOOL |
|
|
27
|
+
EUINT160 |
|
|
28
|
+
EUINT256;
|
|
29
|
+
|
|
21
30
|
event EAdd(
|
|
22
31
|
euint256 indexed lhs,
|
|
23
32
|
euint256 indexed rhs,
|
|
@@ -91,14 +100,14 @@ abstract contract EncryptedOperations is
|
|
|
91
100
|
uint256 eventId
|
|
92
101
|
);
|
|
93
102
|
event EEq(
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
bytes32 indexed lhs,
|
|
104
|
+
bytes32 indexed rhs,
|
|
96
105
|
ebool indexed result,
|
|
97
106
|
uint256 eventId
|
|
98
107
|
);
|
|
99
108
|
event ENe(
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
bytes32 indexed lhs,
|
|
110
|
+
bytes32 indexed rhs,
|
|
102
111
|
ebool indexed result,
|
|
103
112
|
uint256 eventId
|
|
104
113
|
);
|
|
@@ -166,26 +175,28 @@ abstract contract EncryptedOperations is
|
|
|
166
175
|
uint256 eventId
|
|
167
176
|
);
|
|
168
177
|
|
|
178
|
+
function typeToBitMask(ETypes t) internal pure returns (bytes32) {
|
|
179
|
+
return bytes32(1 << uint256(t));
|
|
180
|
+
}
|
|
181
|
+
|
|
169
182
|
modifier checked(euint256 lhs, euint256 rhs) {
|
|
170
|
-
checkInput(euint256.unwrap(lhs), ETypes.Uint256);
|
|
171
|
-
checkInput(euint256.unwrap(rhs), ETypes.Uint256);
|
|
183
|
+
checkInput(euint256.unwrap(lhs), typeToBitMask(ETypes.Uint256));
|
|
184
|
+
checkInput(euint256.unwrap(rhs), typeToBitMask(ETypes.Uint256));
|
|
172
185
|
_;
|
|
173
186
|
}
|
|
174
187
|
|
|
175
188
|
modifier checkedHandle(euint256 handle) {
|
|
176
|
-
checkInput(euint256.unwrap(handle), ETypes.Uint256);
|
|
189
|
+
checkInput(euint256.unwrap(handle), typeToBitMask(ETypes.Uint256));
|
|
177
190
|
_;
|
|
178
191
|
}
|
|
179
192
|
|
|
180
|
-
|
|
193
|
+
|
|
194
|
+
function checkInput(bytes32 input, bytes32 requiredTypes) internal view {
|
|
181
195
|
require(
|
|
182
196
|
isAllowed(input, msg.sender),
|
|
183
197
|
SenderNotAllowedForHandle(input, msg.sender)
|
|
184
198
|
);
|
|
185
|
-
require(
|
|
186
|
-
typeOf(input) == requiredType,
|
|
187
|
-
UnexpectedType(typeOf(input), requiredType)
|
|
188
|
-
);
|
|
199
|
+
require(requiredTypes & typeToBitMask(typeOf(input)) != 0, UnexpectedType(typeOf(input), requiredTypes));
|
|
189
200
|
}
|
|
190
201
|
|
|
191
202
|
function createResultHandle(
|
|
@@ -310,9 +321,9 @@ abstract contract EncryptedOperations is
|
|
|
310
321
|
) external returns (bytes32 result) {
|
|
311
322
|
ETypes lhsType = typeOf(lhs);
|
|
312
323
|
ETypes rhsType = typeOf(rhs);
|
|
313
|
-
checkInput(lhs, lhsType);
|
|
314
|
-
checkInput(rhs, rhsType);
|
|
315
|
-
require(lhsType == rhsType, UnexpectedType(lhsType, rhsType));
|
|
324
|
+
checkInput(lhs, typeToBitMask(lhsType));
|
|
325
|
+
checkInput(rhs, typeToBitMask(rhsType));
|
|
326
|
+
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
316
327
|
result = createResultHandle(EOps.BitAnd, lhsType, lhs, rhs);
|
|
317
328
|
emit EBitAnd(lhs, rhs, result, getNewEventId());
|
|
318
329
|
}
|
|
@@ -323,9 +334,9 @@ abstract contract EncryptedOperations is
|
|
|
323
334
|
) external returns (bytes32 result) {
|
|
324
335
|
ETypes lhsType = typeOf(lhs);
|
|
325
336
|
ETypes rhsType = typeOf(rhs);
|
|
326
|
-
checkInput(lhs, lhsType);
|
|
327
|
-
checkInput(rhs, rhsType);
|
|
328
|
-
require(lhsType == rhsType, UnexpectedType(lhsType, rhsType));
|
|
337
|
+
checkInput(lhs, typeToBitMask(lhsType));
|
|
338
|
+
checkInput(rhs, typeToBitMask(rhsType));
|
|
339
|
+
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
329
340
|
result = createResultHandle(EOps.BitOr, lhsType, lhs, rhs);
|
|
330
341
|
emit EBitOr(lhs, rhs, result, getNewEventId());
|
|
331
342
|
}
|
|
@@ -336,9 +347,9 @@ abstract contract EncryptedOperations is
|
|
|
336
347
|
) external returns (bytes32 result) {
|
|
337
348
|
ETypes lhsType = typeOf(lhs);
|
|
338
349
|
ETypes rhsType = typeOf(rhs);
|
|
339
|
-
checkInput(lhs, lhsType);
|
|
340
|
-
checkInput(rhs, rhsType);
|
|
341
|
-
require(lhsType == rhsType, UnexpectedType(lhsType, rhsType));
|
|
350
|
+
checkInput(lhs, typeToBitMask(lhsType));
|
|
351
|
+
checkInput(rhs, typeToBitMask(rhsType));
|
|
352
|
+
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
342
353
|
result = createResultHandle(EOps.BitXor, lhsType, lhs, rhs);
|
|
343
354
|
emit EBitXor(lhs, rhs, result, getNewEventId());
|
|
344
355
|
}
|
|
@@ -404,30 +415,36 @@ abstract contract EncryptedOperations is
|
|
|
404
415
|
}
|
|
405
416
|
|
|
406
417
|
function eEq(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
) external
|
|
418
|
+
bytes32 lhs,
|
|
419
|
+
bytes32 rhs
|
|
420
|
+
) external returns (ebool result) {
|
|
421
|
+
checkInput(lhs, SUPPORTED_TYPES_MASK);
|
|
422
|
+
checkInput(rhs, SUPPORTED_TYPES_MASK);
|
|
423
|
+
|
|
410
424
|
result = ebool.wrap(
|
|
411
425
|
createResultHandle(
|
|
412
426
|
EOps.Eq,
|
|
413
427
|
ETypes.Bool,
|
|
414
|
-
|
|
415
|
-
|
|
428
|
+
lhs,
|
|
429
|
+
rhs
|
|
416
430
|
)
|
|
417
431
|
);
|
|
418
432
|
emit EEq(lhs, rhs, result, getNewEventId());
|
|
419
433
|
}
|
|
420
434
|
|
|
421
435
|
function eNe(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
) external
|
|
436
|
+
bytes32 lhs,
|
|
437
|
+
bytes32 rhs
|
|
438
|
+
) external returns (ebool result) {
|
|
439
|
+
checkInput(lhs, SUPPORTED_TYPES_MASK);
|
|
440
|
+
checkInput(rhs, SUPPORTED_TYPES_MASK);
|
|
441
|
+
|
|
425
442
|
result = ebool.wrap(
|
|
426
443
|
createResultHandle(
|
|
427
444
|
EOps.Ne,
|
|
428
445
|
ETypes.Bool,
|
|
429
|
-
|
|
430
|
-
|
|
446
|
+
lhs,
|
|
447
|
+
rhs
|
|
431
448
|
)
|
|
432
449
|
);
|
|
433
450
|
emit ENe(lhs, rhs, result, getNewEventId());
|
|
@@ -524,7 +541,7 @@ abstract contract EncryptedOperations is
|
|
|
524
541
|
}
|
|
525
542
|
|
|
526
543
|
function eNot(ebool operand) external returns (ebool result) {
|
|
527
|
-
checkInput(ebool.unwrap(operand), ETypes.Bool);
|
|
544
|
+
checkInput(ebool.unwrap(operand), typeToBitMask(ETypes.Bool));
|
|
528
545
|
result = ebool.wrap(
|
|
529
546
|
createResultHandle(EOps.Not, ETypes.Bool, ebool.unwrap(operand))
|
|
530
547
|
);
|
|
@@ -560,7 +577,7 @@ abstract contract EncryptedOperations is
|
|
|
560
577
|
ETypes randType
|
|
561
578
|
) external returns (bytes32 result) {
|
|
562
579
|
require(isTypeSupported(randType), UnsupportedType(randType));
|
|
563
|
-
checkInput(upperBound, ETypes.Uint256);
|
|
580
|
+
checkInput(upperBound, typeToBitMask(ETypes.Uint256));
|
|
564
581
|
|
|
565
582
|
result = createResultHandle(
|
|
566
583
|
EOps.RandBounded,
|
|
@@ -597,16 +614,16 @@ abstract contract EncryptedOperations is
|
|
|
597
614
|
bytes32 ifTrue,
|
|
598
615
|
bytes32 ifFalse
|
|
599
616
|
) internal view returns (ETypes ifTrueType) {
|
|
600
|
-
checkInput(ebool.unwrap(control), ETypes.Bool);
|
|
617
|
+
checkInput(ebool.unwrap(control), typeToBitMask(ETypes.Bool));
|
|
601
618
|
ifTrueType = typeOf(ifTrue);
|
|
602
619
|
require(
|
|
603
|
-
ifTrueType == ETypes.Uint256 || ifTrueType == ETypes.Bool,
|
|
620
|
+
ifTrueType == ETypes.Uint256 || ifTrueType == ETypes.Bool || ifTrueType == ETypes.AddressOrUint160OrBytes20,
|
|
604
621
|
UnsupportedType(ifTrueType)
|
|
605
622
|
);
|
|
606
623
|
require(
|
|
607
624
|
isAllowed(ifTrue, msg.sender),
|
|
608
625
|
SenderNotAllowedForHandle(ifTrue, msg.sender)
|
|
609
626
|
);
|
|
610
|
-
checkInput(ifFalse, ifTrueType);
|
|
627
|
+
checkInput(ifFalse, typeToBitMask(ifTrueType));
|
|
611
628
|
}
|
|
612
629
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
4
|
import { EventCounter } from "./primitives/EventCounter.sol";
|
|
5
|
-
import { euint256, ebool, ETypes } from "../Types.sol";
|
|
5
|
+
import { euint256, ebool, eaddress, ETypes } from "../Types.sol";
|
|
6
6
|
import { BaseAccessControlList } from "./AccessControl/BaseAccessControlList.sol";
|
|
7
7
|
import { HandleGeneration } from "./primitives/HandleGeneration.sol";
|
|
8
8
|
|
|
@@ -10,4 +10,6 @@ interface ITrivialEncryptionGen {
|
|
|
10
10
|
function asEuint256(uint256 value) external returns (euint256 newEuint256);
|
|
11
11
|
|
|
12
12
|
function asEbool(bool value) external returns (ebool newEbool);
|
|
13
|
+
|
|
14
|
+
function asEaddress(address value) external returns (eaddress newEaddress);
|
|
13
15
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
4
|
import {EventCounter} from "./primitives/EventCounter.sol";
|
|
5
|
-
import {euint256, ebool, ETypes} from "../Types.sol";
|
|
5
|
+
import {euint256, ebool, eaddress, ETypes} from "../Types.sol";
|
|
6
6
|
import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
|
|
7
7
|
import {HandleGeneration} from "./primitives/HandleGeneration.sol";
|
|
8
8
|
import {ITrivialEncryptionGen} from "./TrivialEncryption.gen.sol";
|
|
@@ -29,6 +29,11 @@ abstract contract TrivialEncryption is
|
|
|
29
29
|
return ebool.wrap(newTrivialEncrypt(castedValue, ETypes.Bool));
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function asEaddress(address value) external returns (eaddress newEaddress) {
|
|
33
|
+
bytes32 castedValue = bytes32(uint256(uint160(value)));
|
|
34
|
+
return eaddress.wrap(newTrivialEncrypt(castedValue, ETypes.AddressOrUint160OrBytes20));
|
|
35
|
+
}
|
|
36
|
+
|
|
32
37
|
function newTrivialEncrypt(
|
|
33
38
|
bytes32 plainTextBytes,
|
|
34
39
|
ETypes handleType
|
|
@@ -7,7 +7,7 @@ import {TrivialEncryption} from "../TrivialEncryption.sol";
|
|
|
7
7
|
import {EncryptedOperations} from "../EncryptedOperations.sol";
|
|
8
8
|
import {EncryptedInput} from "../EncryptedInput.sol";
|
|
9
9
|
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
|
|
10
|
-
import {ETypes, ebool, euint256} from "../../Types.sol";
|
|
10
|
+
import {ETypes, ebool, euint256, eaddress} from "../../Types.sol";
|
|
11
11
|
|
|
12
12
|
contract TestHandleMetadata is
|
|
13
13
|
EIP712,
|
|
@@ -29,6 +29,10 @@ contract TestHandleMetadata is
|
|
|
29
29
|
typeOf(embedIndexTypeVersion(someHandle, ETypes.Uint256)) ==
|
|
30
30
|
ETypes.Uint256
|
|
31
31
|
);
|
|
32
|
+
assert(
|
|
33
|
+
typeOf(embedIndexTypeVersion(someHandle, ETypes.AddressOrUint160OrBytes20)) ==
|
|
34
|
+
ETypes.AddressOrUint160OrBytes20
|
|
35
|
+
);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
function testTrivialEncryptionHandleType() public {
|
|
@@ -36,6 +40,8 @@ contract TestHandleMetadata is
|
|
|
36
40
|
assert(typeOf(boolHandle) == ETypes.Bool);
|
|
37
41
|
bytes32 uintHandle = euint256.unwrap(this.asEuint256(42));
|
|
38
42
|
assert(typeOf(uintHandle) == ETypes.Uint256);
|
|
43
|
+
bytes32 addressHandle = eaddress.unwrap(this.asEaddress(address(0xdeadbeef)));
|
|
44
|
+
assert(typeOf(addressHandle) == ETypes.AddressOrUint160OrBytes20);
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
function testOperationsHandleType() public {
|
|
@@ -44,6 +50,8 @@ contract TestHandleMetadata is
|
|
|
44
50
|
ebool control = this.asEbool(true);
|
|
45
51
|
ebool c = this.asEbool(false);
|
|
46
52
|
ebool d = this.asEbool(true);
|
|
53
|
+
eaddress addr1 = this.asEaddress(address(0x0));
|
|
54
|
+
eaddress addr2 = this.asEaddress(address(0xdeadbeef));
|
|
47
55
|
|
|
48
56
|
assert(typeOf(euint256.unwrap(this.eAdd(a, b))) == ETypes.Uint256);
|
|
49
57
|
assert(typeOf(euint256.unwrap(this.eSub(a, b))) == ETypes.Uint256);
|
|
@@ -62,6 +70,7 @@ contract TestHandleMetadata is
|
|
|
62
70
|
this.eIfThenElse(control, ebool.unwrap(c), ebool.unwrap(d))
|
|
63
71
|
) == ETypes.Bool
|
|
64
72
|
);
|
|
73
|
+
assert(typeOf(ebool.unwrap(this.eEq(eaddress.unwrap(addr1), eaddress.unwrap(addr2)))) == ETypes.Bool);
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
function testEIfThenElseChecksTypeCoherence() public {
|
|
@@ -72,7 +81,7 @@ contract TestHandleMetadata is
|
|
|
72
81
|
abi.encodeWithSelector(
|
|
73
82
|
EncryptedOperations.UnexpectedType.selector,
|
|
74
83
|
ETypes.Bool,
|
|
75
|
-
ETypes.Uint256
|
|
84
|
+
typeToBitMask(ETypes.Uint256)
|
|
76
85
|
)
|
|
77
86
|
);
|
|
78
87
|
this.eIfThenElse(control, euint256.unwrap(a), ebool.unwrap(b));
|
|
@@ -83,5 +92,7 @@ contract TestHandleMetadata is
|
|
|
83
92
|
assert(typeOf(euint256.unwrap(a)) == ETypes.Uint256);
|
|
84
93
|
ebool b = this.newEbool("ciphertext", address(this));
|
|
85
94
|
assert(typeOf(ebool.unwrap(b)) == ETypes.Bool);
|
|
95
|
+
eaddress c = this.newEaddress("ciphertext", address(this));
|
|
96
|
+
assert(typeOf(eaddress.unwrap(c)) == ETypes.AddressOrUint160OrBytes20);
|
|
86
97
|
}
|
|
87
98
|
}
|