@inco/lightning 0.6.1 → 0.6.4

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 (43) hide show
  1. package/package.json +1 -1
  2. package/src/DeployUtils.sol +1 -1
  3. package/src/Errors.sol +1 -1
  4. package/src/Lib.alphanet.sol +24 -3
  5. package/src/Lib.demonet.sol +24 -3
  6. package/src/Lib.devnet.sol +24 -3
  7. package/src/Lib.sol +24 -3
  8. package/src/Lib.template.sol +97 -20
  9. package/src/Lib.testnet.sol +24 -3
  10. package/src/libs/incoLightning_alphanet_v0_297966649.sol +24 -3
  11. package/src/libs/incoLightning_alphanet_v1_725458969.sol +24 -3
  12. package/src/libs/incoLightning_demonet_v0_863421733.sol +24 -3
  13. package/src/libs/incoLightning_devnet_v0_340846814.sol +24 -3
  14. package/src/libs/incoLightning_devnet_v1_904635675.sol +24 -3
  15. package/src/libs/incoLightning_testnet_v0_183408998.sol +24 -3
  16. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +1 -1
  17. package/src/lightning-parts/EncryptedInput.sol +52 -16
  18. package/src/lightning-parts/EncryptedOperations.sol +86 -90
  19. package/src/lightning-parts/TEELifecycle.sol +153 -66
  20. package/src/lightning-parts/TEELifecycle.types.sol +7 -0
  21. package/src/lightning-parts/interfaces/ITEELifecycle.sol +13 -2
  22. package/src/lightning-parts/primitives/HandleGeneration.sol +23 -57
  23. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +3 -34
  24. package/src/lightning-parts/test/HandleMetadata.t.sol +41 -4
  25. package/src/lightning-parts/test/InputsFee.t.sol +14 -21
  26. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +6 -2
  27. package/src/shared/IOwnable.sol +10 -0
  28. package/src/shared/IUUPSUpgradable.sol +10 -0
  29. package/src/shared/JsonUtils.sol +16 -0
  30. package/src/shared/TestUtils.sol +50 -0
  31. package/src/shared/TypeUtils.sol +12 -0
  32. package/src/test/FakeIncoInfra/FakeComputeServer.sol +1 -1
  33. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +36 -34
  34. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +33 -18
  35. package/src/test/FakeIncoInfra/KVStore.sol +1 -1
  36. package/src/test/FakeIncoInfra/MockOpHandler.sol +5 -5
  37. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +1 -1
  38. package/src/test/IncoTest.sol +1 -1
  39. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +73 -20
  40. package/src/test/TestAddTwo.t.sol +1 -1
  41. package/src/test/TestFakeInfra.t.sol +13 -3
  42. package/src/version/Version.sol +4 -0
  43. package/src/version/interfaces/IVersion.sol +1 -0
@@ -23,9 +23,9 @@ abstract contract EncryptedOperations is
23
23
  bytes32 constant EUINT256 = bytes32(1 << uint256(ETypes.Uint256));
24
24
 
25
25
  bytes32 constant SUPPORTED_TYPES_MASK =
26
- EBOOL |
27
- EUINT160 |
28
- EUINT256;
26
+ EBOOL |
27
+ EUINT160 |
28
+ EUINT256;
29
29
 
30
30
  event EAdd(
31
31
  euint256 indexed lhs,
@@ -198,41 +198,9 @@ abstract contract EncryptedOperations is
198
198
  function createResultHandle(
199
199
  EOps op,
200
200
  ETypes returnType,
201
- bytes32 lhs,
202
- bytes32 rhs
203
- ) internal returns (bytes32 result) {
204
- result = getOpResultHandle(op, returnType, lhs, rhs);
205
- allowTransientInternal(result, msg.sender);
206
- }
207
-
208
- function createResultHandle(
209
- EOps op,
210
- ETypes returnType,
211
- bytes32 inputA,
212
- bytes32 inputB,
213
- bytes32 inputC
214
- ) internal returns (bytes32 result) {
215
- result = getOpResultHandle(op, returnType, inputA, inputB, inputC);
216
- allowTransientInternal(result, msg.sender);
217
- }
218
-
219
- // todo replace with production implem
220
- function createResultHandle(
221
- EOps op,
222
- ETypes returnType,
223
- uint256 counter,
224
- bytes32 upperBound
225
- ) internal returns (bytes32 result) {
226
- result = getOpResultHandle(op, returnType, counter, upperBound);
227
- allowTransientInternal(result, msg.sender);
228
- }
229
-
230
- function createResultHandle(
231
- EOps op,
232
- ETypes returnType,
233
- bytes32 value
201
+ bytes memory packedInputs
234
202
  ) internal returns (bytes32 result) {
235
- result = getOpResultHandle(op, returnType, value);
203
+ result = getOpResultHandle(op, returnType, packedInputs);
236
204
  allowTransientInternal(result, msg.sender);
237
205
  }
238
206
 
@@ -244,8 +212,10 @@ abstract contract EncryptedOperations is
244
212
  createResultHandle(
245
213
  EOps.Add,
246
214
  ETypes.Uint256,
247
- euint256.unwrap(lhs),
248
- euint256.unwrap(rhs)
215
+ abi.encodePacked(
216
+ euint256.unwrap(lhs),
217
+ euint256.unwrap(rhs)
218
+ )
249
219
  )
250
220
  );
