@@ -6,6 +6,9 @@ use std::sync::Arc;
66use std:: time:: Duration ;
77
88use crate :: eth:: BatchVerifiedEventStream ;
9+ use aligned_batcher_lib:: types:: {
10+ BatchInclusionData , VerificationCommitmentBatch , VerificationData , VerificationDataCommitment ,
11+ } ;
912use aws_sdk_s3:: client:: Client as S3Client ;
1013use eth:: BatchVerifiedFilter ;
1114use ethers:: prelude:: { Middleware , Provider } ;
@@ -18,24 +21,22 @@ use tokio::net::{TcpListener, TcpStream};
1821use tokio:: sync:: { Mutex , RwLock } ;
1922use tokio:: time:: timeout;
2023use tokio_tungstenite:: tungstenite:: error:: ProtocolError ;
21- use tokio_tungstenite:: tungstenite:: protocol:: { CloseFrame , frame:: coding:: CloseCode } ;
24+ use tokio_tungstenite:: tungstenite:: protocol:: { frame:: coding:: CloseCode , CloseFrame } ;
2225use tokio_tungstenite:: tungstenite:: { Error , Message } ;
2326use tokio_tungstenite:: WebSocketStream ;
2427use types:: batch_queue:: BatchQueue ;
2528use types:: errors:: BatcherError ;
26- use aligned_batcher_lib:: types:: { BatchInclusionData , VerificationCommitmentBatch , VerificationData , VerificationDataCommitment } ;
27- use zk_utils:: verify;
2829
2930use crate :: config:: { ConfigFromYaml , ContractDeploymentOutput } ;
3031use crate :: eth:: AlignedLayerServiceManager ;
3132
3233mod config;
3334mod eth;
34- pub mod s3;
35- pub mod types;
3635pub mod gnark;
3736pub mod halo2;
37+ pub mod s3;
3838pub mod sp1;
39+ pub mod types;
3940mod zk_utils;
4041
4142const S3_BUCKET_NAME : & str = "storage.alignedlayer.com" ;
@@ -50,6 +51,7 @@ pub struct Batcher {
5051 max_proof_size : usize ,
5152 max_batch_size : usize ,
5253 last_uploaded_batch_block : Mutex < u64 > ,
54+ pre_verification_is_enabled : bool ,
5355}
5456
5557impl Batcher {
@@ -95,6 +97,7 @@ impl Batcher {
9597 max_proof_size : config. batcher . max_proof_size ,
9698 max_batch_size : config. batcher . max_batch_size ,
9799 last_uploaded_batch_block : Mutex :: new ( last_uploaded_batch_block) ,
100+ pre_verification_is_enabled : config. batcher . pre_verification_is_enabled ,
98101 }
99102 }
100103
@@ -162,12 +165,18 @@ impl Batcher {
162165 message : Message ,
163166 ws_conn_sink : Arc < RwLock < SplitSink < WebSocketStream < TcpStream > , Message > > > ,
164167 ) -> Result < ( ) , tokio_tungstenite:: tungstenite:: Error > {
165- // Deserialize task from message
168+ // Deserialize verification data from message
166169 let verification_data: VerificationData =
167170 serde_json:: from_str ( message. to_text ( ) . expect ( "Message is not text" ) )
168171 . expect ( "Failed to deserialize task" ) ;
169172
170- if verification_data. proof . len ( ) <= self . max_proof_size && verify ( & verification_data) {
173+ if verification_data. proof . len ( ) <= self . max_proof_size {
174+ // When pre-verification is enabled, batcher will verify proofs for faster feedback with clients
175+ if self . pre_verification_is_enabled && !zk_utils:: verify ( & verification_data) {
176+ return Err ( tokio_tungstenite:: tungstenite:: Error :: Protocol (
177+ ProtocolError :: HandshakeIncomplete ,
178+ ) ) ;
179+ }
171180 self . add_to_batch ( verification_data, ws_conn_sink. clone ( ) )
172181 . await ;
173182 } else {
@@ -324,7 +333,8 @@ impl Batcher {
324333 /// finalizes the batch.
325334 async fn handle_new_block ( & self , block_number : u64 ) -> Result < ( ) , BatcherError > {
326335 while let Some ( finalized_batch) = self . is_batch_ready ( block_number) . await {
327- self . finalize_batch ( block_number, finalized_batch, false ) . await ?;
336+ self . finalize_batch ( block_number, finalized_batch, false )
337+ . await ?;
328338 }
329339 Ok ( ( ) )
330340 }
0 commit comments