check binary

This commit is contained in:
Giacomo Pasini 2025-04-24 11:03:43 +02:00
parent 58981a5ea8
commit 7420d1caa3
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
3 changed files with 83 additions and 3 deletions

View File

@ -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 {

View File

@ -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<PathBuf>,
}
#[tokio::main]
@ -27,6 +42,14 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
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<dyn error::Error>> {
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
}
}

View File

@ -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(())
}