@inco/lightning 0.6.8 → 0.6.9

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 (83) hide show
  1. package/README.md +29 -2
  2. package/manifest.yaml +0 -42
  3. package/package.json +5 -2
  4. package/src/CreateXHelper.sol +3 -1
  5. package/src/DeployUtils.sol +36 -71
  6. package/src/Errors.sol +1 -1
  7. package/src/IIncoLightning.sol +2 -0
  8. package/src/IncoLightning.sol +5 -17
  9. package/src/IncoVerifier.sol +12 -18
  10. package/src/Lib.template.sol +40 -159
  11. package/src/Types.sol +233 -97
  12. package/src/interfaces/IIncoLightning.sol +2 -0
  13. package/src/interfaces/IIncoVerifier.sol +7 -12
  14. package/src/interfaces/automata-interfaces/BELE.sol +2 -0
  15. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +9 -11
  16. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +3 -3
  17. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +13 -47
  18. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +2 -0
  19. package/src/interfaces/automata-interfaces/IPcsDao.sol +6 -11
  20. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +4 -7
  21. package/src/interfaces/automata-interfaces/Types.sol +7 -6
  22. package/src/libs/incoLightning_devnet_v1_887305889.sol +5 -3
  23. package/src/libs/incoLightning_testnet_v1_938327937.sol +5 -3
  24. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +41 -75
  25. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +31 -62
  26. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +8 -15
  27. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +5 -12
  28. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +42 -83
  29. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +2 -0
  30. package/src/lightning-parts/DecryptionAttester.sol +14 -28
  31. package/src/lightning-parts/EncryptedInput.sol +23 -52
  32. package/src/lightning-parts/EncryptedOperations.sol +93 -440
  33. package/src/lightning-parts/Fee.sol +3 -1
  34. package/src/lightning-parts/TEELifecycle.sol +95 -225
  35. package/src/lightning-parts/TEELifecycle.types.sol +4 -3
  36. package/src/lightning-parts/TrivialEncryption.sol +6 -20
  37. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +7 -2
  38. package/src/lightning-parts/interfaces/IEncryptedInput.sol +5 -12
  39. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +17 -61
  40. package/src/lightning-parts/interfaces/ITEELifecycle.sol +7 -11
  41. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +2 -0
  42. package/src/lightning-parts/primitives/EventCounter.sol +7 -8
  43. package/src/lightning-parts/primitives/HandleGeneration.sol +20 -32
  44. package/src/lightning-parts/primitives/HandleMetadata.sol +7 -17
  45. package/src/lightning-parts/primitives/LightningAddressGetter.sol +3 -0
  46. package/src/lightning-parts/primitives/SignatureVerifier.sol +91 -27
  47. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +3 -0
  48. package/src/lightning-parts/primitives/interfaces/IEventCounter.sol +2 -0
  49. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +10 -2
  50. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +4 -2
  51. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +2 -0
  52. package/src/lightning-parts/primitives/test/SignatureVerifier.t.sol +838 -0
  53. package/src/lightning-parts/test/Fee.t.sol +6 -6
  54. package/src/lightning-parts/test/HandleMetadata.t.sol +21 -76
  55. package/src/lightning-parts/test/InputsFee.t.sol +7 -28
  56. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +16 -48
  57. package/src/pasted-dependencies/CreateX.sol +146 -419
  58. package/src/pasted-dependencies/ICreateX.sol +58 -102
  59. package/src/periphery/SessionVerifier.sol +5 -7
  60. package/src/shared/IOwnable.sol +3 -0
  61. package/src/shared/IUUPSUpgradable.sol +5 -1
  62. package/src/shared/JsonUtils.sol +3 -5
  63. package/src/shared/TestUtils.sol +14 -13
  64. package/src/test/AddTwo.sol +9 -7
  65. package/src/test/FakeIncoInfra/FakeComputeServer.sol +11 -53
  66. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +35 -118
  67. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +31 -48
  68. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +4 -7
  69. package/src/test/FakeIncoInfra/KVStore.sol +2 -0
  70. package/src/test/FakeIncoInfra/MockOpHandler.sol +9 -31
  71. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +44 -21
  72. package/src/test/IncoTest.sol +15 -9
  73. package/src/test/OpsTest.sol +429 -0
  74. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +58 -104
  75. package/src/test/TestAddTwo.t.sol +4 -3
  76. package/src/test/TestDeploy.t.sol +5 -6
  77. package/src/test/TestExtractDataOfEventTooLarge.t.sol +7 -14
  78. package/src/test/TestFakeInfra.t.sol +15 -38
  79. package/src/test/TestUpgrade.t.sol +40 -135
  80. package/src/test/TestVersion.t.sol +6 -5
  81. package/src/version/IncoLightningConfig.sol +1 -1
  82. package/src/version/Version.sol +48 -51
  83. 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) {
@@ -422,24 +360,14 @@ library e {
422
360
 
423
361
  /// @dev costs the inco fee
424
362
  function randBounded(uint256 upperBound) internal returns (euint256) {
425
- return
426
- euint256.wrap(
427
- inco.eRandBounded{value: inco.getFee()}(
428
- euint256.unwrap(asEuint256(upperBound)),
429
- ETypes.Uint256
430
- )
431
- );
363
+ return euint256.wrap(
364
+ inco.eRandBounded{value: inco.getFee()}(euint256.unwrap(asEuint256(upperBound)), ETypes.Uint256)
365
+ );
432
366
  }
433
367
 
434
368
  /// @dev costs the inco fee
435
369
  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
- );
370
+ return euint256.wrap(inco.eRandBounded{value: inco.getFee()}(euint256.unwrap(s(upperBound)), ETypes.Uint256));
443
371
  }
