-
Notifications
You must be signed in to change notification settings - Fork 8
[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
Conversation
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
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
src/helpers/FmspcTcbHelper.sol
Outdated
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
src/helpers/FmspcTcbHelper.sol
Outdated
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
33baea4
to
838a536
Compare
Not within the scope of FR, but TOB has given us the green light for this changes. cc @Liao1 |
Merged to |
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
andnextUpdate
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.