@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.
Files changed (108) hide show
  1. package/README.md +2 -8
  2. package/manifest.yaml +24 -11
  3. package/package.json +2 -5
  4. package/src/DeployUtils.sol +113 -77
  5. package/src/IIncoLightning.sol +16 -9
  6. package/src/IncoLightning.sol +18 -9
  7. package/src/IncoVerifier.sol +47 -0
  8. package/src/Lib.alphanet.sol +14 -15
  9. package/src/Lib.demonet.sol +14 -15
  10. package/src/Lib.devnet.sol +14 -15
  11. package/src/Lib.sol +14 -15
  12. package/src/Lib.template.sol +15 -44
  13. package/src/Lib.testnet.sol +14 -15
  14. package/src/Types.sol +7 -0
  15. package/src/interfaces/IIncoLightning.sol +20 -0
  16. package/src/interfaces/IIncoVerifier.sol +24 -0
  17. package/src/interfaces/automata-interfaces/BELE.sol +20 -0
  18. package/src/interfaces/automata-interfaces/IAutomataEnclaveIdentityDao.sol +28 -0
  19. package/src/interfaces/automata-interfaces/IFmspcTcbDao.sol +10 -0
  20. package/src/interfaces/automata-interfaces/IPCCSRouter.sol +94 -0
  21. package/src/interfaces/automata-interfaces/IPCCSRouterExtended.sol +10 -0
  22. package/src/interfaces/automata-interfaces/IPcsDao.sol +18 -0
  23. package/src/interfaces/automata-interfaces/IQuoteVerifier.sol +34 -0
  24. package/src/interfaces/automata-interfaces/Types.sol +193 -0
  25. package/src/libs/incoLightning_alphanet_v0_297966649.sol +14 -15
  26. package/src/libs/incoLightning_demonet_v0_863421733.sol +14 -15
  27. package/src/libs/incoLightning_devnet_v0_340846814.sol +14 -15
  28. package/src/libs/incoLightning_testnet_v0_183408998.sol +14 -15
  29. package/src/libs/incoLightning_testnet_v1_938327937.sol +451 -0
  30. package/src/lightning-parts/AccessControl/AdvancedAccessControl.sol +133 -0
  31. package/src/lightning-parts/AccessControl/AdvancedAccessControl.types.sol +18 -0
  32. package/src/lightning-parts/AccessControl/BaseAccessControlList.sol +42 -3
  33. package/src/lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol +25 -0
  34. package/src/lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol +24 -0
  35. package/src/lightning-parts/AccessControl/test/TestAdvancedAccessControl.t.sol +234 -0
  36. package/src/lightning-parts/AccessControl/test/TestBaseAccessControl.t.sol +16 -2
  37. package/src/lightning-parts/DecryptionAttester.sol +45 -0
  38. package/src/lightning-parts/DecryptionAttester.types.sol +7 -0
  39. package/src/lightning-parts/EncryptedInput.sol +10 -13
  40. package/src/lightning-parts/EncryptedOperations.sol +78 -28
  41. package/src/lightning-parts/TEELifecycle.sol +180 -88
  42. package/src/lightning-parts/TrivialEncryption.sol +9 -9
  43. package/src/lightning-parts/interfaces/IDecryptionAttester.sol +9 -0
  44. package/src/lightning-parts/interfaces/IEncryptedInput.sol +19 -0
  45. package/src/lightning-parts/interfaces/IEncryptedOperations.sol +31 -0
  46. package/src/lightning-parts/interfaces/ITEELifecycle.sol +26 -0
  47. package/src/lightning-parts/interfaces/ITrivialEncryption.sol +10 -0
  48. package/src/lightning-parts/primitives/EventCounter.sol +15 -3
  49. package/src/lightning-parts/primitives/HandleGeneration.sol +8 -3
  50. package/src/lightning-parts/primitives/HandleMetadata.sol +1 -1
  51. package/src/lightning-parts/primitives/LightningAddressGetter.sol +10 -0
  52. package/src/lightning-parts/primitives/SignatureVerifier.sol +2 -9
  53. package/src/lightning-parts/primitives/VerifierAddressGetter.sol +13 -0
  54. package/src/lightning-parts/primitives/{EventCounter.gen.sol → interfaces/IEventCounter.sol} +4 -2
  55. package/src/lightning-parts/primitives/interfaces/IHandleGeneration.sol +41 -0
  56. package/src/lightning-parts/primitives/interfaces/ISignatureVerifier.sol +9 -0
  57. package/src/lightning-parts/primitives/interfaces/IVerifierAddressGetter.sol +8 -0
  58. package/src/lightning-parts/test/HandleMetadata.t.sol +25 -6
  59. package/src/lightning-parts/test/TestDecryptionAttestationInSynchronousFlow.t.sol +78 -0
  60. package/src/periphery/SessionVerifier.sol +63 -0
  61. package/src/test/AddTwo.sol +20 -24
  62. package/src/test/FakeIncoInfra/FakeDecryptionAttester.sol +198 -0
  63. package/src/test/FakeIncoInfra/FakeIncoInfraBase.sol +0 -15
  64. package/src/test/FakeIncoInfra/FakeQuoteVerifier.sol +10 -6
  65. package/src/test/FakeIncoInfra/MockOpHandler.sol +0 -7
  66. package/src/test/FakeIncoInfra/MockRemoteAttestation.sol +19 -7
  67. package/src/test/FakeIncoInfra/getOpForSelector.sol +0 -3
  68. package/src/test/IncoTest.sol +12 -11
  69. package/src/test/TEELifecycle/TEELifecycleMockTest.t.sol +98 -77
  70. package/src/test/TestAddTwo.t.sol +16 -9
  71. package/src/test/TestFakeInfra.t.sol +10 -27
  72. package/src/test/TestUpgrade.t.sol +11 -4
  73. package/src/test/TestVersion.t.sol +0 -7
  74. package/src/version/IncoLightningConfig.sol +4 -3
  75. package/src/version/SessionVerifierConfig.sol +8 -0
  76. package/src/version/Version.sol +7 -9
  77. package/src/version/interfaces/IVersion.sol +8 -0
  78. package/src/DeployTEE.sol +0 -153
  79. package/src/IncoLightning.gen.sol +0 -15
  80. package/src/lightning-parts/AccessControl/BaseAccessControlList.gen.sol +0 -19
  81. package/src/lightning-parts/DecryptionHandler.gen.sol +0 -54
  82. package/src/lightning-parts/DecryptionHandler.sol +0 -307
  83. package/src/lightning-parts/DecryptionHandler.types.sol +0 -34
  84. package/src/lightning-parts/EncryptedInput.gen.sol +0 -16
  85. package/src/lightning-parts/EncryptedOperations.gen.sol +0 -59
  86. package/src/lightning-parts/TEELifecycle.gen.sol +0 -58
  87. package/src/lightning-parts/TrivialEncryption.gen.sol +0 -15
  88. package/src/lightning-parts/primitives/HandleGeneration.gen.sol +0 -19
  89. package/src/lightning-parts/primitives/HandleMetadata.gen.sol +0 -4
  90. package/src/lightning-parts/primitives/SignatureVerifier.gen.sol +0 -16
  91. package/src/test/FibonacciDecrypt.sol +0 -49
  92. package/src/test/TEELifecycle/TEELifecycleHWTest.t.sol +0 -119
  93. package/src/test/TEELifecycle/addnode_data/eoa.txt +0 -1
  94. package/src/test/TEELifecycle/addnode_data/quote.bin +0 -0
  95. package/src/test/TEELifecycle/bootstrap_data/ecies_pubkey.bin +0 -1
  96. package/src/test/TEELifecycle/bootstrap_data/eip712_signature.bin +0 -1
  97. package/src/test/TEELifecycle/bootstrap_data/eoa.txt +0 -1
  98. package/src/test/TEELifecycle/bootstrap_data/qe_identity +0 -1
  99. package/src/test/TEELifecycle/bootstrap_data/qe_identity_signature.bin +0 -1
  100. package/src/test/TEELifecycle/bootstrap_data/quote.bin +0 -0
  101. package/src/test/TEELifecycle/bootstrap_data/tcb_info +0 -1
  102. package/src/test/TEELifecycle/bootstrap_data/tcb_info_signature.bin +0 -1
  103. package/src/test/TEELifecycle/test_cert/AttestationReportSigningCA.crl +0 -0
  104. package/src/test/TEELifecycle/test_cert/Intel_SGX_Attestation_RootCA.cer +0 -0
  105. package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_CRL.crl +0 -0
  106. package/src/test/TEELifecycle/test_cert/Intel_SGX_PCK_PlatformCA.cer +0 -0
  107. package/src/test/TEELifecycle/test_cert/Intel_SGX_TCB_Signing.cer +0 -0
  108. package/src/version/Version.gen.sol +0 -14