444
372
 
445
373
  function asEuint256(uint256 a) internal returns (euint256) {
@@ -464,52 +392,37 @@ library e {
464
392
 
465
393
  /// @notice Creates a new encrypted uint256 assuming msg.sender is the user
466
394
  /// @dev costs the inco fee
467
- function newEuint256(
468
- bytes memory ciphertext
469
- ) internal returns (euint256) {
395
+ function newEuint256(bytes memory ciphertext) internal returns (euint256) {
470
396
  return newEuint256(ciphertext, msg.sender);
471
397
  }
472
398
 
473
399
  /// @notice Creates a new encrypted uint256 for the given user.
474
400
  /// @dev costs the inco fee
475
- function newEuint256(
476
- bytes memory ciphertext,
477
- address user
478
- ) internal returns (euint256) {
401
+ function newEuint256(bytes memory ciphertext, address user) internal returns (euint256) {
479
402
  return inco.newEuint256{value: inco.getFee()}(ciphertext, user);
480
403
  }
481
404
 
482
405
  /// @notice Creates a new encrypted bool assuming msg.sender is the user
483
406
  /// @dev costs the inco fee
484
- function newEbool(
485
- bytes memory ciphertext
486
- ) internal returns (ebool) {
407
+ function newEbool(bytes memory ciphertext) internal returns (ebool) {
487
408
  return newEbool(ciphertext, msg.sender);
488
409
  }
489
410
 
490
411
  /// @notice Creates a new encrypted bool for the given user.
491
412
  /// @dev costs the inco fee
492
- function newEbool(
493
- bytes memory ciphertext,
494
- address user
495
- ) internal returns (ebool) {
413
+ function newEbool(bytes memory ciphertext, address user) internal returns (ebool) {
496
414
  return inco.newEbool{value: inco.getFee()}(ciphertext, user);
497
415
  }
498
416
 
499
417
  /// @notice Creates a new encrypted address assuming msg.sender is the user
500
418
  /// @dev costs the inco fee
501
- function newEaddress(
502
- bytes memory ciphertext
503
- ) internal returns (eaddress) {
419
+ function newEaddress(bytes memory ciphertext) internal returns (eaddress) {
504
420
  return newEaddress(ciphertext, msg.sender);
505
421
  }
506
422
 
507
423
  /// @notice Creates a new encrypted address for the given user.
508
424
  /// @dev costs the inco fee
509
- function newEaddress(
510
- bytes memory ciphertext,
511
- address user
512
- ) internal returns (eaddress) {
425
+ function newEaddress(bytes memory ciphertext, address user) internal returns (eaddress) {
513
426
  return inco.newEaddress{value: inco.getFee()}(ciphertext, user);
514
427
  }
515
428
 
@@ -553,48 +466,16 @@ library e {
553
466
  return inco.isAllowed(euint256.unwrap(a), user);
554
467
  }
555
468
 
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
- );
569
- }
570
-
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
- );
584
- }
585
-
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
- );
469
+ function select(ebool control, euint256 ifTrue, euint256 ifFalse) internal returns (euint256) {
470
+ return euint256.wrap(inco.eIfThenElse(s(control), euint256.unwrap(s(ifTrue)), euint256.unwrap(s(ifFalse))));
471
+ }
472
+
473
+ function select(ebool control, ebool ifTrue, ebool ifFalse) internal returns (ebool) {
474
+ return ebool.wrap(inco.eIfThenElse(s(control), ebool.unwrap(s(ifTrue)), ebool.unwrap(s(ifFalse))));
599
475
  }
476
+
477
+ function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
478
+ return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
479
+ }
480
+
600
481
  }
package/src/Types.sol CHANGED
@@ -3,110 +3,247 @@ 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
60
120
 
61
- type ebool is bytes32;
62
- type euint256 is bytes32;
63
- type eaddress is bytes32;
121
+ }
122
+
123
+ type ebool is bytes32;
124
+
125
+ type euint256 is bytes32;
126
+
127
+ type eaddress is bytes32;
64
128
 
65
129
  // matches Zama's ids, cf contracts/inco-fhevm/dependencies/fhevm-0.0.1/contracts/lib/TFHE.sol l24-35
66
130
  // 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
