@inco/lightning 0.3.2 → 0.5.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.
- package/README.md +2 -8
- package/manifest.yaml +24 -11
- package/package.json +2 -5
- package/src/DeployUtils.sol +113 -77
- package/src/IIncoLightning.sol +16 -9
- package/src/IncoLightning.sol +18 -9
- package/src/IncoVerifier.sol +47 -0
- package/src/Lib.alphanet.sol +14 -15
- package/src/Lib.demonet.sol +14 -15
- package/src/Lib.devnet.sol +14 -15
- package/src/Lib.sol +14 -15
- package/src/Lib.template.sol +15 -44
- package/src/Lib.testnet.sol +14 -15
- package/src/Types.sol +7 -0
- package/src/interfaces/IIncoLightning.sol +20 -0
- package/src/interfaces/IIncoVerifier.sol +24 -0
- package/src/interfaces/automata-interfaces/BELE.sol +20 -0
- package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +28 -0
- package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +10 -0
- package/src/interfaces/automata-interfaces/IPCCSRouter.sol +94 -0
- package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +10 -0
- package/src/interfaces/automata-interfaces/IPcsDao.sol +18 -0
- package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +34 -0
- package/src/interfaces/automata-interfaces/Types.sol +193 -0
- package/src/libs/incoLightning_alphanet_v0_297966649.sol +14 -15
- package/src/libs/incoLightning_demonet_v0_863421733.sol +14 -15
- package/src/libs/incoLightning_devnet_v0_340846814.sol +14 -15
- package/src/libs/incoLightning_testnet_v0_183408998.sol +14 -15
- package/src/libs/incoLightning_testnet_v1_938327937.sol +451 -0
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +133 -0
- package/src/lightning-parts/AccessControl/AdvancedAccessControl.types.sol +18 -0
- package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +42 -3
- package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +25 -0
- package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +24 -0
- package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +234 -0
- package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +16 -2
- package/src/lightning-parts/DecryptionAttester.sol +45 -0
- package/src/lightning-parts/DecryptionAttester.types.sol +7 -0
- package/src/lightning-parts/EncryptedInput.sol +10 -13
- package/src/lightning-parts/EncryptedOperations.sol +78 -28
- package/src/lightning-parts/TEELifecycle.sol +180 -88
- package/src/lightning-parts/TrivialEncryption.sol +9 -9
- package/src/lightning-parts/interfaces/IDecryptionAttester.sol +9 -0
- package/src/lightning-parts/interfaces/IEncryptedInput.sol +19 -0
- package/src/lightning-parts/interfaces/IEncryptedOperations.sol +31 -0
- package/src/lightning-parts/interfaces/ITEELifecycle.sol +26 -0
- package/src/lightning-parts/interfaces/ITrivialEncryption.sol +10 -0
- package/src/lightning-parts/primitives/EventCounter.sol +15 -3
- package/src/lightning-parts/primitives/HandleGeneration.sol +8 -3
- package/src/lightning-parts/primitives/HandleMetadata.sol +1 -1
- package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
- package/src/lightning-parts/primitives/SignatureVerifier.sol +2 -9
- package/src/lightning-parts/primitives/VerifierAddressGetter.sol +13 -0
- package/src/lightning-parts/primitives/{EventCounter.gen.sol → interfaces/IEventCounter.sol} +4 -2
- package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +41 -0
- package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +9 -0
- package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +8 -0
- package/src/lightning-parts/test/HandleMetadata.t.sol +25 -6
- package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +78 -0
- package/src/periphery/SessionVerifier.sol +63 -0
- package/src/test/AddTwo.sol +20 -24
- package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +198 -0
- package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +0 -15
- package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +10 -6
- package/src/test/FakeIncoInfra/MockOpHandler.sol +0 -7
- package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +19 -7
- package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -3
- package/src/test/IncoTest.sol +12 -11
- package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +98 -77
- package/src/test/TestAddTwo.t.sol +16 -9
- package/src/test/TestFakeInfra.t.sol +10 -27
- package/src/test/TestUpgrade.t.sol +11 -4
- package/src/test/TestVersion.t.sol +0 -7
- package/src/version/IncoLightningConfig.sol +4 -3
- package/src/version/SessionVerifierConfig.sol +8 -0
- package/src/version/Version.sol +7 -9
- package/src/version/interfaces/IVersion.sol +8 -0
- package/src/DeployTEE.sol +0 -153
- package/src/IncoLightning.gen.sol +0 -15
- package/src/lightning-parts/AccessControl/BaseAccessControlList.gen.sol +0 -19
- package/src/lightning-parts/DecryptionHandler.gen.sol +0 -54
- package/src/lightning-parts/DecryptionHandler.sol +0 -307
- package/src/lightning-parts/DecryptionHandler.types.sol +0 -34
- package/src/lightning-parts/EncryptedInput.gen.sol +0 -16
- package/src/lightning-parts/EncryptedOperations.gen.sol +0 -59
- package/src/lightning-parts/TEELifecycle.gen.sol +0 -58
- package/src/lightning-parts/TrivialEncryption.gen.sol +0 -15
- package/src/lightning-parts/primitives/HandleGeneration.gen.sol +0 -19
- package/src/lightning-parts/primitives/HandleMetadata.gen.sol +0 -4
- package/src/lightning-parts/primitives/SignatureVerifier.gen.sol +0 -16
- package/src/test/FibonacciDecrypt.sol +0 -49
- package/src/test/TEELifecycle/TEELifecycleHWTest.t.sol +0 -119
- package/src/test/TEELifecycle/addnode_data/eoa.txt +0 -1
- package/src/test/TEELifecycle/addnode_data/quote.bin +0 -0
- package/src/test/TEELifecycle/bootstrap_data/ecies_pubkey.bin +0 -1
- package/src/test/TEELifecycle/bootstrap_data/eip712_signature.bin +0 -1
- package/src/test/TEELifecycle/bootstrap_data/eoa.txt +0 -1
- package/src/test/TEELifecycle/bootstrap_data/qe_identity +0 -1
- package/src/test/TEELifecycle/bootstrap_data/qe_identity_signature.bin +0 -1
- package/src/test/TEELifecycle/bootstrap_data/quote.bin +0 -0
- package/src/test/TEELifecycle/bootstrap_data/tcb_info +0 -1
- package/src/test/TEELifecycle/bootstrap_data/tcb_info_signature.bin +0 -1
- package/src/test/TEELifecycle/test_cert/AttestationReportSigningCA.crl +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_Attestation_RootCA.cer +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_CRL.crl +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_PlatformCA.cer +0 -0
- package/src/test/TEELifecycle/test_cert/Intel_SGX_TCB_Signing.cer +0 -0
- package/src/version/Version.gen.sol +0 -14
|
@@ -5,10 +5,10 @@ import {euint256, ebool, EOps, SenderNotAllowedForHandle, ETypes, isTypeSupporte
|
|
|
5
5
|
import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
|
|
6
6
|
import {EventCounter} from "./primitives/EventCounter.sol";
|
|
7
7
|
import {HandleGeneration} from "./primitives/HandleGeneration.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {IEncryptedOperations} from "./interfaces/IEncryptedOperations.sol";
|
|
9
9
|
|
|
10
10
|
abstract contract EncryptedOperations is
|
|
11
|
-
|
|
11
|
+
IEncryptedOperations,
|
|
12
12
|
BaseAccessControlList,
|
|
13
13
|
EventCounter,
|
|
14
14
|
HandleGeneration
|
|
@@ -248,7 +248,9 @@ abstract contract EncryptedOperations is
|
|
|
248
248
|
euint256.unwrap(rhs)
|
|
249
249
|
)
|
|
250
250
|
);
|
|
251
|
-
|
|
251
|
+
uint256 id = getNextEventId();
|
|
252
|
+
emit EAdd(lhs, rhs, result, id);
|
|
253
|
+
setDigest(abi.encodePacked(result, id));
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
function eSub(
|
|
@@ -263,7 +265,9 @@ abstract contract EncryptedOperations is
|
|
|
263
265
|
euint256.unwrap(rhs)
|
|
264
266
|
)
|
|
265
267
|
);
|
|
266
|
-
|
|
268
|
+
uint256 id = getNextEventId();
|
|
269
|
+
emit ESub(lhs, rhs, result, id);
|
|
270
|
+
setDigest(abi.encodePacked(result, id));
|
|
267
271
|
}
|
|
268
272
|
|
|
269
273
|
function eMul(
|
|
@@ -278,8 +282,10 @@ abstract contract EncryptedOperations is
|
|
|
278
282
|
euint256.unwrap(rhs)
|
|
279
283
|
)
|
|
280
284
|
);
|
|
281
|
-
|
|
282
|
-
|
|
285
|
+
uint256 id = getNextEventId();
|
|
286
|
+
emit EMul(lhs, rhs, result, id);
|
|
287
|
+
setDigest(abi.encodePacked(result, id));
|
|
288
|
+
}
|
|
283
289
|
|
|
284
290
|
function eDiv(
|
|
285
291
|
euint256 lhs,
|
|
@@ -293,7 +299,9 @@ abstract contract EncryptedOperations is
|
|
|
293
299
|
euint256.unwrap(rhs)
|
|
294
300
|
)
|
|
295
301
|
);
|
|
296
|
-
|
|
302
|
+
uint256 id = getNextEventId();
|
|
303
|
+
emit EDiv(lhs, rhs, result, id);
|
|
304
|
+
setDigest(abi.encodePacked(result, id));
|
|
297
305
|
}
|
|
298
306
|
|
|
299
307
|
function eRem(
|
|
@@ -308,7 +316,9 @@ abstract contract EncryptedOperations is
|
|
|
308
316
|
euint256.unwrap(rhs)
|
|
309
317
|
)
|
|
310
318
|
);
|
|
311
|
-
|
|
319
|
+
uint256 id = getNextEventId();
|
|
320
|
+
emit ERem(lhs, rhs, result, id);
|
|
321
|
+
setDigest(abi.encodePacked(result, id));
|
|
312
322
|
}
|
|
313
323
|
|
|
314
324
|
function eBitAnd(
|
|
@@ -321,7 +331,9 @@ abstract contract EncryptedOperations is
|
|
|
321
331
|
checkInput(rhs, typeToBitMask(rhsType));
|
|
322
332
|
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
323
333
|
result = createResultHandle(EOps.BitAnd, lhsType, lhs, rhs);
|
|
324
|
-
|
|
334
|
+
uint256 id = getNextEventId();
|
|
335
|
+
emit EBitAnd(lhs, rhs, result, id);
|
|
336
|
+
setDigest(abi.encodePacked(result, id));
|
|
325
337
|
}
|
|
326
338
|
|
|
327
339
|
function eBitOr(
|
|
@@ -334,7 +346,9 @@ abstract contract EncryptedOperations is
|
|
|
334
346
|
checkInput(rhs, typeToBitMask(rhsType));
|
|
335
347
|
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
336
348
|
result = createResultHandle(EOps.BitOr, lhsType, lhs, rhs);
|
|
337
|
-
|
|
349
|
+
uint256 id = getNextEventId();
|
|
350
|
+
emit EBitOr(lhs, rhs, result, id);
|
|
351
|
+
setDigest(abi.encodePacked(result, id));
|
|
338
352
|
}
|
|
339
353
|
|
|
340
354
|
function eBitXor(
|
|
@@ -347,7 +361,9 @@ abstract contract EncryptedOperations is
|
|
|
347
361
|
checkInput(rhs, typeToBitMask(rhsType));
|
|
348
362
|
require(lhsType == rhsType, UnexpectedType(lhsType, typeToBitMask(rhsType)));
|
|
349
363
|
result = createResultHandle(EOps.BitXor, lhsType, lhs, rhs);
|
|
350
|
-
|
|
364
|
+
uint256 id = getNextEventId();
|
|
365
|
+
emit EBitXor(lhs, rhs, result, id);
|
|
366
|
+
setDigest(abi.encodePacked(result, id));
|
|
351
367
|
}
|
|
352
368
|
|
|
353
369
|
function eShl(
|
|
@@ -362,7 +378,9 @@ abstract contract EncryptedOperations is
|
|
|
362
378
|
euint256.unwrap(rhs)
|
|
363
379
|
)
|
|
364
380
|
);
|
|
365
|
-
|
|
381
|
+
uint256 id = getNextEventId();
|
|
382
|
+
emit EShl(lhs, rhs, result, id);
|
|
383
|
+
setDigest(abi.encodePacked(result, id));
|
|
366
384
|
}
|
|
367
385
|
|
|
368
386
|
function eShr(
|
|
@@ -377,7 +395,9 @@ abstract contract EncryptedOperations is
|
|
|
377
395
|
euint256.unwrap(rhs)
|
|
378
396
|
)
|
|
379
397
|
);
|
|
380
|
-
|
|
398
|
+
uint256 id = getNextEventId();
|
|
399
|
+
emit EShr(lhs, rhs, result, id);
|
|
400
|
+
setDigest(abi.encodePacked(result, id));
|
|
381
401
|
}
|
|
382
402
|
|
|
383
403
|
function eRotl(
|
|
@@ -392,7 +412,9 @@ abstract contract EncryptedOperations is
|
|
|
392
412
|
euint256.unwrap(rhs)
|
|
393
413
|
)
|
|
394
414
|
);
|
|
395
|
-
|
|
415
|
+
uint256 id = getNextEventId();
|
|
416
|
+
emit ERotl(lhs, rhs, result, id);
|
|
417
|
+
setDigest(abi.encodePacked(result, id));
|
|
396
418
|
}
|
|
397
419
|
|
|
398
420
|
function eRotr(
|
|
@@ -407,7 +429,9 @@ abstract contract EncryptedOperations is
|
|
|
407
429
|
euint256.unwrap(rhs)
|
|
408
430
|
)
|
|
409
431
|
);
|
|
410
|
-
|
|
432
|
+
uint256 id = getNextEventId();
|
|
433
|
+
emit ERotr(lhs, rhs, result, id);
|
|
434
|
+
setDigest(abi.encodePacked(result, id));
|
|
411
435
|
}
|
|
412
436
|
|
|
413
437
|
function eEq(
|
|
@@ -425,7 +449,9 @@ abstract contract EncryptedOperations is
|
|
|
425
449
|
rhs
|
|
426
450
|
)
|
|
427
451
|
);
|
|
428
|
-
|
|
452
|
+
uint256 id = getNextEventId();
|
|
453
|
+
emit EEq(lhs, rhs, result, id);
|
|
454
|
+
setDigest(abi.encodePacked(result, id));
|
|
429
455
|
}
|
|
430
456
|
|
|
431
457
|
function eNe(
|
|
@@ -443,7 +469,9 @@ abstract contract EncryptedOperations is
|
|
|
443
469
|
rhs
|
|
444
470
|
)
|
|
445
471
|
);
|
|
446
|
-
|
|
472
|
+
uint256 id = getNextEventId();
|
|
473
|
+
emit ENe(lhs, rhs, result, id);
|
|
474
|
+
setDigest(abi.encodePacked(result, id));
|
|
447
475
|
}
|
|
448
476
|
|
|
449
477
|
function eGe(
|
|
@@ -458,7 +486,9 @@ abstract contract EncryptedOperations is
|
|
|
458
486
|
euint256.unwrap(rhs)
|
|
459
487
|
)
|
|
460
488
|
);
|
|
461
|
-
|
|
489
|
+
uint256 id = getNextEventId();
|
|
490
|
+
emit EGe(lhs, rhs, result, id);
|
|
491
|
+
setDigest(abi.encodePacked(result, id));
|
|
462
492
|
}
|
|
463
493
|
|
|
464
494
|
function eGt(
|
|
@@ -473,7 +503,9 @@ abstract contract EncryptedOperations is
|
|
|
473
503
|
euint256.unwrap(rhs)
|
|
474
504
|
)
|
|
475
505
|
);
|
|
476
|
-
|
|
506
|
+
uint256 id = getNextEventId();
|
|
507
|
+
emit EGt(lhs, rhs, result, id);
|
|
508
|
+
setDigest(abi.encodePacked(result, id));
|
|
477
509
|
}
|
|
478
510
|
|
|
479
511
|
function eLe(
|
|
@@ -488,7 +520,9 @@ abstract contract EncryptedOperations is
|
|
|
488
520
|
euint256.unwrap(rhs)
|
|
489
521
|
)
|
|
490
522
|
);
|
|
491
|
-
|
|
523
|
+
uint256 id = getNextEventId();
|
|
524
|
+
emit ELe(lhs, rhs, result, id);
|
|
525
|
+
setDigest(abi.encodePacked(result, id));
|
|
492
526
|
}
|
|
493
527
|
|
|
494
528
|
function eLt(
|
|
@@ -503,7 +537,9 @@ abstract contract EncryptedOperations is
|
|
|
503
537
|
euint256.unwrap(rhs)
|
|
504
538
|
)
|
|
505
539
|
);
|
|
506
|
-
|
|
540
|
+
uint256 id = getNextEventId();
|
|
541
|
+
emit ELt(lhs, rhs, result, id);
|
|
542
|
+
setDigest(abi.encodePacked(result, id));
|
|
507
543
|
}
|
|
508
544
|
|
|
509
545
|
function eMin(
|
|
@@ -518,7 +554,9 @@ abstract contract EncryptedOperations is
|
|
|
518
554
|
euint256.unwrap(rhs)
|
|
519
555
|
)
|
|
520
556
|
);
|
|
521
|
-
|
|
557
|
+
uint256 id = getNextEventId();
|
|
558
|
+
emit EMin(lhs, rhs, result, id);
|
|
559
|
+
setDigest(abi.encodePacked(result, id));
|
|
522
560
|
}
|
|
523
561
|
|
|
524
562
|
function eMax(
|
|
@@ -533,7 +571,9 @@ abstract contract EncryptedOperations is
|
|
|
533
571
|
euint256.unwrap(rhs)
|
|
534
572
|
)
|
|
535
573
|
);
|
|
536
|
-
|
|
574
|
+
uint256 id = getNextEventId();
|
|
575
|
+
emit EMax(lhs, rhs, result, id);
|
|
576
|
+
setDigest(abi.encodePacked(result, id));
|
|
537
577
|
}
|
|
538
578
|
|
|
539
579
|
function eNot(ebool operand) external returns (ebool result) {
|
|
@@ -541,7 +581,9 @@ abstract contract EncryptedOperations is
|
|
|
541
581
|
result = ebool.wrap(
|
|
542
582
|
createResultHandle(EOps.Not, ETypes.Bool, ebool.unwrap(operand))
|
|
543
583
|
);
|
|
544
|
-
|
|
584
|
+
uint256 id = getNextEventId();
|
|
585
|
+
emit ENot(operand, result, id);
|
|
586
|
+
setDigest(abi.encodePacked(result, id));
|
|
545
587
|
}
|
|
546
588
|
|
|
547
589
|
function eCast(
|
|
@@ -551,7 +593,9 @@ abstract contract EncryptedOperations is
|
|
|
551
593
|
bytes32 baseHandle = keccak256(abi.encodePacked(EOps.Cast, ct, toType));
|
|
552
594
|
result = embedTypeVersion(baseHandle, toType);
|
|
553
595
|
allowTransientInternal(result, msg.sender);
|
|
554
|
-
|
|
596
|
+
uint256 id = getNextEventId();
|
|
597
|
+
emit ECast(ct, uint8(toType), result, id);
|
|
598
|
+
setDigest(abi.encodePacked(result, id));
|
|
555
599
|
}
|
|
556
600
|
|
|
557
601
|
function eRand(
|
|
@@ -568,7 +612,9 @@ abstract contract EncryptedOperations is
|
|
|
568
612
|
//NOTE: We pass the incremented randCounter which is incremented using postfix increment above.
|
|
569
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.
|
|
570
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.
|
|
571
|
-
|
|
615
|
+
uint256 id = getNextEventId();
|
|
616
|
+
emit ERand(randCounter, randType, result, id);
|
|
617
|
+
setDigest(abi.encodePacked(result, id));
|
|
572
618
|
}
|
|
573
619
|
|
|
574
620
|
function eRandBounded(
|
|
@@ -588,7 +634,9 @@ abstract contract EncryptedOperations is
|
|
|
588
634
|
//NOTE: We pass the incremented randCounter which is incremented using postfix increment above.
|
|
589
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.
|
|
590
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.
|
|
591
|
-
|
|
637
|
+
uint256 id = getNextEventId();
|
|
638
|
+
emit ERandBounded(randCounter, randType, upperBound, result, id);
|
|
639
|
+
setDigest(abi.encodePacked(result, id));
|
|
592
640
|
}
|
|
593
641
|
|
|
594
642
|
// todo add support in testing framework
|
|
@@ -608,7 +656,9 @@ abstract contract EncryptedOperations is
|
|
|
608
656
|
);
|
|
609
657
|
result = embedTypeVersion(baseHandle, returnType);
|
|
610
658
|
allowTransientInternal(result, msg.sender);
|
|
611
|
-
|
|
659
|
+
uint256 id = getNextEventId();
|
|
660
|
+
emit EIfThenElse(control, ifTrue, ifFalse, result, id);
|
|
661
|
+
setDigest(abi.encodePacked(result, id));
|
|
612
662
|
}
|
|
613
663
|
|
|
614
664
|
function checkEIfThenElseInputs(
|
|
@@ -1,60 +1,82 @@
|
|
|
1
|
-
/// SPDX-License-Identifier: No License
|
|
2
1
|
pragma solidity ^0.8.19;
|
|
3
2
|
|
|
4
|
-
import
|
|
5
|
-
|
|
3
|
+
import {
|
|
4
|
+
BootstrapResult,
|
|
5
|
+
TEEVersion,
|
|
6
|
+
TEEVersionStatus
|
|
7
|
+
} from "./TEELifecycle.types.sol";
|
|
6
8
|
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
7
|
-
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
|
|
8
9
|
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
9
|
-
import {IQuoteVerifier} from "automata-
|
|
10
|
-
import {BELE} from "automata-
|
|
11
|
-
import {HEADER_LENGTH} from "automata-dcap-attestation/types/Constants.sol";
|
|
12
|
-
import {TD10ReportBody, Header} from "automata-dcap-attestation/types/V4Structs.sol";
|
|
10
|
+
import {IQuoteVerifier} from "../interfaces/automata-interfaces/IQuoteVerifier.sol";
|
|
11
|
+
import {BELE} from "../interfaces/automata-interfaces/BELE.sol";
|
|
13
12
|
import {EIP712Upgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
import {ITEELifecycle} from "./interfaces/ITEELifecycle.sol";
|
|
14
|
+
import {
|
|
15
|
+
TcbInfoJsonObj,
|
|
16
|
+
EnclaveIdentityJsonObj,
|
|
17
|
+
IdentityObj,
|
|
18
|
+
TD10ReportBody,
|
|
19
|
+
Header,
|
|
20
|
+
HEADER_LENGTH
|
|
21
|
+
} from "../interfaces/automata-interfaces/Types.sol";
|
|
22
|
+
import {IFmspcTcbDao} from "../interfaces/automata-interfaces/IFmspcTcbDao.sol";
|
|
23
|
+
import {IAutomataEnclaveIdentityDao} from "../interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol";
|
|
24
|
+
|
|
25
|
+
// todo #1031 make TEELifecycle storage upgrade compatible
|
|
26
|
+
abstract contract TEELifecycle is
|
|
27
|
+
ITEELifecycle,
|
|
28
|
+
OwnableUpgradeable,
|
|
29
|
+
EIP712Upgradeable
|
|
30
|
+
{
|
|
31
|
+
error InvalidQuoteVerifierVersion(uint16 actual, uint16 expected);
|
|
32
|
+
error EmptyTcbInfo();
|
|
33
|
+
error EmptyIdentity();
|
|
34
|
+
error BootstrapNotComplete();
|
|
35
|
+
error BootstrapAlreadyCompleted();
|
|
36
|
+
/// @notice TEEVersionHistory must have exactly one version, please call approveNewTEEVersion first
|
|
37
|
+
error TEEVersionHistoryInconsistent();
|
|
38
|
+
error TEEVersionHistoryStatusIsNotPending();
|
|
39
|
+
error InvalidReportMRTD();
|
|
40
|
+
error InvalidBootstrapDataSignature();
|
|
41
|
+
/// @notice MRTD must be exactly 48 bytes
|
|
42
|
+
error MrtdInvalidLength();
|
|
43
|
+
error EOASignerAlreadyInitialized();
|
|
44
|
+
error InvalidMrtdReport();
|
|
45
|
+
error InvalidReportDataSigner();
|
|
21
46
|
|
|
22
47
|
event QuoteVerifierUpdated(uint16 indexed version);
|
|
23
|
-
|
|
48
|
+
event TEEVersionUpdated(TEEVersion teeVersion);
|
|
49
|
+
event NewCovalidatorAdded(address covalidatorAddress, bytes quote);
|
|
24
50
|
event BootstrapStageComplete(
|
|
25
51
|
address indexed newEOASigner,
|
|
26
52
|
BootstrapResult bootstrapResult
|
|
27
53
|
);
|
|
28
54
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
event NewCovalidatorAdded(
|
|
34
|
-
address covalidatorAddress,
|
|
35
|
-
bytes quote
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
bytes32 public constant BootstrapResultStructHash =
|
|
39
|
-
keccak256(bytes(
|
|
40
|
-
"BootstrapResult(bytes ecies_pubkey)"
|
|
41
|
-
));
|
|
55
|
+
bytes32 public constant BootstrapResultStructHash =
|
|
56
|
+
keccak256(bytes("BootstrapResult(bytes ecies_pubkey)"));
|
|
42
57
|
|
|
43
58
|
uint16 public constant QUOTE_VERIFIER_VERSION = 4;
|
|
44
59
|
|
|
45
|
-
IQuoteVerifier quoteVerifier;
|
|
46
|
-
|
|
60
|
+
IQuoteVerifier public quoteVerifier;
|
|
47
61
|
BootstrapResult public VerifiedBootstrapResult;
|
|
62
|
+
bool public BootstrapComplete;
|
|
48
63
|
|
|
49
64
|
TEEVersion[] public TEEVersionHistory;
|
|
50
65
|
bytes public ECIESPubkey;
|
|
51
66
|
mapping(address => bool) public EOASigners;
|
|
52
67
|
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
quoteVerifier =
|
|
57
|
-
|
|
68
|
+
function __TEELifecycle_init(
|
|
69
|
+
IQuoteVerifier _quoteVerifier
|
|
70
|
+
) internal onlyInitializing {
|
|
71
|
+
quoteVerifier = _quoteVerifier;
|
|
72
|
+
uint16 actualQuoteVerifierVersion = quoteVerifier.quoteVersion();
|
|
73
|
+
require(
|
|
74
|
+
actualQuoteVerifierVersion == QUOTE_VERIFIER_VERSION,
|
|
75
|
+
InvalidQuoteVerifierVersion(
|
|
76
|
+
actualQuoteVerifierVersion,
|
|
77
|
+
QUOTE_VERIFIER_VERSION
|
|
78
|
+
)
|
|
79
|
+
);
|
|
58
80
|
}
|
|
59
81
|
|
|
60
82
|
/**
|
|
@@ -62,15 +84,28 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
62
84
|
* @param tcbInfo - The TCB info to upload
|
|
63
85
|
* @param identity - The identity to upload
|
|
64
86
|
*/
|
|
65
|
-
function uploadCollateral(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
function uploadCollateral(
|
|
88
|
+
TcbInfoJsonObj memory tcbInfo,
|
|
89
|
+
EnclaveIdentityJsonObj memory identity
|
|
90
|
+
) public onlyOwner {
|
|
91
|
+
require(bytes(tcbInfo.tcbInfoStr).length != 0, EmptyTcbInfo());
|
|
92
|
+
require(bytes(identity.identityStr).length != 0, EmptyIdentity());
|
|
93
|
+
|
|
94
|
+
IFmspcTcbDao fmspcTcbDao = IFmspcTcbDao(
|
|
95
|
+
quoteVerifier.pccsRouter().fmspcTcbDaoAddr()
|
|
96
|
+
);
|
|
70
97
|
fmspcTcbDao.upsertFmspcTcb(tcbInfo);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
IAutomataEnclaveIdentityDao enclaveIdDao = IAutomataEnclaveIdentityDao(
|
|
99
|
+
quoteVerifier.pccsRouter().qeIdDaoAddr()
|
|
100
|
+
);
|
|
101
|
+
(IdentityObj memory identityObj, ) = enclaveIdDao
|
|
102
|
+
.EnclaveIdentityLib()
|
|
103
|
+
.parseIdentityString(identity.identityStr);
|
|
104
|
+
enclaveIdDao.upsertEnclaveIdentity(
|
|
105
|
+
uint256(identityObj.id),
|
|
106
|
+
4,
|
|
107
|
+
identity
|
|
108
|
+
);
|
|
74
109
|
}
|
|
75
110
|
|
|
76
111
|
/**
|
|
@@ -79,12 +114,19 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
79
114
|
* @param quote - The quote to verify against
|
|
80
115
|
* @param signature - The signature to verify against
|
|
81
116
|
*/
|
|
82
|
-
function verifyBootstrapResult(
|
|
117
|
+
function verifyBootstrapResult(
|
|
118
|
+
BootstrapResult calldata bootstrapResult,
|
|
119
|
+
bytes calldata quote,
|
|
120
|
+
bytes calldata signature
|
|
121
|
+
) public onlyOwner {
|
|
83
122
|
// Make sure the bootstrap is not already complete, and that the contract owner
|
|
84
123
|
// has already submitted the pending TEE MRTD.
|
|
85
|
-
require(!isBootstrapComplete(),
|
|
86
|
-
require(TEEVersionHistory.length == 1,
|
|
87
|
-
require(
|
|
124
|
+
require(!isBootstrapComplete(), BootstrapAlreadyCompleted());
|
|
125
|
+
require(TEEVersionHistory.length == 1, TEEVersionHistoryInconsistent());
|
|
126
|
+
require(
|
|
127
|
+
TEEVersionHistory[0].status == TEEVersionStatus.PENDING,
|
|
128
|
+
TEEVersionHistoryStatusIsNotPending()
|
|
129
|
+
);
|
|
88
130
|
|
|
89
131
|
bytes32 _bootstrapResultDigest = bootstrapResultDigest(bootstrapResult);
|
|
90
132
|
(bool success, bytes memory output) = _verifyAndAttestOnChain(quote);
|
|
@@ -93,10 +135,21 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
93
135
|
bytes memory v0MRTD = TEEVersionHistory[0].mrtd;
|
|
94
136
|
|
|
95
137
|
TD10ReportBody memory tdReport = parseTD10ReportBody(quote);
|
|
96
|
-
(address reportDataSigner, bytes memory reportMRTD) = parseReport(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
require(
|
|
138
|
+
(address reportDataSigner, bytes memory reportMRTD) = parseReport(
|
|
139
|
+
tdReport
|
|
140
|
+
);
|
|
141
|
+
require(
|
|
142
|
+
keccak256(reportMRTD) == keccak256(v0MRTD),
|
|
143
|
+
InvalidReportMRTD()
|
|
144
|
+
);
|
|
145
|
+
address recoveredAddress = ECDSA.recover(
|
|
146
|
+
_bootstrapResultDigest,
|
|
147
|
+
signature
|
|
148
|
+
);
|
|
149
|
+
require(
|
|
150
|
+
recoveredAddress == reportDataSigner,
|
|
151
|
+
InvalidBootstrapDataSignature()
|
|
152
|
+
);
|
|
100
153
|
|
|
101
154
|
VerifiedBootstrapResult = bootstrapResult;
|
|
102
155
|
TEEVersionHistory[0].status = TEEVersionStatus.ACTIVE;
|
|
@@ -112,13 +165,12 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
112
165
|
* @dev This function increments the version number automatically based on the current history
|
|
113
166
|
*/
|
|
114
167
|
function approveNewTEEVersion(bytes calldata newMRTD) public onlyOwner {
|
|
115
|
-
require(newMRTD.length == 48,
|
|
116
|
-
|
|
117
|
-
TEEVersionHistory.push(
|
|
118
|
-
mrtd: newMRTD,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
168
|
+
require(newMRTD.length == 48, MrtdInvalidLength());
|
|
169
|
+
|
|
170
|
+
TEEVersionHistory.push(
|
|
171
|
+
TEEVersion({mrtd: newMRTD, status: TEEVersionStatus.PENDING})
|
|
172
|
+
);
|
|
173
|
+
|
|
122
174
|
emit TEEVersionUpdated(TEEVersionHistory[TEEVersionHistory.length - 1]);
|
|
123
175
|
}
|
|
124
176
|
|
|
@@ -127,16 +179,22 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
127
179
|
* @param quote - The quote from the new covalidator that contains the current MRTD and the eoa address of the new party in the report data
|
|
128
180
|
*/
|
|
129
181
|
function addNewCovalidator(bytes calldata quote) public onlyOwner {
|
|
130
|
-
require(isBootstrapComplete(),
|
|
182
|
+
require(isBootstrapComplete(), BootstrapNotComplete());
|
|
131
183
|
|
|
132
184
|
(bool success, bytes memory output) = _verifyAndAttestOnChain(quote);
|
|
133
185
|
require(success, string(output));
|
|
134
186
|
TD10ReportBody memory tdReport = parseTD10ReportBody(quote);
|
|
135
|
-
(address reportDataSigner, bytes memory reportMRTD) = parseReport(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
require(
|
|
139
|
-
|
|
187
|
+
(address reportDataSigner, bytes memory reportMRTD) = parseReport(
|
|
188
|
+
tdReport
|
|
189
|
+
);
|
|
190
|
+
require(!EOASigners[reportDataSigner], EOASignerAlreadyInitialized());
|
|
191
|
+
|
|
192
|
+
require(
|
|
193
|
+
keccak256(reportMRTD) ==
|
|
194
|
+
keccak256(TEEVersionHistory[TEEVersionHistory.length - 1].mrtd),
|
|
195
|
+
InvalidMrtdReport()
|
|
196
|
+
);
|
|
197
|
+
require(reportDataSigner != address(0), InvalidReportDataSigner());
|
|
140
198
|
emit NewCovalidatorAdded(reportDataSigner, quote);
|
|
141
199
|
EOASigners[reportDataSigner] = true;
|
|
142
200
|
//TODO: Add the new covalidator signers to the Signers contract state
|
|
@@ -147,7 +205,9 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
147
205
|
* @return true if the bootstrap is complete, false otherwise
|
|
148
206
|
*/
|
|
149
207
|
function isBootstrapComplete() public view returns (bool) {
|
|
150
|
-
return
|
|
208
|
+
return
|
|
209
|
+
TEEVersionHistory.length >= 1 &&
|
|
210
|
+
TEEVersionHistory[0].status == TEEVersionStatus.ACTIVE;
|
|
151
211
|
}
|
|
152
212
|
|
|
153
213
|
/**
|
|
@@ -159,12 +219,14 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
159
219
|
* For verification failures, the output is simply a UTF-8 encoded string, describing the reason for failure.
|
|
160
220
|
* @dev can directly type-cast the failed output as a string
|
|
161
221
|
*/
|
|
162
|
-
function _verifyAndAttestOnChain(
|
|
222
|
+
function _verifyAndAttestOnChain(
|
|
223
|
+
bytes calldata rawQuote
|
|
224
|
+
) internal view returns (bool success, bytes memory output) {
|
|
163
225
|
// Parse the header
|
|
164
226
|
Header memory header;
|
|
165
227
|
(success, header) = _parseQuoteHeader(rawQuote);
|
|
166
228
|
if (!success) {
|
|
167
|
-
return (false, bytes("Could not parse quote header"));
|
|
229
|
+
return (false, bytes("Could not parse quote header")); // todo #949 switch the two returned strings for bytes4 identifiers
|
|
168
230
|
}
|
|
169
231
|
|
|
170
232
|
if (QUOTE_VERIFIER_VERSION != header.version) {
|
|
@@ -180,7 +242,9 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
180
242
|
* @notice From https://github.com/automata-network/automata-dcap-attestation/blob/evm-v1.0.0/evm/contracts/AttestationEntrypointBase.sol#L168
|
|
181
243
|
* @notice Parses the header to get basic information about the quote, such as the version, TEE types etc.
|
|
182
244
|
*/
|
|
183
|
-
function _parseQuoteHeader(
|
|
245
|
+
function _parseQuoteHeader(
|
|
246
|
+
bytes calldata rawQuote
|
|
247
|
+
) private pure returns (bool success, Header memory header) {
|
|
184
248
|
success = rawQuote.length >= HEADER_LENGTH;
|
|
185
249
|
if (success) {
|
|
186
250
|
uint16 version = uint16(BELE.leBytesToBeUint(rawQuote[0:2]));
|
|
@@ -209,23 +273,49 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
209
273
|
* @param rawQuote - The raw quote bytes
|
|
210
274
|
* @return report - The parsed TD10 report body
|
|
211
275
|
*/
|
|
212
|
-
function parseTD10ReportBody(
|
|
276
|
+
function parseTD10ReportBody(
|
|
277
|
+
bytes calldata rawQuote
|
|
278
|
+
) public pure returns (TD10ReportBody memory report) {
|
|
213
279
|
report = TD10ReportBody({
|
|
214
|
-
teeTcbSvn: bytes16(rawQuote[HEADER_LENGTH:HEADER_LENGTH+16]),
|
|
215
|
-
mrSeam: bytes(rawQuote[HEADER_LENGTH+16:HEADER_LENGTH+64]),
|
|
216
|
-
mrsignerSeam: bytes(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
280
|
+
teeTcbSvn: bytes16(rawQuote[HEADER_LENGTH:HEADER_LENGTH + 16]),
|
|
281
|
+
mrSeam: bytes(rawQuote[HEADER_LENGTH + 16:HEADER_LENGTH + 64]),
|
|
282
|
+
mrsignerSeam: bytes(
|
|
283
|
+
rawQuote[HEADER_LENGTH + 64:HEADER_LENGTH + 112]
|
|
284
|
+
),
|
|
285
|
+
seamAttributes: bytes8(
|
|
286
|
+
uint64(
|
|
287
|
+
BELE.leBytesToBeUint(
|
|
288
|
+
rawQuote[HEADER_LENGTH + 112:HEADER_LENGTH + 120]
|
|
289
|
+
)
|
|
290
|
+
)
|
|
291
|
+
),
|
|
292
|
+
tdAttributes: bytes8(
|
|
293
|
+
uint64(
|
|
294
|
+
BELE.leBytesToBeUint(
|
|
295
|
+
rawQuote[HEADER_LENGTH + 120:HEADER_LENGTH + 128]
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
),
|
|
299
|
+
xFAM: bytes8(
|
|
300
|
+
uint64(
|
|
301
|
+
BELE.leBytesToBeUint(
|
|
302
|
+
rawQuote[HEADER_LENGTH + 128:HEADER_LENGTH + 136]
|
|
303
|
+
)
|
|
304
|
+
)
|
|
305
|
+
),
|
|
306
|
+
mrTd: bytes(rawQuote[HEADER_LENGTH + 136:HEADER_LENGTH + 184]),
|
|
307
|
+
mrConfigId: bytes(
|
|
308
|
+
rawQuote[HEADER_LENGTH + 184:HEADER_LENGTH + 232]
|
|
309
|
+
),
|
|
310
|
+
mrOwner: bytes(rawQuote[HEADER_LENGTH + 232:HEADER_LENGTH + 280]),
|
|
311
|
+
mrOwnerConfig: bytes(
|
|
312
|
+
rawQuote[HEADER_LENGTH + 280:HEADER_LENGTH + 328]
|
|
313
|
+
),
|
|
314
|
+
rtMr0: bytes(rawQuote[HEADER_LENGTH + 328:HEADER_LENGTH + 376]),
|
|
315
|
+
rtMr1: bytes(rawQuote[HEADER_LENGTH + 376:HEADER_LENGTH + 424]),
|
|
316
|
+
rtMr2: bytes(rawQuote[HEADER_LENGTH + 424:HEADER_LENGTH + 472]),
|
|
317
|
+
rtMr3: bytes(rawQuote[HEADER_LENGTH + 472:HEADER_LENGTH + 520]),
|
|
318
|
+
reportData: bytes(rawQuote[HEADER_LENGTH + 520:HEADER_LENGTH + 584])
|
|
229
319
|
});
|
|
230
320
|
}
|
|
231
321
|
|
|
@@ -235,14 +325,16 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
235
325
|
* @return reportDataSigner - The signing address of the report data signer
|
|
236
326
|
* @return reportMRTD - The MRTD bytes from the report
|
|
237
327
|
*/
|
|
238
|
-
function parseReport(
|
|
328
|
+
function parseReport(
|
|
329
|
+
TD10ReportBody memory tdReport
|
|
330
|
+
) public pure returns (address, bytes memory) {
|
|
239
331
|
return (address(bytes20(tdReport.reportData)), tdReport.mrTd);
|
|
240
332
|
}
|
|
241
333
|
|
|
242
334
|
function bootstrapResultDigest(
|
|
243
335
|
BootstrapResult memory bootstrapResult
|
|
244
336
|
) public view returns (bytes32) {
|
|
245
|
-
return
|
|
337
|
+
return
|
|
246
338
|
_hashTypedDataV4(
|
|
247
339
|
keccak256(
|
|
248
340
|
abi.encode(
|
|
@@ -252,4 +344,4 @@ contract TEELifecycle is OwnableUpgradeable, EIP712Upgradeable {
|
|
|
252
344
|
)
|
|
253
345
|
);
|
|
254
346
|
}
|
|
255
|
-
}
|
|
347
|
+
}
|