@@ -84,10 +84,17 @@ pub async fn is_proof_verified_in_aggregation_mode(
8484 . map_err ( ProofVerificationAggModeError :: BeaconClient ) ?
8585 . unwrap ( ) ;
8686
87- let proof_hashes = decoded_blob ( blob. blob . into ( ) ) ;
87+ let blob_data = hex:: decode ( blob. blob . replace ( "0x" , "" ) ) . expect ( "A valid hex encoded data" ) ;
88+
89+ let proof_hashes = decoded_blob ( blob_data) ;
8890
8991 // decoded blob and get all leaves and see if it the has is inside
90- if proof_hashes. contains ( & [ 0u8 ; 32 ] ) {
92+ let proof_hash_bytes: [ u8 ; 32 ] = hex:: decode ( proof_hash. replace ( "0x" , "" ) )
93+ . unwrap ( )
94+ . try_into ( )
95+ . unwrap ( ) ;
96+
97+ if proof_hashes. contains ( & proof_hash_bytes) {
9198 return Ok ( verify_merkle_root ( proof_hashes, merkle_root) ) ;
9299 } else {
93100 continue ;
@@ -98,7 +105,40 @@ pub async fn is_proof_verified_in_aggregation_mode(
98105}
99106
100107fn decoded_blob ( blob_data : Vec < u8 > ) -> Vec < [ u8 ; 32 ] > {
101- let proof_hashes = vec ! [ ] ;
108+ let mut proof_hashes = vec ! [ ] ;
109+
110+ let mut current_hash = [ 0u8 ; 32 ] ;
111+ let mut current_hash_count = 0 ;
112+ let mut total_bytes_count = 0 ;
113+
114+ let mut i = 0 ;
115+
116+ while i < blob_data. len ( ) {
117+ // Every 32 bytes (or 64 characters) there is a 0x00 acting as padding, so we need to skip the byte (two iterations)
118+ let is_pad = total_bytes_count % 32 == 0 ;
119+ if is_pad {
120+ i += 1 ;
121+ total_bytes_count += 1 ;
122+ continue ;
123+ }
124+
125+ current_hash[ current_hash_count] = blob_data[ i] ;
126+
127+ if current_hash_count + 1 == 32 {
128+ if current_hash == [ 0u8 ; 32 ] {
129+ break ;
130+ }
131+ proof_hashes. push ( current_hash) ;
132+ current_hash = [ 0u8 ; 32 ] ;
133+ current_hash_count = 0 ;
134+ continue ;
135+ } else {
136+ current_hash_count += 1 ;
137+ }
138+
139+ i += 1 ;
140+ total_bytes_count += 1 ;
141+ }
102142
103143 proof_hashes
104144}
0 commit comments