@inco/lightning 0.6.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +29 -2
  3. package/manifest.yaml +35 -42
  4. package/package.json +5 -2
  5. package/src/CreateXHelper.sol +3 -1
  6. package/src/DeployUtils.sol +36 -71
  7. package/src/Errors.sol +1 -1
  8. package/src/IIncoLightning.sol +2 -0
  9. package/src/IncoLightning.sol +5 -17
  10. package/src/IncoVerifier.sol +12 -18
  11. package/src/Lib.alphanet.sol +1 -1
  12. package/src/Lib.sol +1 -1
  13. package/src/Lib.template.sol +35 -153
  14. package/src/Types.sol +231 -97
  15. package/src/interfaces/IIncoLightning.sol +2 -0
  16. package/src/interfaces/IIncoVerifier.sol +6 -12
  17. package/src/interfaces/automata-interfaces/BELE.sol +2 -0
  18. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
  19. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
  20. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
  21. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
  22. package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
  23. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
  24. package/src/interfaces/automata-interfaces/Types.sol +7 -6
  25. package/src/libs/incoLightning_alphanet_v2_976644394.sol +478 -0
  26. package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
  27. package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
  28. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +39 -72
  29. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
  30. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
  31. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
  32. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +44 -84
  33. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
  34. package/src/lightning-parts/DecryptionAttester.sol +14 -28
  35. package/src/lightning-parts/EncryptedInput.sol +23 -52
  36. package/src/lightning-parts/EncryptedOperations.sol +96 -438
  37. package/src/lightning-parts/Fee.sol +3 -1
  38. package/src/lightning-parts/TEELifecycle.sol +94 -223
  39. package/src/lightning-parts/TEELifecycle.types.sol +4 -3
  40. package/src/lightning-parts/TrivialEncryption.sol +6 -20
  41. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
  42. package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
  43. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
  44. package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
  45. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
  46. package/src/lightning-parts/primitives/EventCounter.sol +7 -8
  47. package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
  48. package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
  49. package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
  50. package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
  51. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
  52. package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
  53. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
  54. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
  55. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
  56. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
  57. package/src/lightning-parts/test/Fee.t.sol +6 -6
  58. package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
  59. package/src/lightning-parts/test/InputsFee.t.sol +7 -28
  60. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
  61. package/src/pasted-dependencies/CreateX.sol +154 -455
  62. package/src/pasted-dependencies/ICreateX.sol +55 -102
  63. package/src/periphery/SessionVerifier.sol +10 -8
  64. package/src/shared/IOwnable.sol +3 -0
  65. package/src/shared/IUUPSUpgradable.sol +5 -1
  66. package/src/shared/JsonUtils.sol +3 -5
  67. package/src/shared/TestUtils.sol +15 -13
  68. package/src/test/AddTwo.sol +9 -7
  69. package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
  70. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -119
  71. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
  72. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
  73. package/src/test/FakeIncoInfra/KVStore.sol +2 -0
  74. package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
  75. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +50 -21
  76. package/src/test/IncoTest.sol +22 -9
  77. package/src/test/OpsTest.sol +438 -0
  78. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +57 -104
  79. package/src/test/TestAddTwo.t.sol +4 -3
  80. package/src/test/TestDeploy.t.sol +5 -6
  81. package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -9
  82. package/src/test/TestFakeInfra.t.sol +15 -38
  83. package/src/test/TestUpgrade.t.sol +40 -135
  84. package/src/test/TestVersion.t.sol +6 -5
  85. package/src/version/IncoLightningConfig.sol +2 -2
  86. package/src/version/Version.sol +46 -48
  87. package/src/version/interfaces/IVersion.sol +6 -0
@@ -5,9 +5,9 @@ pragma solidity ^0.8;
5
5
  import {IncoLightning} from "./IncoLightning.sol";
6
6
  import {ebool, euint256, eaddress, ETypes} from "./Types.sol";
7
7
 
8
- IncoLightning constant inco = IncoLightning(
9
- 0x000000000000000000000000000000000000baBe
10
- );
8
+ // forge-lint: disable-next-line(screaming-snake-case-const)
9
+ IncoLightning constant inco = IncoLightning(0x000000000000000000000000000000000000baBe);
10
+ // forge-lint: disable-next-line(screaming-snake-case-const)
11
11
  address constant deployedBy = 0x000000000000000000000000000000000000baBe;
12
12
 
13
13
  function typeOf(bytes32 handle) pure returns (ETypes) {
@@ -15,6 +15,7 @@ function typeOf(bytes32 handle) pure returns (ETypes) {
15
15
  }
16
16
 
17
17
  library e {
18
+
18
19
  function sanitize(euint256 a) internal returns (euint256) {
19
20
  if (euint256.unwrap(a) == bytes32(0)) {
20
21
  return asEuint256(0);
@@ -109,30 +110,15 @@ library e {
109
110
  }
110
111
 
111
112
  function and(euint256 a, euint256 b) internal returns (euint256) {
112
- return
113
- euint256.wrap(
114
- inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b)))
115
- );
113
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
116
114
  }
117
115
 
118
116
  function and(euint256 a, uint256 b) internal returns (euint256) {
119
- return
120
- euint256.wrap(
121
- inco.eBitAnd(
122
- euint256.unwrap(s(a)),
123
- euint256.unwrap(asEuint256(b))
124
- )
125
- );
117
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
126
118
  }
127
119
 
128
120
  function and(uint256 a, euint256 b) internal returns (euint256) {
129
- return
130
- euint256.wrap(
131
- inco.eBitAnd(
132
- euint256.unwrap(asEuint256(a)),
133
- euint256.unwrap(s(b))
134
- )
135
- );
121
+ return euint256.wrap(inco.eBitAnd(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
136
122
  }
137
123
 
138
124
  function and(ebool a, ebool b) internal returns (ebool) {
@@ -140,44 +126,23 @@ library e {
140
126
  }
141
127
 
142
128
  function and(ebool a, bool b) internal returns (ebool) {
143
- return
144
- ebool.wrap(
145
- inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b)))
146
- );
129
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
147
130
  }
148
131
 
149
132
  function and(bool a, ebool b) internal returns (ebool) {
150
- return
151
- ebool.wrap(
152
- inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b)))
153
- );
133
+ return ebool.wrap(inco.eBitAnd(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
154
134
  }
155
135
 
156
136
  function or(euint256 a, euint256 b) internal returns (euint256) {
157
- return
158
- euint256.wrap(
159
- inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b)))
160
- );
137
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
161
138
  }
162
139
 
163
140
  function or(euint256 a, uint256 b) internal returns (euint256) {
164
- return
165
- euint256.wrap(
166
- inco.eBitOr(
167
- euint256.unwrap(s(a)),
168
- euint256.unwrap(asEuint256(b))
169
- )
170
- );
141
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
171
142
  }
172
143
 
173
144
  function or(uint256 a, euint256 b) internal returns (euint256) {
174
- return
175
- euint256.wrap(
176
- inco.eBitOr(
177
- euint256.unwrap(asEuint256(a)),
178
- euint256.unwrap(s(b))
179
- )
180
- );
145
+ return euint256.wrap(inco.eBitOr(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
181
146
  }
182
147
 
183
148
  function or(ebool a, ebool b) internal returns (ebool) {
@@ -185,44 +150,23 @@ library e {
185
150
  }
186
151
 
187
152
  function or(ebool a, bool b) internal returns (ebool) {
188
- return
189
- ebool.wrap(
190
- inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b)))
191
- );
153
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
192
154
  }
193
155
 
194
156
  function or(bool a, ebool b) internal returns (ebool) {
195
- return
196
- ebool.wrap(
197
- inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b)))
198
- );
157
+ return ebool.wrap(inco.eBitOr(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
199
158
  }
200
159
 
201
160
  function xor(euint256 a, euint256 b) internal returns (euint256) {
202
- return
203
- euint256.wrap(
204
- inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b)))
205
- );
161
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(s(b))));
206
162
  }
207
163
 
208
164
  function xor(euint256 a, uint256 b) internal returns (euint256) {
209
- return
210
- euint256.wrap(
211
- inco.eBitXor(
212
- euint256.unwrap(s(a)),
213
- euint256.unwrap(asEuint256(b))
214
- )
215
- );
165
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(s(a)), euint256.unwrap(asEuint256(b))));
216
166
  }
217
167
 
