Skip to content

Commit eacafd3

Browse files
committed
improve docs
Signed-off-by: Jun Kimura <[email protected]>
1 parent b7e5e63 commit eacafd3

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

modules/attestation-report/src/dcap.rs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,34 @@ use serde_with::serde_as;
1010
#[serde_as]
1111
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1212
pub struct DCAPQuote {
13+
/// Raw quote from the DCAP library
1314
#[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Lowercase>")]
1415
pub raw: Vec<u8>,
16+
/// Family Model Specific Platform Configuration (FMSPC) of the processor/platform
1517
#[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Lowercase>")]
1618
pub fmspc: [u8; 6],
19+
/// TCB status of the processor/platform
1720
pub tcb_status: String,
21+
/// Advisory IDs of the processor/platform
1822
pub advisory_ids: Vec<String>,
23+
/// Time when the quote was attested
1924
pub attested_at: Time,
25+
/// Collateral data used to verify the quote
2026
pub collateral: DcapCollateral,
2127
}
2228

2329
impl DCAPQuote {
24-
pub fn new(
25-
raw_quote: Vec<u8>,
26-
fmspc: [u8; 6],
27-
tcb_status: String,
28-
advisory_ids: Vec<String>,
29-
attested_at: Time,
30-
collateral: DcapCollateral,
31-
) -> Self {
32-
DCAPQuote {
33-
raw: raw_quote,
34-
fmspc,
35-
tcb_status,
36-
advisory_ids,
37-
attested_at,
38-
collateral,
39-
}
40-
}
41-
30+
/// Converts the quote to a RAQuote
4231
pub fn to_json(&self) -> Result<String, Error> {
4332
serde_json::to_string(self).map_err(Error::serde_json)
4433
}
4534

35+
/// Parses the quote from a JSON string
4636
pub fn from_json(json: &str) -> Result<Self, Error> {
4737
serde_json::from_str(json).map_err(Error::serde_json)
4838
}
4939

40+
/// Returns the report data from the quote
5041
#[cfg(feature = "std")]
5142
pub fn report_data(&self) -> Result<crate::ReportData, Error> {
5243
use dcap_quote_verifier::types::quotes::version_3::QuoteV3;
@@ -62,25 +53,43 @@ pub enum ZKVMProof {
6253
}
6354

6455
impl ZKVMProof {
56+
/// Returns the commit corresponding to the proof
6557
pub fn commit(&self) -> &[u8] {
6658
match self {
6759
ZKVMProof::Risc0(ref proof) => &proof.commit,
6860
}
6961
}
62+
63+
/// Returns true if the proof is a mock proof
64+
pub fn is_mock(&self) -> bool {
65+
match self {
66+
ZKVMProof::Risc0(ref proof) => proof.is_mock(),
67+
}
68+
}
7069
}
7170

7271
/// Risc0ZKVMProof represents a zkVM proof for RISC Zero
7372
#[serde_as]
7473
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
7574
pub struct Risc0ZKVMProof {
75+
/// A small cryptographic identifier that indicates the method or boot image for zkVM execution
7676
#[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Lowercase>")]
7777
pub image_id: [u8; 32],
7878
#[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Lowercase>")]
79+
/// A Groth16 proof for the correct execution of the guest program.
7980
pub seal: Vec<u8>,
81+
/// The public outputs of dcap-quote-verifier program executed inside the zkVM
8082
#[serde_as(as = "serde_with::hex::Hex<serde_with::formats::Lowercase>")]
8183
pub commit: Vec<u8>,
8284
}
8385

86+
impl Risc0ZKVMProof {
87+
/// Returns true if the proof is a mock proof
88+
pub fn is_mock(&self) -> bool {
89+
self.seal.len() >= 4 && self.seal[0..4] == [0, 0, 0, 0]
90+
}
91+
}
92+
8493
/// ZKDCAPQuote represents a DCAP quote with a zkVM proof
8594
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
8695
pub struct ZKDCAPQuote {
@@ -90,7 +99,7 @@ pub struct ZKDCAPQuote {
9099
pub zkp: ZKVMProof,
91100
/// if true, `zkp` is a mock proof
92101
/// otherwise, `zkp` is a zkVM proof
93-
pub mock: bool,
102+
mock: bool,
94103
}
95104

96105
impl From<ZKDCAPQuote> for RAQuote {
@@ -100,27 +109,37 @@ impl From<ZKDCAPQuote> for RAQuote {
100109
}
101110

102111
impl ZKDCAPQuote {
103-
pub fn new(dcap_quote: DCAPQuote, zkp: ZKVMProof, mock: bool) -> Self {
112+
/// Creates a new ZKDCAPQuote
113+
pub fn new(dcap_quote: DCAPQuote, zkp: ZKVMProof) -> Self {
104114
ZKDCAPQuote {
105115
dcap_quote,
116+
mock: zkp.is_mock(),
106117
zkp,
107-
mock,
108118
}
109119
}
110120

121+
/// Returns true if the proof is a mock proof
122+
pub fn is_mock_zkp(&self) -> bool {
123+
self.mock
124+
}
125+
126+
/// Converts the quote to a JSON string
111127
pub fn to_json(&self) -> Result<String, Error> {
112128
serde_json::to_string(self).map_err(Error::serde_json)
113129
}
114130

131+
/// Parses the quote from a JSON string
115132
pub fn from_json(json: &str) -> Result<Self, Error> {
116133
serde_json::from_str(json).map_err(Error::serde_json)
117134
}
118135

136+
/// Returns the report data from the quote
119137
#[cfg(feature = "std")]
120138
pub fn report_data(&self) -> Result<crate::ReportData, Error> {
121139
self.dcap_quote.report_data()
122140
}
123141

142+
/// Returns the commit corresponding to the zkVM proof
124143
#[cfg(feature = "std")]
125144
pub fn commit(&self) -> Result<dcap_quote_verifier::verifier::VerifiedOutput, Error> {
126145
dcap_quote_verifier::verifier::VerifiedOutput::from_bytes(self.zkp.commit())

modules/attestation-report/src/report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl RAQuote {
157157
RAQuote::DCAP(_) => RAType::DCAP,
158158
RAQuote::ZKDCAP(quote) => {
159159
// currently only support Risc0
160-
if quote.mock {
160+
if quote.is_mock_zkp() {
161161
RAType::MockZKDCAPRisc0
162162
} else {
163163
RAType::ZKDCAPRisc0

modules/remote-attestation/src/dcap_utils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ pub struct DCAPRemoteAttestationResult {
1313

1414
impl DCAPRemoteAttestationResult {
1515
pub fn get_ra_quote(&self, attested_at: Time) -> DCAPQuote {
16-
DCAPQuote::new(
17-
self.raw_quote.clone(),
18-
self.output.fmspc,
19-
self.output.tcb_status.to_string(),
20-
self.output.advisory_ids.clone(),
16+
DCAPQuote {
17+
raw: self.raw_quote.clone(),
18+
fmspc: self.output.fmspc,
19+
tcb_status: self.output.tcb_status.to_string(),
20+
advisory_ids: self.output.advisory_ids.clone(),
2121
attested_at,
22-
DcapCollateral {
22+
collateral: DcapCollateral {
2323
tcbinfo_bytes: self.collateral.tcbinfo_bytes.clone(),
2424
qeidentity_bytes: self.collateral.qeidentity_bytes.clone(),
2525
sgx_intel_root_ca_der: self.collateral.sgx_intel_root_ca_der.clone(),
2626
sgx_tcb_signing_der: self.collateral.sgx_tcb_signing_der.clone(),
2727
sgx_intel_root_ca_crl_der: self.collateral.sgx_intel_root_ca_crl_der.clone(),
2828
sgx_pck_crl_der: self.collateral.sgx_pck_crl_der.clone(),
2929
},
30-
)
30+
}
3131
}
3232
}

modules/remote-attestation/src/zkdcap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ fn zkdcap_ra(
184184
seal,
185185
commit: prover_info.receipt.journal.bytes,
186186
}),
187-
prover_mode.is_dev_mode(),
188187
)
189188
.into(),
190189
)

0 commit comments

Comments
 (0)