From 5db93be12aaf0fb3502513c391a6d3c2120c6a4d Mon Sep 17 00:00:00 2001 From: Preston Ong Date: Tue, 11 Feb 2025 15:26:27 +0800 Subject: [PATCH] tdx module attributes type update --- contracts/bases/TDXModuleBase.sol | 4 ++-- contracts/bases/tcb/TCBInfoV3Base.sol | 7 ++++--- contracts/types/CommonStruct.sol | 4 ++-- contracts/types/V4Structs.sol | 6 +++--- contracts/verifiers/V4QuoteVerifier.sol | 8 ++++---- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/contracts/bases/TDXModuleBase.sol b/contracts/bases/TDXModuleBase.sol index 708cb46..d3248bb 100644 --- a/contracts/bases/TDXModuleBase.sol +++ b/contracts/bases/TDXModuleBase.sol @@ -11,8 +11,8 @@ abstract contract TDXModuleBase { function checkTdxModule( bytes memory mrsignerSeam, bytes memory expectedMrsignerSeam, - bytes8 seamAttributes, - bytes8 expectedSeamAttributes + uint64 seamAttributes, + uint64 expectedSeamAttributes ) internal pure returns (bool) { return mrsignerSeam.equals(expectedMrsignerSeam) && seamAttributes == expectedSeamAttributes; } diff --git a/contracts/bases/tcb/TCBInfoV3Base.sol b/contracts/bases/tcb/TCBInfoV3Base.sol index d36b622..490e5c9 100644 --- a/contracts/bases/tcb/TCBInfoV3Base.sol +++ b/contracts/bases/tcb/TCBInfoV3Base.sol @@ -7,6 +7,7 @@ import { TDXModuleIdentity, TDXModuleTCBLevelsObj } from "@automata-network/on-chain-pccs/helpers/FmspcTcbHelper.sol"; +import {BELE} from "../../utils/BELE.sol"; import "./TCBInfoV2Base.sol"; abstract contract TCBInfoV3Base is TCBInfoV2Base { @@ -60,12 +61,12 @@ abstract contract TCBInfoV3Base is TCBInfoV2Base { function checkTdxModuleTcbStatus(bytes16 teeTcbSvn, TDXModuleIdentity[] memory tdxModuleIdentities) internal pure - returns (bool, TCBStatus, uint8, bytes memory, bytes8) + returns (bool, TCBStatus, uint8, bytes memory, uint64) { uint8 tdxModuleIsvSvn = uint8(teeTcbSvn[0]); uint8 tdxModuleVersion = uint8(teeTcbSvn[1]); bytes memory expectedMrSignerSeam; - bytes8 expectedSeamAttributes; + uint64 expectedSeamAttributes; if (tdxModuleVersion == 0) { return (true, TCBStatus.OK, tdxModuleVersion, expectedMrSignerSeam, expectedSeamAttributes); @@ -87,7 +88,7 @@ abstract contract TCBInfoV3Base is TCBInfoV2Base { tdxModuleIdentityFound = true; moduleStatus = tdxModuleTcbLevels[j].status; expectedMrSignerSeam = currId.mrsigner; - expectedSeamAttributes = currId.attributes; + expectedSeamAttributes = uint64(BELE.leBytesToBeUint(abi.encodePacked(currId.attributes))); break; } } diff --git a/contracts/types/CommonStruct.sol b/contracts/types/CommonStruct.sol index f3c7894..df6ac4d 100644 --- a/contracts/types/CommonStruct.sol +++ b/contracts/types/CommonStruct.sol @@ -59,8 +59,8 @@ struct PCKCertTCB { } struct Output { - uint16 quoteVersion; // BE - bytes4 tee; // BE + uint16 quoteVersion; // BE (we should change this) + bytes4 tee; // BE (we should change this) TCBStatus tcbStatus; bytes6 fmspcBytes; bytes quoteBody; diff --git a/contracts/types/V4Structs.sol b/contracts/types/V4Structs.sol index 1fcf6fa..ef74d23 100644 --- a/contracts/types/V4Structs.sol +++ b/contracts/types/V4Structs.sol @@ -8,9 +8,9 @@ struct TD10ReportBody { bytes16 teeTcbSvn; bytes mrSeam; // 48 bytes bytes mrsignerSeam; // 48 bytes - bytes8 seamAttributes; - bytes8 tdAttributes; - bytes8 xFAM; + uint64 seamAttributes; + uint64 tdAttributes; + uint64 xFAM; bytes mrTd; // 48 bytes bytes mrConfigId; // 48 bytes bytes mrOwner; // 48 bytes diff --git a/contracts/verifiers/V4QuoteVerifier.sol b/contracts/verifiers/V4QuoteVerifier.sol index c3b77df..db5f3e6 100644 --- a/contracts/verifiers/V4QuoteVerifier.sol +++ b/contracts/verifiers/V4QuoteVerifier.sol @@ -269,7 +269,7 @@ contract V4QuoteVerifier is QuoteVerifierBase, TCBInfoV3Base, TDXModuleBase { TCBStatus tdxModuleStatus; uint8 tdxModuleVersion; bytes memory expectedMrSignerSeam; - bytes8 expectedSeamAttributes; + uint64 expectedSeamAttributes; (success, tdxModuleStatus, tdxModuleVersion, expectedMrSignerSeam, expectedSeamAttributes) = checkTdxModuleTcbStatus(quote.reportBody.teeTcbSvn, ret.tdxModuleIdentities); if (!success || tdxModuleStatus == TCBStatus.TCB_REVOKED) { @@ -308,9 +308,9 @@ contract V4QuoteVerifier is QuoteVerifierBase, TCBInfoV3Base, TDXModuleBase { report.teeTcbSvn = bytes16(reportBytes.substring(0, 16)); report.mrSeam = reportBytes.substring(16, 48); report.mrsignerSeam = reportBytes.substring(64, 48); - report.seamAttributes = bytes8(uint64(BELE.leBytesToBeUint(reportBytes.substring(112, 8)))); - report.tdAttributes = bytes8(uint64(BELE.leBytesToBeUint(reportBytes.substring(120, 8)))); - report.xFAM = bytes8(uint64(BELE.leBytesToBeUint(reportBytes.substring(128, 8)))); + report.seamAttributes = uint64(BELE.leBytesToBeUint(reportBytes.substring(112, 8))); + report.tdAttributes = uint64(BELE.leBytesToBeUint(reportBytes.substring(120, 8))); + report.xFAM = uint64(BELE.leBytesToBeUint(reportBytes.substring(128, 8))); report.mrTd = reportBytes.substring(136, 48); report.mrConfigId = reportBytes.substring(184, 48); report.mrOwner = reportBytes.substring(232, 48);