|
1 | | -use crate::gnark::verify_gnark; |
| 1 | +use crate::connection::send_message; |
2 | 2 | use crate::risc_zero::verify_risc_zero_proof; |
3 | 3 | use crate::sp1::verify_sp1_proof; |
4 | | -use aligned_sdk::core::types::{ProvingSystemId, VerificationData}; |
| 4 | +use crate::types::batch_queue::BatchQueue; |
| 5 | +use crate::{gnark::verify_gnark, types::batch_queue::BatchQueueEntry}; |
| 6 | +use aligned_sdk::core::types::{ |
| 7 | + ProofInvalidReason, ProvingSystemId, ValidityResponseMessage, VerificationData, |
| 8 | +}; |
5 | 9 | use ethers::types::U256; |
6 | | -use log::{debug, warn}; |
| 10 | +use log::{debug, info, warn}; |
| 11 | +use tokio::sync::MutexGuard; |
7 | 12 |
|
8 | 13 | pub(crate) async fn verify(verification_data: &VerificationData) -> bool { |
9 | 14 | let verification_data = verification_data.clone(); |
@@ -70,6 +75,57 @@ pub(crate) fn is_verifier_disabled( |
70 | 75 | disabled_verifiers & (U256::one() << verification_data.proving_system as u64) != U256::zero() |
71 | 76 | } |
72 | 77 |
|
| 78 | +pub(crate) async fn filter_disabled_verifiers( |
| 79 | + batch_queue: BatchQueue, |
| 80 | + disabled_verifiers: MutexGuard<'_, U256>, |
| 81 | +) -> BatchQueue { |
| 82 | + let mut removed_entries = Vec::new(); |
| 83 | + let filtered_batch_queue = batch_queue |
| 84 | + .iter() |
| 85 | + .filter_map(|(entry, entry_priority)| { |
| 86 | + info!( |
| 87 | + "Verifying proof for proving system {}", |
| 88 | + entry |
| 89 | + .nonced_verification_data |
| 90 | + .verification_data |
| 91 | + .proving_system |
| 92 | + ); |
| 93 | + let verification_data = &entry.nonced_verification_data.verification_data; |
| 94 | + if !is_verifier_disabled(*disabled_verifiers, verification_data) |
| 95 | + && !removed_entries |
| 96 | + .iter() |
| 97 | + .any(|e: &BatchQueueEntry| e.sender == entry.sender) |
| 98 | + { |
| 99 | + Some((entry.clone(), entry_priority.clone())) |
| 100 | + } else { |
| 101 | + warn!( |
| 102 | + "Verifier for proving system {} is now disabled, removing proofs from batch", |
| 103 | + verification_data.proving_system |
| 104 | + ); |
| 105 | + removed_entries.push(entry.clone()); |
| 106 | + |
| 107 | + None |
| 108 | + } |
| 109 | + }) |
| 110 | + .collect(); |
| 111 | + for entry in removed_entries { |
| 112 | + let ws_sink = entry.messaging_sink.as_ref(); |
| 113 | + if let Some(ws_sink) = ws_sink { |
| 114 | + send_message( |
| 115 | + ws_sink.clone(), |
| 116 | + ValidityResponseMessage::InvalidProof(ProofInvalidReason::DisabledVerifier( |
| 117 | + entry |
| 118 | + .nonced_verification_data |
| 119 | + .verification_data |
| 120 | + .proving_system, |
| 121 | + )), |
| 122 | + ) |
| 123 | + .await; |
| 124 | + } |
| 125 | + } |
| 126 | + filtered_batch_queue |
| 127 | +} |
| 128 | + |
73 | 129 | #[cfg(test)] |
74 | 130 | mod test { |
75 | 131 | use super::is_verifier_disabled; |
|
0 commit comments