Skip to content

Commit

Permalink
fix: changed loop termination logic and batch verification result agg…
Browse files Browse the repository at this point in the history
…regation
  • Loading branch information
haraldh committed Sep 12, 2024
1 parent d95e703 commit ed5b984
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions bin/verify-era-proof-attestation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ mod client;
mod proof;
mod verification;

use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use args::Arguments;
use clap::Parser;
use client::MainNodeClient;
use proof::GetProofsRequest;
use reqwest::Client;
use tokio::{signal, sync::watch, time::sleep};
use tracing::{debug, trace, warn};
use tracing::{error, info, trace, warn};
use tracing_log::LogTracer;
use tracing_subscriber::{filter::LevelFilter, fmt, prelude::*, EnvFilter, Registry};
use url::Url;
Expand All @@ -28,17 +28,17 @@ use crate::verification::{
#[tokio::main]
async fn main() -> Result<()> {
let args = Arguments::parse();

setup_logging(&args.log_level)?;

validate_arguments(&args)?;

let (stop_sender, stop_receiver) = watch::channel(false);

let mut process_handle =
tokio::spawn(verify_batches_proofs(stop_receiver.clone(), args.clone()));
let mut process_handle = tokio::spawn(verify_batches_proofs(stop_receiver, args));

tokio::select! {
_ = &mut process_handle => {},
ret = &mut process_handle => { return ret?; },
_ = signal::ctrl_c() => {
tracing::info!("Stop signal received, shutting down");
stop_sender.send(true).ok();
Expand Down Expand Up @@ -94,21 +94,24 @@ async fn verify_batches_proofs(
};
let mut current_batch_number = first_batch_number;

loop {
if *stop_receiver.borrow() {
tracing::warn!("Stop signal received, shutting down");
break;
}
let mut all_verified = true;

loop {
if let Some((_, end_batch_number)) = args.batch_range {
if current_batch_number > end_batch_number {
break;
}
}

if *stop_receiver.borrow() {
tracing::warn!("Stop signal received, shutting down");
all_verified = false;
break;
}

trace!("Verifying proofs for batch #{}", current_batch_number);

verify_batch_proofs(
all_verified = verify_batch_proofs(
current_batch_number,
&args.rpc_url,
&http_client,
Expand All @@ -121,6 +124,12 @@ async fn verify_batches_proofs(
sleep(args.rate_limit).await;
}

if !all_verified {
bail!("Not all proofs were verified to be correct!");
}

println!("All proofs verified!");

Ok(())
}

Expand All @@ -132,10 +141,12 @@ async fn verify_batch_proofs(
http_client: &Client,
node_client: &MainNodeClient,
attestation_criteria: &args::AttestationCriteriaArgs,
) -> Result<()> {
) -> Result<bool> {
let proofs_request = GetProofsRequest::new(batch_number);
let proofs_response = proofs_request.send(http_client, rpc_url).await?;

let mut batch_verified = false;

for proof in proofs_response
.result
.into_iter()
Expand All @@ -154,7 +165,7 @@ async fn verify_batch_proofs(
let quote_verification_result = verify_attestation_quote(&proof.attestation)?;
let verified_successfully = verify_batch_proof(
&quote_verification_result,
&attestation_criteria,
attestation_criteria,
node_client,
&proof.signature,
L1BatchNumber(proof.l1_batch_number),
Expand All @@ -168,12 +179,17 @@ async fn verify_batch_proofs(
);
log_quote_verification_summary(&quote_verification_result);
} else {
debug!(
batch_verified = true;
info!(
"Verification of the {} proof, produced at {}, succeeded for batch #{}",
tee_type, proof.proved_at, proof.l1_batch_number
);
}
}

Ok(())
if !batch_verified {
error!("Verification failed for batch #{}", batch_number);
}

Ok(batch_verified)
}

0 comments on commit ed5b984

Please sign in to comment.