- }
131
+ enum ETypes {
132
+ Bool,
133
+ Uint4UNSUPPORTED,
134
+ Uint8UNSUPPORTED,
135
+ Uint16UNSUPPORTED,
136
+ Uint32UNSUPPORTED,
137
+ Uint64UNSUPPORTED,
138
+ Uint128UNSUPPORTED,
139
+ AddressOrUint160OrBytes20,
140
+ Uint256,
141
+ Bytes64UNSUPPORTED,
142
+ Bytes128UNSUPPORTED,
143
+ Bytes256UNSUPPORTED,
144
+ EmptyType12, // 12
145
+ EmptyType13, // 13
146
+ EmptyType14, // 14
147
+ EmptyType15, // 15
148
+ EmptyType16, // 16
149
+ EmptyType17, // 17
150
+ EmptyType18, // 18
151
+ EmptyType19, // 19
152
+ EmptyType20,
153
+ EmptyType21,
154
+ EmptyType22,
155
+ EmptyType23,
156
+ EmptyType24,
157
+ EmptyType25,
158
+ EmptyType26,
159
+ EmptyType27,
160
+ EmptyType28,
161
+ EmptyType29,
162
+ EmptyType30,
163
+ EmptyType31,
164
+ EmptyType32,
165
+ EmptyType33,
166
+ EmptyType34,
167
+ EmptyType35,
168
+ EmptyType36,
169
+ EmptyType37,
170
+ EmptyType38,
171
+ EmptyType39,
172
+ EmptyType40,
173
+ EmptyType41,
174
+ EmptyType42,
175
+ EmptyType43,
176
+ EmptyType44,
177
+ EmptyType45,
178
+ EmptyType46,
179
+ EmptyType47,
180
+ EmptyType48,
181
+ EmptyType49,
182
+ EmptyType50,
183
+ EmptyType51,
184
+ EmptyType52,
185
+ EmptyType53,
186
+ EmptyType54,
187
+ EmptyType55,
188
+ EmptyType56,
189
+ EmptyType57,
190
+ EmptyType58,
191
+ EmptyType59,
192
+ EmptyType60,
193
+ EmptyType61,
194
+ EmptyType62,
195
+ EmptyType63,
196
+ EmptyType64,
197
+ EmptyType65,
198
+ EmptyType66,
199
+ EmptyType67,
200
+ EmptyType68,
201
+ EmptyType69,
202
+ EmptyType70,
203
+ EmptyType71,
204
+ EmptyType72,
205
+ EmptyType73,
206
+ EmptyType74,
207
+ EmptyType75,
208
+ EmptyType76,
209
+ EmptyType77,
210
+ EmptyType78,
211
+ EmptyType79,
212
+ EmptyType80,
213
+ EmptyType81,
214
+ EmptyType82,
215
+ EmptyType83,
216
+ EmptyType84,
217
+ EmptyType85,
218
+ EmptyType86,
219
+ EmptyType87,
220
+ EmptyType88,
221
+ EmptyType89,
222
+ EmptyType90,
223
+ EmptyType91,
224
+ EmptyType92,
225
+ EmptyType93,
226
+ EmptyType94,
227
+ EmptyType95,
228
+ EmptyType96,
229
+ EmptyType97,
230
+ EmptyType98,
231
+ EmptyType99,
232
+ List // 100
233
+
234
+ }
98
235
 
99
236
  // check correctness of compute
100
237
  // revert acl
101
238
 
102
239
  /// Checks whether the given type is a valid numeric type or a boolean.
103
240
  /// @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
- }
241
+ function isTypeSupported(ETypes t) pure returns (bool) {
242
+ return t == ETypes.Uint256 || t == ETypes.Bool || t == ETypes.AddressOrUint160OrBytes20;
243
+ }
107
244
 
108
- error SenderNotAllowedForHandle(bytes32 handle, address sender);
109
- error SharerNotAllowedForHandle(bytes32 handle, address sharer);
245
+ error SenderNotAllowedForHandle(bytes32 handle, address sender);
246
+ error SharerNotAllowedForHandle(bytes32 handle, address sharer);
110
247
 
111
248
  string constant EVM_HOST_CHAIN_PREFIX = "evm/";
112
249
  uint8 constant HANDLE_VERSION = 0;
@@ -114,9 +251,7 @@ uint8 constant HANDLE_VERSION = 0;
114
251
  // used to make sure a verifier contract is checking allowance access on purpose, using a bytes4 or bool return type
115
252
  // can lead to forging allowance vouchers using contract calls meant for an unrelated purpose, which lead to access
116
253
  // 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
- );
254
+ bytes32 constant ALLOWANCE_GRANTED_MAGIC_VALUE = keccak256("Inco Read Access on Provided Handle is Granted");
120
255
 
121
256
  // IncoLightning only supports single-valued ciphertexts so this is always 0
122
257
  // NOTE: this must be a uint8 to get hash agreement!
@@ -125,5 +260,6 @@ uint8 constant HANDLE_INDEX = 0;
125
260
  /// Util function to convert an ETypes to a bit mask
126
261
  /// @param t the type to convert to a bit mask
127
262
  function typeToBitMask(ETypes t) pure returns (bytes32) {
128
- return bytes32(1 << uint256(t));
263
+ uint256 one = 1;
264
+ return bytes32(one << uint256(t));
129
265
  }
@@ -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
  }