@inco/lightning 0.4.0 → 0.5.1
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/CHANGELOG.md +4 -0
- package/README.md +2 -0
- package/manifest.yaml +23 -0
- 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 +2 -15
- package/src/Lib.demonet.sol +2 -15
- package/src/Lib.devnet.sol +3 -16
- package/src/Lib.sol +3 -16
- package/src/Lib.template.sol +3 -44
- package/src/Lib.testnet.sol +2 -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 +2 -15
- package/src/libs/incoLightning_demonet_v0_863421733.sol +2 -15
- package/src/libs/incoLightning_devnet_v0_340846814.sol +2 -15
- package/src/libs/incoLightning_devnet_v1_887305889.sol +451 -0
- package/src/libs/incoLightning_testnet_v0_183408998.sol +2 -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 +22 -2
- 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 +4 -3
- package/src/lightning-parts/DecryptionAttester.sol +45 -0
- package/src/lightning-parts/DecryptionAttester.types.sol +7 -0
- package/src/lightning-parts/EncryptedInput.sol +8 -13
- package/src/lightning-parts/EncryptedOperations.sol +2 -2
- package/src/lightning-parts/TEELifecycle.sol +180 -88
- package/src/lightning-parts/TrivialEncryption.sol +8 -10
- 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 +2 -2
- 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} +2 -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 +18 -33
- 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 +5 -4
- 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 -24
- 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
|
@@ -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
|
+
}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
4
|
import {EventCounter} from "./primitives/EventCounter.sol";
|
|
5
|
-
import {euint256, ebool, eaddress,
|
|
5
|
+
import {euint256, ebool, eaddress, ETypes} from "../Types.sol";
|
|
6
6
|
import {BaseAccessControlList} from "./AccessControl/BaseAccessControlList.sol";
|
|
7
7
|
import {HandleGeneration} from "./primitives/HandleGeneration.sol";
|
|
8
|
-
import {
|
|
8
|
+
import {ITrivialEncryption} from "./interfaces/ITrivialEncryption.sol";
|
|
9
9
|
|
|
10
10
|
abstract contract TrivialEncryption is
|
|
11
|
-
|
|
11
|
+
ITrivialEncryption,
|
|
12
12
|
BaseAccessControlList,
|
|
13
13
|
EventCounter,
|
|
14
14
|
HandleGeneration
|
|
@@ -31,7 +31,10 @@ abstract contract TrivialEncryption is
|
|
|
31
31
|
|
|
32
32
|
function asEaddress(address value) external returns (eaddress newEaddress) {
|
|
33
33
|
bytes32 castedValue = bytes32(uint256(uint160(value)));
|
|
34
|
-
return
|
|
34
|
+
return
|
|
35
|
+
eaddress.wrap(
|
|
36
|
+
newTrivialEncrypt(castedValue, ETypes.AddressOrUint160OrBytes20)
|
|
37
|
+
);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
function newTrivialEncrypt(
|
|
@@ -41,12 +44,7 @@ abstract contract TrivialEncryption is
|
|
|
41
44
|
newHandle = getTrivialEncryptHandle(plainTextBytes, handleType);
|
|
42
45
|
allowTransientInternal(newHandle, msg.sender);
|
|
43
46
|
uint256 id = getNextEventId();
|
|
44
|
-
emit TrivialEncrypt(
|
|
45
|
-
newHandle,
|
|
46
|
-
plainTextBytes,
|
|
47
|
-
handleType,
|
|
48
|
-
id
|
|
49
|
-
);
|
|
47
|
+
emit TrivialEncrypt(newHandle, plainTextBytes, handleType, id);
|
|
50
48
|
setDigest(abi.encodePacked(newHandle, id));
|
|
51
49
|
}
|
|
52
50
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import { DecryptionAttestation } from "../DecryptionAttester.types.sol";
|
|
5
|
+
|
|
6
|
+
interface IDecryptionAttester {
|
|
7
|
+
function decryptionAttestationDigest(DecryptionAttestation memory decryption) external view returns (bytes32);
|
|
8
|
+
function isValidDecryptionAttestation(DecryptionAttestation memory decryption, bytes memory signature) external view returns (bool);
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {euint256, ebool, eaddress} from "../../Types.sol";
|
|
5
|
+
|
|
6
|
+
interface IEncryptedInput {
|
|
7
|
+
function newEuint256(
|
|
8
|
+
bytes memory ciphertext,
|
|
9
|
+
address user
|
|
10
|
+
) external returns (euint256 newValue);
|
|
11
|
+
function newEbool(
|
|
12
|
+
bytes memory ciphertext,
|
|
13
|
+
address user
|
|
14
|
+
) external returns (ebool newValue);
|
|
15
|
+
function newEaddress(
|
|
16
|
+
bytes memory ciphertext,
|
|
17
|
+
address user
|
|
18
|
+
) external returns (eaddress newValue);
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {euint256} from "../../Types.sol";
|
|
5
|
+
|
|
6
|
+
interface IEncryptedOperations {
|
|
7
|
+
function eAdd(
|
|
8
|
+
euint256 lhs,
|
|
9
|
+
euint256 rhs
|
|
10
|
+
) external returns (euint256 result);
|
|
11
|
+
function eSub(
|
|
12
|
+
euint256 lhs,
|
|
13
|
+
euint256 rhs
|
|
14
|
+
) external returns (euint256 result);
|
|
15
|
+
function eMul(
|
|
16
|
+
euint256 lhs,
|
|
17
|
+
euint256 rhs
|
|
18
|
+
) external returns (euint256 result);
|
|
19
|
+
function eDiv(
|
|
20
|
+
euint256 lhs,
|
|
21
|
+
euint256 rhs
|
|
22
|
+
) external returns (euint256 result);
|
|
23
|
+
function eRem(
|
|
24
|
+
euint256 lhs,
|
|
25
|
+
euint256 rhs
|
|
26
|
+
) external returns (euint256 result);
|
|
27
|
+
function eBitAnd(
|
|
28
|
+
bytes32 lhs,
|
|
29
|
+
bytes32 rhs
|
|
30
|
+
) external returns (bytes32 result);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {BootstrapResult} from "../TEELifecycle.types.sol";
|
|
5
|
+
import {IQuoteVerifier} from "../../interfaces/automata-interfaces/IQuoteVerifier.sol";
|
|
6
|
+
import {TD10ReportBody} from "../../interfaces/automata-interfaces/Types.sol";
|
|
7
|
+
|
|
8
|
+
interface ITEELifecycle {
|
|
9
|
+
function verifyBootstrapResult(
|
|
10
|
+
BootstrapResult calldata bootstrapResult,
|
|
11
|
+
bytes calldata quote,
|
|
12
|
+
bytes calldata signature
|
|
13
|
+
) external;
|
|
14
|
+
function approveNewTEEVersion(bytes calldata newMRTD) external;
|
|
15
|
+
function addNewCovalidator(bytes calldata quote) external;
|
|
16
|
+
function parseTD10ReportBody(
|
|
17
|
+
bytes calldata rawQuote
|
|
18
|
+
) external pure returns (TD10ReportBody memory report);
|
|
19
|
+
function parseReport(
|
|
20
|
+
TD10ReportBody memory tdReport
|
|
21
|
+
) external pure returns (address, bytes memory);
|
|
22
|
+
function bootstrapResultDigest(
|
|
23
|
+
BootstrapResult memory bootstrapResult
|
|
24
|
+
) external view returns (bytes32);
|
|
25
|
+
function quoteVerifier() external view returns (IQuoteVerifier);
|
|
26
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {euint256, ebool, eaddress} from "../../Types.sol";
|
|
5
|
+
|
|
6
|
+
interface ITrivialEncryption {
|
|
7
|
+
function asEuint256(uint256 value) external returns (euint256 newEuint256);
|
|
8
|
+
function asEbool(bool value) external returns (ebool newEbool);
|
|
9
|
+
function asEaddress(address value) external returns (eaddress newEaddress);
|
|
10
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {IEventCounter} from "./interfaces/IEventCounter.sol";
|
|
5
5
|
|
|
6
6
|
contract EventCounterStorage {
|
|
7
7
|
struct Storage {
|
|
@@ -24,7 +24,7 @@ contract EventCounterStorage {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
contract EventCounter is
|
|
27
|
+
contract EventCounter is IEventCounter, EventCounterStorage {
|
|
28
28
|
function getNewEventId() internal returns (uint256 newEventId) {
|
|
29
29
|
newEventId = getEventCounterStorage().eventCounter++;
|
|
30
30
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ETypes,
|
|
6
|
+
EOps,
|
|
7
|
+
EVM_HOST_CHAIN_PREFIX,
|
|
8
|
+
HANDLE_INDEX
|
|
9
|
+
} from "../../Types.sol";
|
|
5
10
|
import {HandleMetadata} from "./HandleMetadata.sol";
|
|
6
|
-
import {
|
|
11
|
+
import {IHandleGeneration} from "./interfaces/IHandleGeneration.sol";
|
|
7
12
|
|
|
8
|
-
contract HandleGeneration is
|
|
13
|
+
contract HandleGeneration is IHandleGeneration, HandleMetadata {
|
|
9
14
|
function getTrivialEncryptHandle(
|
|
10
15
|
bytes32 plaintextBytes,
|
|
11
16
|
ETypes handleType
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: No License
|
|
2
2
|
pragma solidity ^0.8;
|
|
3
3
|
|
|
4
|
-
import {HANDLE_VERSION, HANDLE_INDEX, ETypes} from "../../Types.sol";
|
|
4
|
+
import { HANDLE_VERSION, HANDLE_INDEX, ETypes } from "../../Types.sol";
|
|
5
5
|
|
|
6
6
|
contract HandleMetadata {
|
|
7
7
|
function embedIndexTypeVersion(
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
abstract contract LightningAddressGetter {
|
|
5
|
+
address internal immutable incoLightningAddress;
|
|
6
|
+
|
|
7
|
+
constructor(address _incoLightningAddress) {
|
|
8
|
+
incoLightningAddress = _incoLightningAddress;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8;
|
|
|
3
3
|
|
|
4
4
|
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
5
5
|
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
6
|
-
import {
|
|
6
|
+
import {ISignatureVerifier} from "./interfaces/ISignatureVerifier.sol";
|
|
7
7
|
import {TEELifecycle} from "../TEELifecycle.sol";
|
|
8
8
|
|
|
9
9
|
contract SignatureVerifierStorage {
|
|
@@ -28,7 +28,7 @@ contract SignatureVerifierStorage {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
contract SignatureVerifier is
|
|
31
|
+
abstract contract SignatureVerifier is ISignatureVerifier, OwnableUpgradeable, SignatureVerifierStorage {
|
|
32
32
|
using ECDSA for bytes32;
|
|
33
33
|
|
|
34
34
|
error SignerNotFound(address signerAddress);
|
|
@@ -36,13 +36,6 @@ contract SignatureVerifier is ISignatureVerifierGen, OwnableUpgradeable, Signatu
|
|
|
36
36
|
event AddedSignatureVerifier(address signerAddress);
|
|
37
37
|
event RemovedSignatureVerifier(address signerAddress);
|
|
38
38
|
|
|
39
|
-
// Reference to the TEELifecycle contract, to get the list of EOA signers
|
|
40
|
-
TEELifecycle teeLifecycle;
|
|
41
|
-
|
|
42
|
-
function __SignatureVerifier_init(address _teeLifecycleAddress) internal {
|
|
43
|
-
teeLifecycle = TEELifecycle(_teeLifecycleAddress);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
39
|
// @todo: This function should be removed once we have a way to read the signers from the TEELifecycle contract
|
|
47
40
|
function addSigner(address signerAddress) external onlyOwner {
|
|
48
41
|
getSigVerifierStorage().isSigner[signerAddress] = true;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: No License
|
|
2
|
+
pragma solidity ^0.8;
|
|
3
|
+
|
|
4
|
+
import {IIncoVerifier} from "../../interfaces/IIncoVerifier.sol";
|
|
5
|
+
import {IVerifierAddressGetter} from "./interfaces/IVerifierAddressGetter.sol";
|
|
6
|
+
|
|
7
|
+
abstract contract VerifierAddressGetter is IVerifierAddressGetter {
|
|
8
|
+
IIncoVerifier public immutable incoVerifier;
|
|
9
|
+
|
|
10
|
+
constructor(address _incoVerifier) {
|
|
11
|
+
incoVerifier = IIncoVerifier(_incoVerifier);
|
|
12
|
+
}
|
|
13
|
+
}
|