Skip to content

Commit

Permalink
add PointsSource to EigenConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Feb 6, 2025
1 parent a7a7c2b commit f933e84
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 48 deletions.
15 changes: 9 additions & 6 deletions core/lib/config/src/configs/da_client/eigen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use serde::Deserialize;
use zksync_basic_types::{secrets::PrivateKey, url::SensitiveUrl, Address};

#[derive(Clone, Debug, PartialEq, Deserialize)]
pub enum PointsSource {
Path(String),
/// g1_url, g2_url
Link((String, String)),
}

/// Configuration for the EigenDA remote disperser client.
#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct EigenConfig {
Expand All @@ -17,12 +24,8 @@ pub struct EigenConfig {
pub wait_for_finalization: bool,
/// Authenticated dispersal
pub authenticated: bool,
/// Optional path to downloaded points directory
pub points_dir: Option<String>,
/// Url to the file containing the G1 point used for KZG
pub g1_url: String,
/// Url to the file containing the G2 point used for KZG
pub g2_url: String,
/// Points source
pub points_source: PointsSource,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
61 changes: 43 additions & 18 deletions core/lib/env_config/src/da_client.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
use std::env;
use std::{env, str::FromStr};

use zksync_config::configs::{
da_client::{
avail::{
AvailClientConfig, AvailSecrets, AVAIL_FULL_CLIENT_NAME, AVAIL_GAS_RELAY_CLIENT_NAME,
use zksync_basic_types::{url::SensitiveUrl, H160};
use zksync_config::{
configs::{
da_client::{
avail::{
AvailClientConfig, AvailSecrets, AVAIL_FULL_CLIENT_NAME,
AVAIL_GAS_RELAY_CLIENT_NAME,
},
celestia::CelestiaSecrets,
eigen::EigenSecrets,
DAClientConfig, AVAIL_CLIENT_CONFIG_NAME, CELESTIA_CLIENT_CONFIG_NAME,
EIGEN_CLIENT_CONFIG_NAME, OBJECT_STORE_CLIENT_CONFIG_NAME,
},
celestia::CelestiaSecrets,
eigen::EigenSecrets,
DAClientConfig, AVAIL_CLIENT_CONFIG_NAME, CELESTIA_CLIENT_CONFIG_NAME,
EIGEN_CLIENT_CONFIG_NAME, OBJECT_STORE_CLIENT_CONFIG_NAME,
secrets::DataAvailabilitySecrets,
AvailConfig,
},
secrets::DataAvailabilitySecrets,
AvailConfig,
EigenConfig,
};

use crate::{envy_load, FromEnv};
Expand All @@ -34,7 +39,29 @@ impl FromEnv for DAClientConfig {
},
}),
CELESTIA_CLIENT_CONFIG_NAME => Self::Celestia(envy_load("da_celestia_config", "DA_")?),
EIGEN_CLIENT_CONFIG_NAME => Self::Eigen(envy_load("da_eigen_config", "DA_")?),
EIGEN_CLIENT_CONFIG_NAME => Self::Eigen(EigenConfig {
disperser_rpc: env::var("DA_DISPERSER_RPC")?,
settlement_layer_confirmation_depth: env::var(
"DA_SETTLEMENT_LAYER_CONFIRMATION_DEPTH",
)?
.parse()?,
eigenda_eth_rpc: Some(SensitiveUrl::from_str(&env::var("DA_EIGENDA_ETH_RPC")?)?),
eigenda_svc_manager_address: H160::from_str(&env::var(
"DA_EIGENDA_SVC_MANAGER_ADDRESS",
)?)?,
wait_for_finalization: env::var("DA_WAIT_FOR_FINALIZATION")?.parse()?,
authenticated: env::var("DA_AUTHENTICATED")?.parse()?,
points_source: match env::var("DA_POINTS_SOURCE")?.as_str() {
"Path" => zksync_config::configs::da_client::eigen::PointsSource::Path(
env::var("DA_POINTS_PATH")?,
),
"Link" => zksync_config::configs::da_client::eigen::PointsSource::Link((
env::var("DA_POINTS_LINK_G1")?,
env::var("DA_POINTS_LINK_G2")?,
)),
_ => anyhow::bail!("Unknown Eigen points type"),
},
}),
OBJECT_STORE_CLIENT_CONFIG_NAME => {
Self::ObjectStore(envy_load("da_object_store", "DA_")?)
}
Expand Down Expand Up @@ -97,6 +124,7 @@ mod tests {
configs::{
da_client::{
avail::{AvailClientConfig, AvailDefaultConfig},
eigen::PointsSource,
DAClientConfig::{self, ObjectStore},
},
object_store::ObjectStoreMode::GCS,
Expand Down Expand Up @@ -258,9 +286,8 @@ mod tests {
DA_EIGENDA_SVC_MANAGER_ADDRESS="0x0000000000000000000000000000000000000123"
DA_WAIT_FOR_FINALIZATION=true
DA_AUTHENTICATED=false
DA_POINTS_DIR="resources/"
DA_G1_URL="resources1"
DA_G2_URL="resources2"
DA_POINTS_SOURCE="Path"
DA_POINTS_PATH="resources"
"#;
lock.set_env(config);

Expand All @@ -276,9 +303,7 @@ mod tests {
.unwrap(),
wait_for_finalization: true,
authenticated: false,
points_dir: Some("resources/".to_string()),
g1_url: "resources1".to_string(),
g2_url: "resources2".to_string(),
points_source: PointsSource::Path("resources".to_string()),
})
);
}
Expand Down
32 changes: 26 additions & 6 deletions core/lib/protobuf_config/src/da_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,20 @@ impl ProtoRepr for proto::DataAvailabilityClient {
wait_for_finalization: *required(&conf.wait_for_finalization)
.context("wait_for_finalization")?,
authenticated: *required(&conf.authenticated).context("authenticated")?,
points_dir: conf.points_dir.clone(),
g1_url: required(&conf.g1_url).context("g1_url")?.clone(),
g2_url: required(&conf.g2_url).context("g2_url")?.clone(),
points_source: match conf.points_source.clone() {
Some(proto::eigen_config::PointsSource::Path(path)) => {
zksync_config::configs::da_client::eigen::PointsSource::Path(path)
}
Some(proto::eigen_config::PointsSource::Link(link)) => {
let g1_url = required(&link.g1_url).context("g1_url")?;
let g2_url = required(&link.g2_url).context("g2_url")?;
zksync_config::configs::da_client::eigen::PointsSource::Link((
g1_url.to_owned(),
g2_url.to_owned(),
))
}
None => return Err(anyhow::anyhow!("Invalid Eigen DA configuration")),
},
}),
proto::data_availability_client::Config::ObjectStore(conf) => {
ObjectStore(object_store_proto::ObjectStore::read(conf)?)
Expand Down Expand Up @@ -135,9 +146,18 @@ impl ProtoRepr for proto::DataAvailabilityClient {
)),
wait_for_finalization: Some(config.wait_for_finalization),
authenticated: Some(config.authenticated),
g1_url: Some(config.g1_url.clone()),
g2_url: Some(config.g2_url.clone()),
points_dir: config.points_dir.as_ref().map(|a| a.to_string()),
points_source: Some(match &config.points_source {
zksync_config::configs::da_client::eigen::PointsSource::Path(path) => {
proto::eigen_config::PointsSource::Path(path.clone())
}
zksync_config::configs::da_client::eigen::PointsSource::Link((
g1_url,
g2_url,
)) => proto::eigen_config::PointsSource::Link(proto::Link {
g1_url: Some(g1_url.clone()),
g2_url: Some(g2_url.clone()),
}),
}),
}),
ObjectStore(config) => proto::data_availability_client::Config::ObjectStore(
object_store_proto::ObjectStore::build(config),
Expand Down
16 changes: 13 additions & 3 deletions core/lib/protobuf_config/src/proto/config/da_client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,26 @@ message CelestiaConfig {
optional uint64 timeout_ms = 4;
}

message Path {
optional string path = 1;
}

message Link {
optional string g1_url = 1;
optional string g2_url = 2;
}

message EigenConfig {
optional string disperser_rpc = 3;
optional uint32 settlement_layer_confirmation_depth = 4;
optional string eigenda_eth_rpc = 5;
optional string eigenda_svc_manager_address = 6;
optional bool wait_for_finalization = 7;
optional bool authenticated = 8;
optional string g1_url = 9;
optional string g2_url = 10;
optional string points_dir = 11;
oneof points_source {
string path = 9;
Link link = 10;
}
reserved 1,2;
reserved "rpc_node_url","inclusion_polling_interval_ms";
}
Expand Down
12 changes: 8 additions & 4 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ mod tests {

use backon::{ConstantBuilder, Retryable};
use serial_test::file_serial;
use zksync_config::{configs::da_client::eigen::EigenSecrets, EigenConfig};
use zksync_config::{
configs::da_client::eigen::{EigenSecrets, PointsSource},
EigenConfig,
};
use zksync_da_client::{types::DispatchResponse, DataAvailabilityClient};
use zksync_types::{secrets::PrivateKey, url::SensitiveUrl, H160};

Expand Down Expand Up @@ -157,9 +160,10 @@ mod tests {
eigenda_svc_manager_address: DEFAULT_EIGENDA_SVC_MANAGER_ADDRESS,
wait_for_finalization: false,
authenticated: false,
points_dir: None,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
g2_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".to_string(),
points_source: PointsSource::Link((
"https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
"https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".to_string(),
))
}
}

Expand Down
14 changes: 7 additions & 7 deletions core/node/da_clients/src/eigen/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rust_kzg_bn254::{blob::Blob, kzg::Kzg, polynomial::PolynomialFormat};
use tempfile::NamedTempFile;
use tokio::task::JoinHandle;
use zksync_basic_types::web3::CallRequest;
use zksync_config::EigenConfig;
use zksync_config::{configs::da_client::eigen::PointsSource, EigenConfig};
use zksync_eth_client::EthInterface;
use zksync_types::{web3, Address, U256, U64};
use zksync_web3_decl::client::{DynClient, L1};
Expand Down Expand Up @@ -225,16 +225,16 @@ impl Verifier {
}

async fn get_points(cfg: &EigenConfig) -> Result<(PointFile, PointFile), VerificationError> {
match &cfg.points_dir {
Some(path) => Ok((
match &cfg.points_source {
PointsSource::Path(path) => Ok((
PointFile::Path(PathBuf::from(format!("{}/{}", path, Self::G1POINT))),
PointFile::Path(PathBuf::from(format!("{}/{}", path, Self::G2POINT))),
)),
None => {
tracing::info!("Points for KZG setup not found, downloading points to a temp file");
PointsSource::Link((g1_url, g2_url)) => {
tracing::info!("Downloading points for KZG setup to a temp file");
Ok((
PointFile::Temp(Self::download_temp_point(&cfg.g1_url).await?),
PointFile::Temp(Self::download_temp_point(&cfg.g2_url).await?),
PointFile::Temp(Self::download_temp_point(g1_url).await?),
PointFile::Temp(Self::download_temp_point(g2_url).await?),
))
}
}
Expand Down
9 changes: 5 additions & 4 deletions core/node/da_clients/src/eigen/verifier/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, str::FromStr, sync::Arc};

use ethabi::{ParamType, Token};
use zksync_config::EigenConfig;
use zksync_config::{configs::da_client::eigen::PointsSource, EigenConfig};
use zksync_types::{
url::SensitiveUrl,
web3::{Bytes, CallRequest},
Expand Down Expand Up @@ -120,9 +120,10 @@ fn test_eigen_config() -> EigenConfig {
eigenda_svc_manager_address: DEFAULT_EIGENDA_SVC_MANAGER_ADDRESS,
wait_for_finalization: false,
authenticated: false,
points_dir: None,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
g2_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".to_string(),
points_source: PointsSource::Link((
"https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
"https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".to_string(),
))
}
}

Expand Down

0 comments on commit f933e84

Please sign in to comment.