@@ -3,10 +3,12 @@ use crate::consensus_state::ConsensusState;
3
3
use crate :: errors:: Error ;
4
4
use crate :: message:: {
5
5
ClientMessage , CommitmentProofs , RegisterEnclaveKeyMessage , UpdateOperatorsMessage ,
6
+ ZKDCAPRegisterEnclaveKeyMessage ,
6
7
} ;
7
8
use alloy_sol_types:: { sol, SolValue } ;
8
9
use attestation_report:: { IASSignedReport , ReportData } ;
9
10
use crypto:: { verify_signature_address, Address , Keccak256 } ;
11
+ use dcap_rs:: types:: quotes:: body:: QuoteBody ;
10
12
use hex_literal:: hex;
11
13
use light_client:: commitments:: {
12
14
CommitmentPrefix , EthABIEncoder , MisbehaviourProxyMessage , ProxyMessage ,
@@ -125,6 +127,9 @@ impl LCPClient {
125
127
ClientMessage :: RegisterEnclaveKey ( msg) => {
126
128
self . register_enclave_key ( ctx, client_id, client_state, msg)
127
129
}
130
+ ClientMessage :: ZKDCAPRegisterEnclaveKey ( msg) => {
131
+ self . zkdcap_register_enclave_key ( ctx, client_id, client_state, msg)
132
+ }
128
133
ClientMessage :: UpdateOperators ( msg) => {
129
134
self . update_operators ( ctx, client_id, client_state, msg)
130
135
}
@@ -192,7 +197,7 @@ impl LCPClient {
192
197
assert ! ( !client_state. frozen) ;
193
198
194
199
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 ) ?;
196
201
197
202
let operator = if let Some ( operator_signature) = message. operator_signature {
198
203
verify_signature_address (
@@ -217,6 +222,50 @@ impl LCPClient {
217
222
Ok ( ( ) )
218
223
}
219
224
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
+
220
269
fn update_operators (
221
270
& self ,
222
271
ctx : & mut dyn HostClientKeeper ,
@@ -456,6 +505,23 @@ pub fn compute_eip712_register_enclave_key_hash(avr: &str) -> [u8; 32] {
456
505
keccak256 ( & compute_eip712_register_enclave_key ( avr) )
457
506
}
458
507
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
+
459
525
pub fn compute_eip712_update_operators (
460
526
client_id : ClientId ,
461
527
nonce : u64 ,
@@ -521,10 +587,10 @@ pub fn compute_eip712_update_operators_hash(
521
587
) )
522
588
}
523
589
524
- // verify_report
590
+ // verify_ias_report
525
591
// - verifies the Attestation Verification Report
526
592
// - calculate a key expiration with client_state and report's timestamp
527
- fn verify_report (
593
+ fn verify_ias_report (
528
594
current_timestamp : Time ,
529
595
client_state : & ClientState ,
530
596
signed_avr : & IASSignedReport ,
0 commit comments