@@ -3,10 +3,12 @@ use crate::consensus_state::ConsensusState;
33use crate :: errors:: Error ;
44use crate :: message:: {
55 ClientMessage , CommitmentProofs , RegisterEnclaveKeyMessage , UpdateOperatorsMessage ,
6+ ZKDCAPRegisterEnclaveKeyMessage ,
67} ;
78use alloy_sol_types:: { sol, SolValue } ;
89use attestation_report:: { IASSignedReport , ReportData } ;
910use crypto:: { verify_signature_address, Address , Keccak256 } ;
11+ use dcap_rs:: types:: quotes:: body:: QuoteBody ;
1012use hex_literal:: hex;
1113use light_client:: commitments:: {
1214 CommitmentPrefix , EthABIEncoder , MisbehaviourProxyMessage , ProxyMessage ,
@@ -125,6 +127,9 @@ impl LCPClient {
125127 ClientMessage :: RegisterEnclaveKey ( msg) => {
126128 self . register_enclave_key ( ctx, client_id, client_state, msg)
127129 }
130+ ClientMessage :: ZKDCAPRegisterEnclaveKey ( msg) => {
131+ self . zkdcap_register_enclave_key ( ctx, client_id, client_state, msg)
132+ }
128133 ClientMessage :: UpdateOperators ( msg) => {
129134 self . update_operators ( ctx, client_id, client_state, msg)
130135 }
@@ -192,7 +197,7 @@ impl LCPClient {
192197 assert ! ( !client_state. frozen) ;
193198
194199 let ( report_data, attestation_time) =
195- verify_report ( ctx. host_timestamp ( ) , & client_state, & message. report ) ?;
200+ verify_ias_report ( ctx. host_timestamp ( ) , & client_state, & message. report ) ?;
196201
197202 let operator = if let Some ( operator_signature) = message. operator_signature {
198203 verify_signature_address (
@@ -217,6 +222,50 @@ impl LCPClient {
217222 Ok ( ( ) )
218223 }
219224
225+ fn zkdcap_register_enclave_key (
226+ & self ,
227+ ctx : & mut dyn HostClientKeeper ,
228+ client_id : ClientId ,
229+ client_state : ClientState ,
230+ message : ZKDCAPRegisterEnclaveKeyMessage ,
231+ ) -> Result < ( ) , Error > {
232+ assert ! ( !client_state. frozen) ;
233+
234+ // TODO
235+ // verify_zkdcap_report(ctx.host_timestamp(), &client_state, &message.commit, &message.proof)?;
236+
237+ let attestation_time =
238+ Time :: from_unix_timestamp ( message. commit . attestation_time as i64 , 0 ) ?;
239+ let report = if let QuoteBody :: SGXQuoteBody ( report) = message. commit . output . quote_body {
240+ report
241+ } else {
242+ return Err ( Error :: unexpected_quote_body ( ) ) ;
243+ } ;
244+ let report_data = ReportData ( report. report_data ) ;
245+
246+ let operator = if let Some ( operator_signature) = message. operator_signature {
247+ verify_signature_address (
248+ compute_eip712_zkdcap_register_enclave_key ( message. commit . hash ( ) ) . as_ref ( ) ,
249+ operator_signature. as_ref ( ) ,
250+ ) ?
251+ } else {
252+ Default :: default ( )
253+ } ;
254+ let expected_operator = report_data. operator ( ) ;
255+ // check if the operator matches the expected operator in the report data
256+ assert ! ( expected_operator. is_zero( ) || operator == expected_operator) ;
257+ self . set_enclave_operator_info (
258+ ctx,
259+ & client_id,
260+ report_data. enclave_key ( ) ,
261+ EKOperatorInfo :: new (
262+ ( attestation_time + client_state. key_expiration ) ?. as_unix_timestamp_secs ( ) ,
263+ operator,
264+ ) ,
265+ ) ;
266+ Ok ( ( ) )
267+ }
268+
220269 fn update_operators (
221270 & self ,
222271 ctx : & mut dyn HostClientKeeper ,
@@ -456,6 +505,23 @@ pub fn compute_eip712_register_enclave_key_hash(avr: &str) -> [u8; 32] {
456505 keccak256 ( & compute_eip712_register_enclave_key ( avr) )
457506}
458507
508+ pub fn compute_eip712_zkdcap_register_enclave_key ( commit_hash : [ u8 ; 32 ] ) -> Vec < u8 > {
509+ // 0x1901 | DOMAIN_SEPARATOR_ZKDCAP_REGISTER_ENCLAVE_KEY | keccak256(keccak256("ZKDCAPRegisterEnclaveKey(bytes32 commit_hash)") | commit_hash)
510+ let type_hash = {
511+ let mut h = Keccak :: v256 ( ) ;
512+ h. update ( & keccak256 ( b"ZKDCAPRegisterEnclaveKey(bytes32 commit_hash)" ) ) ;
513+ h. update ( & commit_hash) ;
514+ let mut result = [ 0u8 ; 32 ] ;
515+ h. finalize ( result. as_mut ( ) ) ;
516+ result
517+ } ;
518+ [ 0x19 , 0x01 ]
519+ . into_iter ( )
520+ . chain ( LCP_CLIENT_DOMAIN_SEPARATOR )
521+ . chain ( type_hash)
522+ . collect ( )
523+ }
524+
459525pub fn compute_eip712_update_operators (
460526 client_id : ClientId ,
461527 nonce : u64 ,
@@ -521,10 +587,10 @@ pub fn compute_eip712_update_operators_hash(
521587 ) )
522588}
523589
524- // verify_report
590+ // verify_ias_report
525591// - verifies the Attestation Verification Report
526592// - calculate a key expiration with client_state and report's timestamp
527- fn verify_report (
593+ fn verify_ias_report (
528594 current_timestamp : Time ,
529595 client_state : & ClientState ,
530596 signed_avr : & IASSignedReport ,
0 commit comments