From c1d14a1ef9e72eeb82f8457259421f94cb533090 Mon Sep 17 00:00:00 2001 From: Petar Radovic Date: Wed, 23 Apr 2025 18:50:38 +0200 Subject: [PATCH] nomos types needed for client --- sz-poc-offsite-2025/evm/lightnode/Cargo.toml | 5 +- sz-poc-offsite-2025/evm/lightnode/src/lib.rs | 58 ++++++------------- sz-poc-offsite-2025/evm/lightnode/src/main.rs | 34 ++--------- sz-poc-offsite-2025/evm/processor/Cargo.toml | 2 +- .../evm/sequencer-node/src/main.rs | 23 +++++--- 5 files changed, 42 insertions(+), 80 deletions(-) diff --git a/sz-poc-offsite-2025/evm/lightnode/Cargo.toml b/sz-poc-offsite-2025/evm/lightnode/Cargo.toml index 7b0ad6a..57dd20a 100644 --- a/sz-poc-offsite-2025/evm/lightnode/Cargo.toml +++ b/sz-poc-offsite-2025/evm/lightnode/Cargo.toml @@ -11,4 +11,7 @@ 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" } +crypto-bigint = { version = "0.5.5", features = ["serde"] } +risc0-zkvm = { version = "2" } +indexmap = { version = "1.9.3" } +url = { version = "2" } diff --git a/sz-poc-offsite-2025/evm/lightnode/src/lib.rs b/sz-poc-offsite-2025/evm/lightnode/src/lib.rs index fd5dae8..d2d4254 100644 --- a/sz-poc-offsite-2025/evm/lightnode/src/lib.rs +++ b/sz-poc-offsite-2025/evm/lightnode/src/lib.rs @@ -1,60 +1,36 @@ use std::ops::Range; use executor_http_client::{BasicAuthCredentials, ExecutorHttpClient}; -use kzgrs_backend::common::share::DaShare; +use nomos::CryptarchiaInfo; use reqwest::Url; use serde::{Deserialize, Serialize}; use tracing::{error, error_span, info}; -pub const DA_GET_RANGE: &str = "/da/get-range"; +pub const CRYPTARCHIA_INFO: &str = "/cryptarchia/info"; +pub const STORAGE_BLOCK: &str = "/storage/block"; -pub struct NomosDa { - url: Url, - client: ExecutorHttpClient, +mod nomos; + +pub struct NomosClient { + base_url: Url, reqwest_client: reqwest::Client, } -impl NomosDa { - pub fn new(basic_auth: BasicAuthCredentials, url: Url) -> Self { +impl NomosClient { + pub fn new(base_url: Url) -> Self { Self { - client: ExecutorHttpClient::new(Some(basic_auth)), - url, + base_url, reqwest_client: reqwest::Client::new(), } } - pub async fn get_indexer_range( + pub async fn get_cryptarchia_info( &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![] - } - } + base_url: Url, + ) -> Result { + let url = base_url.join(CRYPTARCHIA_INFO).expect("Invalid URL"); + let response = self.reqwest_client.get(url).send().await?; + let info = response.json::().await?; + Ok(info) } } - -#[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 index 0e8f7c1..c691c94 100644 --- a/sz-poc-offsite-2025/evm/lightnode/src/main.rs +++ b/sz-poc-offsite-2025/evm/lightnode/src/main.rs @@ -1,7 +1,7 @@ use clap::Parser; -use evm_lightnode::NomosDa; -use executor_http_client::BasicAuthCredentials; -use reqwest::Url; +use evm_lightnode::NomosClient; +use url::Url; + use std::error; use tracing_subscriber::{EnvFilter, fmt}; @@ -10,14 +10,6 @@ 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, } @@ -26,28 +18,14 @@ struct Args { async fn main() -> Result<(), Box> { let args = Args::parse(); + let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string()); + 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); - }); + let consensus = NomosClient::new(Url::parse(&url).unwrap()); Ok(()) } diff --git a/sz-poc-offsite-2025/evm/processor/Cargo.toml b/sz-poc-offsite-2025/evm/processor/Cargo.toml index e82fcd9..749cbf3 100644 --- a/sz-poc-offsite-2025/evm/processor/Cargo.toml +++ b/sz-poc-offsite-2025/evm/processor/Cargo.toml @@ -8,4 +8,4 @@ executor-http-client = { git = "https://github.com/logos-co/nomos", branch = "ma reqwest = "0.11" kzgrs-backend = { git = "https://github.com/logos-co/nomos", branch = "master" } bincode = "1" -reth-tracing = { workspace = true } \ No newline at end of file +reth-tracing = { workspace = true } diff --git a/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs b/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs index 82d5ad2..7762e63 100644 --- a/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs +++ b/sz-poc-offsite-2025/evm/sequencer-node/src/main.rs @@ -1,4 +1,4 @@ -use evm_processor::{Processor, NomosDa, BasicAuthCredentials}; +use evm_processor::{BasicAuthCredentials, NomosDa, Processor}; use futures::TryStreamExt as _; use reth::{ api::{FullNodeTypes, NodePrimitives, NodeTypes}, @@ -25,13 +25,15 @@ where continue; }; info!(committed_chain = ?new.range(), "Received commit"); - processor.process_blocks( - new.inner() - .0 - .clone() - .into_blocks() - .map(reth_ethereum::primitives::RecoveredBlock::into_block), - ).await; + processor + .process_blocks( + new.inner() + .0 + .clone() + .into_blocks() + .map(reth_ethereum::primitives::RecoveredBlock::into_block), + ) + .await; ctx.events .send(ExExEvent::FinishedHeight(new.tip().num_hash())) @@ -57,7 +59,10 @@ fn main() -> eyre::Result<()> { 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::Url::parse(&url).unwrap()); + let da = NomosDa::new( + BasicAuthCredentials::new(user, Some(password)), + url::Url::parse(&url).unwrap(), + ); let processor = Processor::new(da); let handle = Box::pin( builder