package/src/Lib.sol CHANGED
@@ -5,12 +5,11 @@
5
5
  /// SPDX-License-Identifier: No License
6
6
  pragma solidity ^0.8;
7
7
 
8
- import "./IncoLightning.sol";
9
- import { ebool, euint256, eaddress, ETypes, isTypeSupported } from "./Types.sol";
8
+ import { IncoLightning } from "./IncoLightning.sol";
9
+ import { ebool, euint256, eaddress, ETypes } from "./Types.sol";
10
10
 
11
11
  IncoLightning constant inco = IncoLightning(0x63D8135aF4D393B1dB43B649010c8D3EE19FC9fd);
12
12
  address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
13
- uint256 constant defaultDecryptionDelayLimit = 2 hours;
14
13
 
15
14
  function typeOf(bytes32 handle) pure returns (ETypes) {
16
15
  return ETypes(uint8(uint256(handle) >> 8));
@@ -410,6 +409,18 @@ library e {
410
409
  inco.allow(eaddress.unwrap(a), to);
411
410
  }
412
411
 
412
+ function reveal(euint256 a) internal {
413
+ inco.reveal(euint256.unwrap(a));
414
+ }
415
+
416
+ function reveal(ebool a) internal {
417
+ inco.reveal(ebool.unwrap(a));
418
+ }
419
+
420
+ function reveal(eaddress a) internal {
421
+ inco.reveal(eaddress.unwrap(a));
422
+ }
423
+
413
424
  function allowThis(euint256 a) internal {
414
425
  allow(a, address(this));
415
426
  }
@@ -437,16 +448,4 @@ library e {
437
448
  function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
438
449
  return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
439
450
  }
440
-
441
- function requestDecryption(euint256 a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
442
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, euint256.unwrap(s(a)), callbackData);
443
- }
444
-
445
- function requestDecryption(ebool a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
446
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, ebool.unwrap(s(a)), callbackData);
447
- }
448
-
449
- function requestDecryption(eaddress a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
450
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, eaddress.unwrap(s(a)), callbackData);
451
- }
452
451
  }
