@@ -10,43 +10,34 @@ use serde_with::serde_as;
1010#[ serde_as]
1111#[ derive( Clone , Debug , PartialEq , Serialize , Deserialize ) ]
1212pub 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
2329impl 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
6455impl 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 ) ]
7574pub 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 ) ]
8695pub 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
96105impl From < ZKDCAPQuote > for RAQuote {
@@ -100,27 +109,37 @@ impl From<ZKDCAPQuote> for RAQuote {
100109}
101110
102111impl 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 ( ) )
0 commit comments