@@ -6,12 +6,34 @@ use ethers::{
66 providers:: { Http , Middleware , Provider } ,
77 types:: Filter ,
88} ;
9+ use log:: warn;
910use sha3:: { Digest , Keccak256 } ;
1011
1112/// How much to go back from current block if from_block is not provided
1213/// 7500 blocks = 25hr
1314const FROM_BLOCKS_AGO_DEFAULT : u64 = 7500 ;
1415
16+ #[ derive( Debug ) ]
17+ pub enum ProofData {
18+ SP1 {
19+ vk : [ u8 ; 32 ] ,
20+ public_inputs : Vec < u8 > ,
21+ } ,
22+ }
23+
24+ impl ProofData {
25+ fn commitment ( & self ) -> [ u8 ; 32 ] {
26+ match self {
27+ ProofData :: SP1 { vk, public_inputs } => {
28+ let mut hasher = Keccak256 :: new ( ) ;
29+ hasher. update ( vk) ;
30+ hasher. update ( public_inputs) ;
31+ hasher. finalize ( ) . into ( )
32+ }
33+ }
34+ }
35+ }
36+
1537#[ derive( Debug ) ]
1638pub enum ProofVerificationAggModeError {
1739 ProvingSystemNotSupportedInAggMode ,
@@ -41,7 +63,7 @@ pub enum ProofVerificationAggModeError {
4163/// 6. Checking if the given proof hash exists within the blob’s proofs
4264/// 7. Reconstructing the Merkle root and verifying it against the commitment stored in the contract
4365pub async fn is_proof_verified_in_aggregation_mode (
44- proof_hash : [ u8 ; 32 ] ,
66+ proof_data : ProofData ,
4567 network : Network ,
4668 eth_rpc_url : String ,
4769 beacon_client_url : String ,
@@ -114,10 +136,10 @@ pub async fn is_proof_verified_in_aggregation_mode(
114136 } ;
115137
116138 let blob_data = hex:: decode ( blob. blob . replace ( "0x" , "" ) ) . expect ( "A valid hex encoded data" ) ;
117- let proof_hashes = decoded_blob ( blob_data) ;
139+ let proof_commitments = decoded_blob ( blob_data) ;
118140
119- if proof_hashes . contains ( & proof_hash ) {
120- if verify_blob_merkle_root ( proof_hashes , merkle_root) {
141+ if proof_commitments . contains ( & proof_data . commitment ( ) ) {
142+ if verify_blob_merkle_root ( proof_commitments , merkle_root) {
121143 return Ok ( merkle_root) ;
122144 } else {
123145 return Err ( ProofVerificationAggModeError :: UnmatchedBlobAndEventMerkleRoot ) ;
@@ -171,9 +193,9 @@ pub fn combine_hashes(hash_a: &[u8; 32], hash_b: &[u8; 32]) -> [u8; 32] {
171193 hasher. finalize ( ) . into ( )
172194}
173195
174- fn verify_blob_merkle_root ( mut proof_hashes : Vec < [ u8 ; 32 ] > , merkle_root : [ u8 ; 32 ] ) -> bool {
175- while proof_hashes . len ( ) > 1 {
176- proof_hashes = proof_hashes
196+ fn verify_blob_merkle_root ( mut commitments : Vec < [ u8 ; 32 ] > , merkle_root : [ u8 ; 32 ] ) -> bool {
197+ while commitments . len ( ) > 1 {
198+ commitments = commitments
177199 . chunks ( 2 )
178200 . map ( |chunk| match chunk {
179201 [ a, b] => combine_hashes ( a, b) ,
@@ -183,5 +205,5 @@ fn verify_blob_merkle_root(mut proof_hashes: Vec<[u8; 32]>, merkle_root: [u8; 32
183205 . collect ( )
184206 }
185207
186- proof_hashes [ 0 ] == merkle_root
208+ commitments [ 0 ] == merkle_root
187209}
0 commit comments