From 10ecbfffea2cabbdd26a030a744fa24b9394a2c6 Mon Sep 17 00:00:00 2001 From: Petar Radovic Date: Wed, 23 Apr 2025 17:08:23 +0200 Subject: [PATCH] lightnode --- sz-poc-offsite-2025/Cargo.toml | 8 ++- sz-poc-offsite-2025/evm/lightnode/Cargo.toml | 14 +++++ sz-poc-offsite-2025/evm/lightnode/src/lib.rs | 60 +++++++++++++++++++ sz-poc-offsite-2025/evm/lightnode/src/main.rs | 53 ++++++++++++++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 sz-poc-offsite-2025/evm/lightnode/Cargo.toml create mode 100644 sz-poc-offsite-2025/evm/lightnode/src/lib.rs create mode 100644 sz-poc-offsite-2025/evm/lightnode/src/main.rs diff --git a/sz-poc-offsite-2025/Cargo.toml b/sz-poc-offsite-2025/Cargo.toml index 0e54241..39d67be 100644 --- a/sz-poc-offsite-2025/Cargo.toml +++ b/sz-poc-offsite-2025/Cargo.toml @@ -1,5 +1,10 @@ [workspace] -members = ["evm/processor", "evm/sequencer-node", "evm/prover"] +members = [ + "evm/processor", + "evm/sequencer-node", + "evm/prover", + "evm/proof-checker", +] resolver = "3" [workspace.package] @@ -10,6 +15,7 @@ edition = "2024" evm-processor = { path = "evm/processor" } evm-sequencer-node = { path = "evm/sequencer-node" } evm-prover = { path = "evm/prover" } +evm-proof-checker = { path = "evm/proof-checker" } # External eyre = { version = "0.6" } diff --git a/sz-poc-offsite-2025/evm/lightnode/Cargo.toml b/sz-poc-offsite-2025/evm/lightnode/Cargo.toml new file mode 100644 index 0000000..7b0ad6a --- /dev/null +++ b/sz-poc-offsite-2025/evm/lightnode/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "evm-lightnode" +edition = { workspace = true } + +[dependencies] +clap = { version = "4.5", features = ["derive"] } +reqwest = { version = "0.11", features = ["blocking", "json"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } +executor-http-client = { git = "https://github.com/logos-co/nomos", branch = "master" } +tokio = { version = "1", features = ["full"] } +kzgrs-backend = { git = "https://github.com/logos-co/nomos.git", branch = "master", package = "kzgrs-backend" } diff --git a/sz-poc-offsite-2025/evm/lightnode/src/lib.rs b/sz-poc-offsite-2025/evm/lightnode/src/lib.rs new file mode 100644 index 0000000..fd5dae8 --- /dev/null +++ b/sz-poc-offsite-2025/evm/lightnode/src/lib.rs @@ -0,0 +1,60 @@ +use std::ops::Range; + +use executor_http_client::{BasicAuthCredentials, ExecutorHttpClient}; +use kzgrs_backend::common::share::DaShare; +use reqwest::Url; +use serde::{Deserialize, Serialize}; +use tracing::{error, error_span, info}; + +pub const DA_GET_RANGE: &str = "/da/get-range"; + +pub struct NomosDa { + url: Url, + client: ExecutorHttpClient, + reqwest_client: reqwest::Client, +} + +impl NomosDa { + pub fn new(basic_auth: BasicAuthCredentials, url: Url) -> Self { + Self { + client: ExecutorHttpClient::new(Some(basic_auth)), + url, + reqwest_client: reqwest::Client::new(), + } + } + + pub async fn get_indexer_range( + &self, + app_id: [u8; 32], + range: Range<[u8; 8]>, + ) -> Vec<([u8; 8], Vec)> { + let endpoint = self + .url + .join(DA_GET_RANGE) + .expect("Failed to construct valid URL"); + + match self + .reqwest_client + .post(endpoint) + .header("Content-Type", "application/json") + .body(serde_json::to_string(&GetRangeReq { app_id, range }).unwrap()) + .send() + .await + .unwrap() + .json::)>>() + .await + { + Ok(data) => data, + Err(e) => { + error!("Failed to get indexer range: {e}"); + vec![] + } + } + } +} + +#[derive(Serialize, Deserialize)] +struct GetRangeReq { + pub app_id: [u8; 32], + pub range: Range<[u8; 8]>, +} diff --git a/sz-poc-offsite-2025/evm/lightnode/src/main.rs b/sz-poc-offsite-2025/evm/lightnode/src/main.rs new file mode 100644 index 0000000..9bc12c6 --- /dev/null +++ b/sz-poc-offsite-2025/evm/lightnode/src/main.rs @@ -0,0 +1,53 @@ +use clap::Parser; +use evm_proof_checker::NomosDa; +use executor_http_client::BasicAuthCredentials; +use reqwest::Url; +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")] +struct Args { + // #[clap(long, required = true)] + // block: u64, + + // #[clap(long, required = true)] + // proof_file_path: String, + + // #[clap(long)] + // zeth_binary_dir: Option, + #[clap(long, default_value = "info")] + log_level: String, +} + +#[tokio::main] +async fn main() -> Result<(), Box> { + let args = Args::parse(); + + let filter = + EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&args.log_level)); + + fmt::fmt().with_env_filter(filter).with_target(false).init(); + + let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string()); + let user = std::env::var("NOMOS_USER").unwrap_or_default(); + let password = std::env::var("NOMOS_PASSWORD").unwrap_or_default(); + let da = NomosDa::new( + BasicAuthCredentials::new(user, Some(password)), + Url::parse(&url).unwrap(), + ); + + let from = 0u64.to_be_bytes(); + let to = 1u64.to_be_bytes(); + + da.get_indexer_range([0; 32], from..to) + .await + .iter() + .for_each(|(key, value)| { + println!("Key: {:?}, Value: {:?}", key, value); + }); + + Ok(()) +}