251
221
  uint256 id = getNextEventId();
@@ -261,8 +231,10 @@ abstract contract EncryptedOperations is
261
231
  createResultHandle(
262
232
  EOps.Sub,
263
233
  ETypes.Uint256,
264
- euint256.unwrap(lhs),
265
- euint256.unwrap(rhs)
234
+ abi.encodePacked(
235
+ euint256.unwrap(lhs),
236
+ euint256.unwrap(rhs)
237
+ )
266
238
  )
267
239
  );
268
240
  uint256 id = getNextEventId();
@@ -278,8 +250,10 @@ abstract contract EncryptedOperations is
278
250
  createResultHandle(
279
251
  EOps.Mul,
280
252
  ETypes.Uint256,
281
- euint256.unwrap(lhs),
282
- euint256.unwrap(rhs)
253
+ abi.encodePacked(
254
+ euint256.unwrap(lhs),
255
+ euint256.unwrap(rhs)
256
+ )
283
257
  )
284
258
  );
285
259
  uint256 id = getNextEventId();
@@ -295,8 +269,10 @@ abstract contract EncryptedOperations is
295
269
  createResultHandle(
296
270
  EOps.Div,
297
271
  ETypes.Uint256,
298
- euint256.unwrap(lhs),
299
- euint256.unwrap(rhs)
272
+ abi.encodePacked(
273
+ euint256.unwrap(lhs),
274
+ euint256.unwrap(rhs)
275
+ )
300
276
  )
301
277
  );
302
278
  uint256 id = getNextEventId();
@@ -312,8 +288,10 @@ abstract contract EncryptedOperations is
312
288
  createResultHandle(
313
289
  EOps.Rem,
314
290
  ETypes.Uint256,
315
- euint256.unwrap(lhs),
316
- euint256.unwrap(rhs)
291
+ abi.encodePacked(
292
+ euint256.unwrap(lhs),
293
+ euint256.unwrap(rhs)
294
+ )
317
295
  )
318
296
  );
319
297
  uint256 id = getNextEventId();
@@ -330,8 +308,8 @@ abstract contract EncryptedOperations is
330
308
  checkInput(lhs, typeToBitMask(lhsType));
331
309
  checkInput(rhs, typeToBitMask(rhsType));
332
310
  require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
333
- result = createResultHandle(EOps.BitAnd, lhsType, lhs, rhs);
334
311
  uint256 id = getNextEventId();
312
+ result = createResultHandle(EOps.BitAnd, lhsType, abi.encodePacked(lhs, rhs));
335
313
  emit EBitAnd(lhs, rhs, result, id);
336
314
  setDigest(abi.encodePacked(result, id));
337
315
  }
@@ -345,8 +323,8 @@ abstract contract EncryptedOperations is
345
323
  checkInput(lhs, typeToBitMask(lhsType));
346
324
  checkInput(rhs, typeToBitMask(rhsType));
347
325
  require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
348
- result = createResultHandle(EOps.BitOr, lhsType, lhs, rhs);
349
326
  uint256 id = getNextEventId();
327
+ result = createResultHandle(EOps.BitOr, lhsType, abi.encodePacked(lhs, rhs));
350
328
  emit EBitOr(lhs, rhs, result, id);
351
329
  setDigest(abi.encodePacked(result, id));
352
330
  }
@@ -360,8 +338,8 @@ abstract contract EncryptedOperations is
360
338
  checkInput(lhs, typeToBitMask(lhsType));
361
339
  checkInput(rhs, typeToBitMask(rhsType));
362
340
  require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
363
- result = createResultHandle(EOps.BitXor, lhsType, lhs, rhs);
364
341
  uint256 id = getNextEventId();
342
+ result = createResultHandle(EOps.BitXor, lhsType, abi.encodePacked(lhs, rhs));
365
343
  emit EBitXor(lhs, rhs, result, id);