@@ -2,16 +2,14 @@
2
2
  // SPDX-License-Identifier: No License
3
3
  pragma solidity ^0.8;
4
4
 
5
- import "./IncoLightning.sol";
6
- import {ebool, euint256, eaddress, ETypes, isTypeSupported} from "./Types.sol";
5
+ import {IncoLightning} from "./IncoLightning.sol";
6
+ import {ebool, euint256, eaddress, ETypes} from "./Types.sol";
7
7
 
8
8
  IncoLightning constant inco = IncoLightning(
9
9
  0x000000000000000000000000000000000000baBe
10
10
  );
11
11
  address constant deployedBy = 0x000000000000000000000000000000000000baBe;
12
12
 
13
- uint256 constant defaultDecryptionDelayLimit = 2 hours;
14
-
15
13
  function typeOf(bytes32 handle) pure returns (ETypes) {
16
14
  return ETypes(uint8(uint256(handle) >> 8));
17
15
  }
@@ -444,6 +442,18 @@ library e {
444
442
  inco.allow(eaddress.unwrap(a), to);
445
443
  }
446
444
 
445
+ function reveal(euint256 a) internal {
446
+ inco.reveal(euint256.unwrap(a));
447
+ }
448
+
449
+ function reveal(ebool a) internal {
450
+ inco.reveal(ebool.unwrap(a));
451
+ }
452
+
453
+ function reveal(eaddress a) internal {
454
+ inco.reveal(eaddress.unwrap(a));
455
+ }
456
+
447
457
  function allowThis(euint256 a) internal {
448
458
  allow(a, address(this));
449
459
  }
@@ -459,7 +469,7 @@ library e {
459
469
  function isAllowed(address user, euint256 a) internal view returns (bool) {
460
470
  return inco.isAllowed(euint256.unwrap(a), user);
461
471
  }
462
-
472
+
463
473
  function select(
464
474
  ebool control,
465
475
  euint256 ifTrue,
@@ -504,43 +514,4 @@ library e {
504
514
  )
505
515
  );
506
516
  }
507
-
508
- function requestDecryption(
509
- euint256 a,
510
- bytes4 callbackSelector,
511
- bytes memory callbackData
512
- ) internal returns (uint256 requestId) {
513
- requestId = inco.requestDecryption(
514
- callbackSelector,
515
- block.timestamp + defaultDecryptionDelayLimit,
516
- euint256.unwrap(s(a)),
517
- callbackData
518
- );
519
- }
520
-
521
- function requestDecryption(
522
- ebool a,
523
- bytes4 callbackSelector,
524
- bytes memory callbackData
525
- ) internal returns (uint256 requestId) {
526
- requestId = inco.requestDecryption(
527
- callbackSelector,
528
- block.timestamp + defaultDecryptionDelayLimit,
529
- ebool.unwrap(s(a)),
530
- callbackData
531
- );
532
- }
533
-
534
- function requestDecryption(
535
- eaddress a,
536
- bytes4 callbackSelector,
537
- bytes memory callbackData
538
- ) internal returns (uint256 requestId) {
539
- requestId = inco.requestDecryption(
540
- callbackSelector,
541
- block.timestamp + defaultDecryptionDelayLimit,
542
- eaddress.unwrap(s(a)),
543
- callbackData
544
- );
545
- }
546
517
  }
