44use crate :: { args:: AttestationPolicyArgs , client:: JsonRpcClient } ;
55use anyhow:: { Context , Result } ;
66use hex:: encode;
7- use secp256k1:: { constants :: PUBLIC_KEY_SIZE , ecdsa :: Signature , Message , PublicKey } ;
7+ use secp256k1:: Message ;
88use teepot:: {
99 client:: TcbLevel ,
10+ ethereum:: recover_signer,
1011 quote:: {
1112 error:: QuoteContext , tee_qv_get_collateral, verify_quote_with_collateral,
1213 QuoteVerificationResult , Report ,
1314 } ,
1415} ;
1516use tracing:: { debug, info, warn} ;
16- use zksync_basic_types:: { L1BatchNumber , H256 } ;
17+ use zksync_basic_types:: L1BatchNumber ;
1718
1819pub async fn verify_batch_proof (
1920 quote_verification_result : & QuoteVerificationResult ,
@@ -27,22 +28,38 @@ pub async fn verify_batch_proof(
2728 }
2829
2930 let batch_no = batch_number. 0 ;
30-
31- let public_key = PublicKey :: from_slice (
32- & quote_verification_result. quote . get_report_data ( ) [ ..PUBLIC_KEY_SIZE ] ,
33- ) ?;
34- debug ! ( batch_no, "public key: {}" , public_key) ;
35-
3631 let root_hash = node_client. get_root_hash ( batch_number) . await ?;
37- debug ! ( batch_no, "root hash: {}" , root_hash) ;
32+ let ethereum_address_from_quote = & quote_verification_result. quote . get_report_data ( ) [ ..20 ] ;
33+ let signature_bytes: & [ u8 ; 65 ] = signature. try_into ( ) ?;
34+ let root_hash_bytes = root_hash. as_bytes ( ) ;
35+ let root_hash_msg = Message :: from_digest_slice ( root_hash_bytes) ?;
36+ let ethereum_address_from_signature = recover_signer ( signature_bytes, & root_hash_msg) ?;
37+ let verification_successful = ethereum_address_from_signature == ethereum_address_from_quote;
38+ debug ! (
39+ batch_no,
40+ "Root hash: {}. Ethereum address from the attestation quote: {}. Ethereum address from the signature: {}." ,
41+ root_hash,
42+ encode( ethereum_address_from_quote) ,
43+ encode( ethereum_address_from_signature) ,
44+ ) ;
3845
39- let is_verified = verify_signature ( signature, public_key, root_hash) ?;
40- if is_verified {
41- info ! ( batch_no, signature = %encode( signature) , "Signature verified successfully." ) ;
46+ if verification_successful {
47+ info ! (
48+ batch_no,
49+ signature = encode( signature) ,
50+ ethereum_address = encode( ethereum_address_from_quote) ,
51+ "Signature verified successfully."
52+ ) ;
4253 } else {
43- warn ! ( batch_no, signature = %encode( signature) , "Failed to verify signature!" ) ;
54+ warn ! (
55+ batch_no,
56+ signature = encode( signature) ,
57+ ethereum_address_from_signature = encode( ethereum_address_from_signature) ,
58+ ethereum_address_from_quote = encode( ethereum_address_from_quote) ,
59+ "Failed to verify signature!"
60+ ) ;
4461 }
45- Ok ( is_verified )
62+ Ok ( verification_successful )
4663}
4764
4865pub fn verify_attestation_quote ( attestation_quote_bytes : & [ u8 ] ) -> Result < QuoteVerificationResult > {
@@ -85,12 +102,6 @@ pub fn log_quote_verification_summary(quote_verification_result: &QuoteVerificat
85102 ) ;
86103}
87104
88- fn verify_signature ( signature : & [ u8 ] , public_key : PublicKey , root_hash : H256 ) -> Result < bool > {
89- let signature = Signature :: from_compact ( signature) ?;
90- let root_hash_msg = Message :: from_digest_slice ( & root_hash. 0 ) ?;
91- Ok ( signature. verify ( & root_hash_msg, & public_key) . is_ok ( ) )
92- }
93-
94105fn is_quote_matching_policy (
95106 attestation_policy : & AttestationPolicyArgs ,
96107 quote_verification_result : & QuoteVerificationResult ,
0 commit comments