Skip to content

[TOB] DEV-3793: Time-Insensitive Content Hash for EnclaveIdentity and FMSPC TCBInfo JSON Collaterals #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

preston4896
Copy link
Collaborator

The goal of this PR is to create another attestation entry for JSON collaterals, to store "time-insensitive" and content-specific hash of a JSON Collateral, which we describe it as "content hashes".

The content hash of a JSON collateral is computed by simply taking all values, omitting issueDate and nextUpdate fields, to only keep track of content-specific changes (such as the TCB Status), regardless of when the JSON collateral is being issued.

This allows us to treat both JSON collaterals (same TCBLevel, but issued at different timestamps) as identical.

@preston4896 preston4896 marked this pull request as ready for review February 13, 2025 07:48
@preston4896 preston4896 changed the title DEV-3793: Time-Insensitive Content Hash for EnclaveIdentity and FMSPC TCBInfo JSON Collaterals [TOB] DEV-3793: Time-Insensitive Content Hash for EnclaveIdentity and FMSPC TCBInfo JSON Collaterals Feb 13, 2025
Comment on lines 21 to 28
function _storeIdentityContentHash(bytes32 identityKey, bytes32 contentHash) internal override {
// write content hash to storage anyway regardless of whether it changes
// it is still cheaper to directly write the unchanged non-zero values to the same slot
// instead of, SLOAD-ing and comparing the values, then write to storage slot
// this saves gas by skipping SLOAD
bytes32 contentHashKey = _computeContentHashKey(identityKey);
resolver.attest(contentHashKey, abi.encodePacked(contentHash), bytes32(0));
}

Check warning

Code scanning / Slither

Unused return

AutomataEnclaveIdentityDao._storeIdentityContentHash(bytes32,bytes32) (src/automata_pccs/AutomataEnclaveIdentityDao.sol#21-28) ignores return value by resolver.attest(contentHashKey,abi.encodePacked(contentHash),bytes32(0)) (src/automata_pccs/AutomataEnclaveIdentityDao.sol#27)
Comment on lines 48 to 55
function _storeFmspcTcbContentHash(bytes32 tcbKey, bytes32 contentHash) internal override {
// write content hash to storage anyway regardless of whether it changes
// it is still cheaper to directly write the unchanged non-zero values to the same slot
// instead of, SLOAD-ing and comparing the values, then write to storage slot
// this saves gas by skipping SLOAD
bytes32 contentHashKey = _computeContentHashKey(tcbKey);
resolver.attest(contentHashKey, abi.encodePacked(contentHash), bytes32(0));
}

Check warning

Code scanning / Slither

Unused return

AutomataFmspcTcbDao._storeFmspcTcbContentHash(bytes32,bytes32) (src/automata_pccs/AutomataFmspcTcbDao.sol#48-55) ignores return value by resolver.attest(contentHashKey,abi.encodePacked(contentHash),bytes32(0)) (src/automata_pccs/AutomataFmspcTcbDao.sol#54)
Comment on lines 110 to 135
function generateFmspcTcbContentHash(
TcbInfoBasic memory tcbInfoContent,
string memory tcbLevelsString,
string memory tdxModuleString,
string memory tdxModuleIdentitiesString
) external pure returns (bytes32 contentHash) {
bytes memory content = abi.encodePacked(
tcbInfoContent.tcbType,
tcbInfoContent.id,
tcbInfoContent.version,
tcbInfoContent.evaluationDataNumber,
tcbInfoContent.fmspc,
tcbInfoContent.pceid,
bytes(tcbLevelsString)
);

if (bytes(tdxModuleString).length > 0) {
content = abi.encodePacked(content, bytes(tdxModuleString));
}

if (bytes(tdxModuleIdentitiesString).length > 0) {
content = abi.encodePacked(content, bytes(tdxModuleIdentitiesString));
}

contentHash = keccak256(content);
}

Check failure

Code scanning / Slither

ABI encodePacked Collision

FmspcTcbHelper.generateFmspcTcbContentHash(TcbInfoBasic,string,string,string) (src/helpers/FmspcTcbHelper.sol#110-135) calls abi.encodePacked() with multiple dynamic arguments: - content = abi.encodePacked(content,bytes(tdxModuleIdentitiesString)) (src/helpers/FmspcTcbHelper.sol#131)
Comment on lines 110 to 135
function generateFmspcTcbContentHash(
TcbInfoBasic memory tcbInfoContent,
string memory tcbLevelsString,
string memory tdxModuleString,
string memory tdxModuleIdentitiesString
) external pure returns (bytes32 contentHash) {
bytes memory content = abi.encodePacked(
tcbInfoContent.tcbType,
tcbInfoContent.id,
tcbInfoContent.version,
tcbInfoContent.evaluationDataNumber,
tcbInfoContent.fmspc,
tcbInfoContent.pceid,
bytes(tcbLevelsString)
);

if (bytes(tdxModuleString).length > 0) {
content = abi.encodePacked(content, bytes(tdxModuleString));
}

if (bytes(tdxModuleIdentitiesString).length > 0) {
content = abi.encodePacked(content, bytes(tdxModuleIdentitiesString));
}

contentHash = keccak256(content);
}

Check failure

Code scanning / Slither

ABI encodePacked Collision

FmspcTcbHelper.generateFmspcTcbContentHash(TcbInfoBasic,string,string,string) (src/helpers/FmspcTcbHelper.sol#110-135) calls abi.encodePacked() with multiple dynamic arguments: - content = abi.encodePacked(content,bytes(tdxModuleString)) (src/helpers/FmspcTcbHelper.sol#127)
@preston4896 preston4896 changed the base branch from main to development February 14, 2025 06:23
@preston4896
Copy link
Collaborator Author

Not within the scope of FR, but TOB has given us the green light for this changes. cc @Liao1

@preston4896 preston4896 requested a review from Liao1 March 3, 2025 03:21
@preston4896
Copy link
Collaborator Author

Merged to development: db69757

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants