@@ -101,20 +101,40 @@ abstract contract FmspcTcbDao is DaoBase, SigVerifyBase {
101
101
* @param tcbInfoObj See {FmspcTcbHelper.sol} to learn more about the structure definition
102
102
*/
103
103
function upsertFmspcTcb (TcbInfoJsonObj calldata tcbInfoObj ) external returns (bytes32 attestationId ) {
104
- _validateTcbInfo (tcbInfoObj);
105
- (
106
- bytes memory req ,
107
- bytes32 key ,
108
- uint8 tcbId ,
109
- bytes6 fmspc ,
110
- uint32 version ,
111
- uint64 issueDateTimestamp ,
112
- uint32 evaluationDataNumber
113
- ) = _buildTcbAttestationRequest (tcbInfoObj);
114
104
bytes32 hash = sha256 (bytes (tcbInfoObj.tcbInfoStr));
105
+
106
+ // parse tcb info basic here so we can compute the key
107
+ (
108
+ TcbInfoBasic memory tcbInfo ,
109
+ string memory tcbLevelsString ,
110
+ string memory tdxModuleString ,
111
+ string memory tdxModuleIdentitiesString
112
+ ) = FmspcTcbLib.parseTcbString (tcbInfoObj.tcbInfoStr);
113
+ bytes32 key = FMSPC_TCB_KEY (uint8 (tcbInfo.id), tcbInfo.fmspc, tcbInfo.version);
114
+
115
+ _checkCollateralDuplicate (key, hash);
116
+ _validateTcbInfo (tcbInfoObj);
117
+
118
+ bytes memory req = _buildTcbAttestationRequest (
119
+ key,
120
+ tcbInfoObj,
121
+ tcbInfo,
122
+ tcbLevelsString,
123
+ tdxModuleString,
124
+ tdxModuleIdentitiesString
125
+ );
126
+
115
127
attestationId = _attestTcb (req, hash, key);
116
- _storeTcbInfoIssueEvaluation (key, issueDateTimestamp, evaluationDataNumber);
117
- emit UpsertedFmpscTcb (tcbId, fmspc, version);
128
+ _storeTcbInfoIssueEvaluation (
129
+ key,
130
+ tcbInfo.issueDate,
131
+ tcbInfo.evaluationDataNumber
132
+ );
133
+ emit UpsertedFmpscTcb (
134
+ uint8 (tcbInfo.id),
135
+ tcbInfo.fmspc,
136
+ tcbInfo.version
137
+ );
118
138
}
119
139
120
140
/**
@@ -142,55 +162,35 @@ abstract contract FmspcTcbDao is DaoBase, SigVerifyBase {
142
162
/**
143
163
* @notice constructs the TcbInfo.json attestation data
144
164
*/
145
- function _buildTcbAttestationRequest (TcbInfoJsonObj calldata tcbInfoObj )
165
+ function _buildTcbAttestationRequest (
166
+ bytes32 key ,
167
+ TcbInfoJsonObj calldata tcbInfoObj ,
168
+ TcbInfoBasic memory tcbInfo ,
169
+ string memory tcbLevelsString ,
170
+ string memory tdxModuleString ,
171
+ string memory tdxModuleIdentitiesString
172
+ )
146
173
private
147
174
view
148
- returns
149
- (
150
- bytes memory reqData ,
151
- bytes32 key ,
152
- uint8 id ,
153
- bytes6 fmspc ,
154
- uint32 version ,
155
- uint64 issueDateTimestamp ,
156
- uint32 evaluationDataNumber
157
- )
175
+ returns (bytes memory reqData )
158
176
{
159
- TcbInfoBasic memory tcbInfo;
160
-
161
- string memory tcbLevelsString;
162
- string memory tdxModuleString;
163
- string memory tdxModuleIdentitiesString;
164
- (
165
- tcbInfo,
166
- tcbLevelsString,
167
- tdxModuleString,
168
- tdxModuleIdentitiesString
169
- ) = FmspcTcbLib.parseTcbString (tcbInfoObj.tcbInfoStr);
170
-
171
177
// check expiration before continuing...
172
178
if (block .timestamp < tcbInfo.issueDate || block .timestamp > tcbInfo.nextUpdate) {
173
179
revert TCB_Expired ();
174
180
}
175
181
176
182
// Make sure new collateral is "newer"
177
- id = uint8 (tcbInfo.id);
178
- fmspc = tcbInfo.fmspc;
179
- version = tcbInfo.version;
180
- key = FMSPC_TCB_KEY (id, fmspc, version);
181
183
(uint64 existingIssueDate , uint32 existingEvaluationDataNumber ) = _loadTcbInfoIssueEvaluation (key);
182
184
if (existingIssueDate > 0 ) {
183
185
/// I don't think there can be a scenario where an existing tcbinfo with a higher evaluation data number
184
186
/// to be issued BEFORE a new tcbinfo with a lower evaluation data number
185
187
bool outOfDate = tcbInfo.evaluationDataNumber < existingEvaluationDataNumber ||
186
- tcbInfo.issueDate < existingIssueDate;
188
+ tcbInfo.issueDate <= existingIssueDate;
187
189
if (outOfDate) {
188
190
revert TCB_Out_Of_Date ();
189
191
}
190
192
}
191
193
192
- issueDateTimestamp = tcbInfo.issueDate;
193
- evaluationDataNumber = tcbInfo.evaluationDataNumber;
194
194
TCBLevelsObj[] memory tcbLevels = FmspcTcbLib.parseTcbLevels (tcbInfo.version, tcbLevelsString);
195
195
bytes memory encodedTcbLevels = _encodeTcbLevels (tcbLevels);
196
196
if (tcbInfo.version < 3 ) {
0 commit comments