218
168
  function xor(uint256 a, euint256 b) internal returns (euint256) {
219
- return
220
- euint256.wrap(
221
- inco.eBitXor(
222
- euint256.unwrap(asEuint256(a)),
223
- euint256.unwrap(s(b))
224
- )
225
- );
169
+ return euint256.wrap(inco.eBitXor(euint256.unwrap(asEuint256(a)), euint256.unwrap(s(b))));
226
170
  }
227
171
 
228
172
  function xor(ebool a, ebool b) internal returns (ebool) {
@@ -230,17 +174,11 @@ library e {
230
174
  }
231
175
 
232
176
  function xor(ebool a, bool b) internal returns (ebool) {
233
- return
234
- ebool.wrap(
235
- inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b)))
236
- );
177
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(s(a)), ebool.unwrap(asEbool(b))));
237
178
  }
238
179
 
239
180
  function xor(bool a, ebool b) internal returns (ebool) {
240
- return
241
- ebool.wrap(
242
- inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b)))
243
- );
181
+ return ebool.wrap(inco.eBitXor(ebool.unwrap(asEbool(a)), ebool.unwrap(s(b))));
244
182
  }
245
183
 
246
184
  function shl(euint256 a, euint256 b) internal returns (euint256) {
@@ -423,23 +361,14 @@ library e {
423
361
  /// @dev costs the inco fee
424
362
  function randBounded(uint256 upperBound) internal returns (euint256) {
425
363
  return
426
- euint256.wrap(
427
- inco.eRandBounded{value: inco.getFee()}(
428
- euint256.unwrap(asEuint256(upperBound)),
429
- ETypes.Uint256
430
- )
364
+ euint256.wrap(
365
+ inco.eRandBounded{value: inco.getFee()}(euint256.unwrap(asEuint256(upperBound)), ETypes.Uint256)
431
366
  );
432
367
  }
433
368
 
434
369
  /// @dev costs the inco fee
435
370
  function randBounded(euint256 upperBound) internal returns (euint256) {
436
- return
437
- euint256.wrap(
438
- inco.eRandBounded{value: inco.getFee()}(
439
- euint256.unwrap(s(upperBound)),
440
- ETypes.Uint256
441
- )
442
- );
371
+ return euint256.wrap(inco.eRandBounded{value: inco.getFee()}(euint256.unwrap(s(upperBound)), ETypes.Uint256));
443
372
  }
444
373
 
445
374
  function asEuint256(uint256 a) internal returns (euint256) {
@@ -464,52 +393,37 @@ library e {
464
393
 
465
394
  /// @notice Creates a new encrypted uint256 assuming msg.sender is the user
466
395
  /// @dev costs the inco fee
467
- function newEuint256(
468
- bytes memory ciphertext
469
- ) internal returns (euint256) {
396
+ function newEuint256(bytes memory ciphertext) internal returns (euint256) {
470
397
  return newEuint256(ciphertext, msg.sender);
471
398
  }
472
399
 
473
400
  /// @notice Creates a new encrypted uint256 for the given user.
474
401
  /// @dev costs the inco fee
475
- function newEuint256(
476
- bytes memory ciphertext,
477
- address user
478
- ) internal returns (euint256) {
402
+ function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
479
403
  return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
480
404
  }
481
405
 
482
406
  /// @notice Creates a new encrypted bool assuming msg.sender is the user
483
407
  /// @dev costs the inco fee
484
- function newEbool(
485
- bytes memory ciphertext
486
- ) internal returns (ebool) {
408
+ function newEbool(bytes memory ciphertext) internal returns (ebool) {
487
409
  return newEbool(ciphertext, msg.sender);
488
410
  }
489
411
 
490
412
  /// @notice Creates a new encrypted bool for the given user.
491
413
  /// @dev costs the inco fee
492
- function newEbool(
493
- bytes memory ciphertext,
494
- address user
495
- ) internal returns (ebool) {
414
+ function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
496
415
  return inco.newEbool{value: inco.getFee()}(ciphertext, user);
497
416
  }
498
417
 
499
418
  /// @notice Creates a new encrypted address assuming msg.sender is the user
500
419
  /// @dev costs the inco fee
501
- function newEaddress(
502
- bytes memory ciphertext
503
- ) internal returns (eaddress) {
420
+ function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
504
421
  return newEaddress(ciphertext, msg.sender);
505
422
  }
506
423
 
507
424
  /// @notice Creates a new encrypted address for the given user.
508
425
  /// @dev costs the inco fee
509
- function newEaddress(
510
- bytes memory ciphertext,
511
- address user
512
- ) internal returns (eaddress) {
426
+ function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
513
427
  return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
514
428
  }
515
429
 
@@ -553,48 +467,16 @@ library e {
553
467
  return inco.isAllowed(euint256.unwrap(a), user);
554
468
  }
555
469
 
556
- function select(
557
- ebool control,
558
- euint256 ifTrue,
559
- euint256 ifFalse
560
- ) internal returns (euint256) {
561
- return
562
- euint256.wrap(
563
- inco.eIfThenElse(
564
- s(control),
565
- euint256.unwrap(s(ifTrue)),
566
- euint256.unwrap(s(ifFalse))
567
- )
568
- );
470
+ function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
471
+ return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
569
472
  }
570
473
 
571
- function select(
572
- ebool control,
573
- ebool ifTrue,
574
- ebool ifFalse
575
- ) internal returns (ebool) {
576
- return
577
- ebool.wrap(
578
- inco.eIfThenElse(
579
- s(control),
580
- ebool.unwrap(s(ifTrue)),
581
- ebool.unwrap(s(ifFalse))
582
- )
583
- );
474
+ function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
475
+ return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
584
476
  }
585
477
 
586
- function select(
587
- ebool control,
588
- eaddress ifTrue,
589
- eaddress ifFalse
590
- ) internal returns (eaddress) {
591
- return
592
- eaddress.wrap(
593
- inco.eIfThenElse(
594
- s(control),
595
- eaddress.unwrap(s(ifTrue)),
596
- eaddress.unwrap(s(ifFalse))
597
- )
598
- );
478
+ function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
479
+ return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
599
480
  }
481
+
600
482
  }
package/src/Types.sol CHANGED
@@ -3,110 +3,245 @@ pragma solidity ^0.8;
3
3
 
4
4
  // matches Zama's ids, cf contracts/inco-fhevm/dependencies/fhevm-0.0.1/contracts/contracts/TFHEExecutor.sol l97-124
5
5
  // https://github.com/zama-ai/fhevm/blob/be14f85eb5b17ee868bfa66c2c6c5db61d67c89f/lib/TFHEExecutor.sol#L86
6
- enum EOps {
7
- Add, // 0
8
- Sub, // 1
9
- Mul, // 2
10
- Div, // 3
11
- Rem, // 4
12
- BitAnd, // 5
13
- BitOr, // 6
14
- BitXor, // 7
15
- Shl, // 8
16
- Shr, // 9
17
- Rotl, // 10
18
- Rotr, // 11
19
- Eq, // 12
20
- Ne, // 13
21
- Ge, // 14
22
- Gt, // 15
23
- Le, // 16
24
- Lt, // 17
25
- Min, // 18
26
- Max, // 19
27
- NegUNSUPPORTED, // 20
28
- Not, // 21
29
- NewInput, // 22
30
- Cast, // 23
31
- TrivialEncrypt, // 24
32
- IfThenElse, // 25
33
- Rand, // 26
34
- RandBounded, // 27
35
- // These are pseudo-ops part of the decryption/callback system but we need to generate code for them so I am including them
36
- DecryptionRequested, // 28
37
- RequestFulfilled, // 29
38
- EOP30, EOP31, EOP32, EOP33, EOP34, EOP35, EOP36, EOP37, EOP38, EOP39,
39
- // Pseudo-operation for an ACL (persistent) allow
40
- Allow, // 40
41
- Reveal, // 41
42
- EOP42, EOP43, EOP44, EOP45, EOP46, EOP47, EOP48, EOP49,
43
- EOP50, EOP51, EOP52, EOP53, EOP54, EOP55, EOP56, EOP57, EOP58, EOP59,
44
- EOP60, EOP61, EOP62, EOP63, EOP64, EOP65, EOP66, EOP67, EOP68, EOP69,
45
- EOP70, EOP71, EOP72, EOP73, EOP74, EOP75, EOP76, EOP77, EOP78, EOP79,
46
- EOP80, EOP81, EOP82, EOP83, EOP84, EOP85, EOP86, EOP87, EOP88, EOP89,
47
- EOP90, EOP91, EOP92, EOP93, EOP94, EOP95, EOP96, EOP97, EOP98, EOP99,
48
- NewEList, // 100
49
- EListGet, // 101
50
- EListGetOr, // 102
51
- EListSet, // 103
52
- EListInsert, // 104
53
- EListAppend, // 105
54
- EListConcat, // 106
55
- EListSlice, // 107
56
- EListRange, // 108
57
- EListShuffle, // 109
58
- EListReverse // 110
59
- }
6
+ enum EOps {
7
+ Add, // 0
8
+ Sub, // 1
9
+ Mul, // 2
10
+ Div, // 3
11
+ Rem, // 4
12
+ BitAnd, // 5
13
+ BitOr, // 6
14
+ BitXor, // 7
15
+ Shl, // 8
16
+ Shr, // 9
17
+ Rotl, // 10
18
+ Rotr, // 11
19
+ Eq, // 12
20
+ Ne, // 13
21
+ Ge, // 14
22
+ Gt, // 15
23
+ Le, // 16
24
+ Lt, // 17
25
+ Min, // 18
26
+ Max, // 19
27
+ NegUNSUPPORTED, // 20
28
+ Not, // 21
29
+ NewInput, // 22
30
+ Cast, // 23
31
+ TrivialEncrypt, // 24
32
+ IfThenElse, // 25
33
+ Rand, // 26
34
+ RandBounded, // 27
35
+ // These are pseudo-ops part of the decryption/callback system but we need to generate code for them so I am including them
36
+ DecryptionRequested, // 28
37
+ RequestFulfilled, // 29
38
+ EOP30,
39
+ EOP31,
40
+ EOP32,
41
+ EOP33,
42
+ EOP34,
43
+ EOP35,
44
+ EOP36,
45
+ EOP37,
46
+ EOP38,
47
+ EOP39,
48
+ // Pseudo-operation for an ACL (persistent) allow
49
+ Allow, // 40
50
+ Reveal, // 41
51
+ EOP42,
52
+ EOP43,
53
+ EOP44,
54
+ EOP45,
55
+ EOP46,
56
+ EOP47,
57
+ EOP48,
58
+ EOP49,
59
+ EOP50,
60
+ EOP51,
61
+ EOP52,
62
+ EOP53,
63
+ EOP54,
64
+ EOP55,
65
+ EOP56,
66
+ EOP57,
67
+ EOP58,
68
+ EOP59,
69
+ EOP60,
70
+ EOP61,
71
+ EOP62,
72
+ EOP63,
73
+ EOP64,
74
+ EOP65,
75
+ EOP66,
76
+ EOP67,
77
+ EOP68,
78
+ EOP69,
79
+ EOP70,
80
+ EOP71,
81
+ EOP72,
82
+ EOP73,
83
+ EOP74,
84
+ EOP75,
85
+ EOP76,
86
+ EOP77,
87
+ EOP78,
88
+ EOP79,
89
+ EOP80,
90
+ EOP81,
91
+ EOP82,
92
+ EOP83,
93
+ EOP84,
94
+ EOP85,
95
+ EOP86,
96
+ EOP87,
97
+ EOP88,
98
+ EOP89,
99
+ EOP90,
100
+ EOP91,
101
+ EOP92,
102
+ EOP93,
103
+ EOP94,
104
+ EOP95,
105
+ EOP96,
106
+ EOP97,
107
+ EOP98,
108
+ EOP99,
109
+ NewEList, // 100
110
+ EListGet, // 101
111
+ EListGetOr, // 102
112
+ EListSet, // 103
113
+ EListInsert, // 104
114
+ EListAppend, // 105
115
+ EListConcat, // 106
116
+ EListSlice, // 107
117
+ EListRange, // 108
118
+ EListShuffle, // 109
119
+ EListReverse // 110
120
+ }
121
+
122
+ type ebool is bytes32;
123
+
124
+ type euint256 is bytes32;
60
125
 
61
- type ebool is bytes32;
62
- type euint256 is bytes32;
63
- type eaddress is bytes32;
126
+ type eaddress is bytes32;
64
127
 
65
128
  // matches Zama's ids, cf contracts/inco-fhevm/dependencies/fhevm-0.0.1/contracts/lib/TFHE.sol l24-35
66
129
  // https://github.com/zama-ai/fhevm/blob/61c0b3593414082b2da6e591252ed3721fe922d7/lib/TFHE.sol#L26
67
- enum ETypes {
68
- Bool,
69
- Uint4UNSUPPORTED,
70
- Uint8UNSUPPORTED,
71
- Uint16UNSUPPORTED,
72
- Uint32UNSUPPORTED,
73
- Uint64UNSUPPORTED,
74
- Uint128UNSUPPORTED,
75
- AddressOrUint160OrBytes20,
76
- Uint256,
77
- Bytes64UNSUPPORTED,
78
- Bytes128UNSUPPORTED,
79
- Bytes256UNSUPPORTED,
80
- EmptyType12, // 12
81
- EmptyType13, // 13
82
- EmptyType14, // 14
83
- EmptyType15, // 15
84
- EmptyType16, // 16
85
- EmptyType17, // 17
86
- EmptyType18, // 18
87
- EmptyType19, // 19
88
- EmptyType20, EmptyType21, EmptyType22, EmptyType23, EmptyType24, EmptyType25, EmptyType26, EmptyType27, EmptyType28, EmptyType29,
89
- EmptyType30, EmptyType31, EmptyType32, EmptyType33, EmptyType34, EmptyType35, EmptyType36, EmptyType37, EmptyType38, EmptyType39,
90
- EmptyType40, EmptyType41, EmptyType42, EmptyType43, EmptyType44, EmptyType45, EmptyType46, EmptyType47, EmptyType48, EmptyType49,
91
- EmptyType50, EmptyType51, EmptyType52, EmptyType53, EmptyType54, EmptyType55, EmptyType56, EmptyType57, EmptyType58, EmptyType59,
92
- EmptyType60, EmptyType61, EmptyType62, EmptyType63, EmptyType64, EmptyType65, EmptyType66, EmptyType67, EmptyType68, EmptyType69,
93
- EmptyType70, EmptyType71, EmptyType72, EmptyType73, EmptyType74, EmptyType75, EmptyType76, EmptyType77, EmptyType78, EmptyType79,
94
- EmptyType80, EmptyType81, EmptyType82, EmptyType83, EmptyType84, EmptyType85, EmptyType86, EmptyType87, EmptyType88, EmptyType89,
95
- EmptyType90, EmptyType91, EmptyType92, EmptyType93, EmptyType94, EmptyType95, EmptyType96, EmptyType97, EmptyType98, EmptyType99,
96
- List // 100
97
- }
130
+ enum ETypes {
131
+ Bool,
132
+ Uint4UNSUPPORTED,
133
+ Uint8UNSUPPORTED,
134
+ Uint16UNSUPPORTED,
135
+ Uint32UNSUPPORTED,
136
+ Uint64UNSUPPORTED,
137
+ Uint128UNSUPPORTED,
138
+ AddressOrUint160OrBytes20,
139
+ Uint256,
140
+ Bytes64UNSUPPORTED,
141
+ Bytes128UNSUPPORTED,
142
+ Bytes256UNSUPPORTED,
143
+ EmptyType12, // 12
144
+ EmptyType13, // 13
145
+ EmptyType14, // 14
146
+ EmptyType15, // 15
147
+ EmptyType16, // 16
148
+ EmptyType17, // 17
149
+ EmptyType18, // 18
150
+ EmptyType19, // 19
151
+ EmptyType20,
152
+ EmptyType21,
153
+ EmptyType22,
154
+ EmptyType23,
155
+ EmptyType24,
156
+ EmptyType25,
157
+ EmptyType26,
158
+ EmptyType27,
159
+ EmptyType28,
160
+ EmptyType29,
161
+ EmptyType30,
162
+ EmptyType31,
163
+ EmptyType32,
164
+ EmptyType33,
165
+ EmptyType34,
166
+ EmptyType35,
167
+ EmptyType36,
168
+ EmptyType37,
169
+ EmptyType38,
170
+ EmptyType39,
171
+ EmptyType40,
172
+ EmptyType41,
173
+ EmptyType42,
174
+ EmptyType43,
175
+ EmptyType44,
176
+ EmptyType45,
177
+ EmptyType46,
178
+ EmptyType47,
179
+ EmptyType48,
180
+ EmptyType49,
181
+ EmptyType50,
182
+ EmptyType51,
183
+ EmptyType52,
184
+ EmptyType53,
185
+ EmptyType54,
186
+ EmptyType55,
187
+ EmptyType56,
188
+ EmptyType57,
189
+ EmptyType58,
190
+ EmptyType59,
191
+ EmptyType60,
192
+ EmptyType61,
193
+ EmptyType62,
194
+ EmptyType63,
195
+ EmptyType64,
196
+ EmptyType65,
197
+ EmptyType66,
198
+ EmptyType67,
199
+ EmptyType68,
200
+ EmptyType69,
201
+ EmptyType70,
202
+ EmptyType71,
203
+ EmptyType72,
204
+ EmptyType73,
205
+ EmptyType74,
206
+ EmptyType75,
207
+ EmptyType76,
208
+ EmptyType77,
209
+ EmptyType78,
210
+ EmptyType79,
211
+ EmptyType80,
212
+ EmptyType81,
213
+ EmptyType82,
214
+ EmptyType83,
215
+ EmptyType84,
216
+ EmptyType85,
217
+ EmptyType86,
218
+ EmptyType87,
219
+ EmptyType88,
220
+ EmptyType89,
221
+ EmptyType90,
222
+ EmptyType91,
223
+ EmptyType92,
224
+ EmptyType93,
225
+ EmptyType94,
226
+ EmptyType95,
227
+ EmptyType96,
228
+ EmptyType97,
229
+ EmptyType98,
230
+ EmptyType99,
231
+ List // 100
232
+ }
98
233
 
99
234
  // check correctness of compute
100
235
  // revert acl
101
236
 
102
237
  /// Checks whether the given type is a valid numeric type or a boolean.
103
238
  /// @param t the type to check
104
- function isTypeSupported(ETypes t) pure returns (bool) {
105
- return t == ETypes.Uint256 || t == ETypes.Bool || t == ETypes.AddressOrUint160OrBytes20;
106
- }
239
+ function isTypeSupported(ETypes t) pure returns (bool) {
240
+ return t == ETypes.Uint256 || t == ETypes.Bool || t == ETypes.AddressOrUint160OrBytes20;
241
+ }
107
242
 
108
- error SenderNotAllowedForHandle(bytes32 handle, address sender);
109
- error SharerNotAllowedForHandle(bytes32 handle, address sharer);
243
+ error SenderNotAllowedForHandle(bytes32 handle, address sender);
244
+ error SharerNotAllowedForHandle(bytes32 handle, address sharer);
110
245
 
111
246
  string constant EVM_HOST_CHAIN_PREFIX = "evm/";
112
247
  uint8 constant HANDLE_VERSION = 0;
@@ -114,9 +249,7 @@ uint8 constant HANDLE_VERSION = 0;
114
249
  // used to make sure a verifier contract is checking allowance access on purpose, using a bytes4 or bool return type
115
250
  // can lead to forging allowance vouchers using contract calls meant for an unrelated purpose, which lead to access
116
251
  // theft. Its a common pattern, notably used in EIP1271 (Signature Validation Procedure for Contracts)
117
- bytes32 constant ALLOWANCE_GRANTED_MAGIC_VALUE = keccak256(
118
- "Inco Read Access on Provided Handle is Granted"
119
- );
252
+ bytes32 constant ALLOWANCE_GRANTED_MAGIC_VALUE = keccak256("Inco Read Access on Provided Handle is Granted");
120
253
 
121
254
  // IncoLightning only supports single-valued ciphertexts so this is always 0
122
255
  // NOTE: this must be a uint8 to get hash agreement!
@@ -125,5 +258,6 @@ uint8 constant HANDLE_INDEX = 0;
125
258
  /// Util function to convert an ETypes to a bit mask
126
259
  /// @param t the type to convert to a bit mask
127
260
  function typeToBitMask(ETypes t) pure returns (bytes32) {
128
- return bytes32(1 << uint256(t));
261
+ uint256 one = 1;
262
+ return bytes32(one << uint256(t));
129
263
  }
@@ -16,5 +16,7 @@ interface IIncoLightning is
16
16
  IHandleGeneration,
17
17
  IVersion
18
18
  {
19
+
19
20
  function initialize(address owner) external;
21
+
20
22
  }