diff --git a/sz-poc-offsite-2025/evm/lightnode/src/lib.rs b/sz-poc-offsite-2025/evm/lightnode/src/lib.rs index d14c182..95f26e3 100644 --- a/sz-poc-offsite-2025/evm/lightnode/src/lib.rs +++ b/sz-poc-offsite-2025/evm/lightnode/src/lib.rs @@ -6,6 +6,7 @@ pub const CRYPTARCHIA_INFO: &str = "cryptarchia/info"; pub const STORAGE_BLOCK: &str = "storage/block"; pub mod nomos; +pub mod proofcheck; #[derive(Clone, Debug)] pub struct Credentials { diff --git a/sz-poc-offsite-2025/evm/lightnode/src/main.rs b/sz-poc-offsite-2025/evm/lightnode/src/main.rs index 8c92468..a37dbda 100644 --- a/sz-poc-offsite-2025/evm/lightnode/src/main.rs +++ b/sz-poc-offsite-2025/evm/lightnode/src/main.rs @@ -1,18 +1,33 @@ use clap::Parser; -use evm_lightnode::{Credentials, NomosClient, nomos::HeaderId}; +use evm_lightnode::{Credentials, NomosClient, nomos::HeaderId, proofcheck}; use tracing::info; use url::Url; - +use std::path::PathBuf; use std::error; use tracing_subscriber::{EnvFilter, fmt}; const TESTNET_EXECUTOR: &str = "https://testnet.nomos.tech/node/3/"; #[derive(Parser, Debug)] -#[clap(author, version, about = "Ethereum Proof Generation Tool")] +#[clap(author, version, about = "Light Node validator")] struct Args { #[clap(long, default_value = "info")] log_level: String, + + #[clap(long, default_value = "http://localhost:8546")] + rpc: Url, + + #[clap(long, default_value = "http://localhost:8070")] + prover_url: Url, + + #[clap(long)] + start_block: u64, + + #[clap(long, default_value = "10")] + batch_size: u64, + + #[clap(long)] + zeth_binary_dir: Option, } #[tokio::main] @@ -27,6 +42,14 @@ async fn main() -> Result<(), Box> { password: Some(password), }; + proofcheck::verify_proof( + args.start_block, + args.batch_size, + &args.rpc, + &args.prover_url, + &args.zeth_binary_dir.unwrap_or_else(|| std::env::current_dir().unwrap()).join("zeth-ethereum"), + ).await?; + let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&args.log_level)); @@ -48,4 +71,6 @@ async fn main() -> Result<(), Box> { tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; } + + } diff --git a/sz-poc-offsite-2025/evm/lightnode/src/proofcheck.rs b/sz-poc-offsite-2025/evm/lightnode/src/proofcheck.rs new file mode 100644 index 0000000..888e8d1 --- /dev/null +++ b/sz-poc-offsite-2025/evm/lightnode/src/proofcheck.rs @@ -0,0 +1,54 @@ +use tokio::process::Command; +use std::path::Path; +use reqwest::Url; +use tracing::{error, info}; + +pub async fn verify_proof( + block_number: u64, + block_count: u64, + rpc: &Url, + prover_url: &Url, + zeth_bin: &Path, +) -> Result<(), String> { + info!( + "Verifying proof for blocks {}-{}", + block_number, + block_number + block_count - 1 + ); + + let proof = reqwest::get(format!( + "{}/?block_start={}&block_count={}", + prover_url, block_number, block_count + )).await + .map_err(|e| format!("Failed to fetch proof: {}", e))? + .bytes() + .await + .map_err(|e| format!("Failed to read proof response: {}", e))?; + let filename = format!("{}-{}.zkp", block_number, block_count + block_number); + tokio::fs::write(&filename, &proof) + .await + .map_err(|e| format!("Failed to write proof to file: {}", e))?; + + + let output = Command::new(zeth_bin) + .args([ + "verify", + &format!("--rpc={}", rpc), + &format!("--block-number={}", block_number), + &format!("--block-count={}", block_count), + &format!("--file={}", filename), + ]) + .output().await + .map_err(|e| format!("Failed to execute zeth-ethereum verify: {}", e))?; + + if !output.status.success() { + let stderr = String::from_utf8_lossy(&output.stderr); + error!("zeth-ethereum verify command failed: {}", stderr); + return Err(format!( + "zeth-ethereum verify command failed with status: {}\nStderr: {}", + output.status, stderr + )); + } + + Ok(()) +}