@@ -101,20 +101,40 @@ abstract contract FmspcTcbDao is DaoBase, SigVerifyBase {
101101 * @param tcbInfoObj See {FmspcTcbHelper.sol} to learn more about the structure definition
102102 */
103103 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);
114104 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+
115127 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+ );
118138 }
119139
120140 /**
@@ -142,55 +162,35 @@ abstract contract FmspcTcbDao is DaoBase, SigVerifyBase {
142162 /**
143163 * @notice constructs the TcbInfo.json attestation data
144164 */
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+ )
146173 private
147174 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 )
158176 {
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-
171177 // check expiration before continuing...
172178 if (block .timestamp < tcbInfo.issueDate || block .timestamp > tcbInfo.nextUpdate) {
173179 revert TCB_Expired ();
174180 }
175181
176182 // 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);
181183 (uint64 existingIssueDate , uint32 existingEvaluationDataNumber ) = _loadTcbInfoIssueEvaluation (key);
182184 if (existingIssueDate > 0 ) {
183185 /// I don't think there can be a scenario where an existing tcbinfo with a higher evaluation data number
184186 /// to be issued BEFORE a new tcbinfo with a lower evaluation data number
185187 bool outOfDate = tcbInfo.evaluationDataNumber < existingEvaluationDataNumber ||
186- tcbInfo.issueDate < existingIssueDate;
188+ tcbInfo.issueDate <= existingIssueDate;
187189 if (outOfDate) {
188190 revert TCB_Out_Of_Date ();
189191 }
190192 }
191193
192- issueDateTimestamp = tcbInfo.issueDate;
193- evaluationDataNumber = tcbInfo.evaluationDataNumber;
194194 TCBLevelsObj[] memory tcbLevels = FmspcTcbLib.parseTcbLevels (tcbInfo.version, tcbLevelsString);
195195 bytes memory encodedTcbLevels = _encodeTcbLevels (tcbLevels);
196196 if (tcbInfo.version < 3 ) {
0 commit comments