@@ -5,12 +5,11 @@
5
5
  /// SPDX-License-Identifier: No License
6
6
  pragma solidity ^0.8;
7
7
 
8
- import "./IncoLightning.sol";
9
- import { ebool, euint256, eaddress, ETypes, isTypeSupported } from "./Types.sol";
8
+ import { IncoLightning } from "./IncoLightning.sol";
9
+ import { ebool, euint256, eaddress, ETypes } from "./Types.sol";
10
10
 
11
11
  IncoLightning constant inco = IncoLightning(0x63D8135aF4D393B1dB43B649010c8D3EE19FC9fd);
12
12
  address constant deployedBy = 0x8202D2D747784Cb7D48868E44C42C4bf162a70BC;
13
- uint256 constant defaultDecryptionDelayLimit = 2 hours;
14
13
 
15
14
  function typeOf(bytes32 handle) pure returns (ETypes) {
16
15
  return ETypes(uint8(uint256(handle) >> 8));
@@ -410,6 +409,18 @@ library e {
410
409
  inco.allow(eaddress.unwrap(a), to);
411
410
  }
412
411
 
412
+ function reveal(euint256 a) internal {
413
+ inco.reveal(euint256.unwrap(a));
414
+ }
415
+
416
+ function reveal(ebool a) internal {
417
+ inco.reveal(ebool.unwrap(a));
418
+ }
419
+
420
+ function reveal(eaddress a) internal {
421
+ inco.reveal(eaddress.unwrap(a));
422
+ }
423
+
413
424
  function allowThis(euint256 a) internal {
414
425
  allow(a, address(this));
415
426
  }
@@ -437,16 +448,4 @@ library e {
437
448
  function select(ebool control, eaddress ifTrue, eaddress ifFalse) internal returns (eaddress) {
438
449
  return eaddress.wrap(inco.eIfThenElse(s(control), eaddress.unwrap(s(ifTrue)), eaddress.unwrap(s(ifFalse))));
439
450
  }
440
-
441
- function requestDecryption(euint256 a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
442
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, euint256.unwrap(s(a)), callbackData);
443
- }
444
-
445
- function requestDecryption(ebool a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
446
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, ebool.unwrap(s(a)), callbackData);
447
- }
448
-
449
- function requestDecryption(eaddress a, bytes4 callbackSelector, bytes memory callbackData) internal returns (uint256 requestId) {
450
- requestId = inco.requestDecryption(callbackSelector, block.timestamp + defaultDecryptionDelayLimit, eaddress.unwrap(s(a)), callbackData);
451
- }
452
451
  }
package/src/Types.sol CHANGED
@@ -108,6 +108,13 @@ pragma solidity ^0.8;
108
108
  string constant EVM_HOST_CHAIN_PREFIX = "evm/";
109
109
  uint8 constant HANDLE_VERSION = 0;
110
110
 
111
+ // used to make sure a verifier contract is checking allowance access on purpose, using a bytes4 or bool return type
112
+ // can lead to forging allowance vouchers using contract calls meant for an unrelated purpose, which lead to access
113
+ // theft. Its a common pattern, notably used in EIP1271 (Signature Validation Procedure for Contracts)
114
+ bytes32 constant ALLOWANCE_GRANTED_MAGIC_VALUE = keccak256(
115
+ "Inco Read Access on Provided Handle is Granted"
116
+ );
117
+
111
118
  // IncoLightning only supports single-valued ciphertexts so this is always 0
112
119
  // NOTE: this must be a uint8 to get hash agreement!