366
344
  setDigest(abi.encodePacked(result, id));
367
345
  }
@@ -374,8 +352,10 @@ abstract contract EncryptedOperations is
374
352
  createResultHandle(
375
353
  EOps.Shl,
376
354
  ETypes.Uint256,
377
- euint256.unwrap(lhs),
378
- euint256.unwrap(rhs)
355
+ abi.encodePacked(
356
+ euint256.unwrap(lhs),
357
+ euint256.unwrap(rhs)
358
+ )
379
359
  )
380
360
  );
381
361
  uint256 id = getNextEventId();
@@ -391,8 +371,10 @@ abstract contract EncryptedOperations is
391
371
  createResultHandle(
392
372
  EOps.Shr,
393
373
  ETypes.Uint256,
394
- euint256.unwrap(lhs),
395
- euint256.unwrap(rhs)
374
+ abi.encodePacked(
375
+ euint256.unwrap(lhs),
376
+ euint256.unwrap(rhs)
377
+ )
396
378
  )
397
379
  );
398
380
  uint256 id = getNextEventId();
@@ -408,8 +390,10 @@ abstract contract EncryptedOperations is
408
390
  createResultHandle(
409
391
  EOps.Rotl,
410
392
  ETypes.Uint256,
411
- euint256.unwrap(lhs),
412
- euint256.unwrap(rhs)
393
+ abi.encodePacked(
394
+ euint256.unwrap(lhs),
395
+ euint256.unwrap(rhs)
396
+ )
413
397
  )
414
398
  );
415
399
  uint256 id = getNextEventId();
@@ -425,8 +409,10 @@ abstract contract EncryptedOperations is
425
409
  createResultHandle(
426
410
  EOps.Rotr,
427
411
  ETypes.Uint256,
428
- euint256.unwrap(lhs),
429
- euint256.unwrap(rhs)
412
+ abi.encodePacked(
413
+ euint256.unwrap(lhs),
414
+ euint256.unwrap(rhs)
415
+ )
430
416
  )
431
417
  );
432
418
  uint256 id = getNextEventId();
@@ -445,8 +431,10 @@ abstract contract EncryptedOperations is
445
431
  createResultHandle(
446
432
  EOps.Eq,
447
433
  ETypes.Bool,
448
- lhs,
449
- rhs
434
+ abi.encodePacked(
435
+ lhs,
436
+ rhs
437
+ )
450
438
  )
451
439
  );
452
440
  uint256 id = getNextEventId();
@@ -465,8 +453,10 @@ abstract contract EncryptedOperations is
465
453
  createResultHandle(
466
454
  EOps.Ne,
467
455
  ETypes.Bool,
468
- lhs,
469
- rhs
456
+ abi.encodePacked(
457
+ lhs,
458
+ rhs
459
+ )
470
460
  )
471
461
  );
472
462
  uint256 id = getNextEventId();
@@ -482,8 +472,10 @@ abstract contract EncryptedOperations is
482
472
  createResultHandle(
483
473
  EOps.Ge,
484
474
  ETypes.Bool,
485
- euint256.unwrap(lhs),
486
- euint256.unwrap(rhs)
475
+ abi.encodePacked(
476
+ euint256.unwrap(lhs),
477
+ euint256.unwrap(rhs)
478
+ )
487
479
  )
488
480
  );
489
481
  uint256 id = getNextEventId();
@@ -499,8 +491,10 @@ abstract contract EncryptedOperations is
499
491
  createResultHandle(
500
492
  EOps.Gt,
501
493
  ETypes.Bool,
502
- euint256.unwrap(lhs),
503
- euint256.unwrap(rhs)
494
+ abi.encodePacked(
495
+ euint256.unwrap(lhs),
496
+ euint256.unwrap(rhs)
497
+ )
504
498
  )
505
499
  );
506
500
  uint256 id = getNextEventId();
@@ -516,8 +510,10 @@ abstract contract EncryptedOperations is
516
510
  createResultHandle(
517
511
  EOps.Le,
518
512
  ETypes.Bool,
519
- euint256.unwrap(lhs),
520
- euint256.unwrap(rhs)
513
+ abi.encodePacked(
514
+ euint256.unwrap(lhs),
515
+ euint256.unwrap(rhs)
516
+ )
521
517
  )
522
518
  );
523
519
  uint256 id = getNextEventId();
@@ -533,8 +529,10 @@ abstract contract EncryptedOperations is
533
529
  createResultHandle(
534
530
  EOps.Lt,
535
531
  ETypes.Bool,
536
- euint256.unwrap(lhs),
537
- euint256.unwrap(rhs)
532
+ abi.encodePacked(
533
+ euint256.unwrap(lhs),
534
+ euint256.unwrap(rhs)
535
+ )
538
536
  )
539
537
  );
540
538
  uint256 id = getNextEventId();
@@ -550,8 +548,10 @@ abstract contract EncryptedOperations is
550
548
  createResultHandle(
551
549
  EOps.Min,
552
550
  ETypes.Uint256,
553
- euint256.unwrap(lhs),
554
- euint256.unwrap(rhs)
551
+ abi.encodePacked(
552
+ euint256.unwrap(lhs),
553
+ euint256.unwrap(rhs)
554
+ )
555
555
  )
556
556
  );
557
557
  uint256 id = getNextEventId();
@@ -567,8 +567,10 @@ abstract contract EncryptedOperations is
567
567
  createResultHandle(
568
568
  EOps.Max,
569
569
  ETypes.Uint256,
570
- euint256.unwrap(lhs),
571
- euint256.unwrap(rhs)
570
+ abi.encodePacked(
571
+ euint256.unwrap(lhs),
572
+ euint256.unwrap(rhs)
573
+ )
572
574
  )
573
575
  );
574
576
  uint256 id = getNextEventId();
@@ -579,7 +581,7 @@ abstract contract EncryptedOperations is
579
581
  function eNot(ebool operand) external returns (ebool result) {
580
582
  checkInput(ebool.unwrap(operand), typeToBitMask(ETypes.Bool));
581
583
  result = ebool.wrap(
582
- createResultHandle(EOps.Not, ETypes.Bool, ebool.unwrap(operand))
584
+ createResultHandle(EOps.Not, ETypes.Bool, abi.encodePacked(ebool.unwrap(operand)))
583
585
  );
584
586
  uint256 id = getNextEventId();
585
587
  emit ENot(operand, result, id);
@@ -590,7 +592,7 @@ abstract contract EncryptedOperations is
590
592
  bytes32 ct,
591
593
  ETypes toType
592
594
  ) external returns (bytes32 result) {
593
- bytes32 baseHandle = keccak256(abi.encodePacked(EOps.Cast, ct, toType));
595
+ bytes32 baseHandle = keccak256(abi.encodePacked(EOps.Cast, ct));
594
596
  result = embedTypeVersion(baseHandle, toType);
595
597
  allowTransientInternal(result, msg.sender);
596
598
  uint256 id = getNextEventId();
@@ -602,16 +604,12 @@ abstract contract EncryptedOperations is
602
604
  ETypes randType
603
605
  ) external paying payable returns (bytes32 result) {
604
606
  require(isTypeSupported(randType), UnsupportedType(randType));
605
-
607
+ randCounter++;
606
608
  result = createResultHandle(
607
609
  EOps.Rand,
608
- randType,
609
- bytes32(randCounter++),
610
- bytes32(uint256(randType))
610
+ randType,
611
+ abi.encodePacked(bytes32(randCounter))
611
612
  );
612
- //NOTE: We pass the incremented randCounter which is incremented using postfix increment above.
613
- // Due to postfix returning the value before incrementing, the emitted randCounter will be larger by one than the number used to build the handle.
614
- // So for security and replayability reasons, we always use the incremented randCounter when seeding on the covalidator side, which is fine for as long as we're consistent.
615
613
  uint256 id = getNextEventId();
616
614
  emit ERand(randCounter, randType, result, id);
617
615
  setDigest(abi.encodePacked(result, id));
@@ -623,17 +621,15 @@ abstract contract EncryptedOperations is
623
621
  ) external paying payable returns (bytes32 result) {
624
622
  require(isTypeSupported(randType), UnsupportedType(randType));
625
623
  checkInput(upperBound, typeToBitMask(ETypes.Uint256));
626
-
624
+ randCounter++;
627
625
  result = createResultHandle(
628
626
  EOps.RandBounded,
629
627
  randType,
630
- bytes32(randCounter++),
631
- upperBound,
632
- bytes32(uint256(randType))
628
+ abi.encodePacked(
629
+ bytes32(randCounter),
630
+ upperBound
631
+ )
633
632
  );
634
- //NOTE: We pass the incremented randCounter which is incremented using postfix increment above.
635
- // Due to postfix returning the value before incrementing, the emitted randCounter will be larger by one than the number used to build the handle.
636
- // So for security and replayability reasons, we always use the incremented randCounter when seeding on the covalidator side, which is fine for as long as we're consistent.
637
633
  uint256 id = getNextEventId();
638
634
  emit ERandBounded(randCounter, randType, upperBound, result, id);
639
635
  setDigest(abi.encodePacked(result, id));