Skip to content

Commit fcac386

Browse files
committed
Move proof verification before batch verifications
1 parent 859590a commit fcac386

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

crates/batcher/src/lib.rs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -768,46 +768,6 @@ impl Batcher {
768768
nonced_verification_data = aux_verification_data
769769
}
770770

771-
// When pre-verification is enabled, batcher will verify proofs for faster feedback with clients
772-
if self.pre_verification_is_enabled {
773-
let verification_data = &nonced_verification_data.verification_data;
774-
if self
775-
.is_verifier_disabled(verification_data.proving_system)
776-
.await
777-
{
778-
warn!(
779-
"Verifier for proving system {} is disabled, skipping verification",
780-
verification_data.proving_system
781-
);
782-
send_message(
783-
ws_conn_sink.clone(),
784-
SubmitProofResponseMessage::InvalidProof(ProofInvalidReason::DisabledVerifier(
785-
verification_data.proving_system,
786-
)),
787-
)
788-
.await;
789-
self.metrics.user_error(&[
790-
"disabled_verifier",
791-
&format!("{}", verification_data.proving_system),
792-
]);
793-
return Ok(());
794-
}
795-
796-
if !zk_utils::verify(verification_data).await {
797-
error!("Invalid proof detected. Verification failed");
798-
send_message(
799-
ws_conn_sink.clone(),
800-
SubmitProofResponseMessage::InvalidProof(ProofInvalidReason::RejectedProof),
801-
)
802-
.await;
803-
self.metrics.user_error(&[
804-
"rejected_proof",
805-
&format!("{}", verification_data.proving_system),
806-
]);
807-
return Ok(());
808-
}
809-
}
810-
811771
// We don't need a batch state lock here, since if the user locks its funds
812772
// after the check, some blocks should pass until he can withdraw.
813773
// It is safe to do just do this here.
@@ -936,6 +896,47 @@ impl Batcher {
936896
return Ok(());
937897
}
938898

899+
900+
// When pre-verification is enabled, batcher will verify proofs for faster feedback with clients
901+
if self.pre_verification_is_enabled {
902+
let verification_data = &nonced_verification_data.verification_data;
903+
if self
904+
.is_verifier_disabled(verification_data.proving_system)
905+
.await
906+
{
907+
warn!(
908+
"Verifier for proving system {} is disabled, skipping verification",
909+
verification_data.proving_system
910+
);
911+
send_message(
912+
ws_conn_sink.clone(),
913+
SubmitProofResponseMessage::InvalidProof(ProofInvalidReason::DisabledVerifier(
914+
verification_data.proving_system,
915+
)),
916+
)
917+
.await;
918+
self.metrics.user_error(&[
919+
"disabled_verifier",
920+
&format!("{}", verification_data.proving_system),
921+
]);
922+
return Ok(());
923+
}
924+
925+
if !zk_utils::verify(verification_data).await {
926+
error!("Invalid proof detected. Verification failed");
927+
send_message(
928+
ws_conn_sink.clone(),
929+
SubmitProofResponseMessage::InvalidProof(ProofInvalidReason::RejectedProof),
930+
)
931+
.await;
932+
self.metrics.user_error(&[
933+
"rejected_proof",
934+
&format!("{}", verification_data.proving_system),
935+
]);
936+
return Ok(());
937+
}
938+
}
939+
939940
// * ---------------------------------------------------------------------*
940941
// * Perform validation over batcher queue *
941942
// * ---------------------------------------------------------------------*

0 commit comments

Comments
 (0)