Skip to content

Commit 86665e9

Browse files
committed
fix output format
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent e6add9c commit 86665e9

File tree

5 files changed

+59
-42
lines changed

5 files changed

+59
-42
lines changed

contracts/DCAPValidator.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.12;
33

44
library DCAPValidator {
5-
uint256 internal constant SGX_QUOTE_BODY_OFFSET = 63;
5+
uint256 internal constant SGX_QUOTE_BODY_OFFSET = 67;
66
uint256 internal constant ATTRIBUTES_OFFSET = SGX_QUOTE_BODY_OFFSET + 16 + 4 + 28;
77
uint256 internal constant MRENCLAVE_OFFSET = ATTRIBUTES_OFFSET + 16;
88
uint256 internal constant MRENCLAVE_END_OFFSET = MRENCLAVE_OFFSET + 32;
@@ -32,23 +32,23 @@ library DCAPValidator {
3232
string[] advisoryIDs;
3333
}
3434

35-
function parseCommit(bytes calldata commit) public pure returns (Output memory) {
36-
require(bytes2(commit[0:2]) == hex"0000", "unexpected version");
37-
require(uint16(bytes2(commit[2:4])) == 3, "unexpected quote version");
38-
require(uint32(bytes4(commit[4:8])) == 0, "unexpected tee type");
35+
function parseOutput(bytes calldata outputBytes) public pure returns (Output memory) {
36+
require(bytes2(outputBytes[0:2]) == hex"0000", "unexpected version");
37+
require(uint16(bytes2(outputBytes[2:4])) == 3, "unexpected quote version");
38+
require(uint32(bytes4(outputBytes[4:8])) == 0, "unexpected tee type");
3939

4040
Output memory output;
41-
output.tcbStatus = uint8(commit[8]);
42-
output.sgxIntelRootCAHash = bytes32(commit[15:47]);
43-
output.validityNotBeforeMax = uint64(bytes8(commit[47:55]));
44-
output.validityNotAfterMin = uint64(bytes8(commit[55:63]));
45-
output.enclaveDebugEnabled = uint8(commit[ATTRIBUTES_OFFSET]) & uint8(2) != 0;
46-
output.mrenclave = bytes32(commit[MRENCLAVE_OFFSET:MRENCLAVE_END_OFFSET]);
41+
output.tcbStatus = uint8(outputBytes[8]);
42+
output.sgxIntelRootCAHash = bytes32(outputBytes[19:51]);
43+
output.validityNotBeforeMax = uint64(bytes8(outputBytes[51:59]));
44+
output.validityNotAfterMin = uint64(bytes8(outputBytes[59:67]));
45+
output.enclaveDebugEnabled = uint8(outputBytes[ATTRIBUTES_OFFSET]) & uint8(2) != 0;
46+
output.mrenclave = bytes32(outputBytes[MRENCLAVE_OFFSET:MRENCLAVE_END_OFFSET]);
4747

48-
require(commit[REPORT_DATA_OFFSET] == 0x01, "unexpected report data version");
49-
output.enclaveKey = address(bytes20(commit[REPORT_DATA_ENCLAVE_KEY_OFFSET:REPORT_DATA_OPERATOR_OFFSET]));
50-
output.operator = address(bytes20(commit[REPORT_DATA_OPERATOR_OFFSET:REPORT_DATA_OPERATOR_END_OFFSET]));
51-
output.advisoryIDs = abi.decode(commit[ADVISORY_IDS_OFFSET:commit.length], (string[]));
48+
require(outputBytes[REPORT_DATA_OFFSET] == 0x01, "unexpected report data version");
49+
output.enclaveKey = address(bytes20(outputBytes[REPORT_DATA_ENCLAVE_KEY_OFFSET:REPORT_DATA_OPERATOR_OFFSET]));
50+
output.operator = address(bytes20(outputBytes[REPORT_DATA_OPERATOR_OFFSET:REPORT_DATA_OPERATOR_END_OFFSET]));
51+
output.advisoryIDs = abi.decode(outputBytes[ADVISORY_IDS_OFFSET:outputBytes.length], (string[]));
5252
return output;
5353
}
5454

contracts/LCPClientZKDCAPBase.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ abstract contract LCPClientZKDCAPBase is LCPClientBase {
132132
revert LCPClientZKDCAPRisc0ImageIdNotSet();
133133
}
134134
// NOTE: the client must revert if the proof is invalid
135-
riscZeroVerifier.verify(message.proof, clientStorage.zkDCAPRisc0ImageId, sha256(message.commit));
136-
DCAPValidator.Output memory output = DCAPValidator.parseCommit(message.commit);
135+
riscZeroVerifier.verify(
136+
message.proof, clientStorage.zkDCAPRisc0ImageId, sha256(message.quote_verification_output)
137+
);
138+
DCAPValidator.Output memory output = DCAPValidator.parseOutput(message.quote_verification_output);
137139
if (output.sgxIntelRootCAHash != intelRootCAHash) {
138140
revert LCPClientZKDCAPUnexpectedIntelRootCAHash();
139141
}
@@ -177,7 +179,7 @@ abstract contract LCPClientZKDCAPBase is LCPClientBase {
177179
operator = verifyECDSASignature(
178180
keccak256(
179181
LCPOperator.computeEIP712ZKDCAPRegisterEnclaveKey(
180-
clientStorage.clientState.zkdcap_verifier_infos[0], keccak256(message.commit)
182+
clientStorage.clientState.zkdcap_verifier_infos[0], keccak256(message.quote_verification_output)
181183
)
182184
),
183185
message.operator_signature

contracts/proto/ibc/lightclients/lcp/v1/LCP.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
647647
//struct definition
648648
struct Data {
649649
uint32 zkvm_type;
650-
bytes commit;
650+
bytes quote_verification_output;
651651
bytes proof;
652652
bytes operator_signature;
653653
}
@@ -701,7 +701,7 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
701701
pointer += _read_zkvm_type(pointer, bs, r);
702702
} else
703703
if (fieldId == 2) {
704-
pointer += _read_commit(pointer, bs, r);
704+
pointer += _read_quote_verification_output(pointer, bs, r);
705705
} else
706706
if (fieldId == 3) {
707707
pointer += _read_proof(pointer, bs, r);
@@ -743,13 +743,13 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
743743
* @param r The in-memory struct
744744
* @return The number of bytes decoded
745745
*/
746-
function _read_commit(
746+
function _read_quote_verification_output(
747747
uint256 p,
748748
bytes memory bs,
749749
Data memory r
750750
) internal pure returns (uint) {
751751
(bytes memory x, uint256 sz) = ProtoBufRuntime._decode_bytes(p, bs);
752-
r.commit = x;
752+
r.quote_verification_output = x;
753753
return sz;
754754
}
755755

@@ -829,14 +829,14 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
829829
);
830830
pointer += ProtoBufRuntime._encode_uint32(r.zkvm_type, pointer, bs);
831831
}
832-
if (r.commit.length != 0) {
832+
if (r.quote_verification_output.length != 0) {
833833
pointer += ProtoBufRuntime._encode_key(
834834
2,
835835
ProtoBufRuntime.WireType.LengthDelim,
836836
pointer,
837837
bs
838838
);
839-
pointer += ProtoBufRuntime._encode_bytes(r.commit, pointer, bs);
839+
pointer += ProtoBufRuntime._encode_bytes(r.quote_verification_output, pointer, bs);
840840
}
841841
if (r.proof.length != 0) {
842842
pointer += ProtoBufRuntime._encode_key(
@@ -900,7 +900,7 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
900900
) internal pure returns (uint) {
901901
uint256 e;
902902
e += 1 + ProtoBufRuntime._sz_uint32(r.zkvm_type);
903-
e += 1 + ProtoBufRuntime._sz_lendelim(r.commit.length);
903+
e += 1 + ProtoBufRuntime._sz_lendelim(r.quote_verification_output.length);
904904
e += 1 + ProtoBufRuntime._sz_lendelim(r.proof.length);
905905
e += 1 + ProtoBufRuntime._sz_lendelim(r.operator_signature.length);
906906
return e;
@@ -915,7 +915,7 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
915915
return false;
916916
}
917917

918-
if (r.commit.length != 0) {
918+
if (r.quote_verification_output.length != 0) {
919919
return false;
920920
}
921921

@@ -939,7 +939,7 @@ library IbcLightclientsLcpV1ZKDCAPRegisterEnclaveKeyMessage {
939939
*/
940940
function store(Data memory input, Data storage output) internal {
941941
output.zkvm_type = input.zkvm_type;
942-
output.commit = input.commit;
942+
output.quote_verification_output = input.quote_verification_output;
943943
output.proof = input.proof;
944944
output.operator_signature = input.operator_signature;
945945

proto/ibc/lightclients/lcp/v1/LCP.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ message RegisterEnclaveKeyMessage {
1919

2020
message ZKDCAPRegisterEnclaveKeyMessage {
2121
uint32 zkvm_type = 1;
22-
bytes commit = 2;
22+
bytes quote_verification_output = 2;
2323
bytes proof = 3;
2424
bytes operator_signature = 4;
2525
}

test/ZKDCAPVerifier.t.sol

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,49 @@ contract ZKDCAPVerifierTest is BasicTest {
5959
);
6060
}
6161

62-
function testParseCommit() public view {
63-
bytes memory commit =
64-
hex"00000003000000000500906ed50000a1acc73eb45794fa1734f14d882e91925b6006f79d3bb2460df9d01b333d700900000000679885950000000067c00a9c15150b07ff800e000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000000000000700000000000000813c146e403f203f2784fa222b3edeac70727dee21c0b08f74883aa189e7b0ed000000000000000000000000000000000000000000000000000000000000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017dcf7408c72ebe9076aebbb208d2c85e62050db4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030333334000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030363135000000000000000000000000000000000000";
65-
DCAPValidator.Output memory output = DCAPValidatorTestHelper.parseCommit(commit);
62+
function testParseOutputSWHardeningNeeded() public pure {
63+
bytes memory outputBytes =
64+
hex"0000000300000000050000001200906ed50000a1acc73eb45794fa1734f14d882e91925b6006f79d3bb2460df9d01b333d70090000000067b3f1fa0000000067db736115150b07ff800e00000000000000000000000000000000000000000000000000000000000000000000000000000000000500000000000000070000000000000026ae825ffce1cf9dcdf682614f4d36704e7bca087bbb5264aca9301d7824cec8000000000000000000000000000000000000000000000000000000000000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c170f98628b3a01b15654fbfaad1aaf3419b2c3c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030333334000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030363135000000000000000000000000000000000000";
65+
DCAPValidator.Output memory output = DCAPValidatorTestHelper.parseOutput(outputBytes);
6666
assertEq(
6767
output.sgxIntelRootCAHash, bytes32(hex"a1acc73eb45794fa1734f14d882e91925b6006f79d3bb2460df9d01b333d7009")
6868
);
6969
assertTrue(output.tcbStatus == DCAPValidator.TCB_STATUS_SW_HARDENING_NEEDED);
7070
assertFalse(output.enclaveDebugEnabled);
71-
assertEq(output.mrenclave, bytes32(hex"813c146e403f203f2784fa222b3edeac70727dee21c0b08f74883aa189e7b0ed"));
72-
assertEq(output.enclaveKey, address(bytes20(hex"7dcf7408c72ebe9076aebbb208d2c85e62050db4")));
71+
assertEq(output.mrenclave, bytes32(hex"26ae825ffce1cf9dcdf682614f4d36704e7bca087bbb5264aca9301d7824cec8"));
72+
assertEq(output.enclaveKey, address(bytes20(hex"c170f98628b3a01b15654fbfaad1aaf3419b2c3c")));
7373
assertEq(output.operator, address(0));
7474
assertEq(output.advisoryIDs.length, 2);
7575
assertEq(output.advisoryIDs[0], "INTEL-SA-00334");
7676
assertEq(output.advisoryIDs[1], "INTEL-SA-00615");
7777
}
7878

79-
function testParseCommitEnclaveDebugEnabled() public view {
80-
bytes memory commit =
81-
hex"00000003000000000500906ed50000a1acc73eb45794fa1734f14d882e91925b6006f79d3bb2460df9d01b333d700900000000679afeb70000000067c2831415150b07ff800e000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000700000000000000813c146e403f203f2784fa222b3edeac70727dee21c0b08f74883aa189e7b0ed000000000000000000000000000000000000000000000000000000000000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017c10dd734cac9a4588b7886b2a4820cba182907d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030333334000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030363135000000000000000000000000000000000000";
82-
DCAPValidator.Output memory output = DCAPValidatorTestHelper.parseCommit(commit);
79+
function testParseOutputSimulationUpToDate() public pure {
80+
bytes memory outputBytes =
81+
hex"0000000300000000000000000000606a000000d61f4e3d30011899d16131d4c940ef1f75ec53d7f9a70cbb3aab1f5ab0235b2b000000000000000100000000ffffffff4820f3376ae6b2f2034d3b7a4b48a7780000000000000000000000000000000000000000000000000000000000000000070000000000000007000000000000003a354bf808b89267b19c6b390ee484d1bee8d301d0058fac511a900d5d0a6f68000000000000000000000000000000000000000000000000000000000000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019c69756b02dd84ad5d7a11758025ae4a7edf938d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000";
82+
DCAPValidator.Output memory output = DCAPValidatorTestHelper.parseOutput(outputBytes);
83+
assertEq(
84+
output.sgxIntelRootCAHash, bytes32(hex"d61f4e3d30011899d16131d4c940ef1f75ec53d7f9a70cbb3aab1f5ab0235b2b")
85+
);
86+
assertTrue(output.tcbStatus == DCAPValidator.TCB_STATUS_UP_TO_DATE);
87+
assertTrue(output.enclaveDebugEnabled);
88+
assertEq(output.mrenclave, bytes32(hex"3a354bf808b89267b19c6b390ee484d1bee8d301d0058fac511a900d5d0a6f68"));
89+
assertEq(output.enclaveKey, address(bytes20(hex"9c69756b02dd84ad5d7a11758025ae4a7edf938d")));
90+
assertEq(output.operator, address(0));
91+
assertEq(output.advisoryIDs.length, 0);
92+
}
93+
94+
function testParseCommitEnclaveDebugEnabled() public pure {
95+
bytes memory outputBytes =
96+
hex"0000000300000000050000001200906ed50000a1acc73eb45794fa1734f14d882e91925b6006f79d3bb2460df9d01b333d70090000000067b42fdd0000000067dbb9ea15150b07ff800e00000000000000000000000000000000000000000000000000000000000000000000000000000000000700000000000000070000000000000026ae825ffce1cf9dcdf682614f4d36704e7bca087bbb5264aca9301d7824cec8000000000000000000000000000000000000000000000000000000000000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001988143c0a5645a38c7900b3102859d136f3bcc2c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030333334000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e494e54454c2d53412d3030363135000000000000000000000000000000000000";
97+
DCAPValidator.Output memory output = DCAPValidatorTestHelper.parseOutput(outputBytes);
8398
assertEq(
8499
output.sgxIntelRootCAHash, bytes32(hex"a1acc73eb45794fa1734f14d882e91925b6006f79d3bb2460df9d01b333d7009")
85100
);
86101
assertTrue(output.tcbStatus == DCAPValidator.TCB_STATUS_SW_HARDENING_NEEDED);
87102
assertTrue(output.enclaveDebugEnabled);
88-
assertEq(output.mrenclave, bytes32(hex"813c146e403f203f2784fa222b3edeac70727dee21c0b08f74883aa189e7b0ed"));
89-
assertEq(output.enclaveKey, address(bytes20(hex"7c10dd734cac9a4588b7886b2a4820cba182907d")));
103+
assertEq(output.mrenclave, bytes32(hex"26ae825ffce1cf9dcdf682614f4d36704e7bca087bbb5264aca9301d7824cec8"));
104+
assertEq(output.enclaveKey, address(bytes20(hex"988143c0a5645a38c7900b3102859d136f3bcc2c")));
90105
assertEq(output.operator, address(0));
91106
assertEq(output.advisoryIDs.length, 2);
92107
assertEq(output.advisoryIDs[0], "INTEL-SA-00334");
@@ -95,7 +110,7 @@ contract ZKDCAPVerifierTest is BasicTest {
95110
}
96111

97112
library DCAPValidatorTestHelper {
98-
function parseCommit(bytes calldata commit) public pure returns (DCAPValidator.Output memory) {
99-
return DCAPValidator.parseCommit(commit);
113+
function parseOutput(bytes calldata outputBytes) public pure returns (DCAPValidator.Output memory) {
114+
return DCAPValidator.parseOutput(outputBytes);
100115
}
101116
}

0 commit comments

Comments
 (0)