@@ -10,6 +10,7 @@ use attestation_report::{IASSignedReport, ReportData};
1010use crypto:: { verify_signature_address, Address , Keccak256 } ;
1111use dcap_quote_verifier:: types:: quotes:: body:: QuoteBody ;
1212use dcap_quote_verifier:: types:: SGX_TEE_TYPE ;
13+ use dcap_quote_verifier:: verifier:: Status ;
1314use hex_literal:: hex;
1415use light_client:: commitments:: {
1516 CommitmentPrefix , EthABIEncoder , MisbehaviourProxyMessage , ProxyMessage ,
@@ -246,52 +247,72 @@ impl LCPClient {
246247 let zkdcap_verifier_info = & client_state. zkdcap_verifier_infos [ 0 ] ;
247248 assert ! ( message. zkvm_type == ZKVMType :: Risc0 ) ;
248249 let ( selector, seal) = message. risc0_seal_selector ( ) ?;
250+ let output = message. quote_verification_output ;
249251
250252 zkvm:: verifier:: verify_groth16_proof (
251253 selector,
252254 seal,
253255 zkdcap_verifier_info. program_id ,
254- message . quote_verification_output . to_bytes ( ) ,
256+ output . to_bytes ( ) ,
255257 ) ?;
256258
257- let report =
258- if let QuoteBody :: SGXQuoteBody ( report) = message. quote_verification_output . quote_body {
259- report
260- } else {
261- return Err ( Error :: unexpected_quote_body ( ) ) ;
262- } ;
259+ let report = if let QuoteBody :: SGXQuoteBody ( report) = output. quote_body {
260+ report
261+ } else {
262+ return Err ( Error :: unexpected_quote_body ( ) ) ;
263+ } ;
263264 let report_data = ReportData ( report. report_data ) ;
264265
265266 assert_eq ! (
266267 report. mrenclave. as_slice( ) ,
267268 client_state. mr_enclave. as_slice( ) ,
268269 "mrenclave mismatch"
269270 ) ;
271+ assert_eq ! ( output. quote_version, 3 , "unexpected quote version" ) ;
272+ assert_eq ! ( output. tee_type, SGX_TEE_TYPE , "unexpected tee type" ) ;
270273 assert_eq ! (
271- message. quote_verification_output. quote_version, 3 ,
272- "unexpected quote version"
273- ) ;
274- assert_eq ! (
275- message. quote_verification_output. tee_type, SGX_TEE_TYPE ,
276- "unexpected tee type"
277- ) ;
278- assert_eq ! (
279- message. quote_verification_output. sgx_intel_root_ca_hash,
274+ output. sgx_intel_root_ca_hash,
280275 remote_attestation:: dcap:: INTEL_ROOT_CA_HASH ,
281276 ) ;
277+
278+ #[ allow( clippy:: comparison_chain) ]
279+ #[ allow( clippy:: assertions_on_constants) ]
280+ let new_client_state = if client_state. latest_tcb_evaluation_data_number
281+ < output. min_tcb_evaluation_data_number
282+ {
283+ Some ( ClientState {
284+ latest_tcb_evaluation_data_number : output. min_tcb_evaluation_data_number ,
285+ ..client_state. clone ( )
286+ } )
287+ } else if client_state. latest_tcb_evaluation_data_number
288+ > output. min_tcb_evaluation_data_number
289+ {
290+ if !client_state. allow_previous_tcb_evaluation_data_number
291+ || client_state. latest_tcb_evaluation_data_number
292+ != output. min_tcb_evaluation_data_number + 1
293+ {
294+ assert ! ( false , "unexpected tcb evaluation data number" ) ;
295+ }
296+ None
297+ } else {
298+ None
299+ } ;
300+
282301 assert ! (
283- message
284- . quote_verification_output
302+ output
285303 . validity
286304 . validate_time( ctx. host_timestamp( ) . as_unix_timestamp_secs( ) ) ,
287305 "invalid validity intersection"
288306 ) ;
289- let tcb_status = message . quote_verification_output . status . to_string ( ) ;
307+
290308 assert ! (
291- tcb_status == "UpToDate" || client_state. allowed_quote_statuses. contains( & tcb_status) ,
309+ output. status == Status :: Ok
310+ || client_state
311+ . allowed_quote_statuses
312+ . contains( & output. status. to_string( ) ) ,
292313 "unexpected tcb status"
293314 ) ;
294- for advisory_id in message . quote_verification_output . advisory_ids . iter ( ) {
315+ for advisory_id in output . advisory_ids . iter ( ) {
295316 assert ! (
296317 client_state. allowed_advisory_ids. contains( advisory_id) ,
297318 "unexpected advisory id"
@@ -302,7 +323,7 @@ impl LCPClient {
302323 verify_signature_address (
303324 compute_eip712_zkdcap_register_enclave_key (
304325 zkdcap_verifier_info,
305- keccak256 ( & message . quote_verification_output . to_bytes ( ) ) ,
326+ keccak256 ( & output . to_bytes ( ) ) ,
306327 )
307328 . as_ref ( ) ,
308329 operator_signature. as_ref ( ) ,
@@ -317,11 +338,11 @@ impl LCPClient {
317338 ctx,
318339 & client_id,
319340 report_data. enclave_key ( ) ,
320- EKOperatorInfo :: new (
321- message. quote_verification_output . validity . not_after_min ,
322- operator,
323- ) ,
341+ EKOperatorInfo :: new ( output. validity . not_after_min , operator) ,
324342 ) ;
343+ if let Some ( new_client_state) = new_client_state {
344+ ctx. store_any_client_state ( client_id, new_client_state. into ( ) ) ?;
345+ }
325346 Ok ( ( ) )
326347 }
327348
@@ -566,16 +587,16 @@ pub fn compute_eip712_register_enclave_key_hash(avr: &str) -> [u8; 32] {
566587
567588pub fn compute_eip712_zkdcap_register_enclave_key (
568589 zkdcap_verifier_info : & ZKDCAPVerifierInfo ,
569- commit_hash : [ u8 ; 32 ] ,
590+ output_hash : [ u8 ; 32 ] ,
570591) -> Vec < u8 > {
571- // 0x1901 | DOMAIN_SEPARATOR_ZKDCAP_REGISTER_ENCLAVE_KEY | keccak256(keccak256("ZKDCAPRegisterEnclaveKey(bytes zkDCAPVerifierInfo,bytes32 commitHash )") | keccak256(zkdcap_verifier_info) | commit_hash )
592+ // 0x1901 | DOMAIN_SEPARATOR_ZKDCAP_REGISTER_ENCLAVE_KEY | keccak256(keccak256("ZKDCAPRegisterEnclaveKey(bytes zkDCAPVerifierInfo,bytes32 outputHash )") | keccak256(zkdcap_verifier_info) | output_hash )
572593 let type_hash = {
573594 let mut h = Keccak :: v256 ( ) ;
574595 h. update ( & keccak256 (
575- b"ZKDCAPRegisterEnclaveKey(bytes zkDCAPVerifierInfo,bytes32 commitHash )" ,
596+ b"ZKDCAPRegisterEnclaveKey(bytes zkDCAPVerifierInfo,bytes32 outputHash )" ,
576597 ) ) ;
577598 h. update ( & keccak256 ( zkdcap_verifier_info. to_bytes ( ) . as_ref ( ) ) ) ;
578- h. update ( & commit_hash ) ;
599+ h. update ( & output_hash ) ;
579600 let mut result = [ 0u8 ; 32 ] ;
580601 h. finalize ( result. as_mut ( ) ) ;
581602 result
0 commit comments