113
120
  uint8 constant HANDLE_INDEX = 0;
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {IEncryptedInput} from "../lightning-parts/interfaces/IEncryptedInput.sol";
5
+ import {IEncryptedOperations} from "../lightning-parts/interfaces/IEncryptedOperations.sol";
6
+ import {ITrivialEncryption} from "../lightning-parts/interfaces/ITrivialEncryption.sol";
7
+ import {IBaseAccessControlList} from "../lightning-parts/AccessControl/interfaces/IBaseAccessControlList.sol";
8
+ import {IHandleGeneration} from "../lightning-parts/primitives/interfaces/IHandleGeneration.sol";
9
+ import {IVersion} from "../version/interfaces/IVersion.sol";
10
+
11
+ interface IIncoLightning is
12
+ IEncryptedInput,
13
+ IEncryptedOperations,
14
+ ITrivialEncryption,
15
+ IBaseAccessControlList,
16
+ IHandleGeneration,
17
+ IVersion
18
+ {
19
+ function initialize(address owner) external;
20
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {IAdvancedAccessControl} from "../lightning-parts/AccessControl/interfaces/IAdvancedAccessControl.sol";
5
+ import {IDecryptionAttester} from "../lightning-parts/interfaces/IDecryptionAttester.sol";
6
+ import {ITEELifecycle} from "../lightning-parts/interfaces/ITEELifecycle.sol";
7
+ import {IQuoteVerifier} from "./automata-interfaces/IQuoteVerifier.sol";
8
+ import {ISignatureVerifier} from "../lightning-parts/primitives/interfaces/ISignatureVerifier.sol";
9
+
10
+ interface IIncoVerifier is
11
+ IAdvancedAccessControl,
12
+ IDecryptionAttester,
13
+ ITEELifecycle,
14
+ ISignatureVerifier
15
+ {
16
+ function initialize(
17
+ address owner,
18
+ string memory name,
19
+ string memory version,
20
+ IQuoteVerifier quoteVerifier
21
+ ) external;
22
+ function getEIP712Name() external view returns (string memory);
23
+ function getEIP712Version() external view returns (string memory);
24
+ }
@@ -0,0 +1,20 @@
1
+ //SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ /**
5
+ * @notice Converts a little-endian encoded bytes to a big-endian uint256 integer
6
+ */
7
+ library BELE {
8
+ function leBytesToBeUint(bytes memory encoded) internal pure returns (uint256 decoded) {
9
+ for (uint256 i = 0; i < encoded.length; i++) {
10
+ uint256 digits = uint256(uint8(bytes1(encoded[i])));
11
+ uint256 upperDigit = digits / 16;
12
+ uint256 lowerDigit = digits % 16;
13
+
14
+ uint256 acc = lowerDigit * (16 ** (2 * i));
15
+ acc += upperDigit * (16 ** ((2 * i) + 1));
16
+
17
+ decoded += acc;
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8;
3
+
4
+ import {EnclaveIdentityJsonObj, IdentityObj} from "./Types.sol";
5
+
6
+ // only the functions we need have been included here
7
+ interface IEnclaveIdentityHelper {
8
+ function parseIdentityString(
9
+ string calldata identityStr
10
+ )
11
+ external
12
+ pure
13
+ returns (IdentityObj memory identity, string memory identityTcbString);
14
+ }
15
+
16
+ // only the functions we need have been included here
17
+ interface IAutomataEnclaveIdentityDao {
18
+ function upsertEnclaveIdentity(
19
+ uint256 id,
20
+ uint256 version,
21
+ EnclaveIdentityJsonObj calldata enclaveIdentityObj
22
+ ) external returns (bytes32 attestationId);
23
+
24
+ function EnclaveIdentityLib()
25
+ external
26
+ view
27
+ returns (IEnclaveIdentityHelper);
28
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {TcbInfoJsonObj} from "./Types.sol";
5
+
6
+ interface IFmspcTcbDao {
7
+ function upsertFmspcTcb(
8
+ TcbInfoJsonObj calldata tcbInfoObj
9
+ ) external returns (bytes32 attestationId);
10
+ }
@@ -0,0 +1,94 @@
1
+ //SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ import {
5
+ EnclaveIdentityJsonObj,
6
+ IdentityObj,
7
+ EnclaveId,
8
+ CA,
9
+ TcbInfoJsonObj,
10
+ TCBLevelsObj,
11
+ TcbInfoBasic,
12
+ TcbId,
13
+ TDXModule,
14
+ TDXModuleIdentity
15
+ } from "./Types.sol";
16
+
17
+ /**
18
+ * @title PCCS Router Interface
19
+ * @notice The PCCS Router is a central contract that serves all other contracts in the network
20
+ * to fetch collaterals from the On Chain PCCS
21
+ */
22
+ interface IPCCSRouter {
23
+ function qeIdDaoAddr() external view returns (address);
24
+
25
+ function fmspcTcbDaoAddr() external view returns (address);
26
+
27
+ function pckDaoAddr() external view returns (address);
28
+
29
+ function pcsDaoAddr() external view returns (address);
30
+
31
+ function pckHelperAddr() external view returns (address);
32
+
33
+ function crlHelperAddr() external view returns (address);
34
+
35
+ function fmspcTcbHelperAddr() external view returns (address);
36
+
37
+ function getQeIdentity(
38
+ EnclaveId id,
39
+ uint256 quoteVersion
40
+ ) external view returns (IdentityObj memory);
41
+
42
+ function getQeIdentityContentHash(
43
+ EnclaveId id,
44
+ uint256 version
45
+ ) external view returns (bytes32);
46
+
47
+ function getFmspcTcbV2(
48
+ bytes6 fmspc
49
+ ) external view returns (TCBLevelsObj[] memory);
50
+
51
+ function getFmspcTcbV3(
52
+ TcbId id,
53
+ bytes6 fmspc
54
+ )
55
+ external
56
+ view
57
+ returns (
58
+ TCBLevelsObj[] memory,
59
+ TDXModule memory,
60
+ TDXModuleIdentity[] memory
61
+ );
62
+
63
+ function getFmspcTcbContentHash(
64
+ TcbId id,
65
+ bytes6 fmspc,
66
+ uint32 version
67
+ ) external view returns (bytes32);
68
+
69
+ function getPckCert(
70
+ string calldata qeid,
71
+ string calldata platformCpuSvn,
72
+ string calldata platformPceSvn,
73
+ string calldata pceid
74
+ ) external view returns (bytes memory);
75
+
76
+ function getCert(CA ca) external view returns (bytes memory);
77
+
78
+ function getCrl(CA ca) external view returns (bytes memory);
79
+
80
+ function getCertHash(CA ca) external view returns (bytes32);
81
+
82
+ function getCrlHash(CA ca) external view returns (bytes32);
83
+
84
+ // *withTimestamp() methods to check collateral expiration status based on the provided timestamp
85
+ function getCertHashWithTimestamp(
86
+ CA ca,
87
+ uint64 timestamp
88
+ ) external view returns (bytes32);
89
+
90
+ function getCrlHashWithTimestamp(
91
+ CA ca,
92
+ uint64 timestamp
93
+ ) external view returns (bytes32);
94
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: No License
2
+ pragma solidity ^0.8;
3
+
4
+ import {IPCCSRouter} from "./IPCCSRouter.sol";
5
+
6
+ /// @dev we declare this interface because the one exported from the automata-dcap-attestation package is missing some
7
+ /// external functions.
8
+ interface IPCCSRouterExtended is IPCCSRouter {
9
+ function setAuthorized(address caller, bool authorized) external;
10
+ }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {CA} from "./Types.sol";
5
+
6
+ interface IPcsDao {
7
+ function upsertPcsCertificates(
8
+ CA ca,
9
+ bytes calldata cert
10
+ ) external returns (bytes32 attestationId);
11
+ function upsertPckCrl(
12
+ CA ca,
13
+ bytes calldata crl
14
+ ) external returns (bytes32 attestationId);
15
+ function upsertRootCACrl(
16
+ bytes calldata rootcacrl
17
+ ) external returns (bytes32 attestationId);
18
+ }
@@ -0,0 +1,34 @@
1
+ //SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ import {IPCCSRouter} from "./IPCCSRouter.sol";
5
+ import {Header} from "./Types.sol";
6
+
7
+ /**
8
+ * @title Automata DCAP Quote Verifier
9
+ * @notice Provides the interface to implement version-specific verifiers
10
+ */
11
+ interface IQuoteVerifier {
12
+ /**
13
+ * @dev this method must be immutable
14
+ * @return an instance of the PCCSRouter interface
15
+ */
16
+ function pccsRouter() external view returns (IPCCSRouter);
17
+
18
+ /**
19
+ * @notice the quote version supported by this verifier
20
+ */
21
+ function quoteVersion() external view returns (uint16);
22
+
23
+ function verifyQuote(
24
+ Header calldata,
25
+ bytes calldata
26
+ ) external view returns (bool, bytes memory);
27
+
28
+ /**
29
+ * @notice additional check on the public output obtained from the ZK Program execution
30
+ */
31
+ function verifyZkOutput(
32
+ bytes calldata
33
+ ) external view returns (bool, bytes memory);
34
+ }
@@ -0,0 +1,193 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ // https://github.com/intel/SGXDataCenterAttestationPrimitives/blob/e7604e02331b3377f3766ed3653250e03af72d45/QuoteVerification/QVL/Src/AttestationLibrary/src/CertVerification/X509Constants.h#L64
5
+ uint256 constant TCB_CPUSVN_SIZE = 16;
6
+
7
+ enum TcbId {
8
+ /// the "id" field is absent from TCBInfo V2
9
+ /// which defaults TcbId to SGX
10
+ /// since TDX TCBInfos are only included in V3 or above
11
+ SGX,
12
+ TDX
13
+ }
14
+
15
+ /**
16
+ * @dev This is a simple representation of the TCBInfo.json in string as a Solidity object.
17
+ * @param tcbInfo: tcbInfoJson.tcbInfo string object body
18
+ * @param signature The signature to be passed as bytes array
19
+ */
20
+ struct TcbInfoJsonObj {
21
+ string tcbInfoStr;
22
+ bytes signature;
23
+ }
24
+
25
+ /// @dev Solidity object representing TCBInfo.json excluding TCBLevels
26
+ struct TcbInfoBasic {
27
+ /// the name "tcbType" can be confusing/misleading
28
+ /// as the tcbType referred here in this struct is the type
29
+ /// of TCB level composition that determines TCB level comparison logic
30
+ /// It is not the same as the "type" parameter passed as an argument to the
31
+ /// getTcbInfo() API method described in Section 4.2.3 of the Intel PCCS Design Document
32
+ /// Instead, getTcbInfo() "type" argument should be checked against the "id" value of this struct
33
+ /// which represents the TEE type for the given TCBInfo
34
+ uint8 tcbType;
35
+ TcbId id;
36
+ uint32 version;
37
+ uint64 issueDate;
38
+ uint64 nextUpdate;
39
+ uint32 evaluationDataNumber;
40
+ bytes6 fmspc;
41
+ bytes2 pceid;
42
+ }
43
+
44
+ struct TCBLevelsObj {
45
+ uint16 pcesvn;
46
+ uint8[] sgxComponentCpuSvns;
47
+ uint8[] tdxComponentCpuSvns;
48
+ uint64 tcbDateTimestamp;
49
+ TCBStatus status;
50
+ string[] advisoryIDs;
51
+ }
52
+
53
+ struct TDXModule {
54
+ bytes mrsigner; // 48 bytes
55
+ bytes8 attributes;
56
+ bytes8 attributesMask;
57
+ }
58
+
59
+ struct TDXModuleIdentity {
60
+ string id;
61
+ bytes8 attributes;
62
+ bytes8 attributesMask;
63
+ bytes mrsigner; // 48 bytes
64
+ TDXModuleTCBLevelsObj[] tcbLevels;
65
+ }
66
+
67
+ struct TDXModuleTCBLevelsObj {
68
+ uint8 isvsvn;
69
+ uint64 tcbDateTimestamp;
70
+ TCBStatus status;
71
+ }
72
+
73
+ enum TCBStatus {
74
+ OK,
75
+ TCB_SW_HARDENING_NEEDED,
76
+ TCB_CONFIGURATION_AND_SW_HARDENING_NEEDED,
77
+ TCB_CONFIGURATION_NEEDED,
78
+ TCB_OUT_OF_DATE,
79
+ TCB_OUT_OF_DATE_CONFIGURATION_NEEDED,
80
+ TCB_REVOKED,
81
+ TCB_UNRECOGNIZED
82
+ }
83
+
84
+ enum CA {
85
+ ROOT,
86
+ PROCESSOR,
87
+ PLATFORM,
88
+ SIGNING
89
+ }
90
+
91
+ enum EnclaveId {
92
+ QE,
93
+ QVE,
94
+ TD_QE
95
+ }
96
+
97
+ /**
98
+ * @dev This is a simple representation of the Identity.json in string as a Solidity object.
99
+ * @param identityStr Identity string object body. Needs to be parsed
100
+ * and converted as IdentityObj.
101
+ * @param signature The signature to be passed as bytes array
102
+ */
103
+ struct EnclaveIdentityJsonObj {
104
+ string identityStr;
105
+ bytes signature;
106
+ }
107
+
108
+ /// @dev Full Solidity Object representation of Identity.json
109
+ struct IdentityObj {
110
+ EnclaveId id;
111
+ uint32 version;
112
+ uint64 issueDateTimestamp; // UNIX Epoch Timestamp in seconds
113
+ uint64 nextUpdateTimestamp; // UNIX Epoch Timestamp in seconds
114
+ uint32 tcbEvaluationDataNumber;
115
+ bytes4 miscselect;
116
+ bytes4 miscselectMask;
117
+ bytes16 attributes;
118
+ bytes16 attributesMask;
119
+ bytes32 mrsigner;
120
+ uint16 isvprodid;
121
+ Tcb[] tcb;
122
+ }
123
+
124
+ enum EnclaveIdTcbStatus {
125
+ SGX_ENCLAVE_REPORT_ISVSVN_NOT_SUPPORTED,
126
+ OK,
127
+ SGX_ENCLAVE_REPORT_ISVSVN_REVOKED,
128
+ SGX_ENCLAVE_REPORT_ISVSVN_OUT_OF_DATE
129
+ }
130
+
131
+ struct Tcb {
132
+ uint16 isvsvn;
133
+ uint256 dateTimestamp;
134
+ EnclaveIdTcbStatus status;
135
+ }
136
+
137
+ /**
138
+ * @notice The Quote Header struct definition
139
+ * @dev https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/16b7291a7a86e486fdfcf1dfb4be885c0cc00b4e/Src/AttestationLibrary/src/QuoteVerification/QuoteStructures.h#L42-L53
140
+ * @dev Section A.3 of Intel V4 TDX DCAP API Library Documentation
141
+ */
142
+ struct Header {
143
+ uint16 version; // LE -> BE
144
+ bytes2 attestationKeyType;
145
+ bytes4 teeType;
146
+ bytes2 qeSvn;
147
+ bytes2 pceSvn;
148
+ bytes16 qeVendorId;
149
+ bytes20 userData;
150
+ }
151
+
152
+ /**
153
+ * @notice V4 Intel TDX Quote uses this struct as the quote body
154
+ * @dev Section A.3.2 of Intel V4 TDX DCAP API Library Documentation
155
+ * @dev https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/7e5b2a13ca5472de8d97dd7d7024c2ea5af9a6ba/Src/AttestationLibrary/src/QuoteVerification/QuoteStructures.h#L82-L103
156
+ */
157
+ struct TD10ReportBody {
158
+ bytes16 teeTcbSvn;
159
+ bytes mrSeam; // 48 bytes
160
+ bytes mrsignerSeam; // 48 bytes
161
+ bytes8 seamAttributes;
162
+ bytes8 tdAttributes;
163
+ bytes8 xFAM;
164
+ bytes mrTd; // 48 bytes
165
+ bytes mrConfigId; // 48 bytes
166
+ bytes mrOwner; // 48 bytes
167
+ bytes mrOwnerConfig; // 48 bytes
168
+ bytes rtMr0; // 48 bytes
169
+ bytes rtMr1; // 48 bytes
170
+ bytes rtMr2; // 48 bytes
171
+ bytes rtMr3; // 48 bytes
172
+ bytes reportData; // 64 bytes
173
+ }
174
+
175
+ /// @dev https://github.com/intel/SGX-TDX-DCAP-QuoteVerificationLibrary/blob/16b7291a7a86e486fdfcf1dfb4be885c0cc00b4e/Src/AttestationLibrary/src/QuoteVerification/QuoteConstants.h
176
+ uint16 constant HEADER_LENGTH = 48;
177
+ // bytes2 constant SUPPORTED_ATTESTATION_KEY_TYPE = 0x0200; // ECDSA_256_WITH_P256_CURVE (LE)
178
+ // // TEE_TYPE are little-endian encoded, hence reversing the order of bytes
179
+ // bytes4 constant SGX_TEE = 0x00000000;
180
+ bytes4 constant TDX_TEE = 0x81000000;
181
+ // bytes16 constant VALID_QE_VENDOR_ID = 0x939a7233f79c4ca9940a0db3957f0607;
182
+ // uint16 constant ENCLAVE_REPORT_LENGTH = 384;
183
+ // uint16 constant TD_REPORT10_LENGTH = 584;
184
+
185
+ // Header (48 bytes) + Body (minimum 384 bytes) + AuthDataSize (4 bytes) + AuthData:
186
+ // ECDSA_SIGNATURE (64 bytes) + ECDSA_KEY (64 bytes) + QE_REPORT_BYTES (384 bytes)
187
+ // + QE_REPORT_SIGNATURE (64 bytes) + QE_AUTH_DATA_SIZE (2 bytes) + QE_CERT_DATA_TYPE (2 bytes)
188
+ // + QE_CERT_DATA_SIZE (4 bytes)
189
+ uint16 constant MINIMUM_QUOTE_LENGTH = 1020;
190
+
191
+ // // timestamp + tcb_info_hash + identity_hash + root_ca_hash + tcb_signing_hash + root_crl_hash + pck_crl_hash
192
+ // // 8 + 6 * 32 = 200
193
+ // uint16 constant VERIFIED_OUTPUT_COLLATERAL_HASHES_LENGTH = 200;