Skip to content

Commit

Permalink
remove VerifierConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Jan 21, 2025
1 parent 2880367 commit 5a7e533
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 93 deletions.
34 changes: 10 additions & 24 deletions core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ use tonic::{
transport::{Channel, ClientTlsConfig, Endpoint},
Streaming,
};
use url::Url;
use zksync_config::EigenConfig;
use zksync_web3_decl::client::{Client, DynClient, L1};

use super::{
blob_info::BlobInfo,
disperser::BlobInfo as DisperserBlobInfo,
verifier::{Verifier, VerifierConfig},
GetBlobData,
blob_info::BlobInfo, disperser::BlobInfo as DisperserBlobInfo, verifier::Verifier, GetBlobData,
};
use crate::eigen::{
blob_info,
Expand Down Expand Up @@ -45,37 +41,27 @@ impl RawEigenClient {

pub async fn new(
private_key: SecretKey,
config: EigenConfig,
cfg: EigenConfig,
get_blob_data: Arc<dyn GetBlobData>,
) -> anyhow::Result<Self> {
let endpoint =
Endpoint::from_str(config.disperser_rpc.as_str())?.tls_config(ClientTlsConfig::new())?;
Endpoint::from_str(cfg.disperser_rpc.as_str())?.tls_config(ClientTlsConfig::new())?;
let client = DisperserClient::connect(endpoint).await?;

let verifier_config = VerifierConfig {
rpc_url: config
.eigenda_eth_rpc
.clone()
.ok_or(anyhow::anyhow!("EigenDA ETH RPC not set"))?,
svc_manager_addr: config.eigenda_svc_manager_address,
max_blob_size: Self::BLOB_SIZE_LIMIT as u32,
g1_url: Url::parse(&config.g1_url)?,
g2_url: Url::parse(&config.g2_url)?,
points_dir: config.points_dir.clone(),
settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth,
};

let url = verifier_config.rpc_url.clone();
let query_client: Client<L1> = Client::http(url)?.build();
let rpc_url = cfg
.eigenda_eth_rpc
.clone()
.ok_or(anyhow::anyhow!("EigenDA ETH RPC not set"))?;
let query_client: Client<L1> = Client::http(rpc_url)?.build();
let query_client = Box::new(query_client) as Box<DynClient<L1>>;

let verifier = Verifier::new(verifier_config, Arc::new(query_client))
let verifier = Verifier::new(cfg.clone(), Arc::new(query_client))
.await
.context("Failed to create verifier")?;
Ok(RawEigenClient {
client,
private_key,
config,
config: cfg,
verifier,
get_blob_data,
})
Expand Down
60 changes: 25 additions & 35 deletions core/node/da_clients/src/eigen/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ use ark_bn254::{Fq, G1Affine};
use ethabi::{encode, ParamType, Token};
use rust_kzg_bn254::{blob::Blob, kzg::Kzg, polynomial::PolynomialFormat};
use tempfile::NamedTempFile;
use url::Url;
use zksync_basic_types::web3::CallRequest;
use zksync_config::EigenConfig;
use zksync_eth_client::{EnrichedClientError, EthInterface};
use zksync_types::{url::SensitiveUrl, web3, Address, U256};
use zksync_types::{web3, Address, U256};
use zksync_web3_decl::client::{DynClient, L1};

use super::blob_info::{BatchHeader, BlobHeader, BlobInfo, BlobQuorumParam, G1Commitment};
use super::{
blob_info::{BatchHeader, BlobHeader, BlobInfo, BlobQuorumParam, G1Commitment},
sdk::RawEigenClient,
};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -175,18 +178,6 @@ pub enum VerificationError {
LinkError(String),
}

/// Configuration for the verifier used for authenticated dispersals
#[derive(Debug, Clone)]
pub struct VerifierConfig {
pub rpc_url: SensitiveUrl,
pub svc_manager_addr: Address,
pub max_blob_size: u32,
pub points_dir: Option<String>,
pub g1_url: Url,
pub g2_url: Url,
pub settlement_layer_confirmation_depth: u32,
}

#[derive(Debug)]
enum PointFile {
Temp(NamedTempFile),
Expand All @@ -208,8 +199,8 @@ impl PointFile {
#[derive(Debug)]
pub struct Verifier {
kzg: Kzg,
cfg: VerifierConfig,
signing_client: Arc<dyn VerifierClient>,
cfg: EigenConfig,
client: Arc<dyn VerifierClient>,
}

impl Verifier {
Expand All @@ -219,7 +210,7 @@ impl Verifier {
pub const G2POINT: &'static str = "g2.point.powerOf2";
pub const POINT_SIZE: u32 = 32;

async fn download_temp_point(url: Url) -> Result<NamedTempFile, VerificationError> {
async fn download_temp_point(url: &String) -> Result<NamedTempFile, VerificationError> {
let response = reqwest::get(url)
.await
.map_err(|e| VerificationError::LinkError(e.to_string()))
Expand All @@ -242,7 +233,7 @@ impl Verifier {
Ok(file)
}

async fn get_points(cfg: &VerifierConfig) -> Result<(PointFile, PointFile), VerificationError> {
async fn get_points(cfg: &EigenConfig) -> Result<(PointFile, PointFile), VerificationError> {
match &cfg.points_dir {
Some(path) => Ok((
PointFile::Path(format!("{}/{}", path, Self::G1POINT)),
Expand All @@ -251,18 +242,18 @@ impl Verifier {
None => {
tracing::info!("Points for KZG setup not found, downloading temporary points");
Ok((
PointFile::Temp(Self::download_temp_point(cfg.g1_url.clone()).await?),
PointFile::Temp(Self::download_temp_point(cfg.g2_url.clone()).await?),
PointFile::Temp(Self::download_temp_point(&cfg.g1_url).await?),
PointFile::Temp(Self::download_temp_point(&cfg.g2_url).await?),
))
}
}
}

pub(crate) async fn new(
cfg: VerifierConfig,
signing_client: Arc<dyn VerifierClient>,
cfg: EigenConfig,
client: Arc<dyn VerifierClient>,
) -> Result<Self, VerificationError> {
let srs_points_to_load = cfg.max_blob_size / Self::POINT_SIZE;
let srs_points_to_load = RawEigenClient::blob_size_limit() as u32 / Self::POINT_SIZE; // TODO: MAKE BLOB_SIZE_LIMIT part of Self?
let (g1_point_file, g2_point_file) = Self::get_points(&cfg).await?;
let g1_point_file_path = g1_point_file.path().to_string();
let g2_point_file_path = g2_point_file.path().to_string();
Expand All @@ -281,11 +272,7 @@ impl Verifier {
.map_err(|e| VerificationError::Kzg(KzgError::Setup(e.to_string())))?
.map_err(KzgError::Internal)?;

Ok(Self {
kzg,
cfg,
signing_client,
})
Ok(Self { kzg, cfg, client })
}

/// Return the commitment from a blob
Expand Down Expand Up @@ -432,9 +419,9 @@ impl Verifier {
&self,
blob_info: &BlobInfo,
) -> Result<Vec<u8>, VerificationError> {
self.signing_client
self.client
.as_ref()
.batch_id_to_batch_metadata_hash(blob_info, self.cfg.svc_manager_addr)
.batch_id_to_batch_metadata_hash(blob_info, self.cfg.eigenda_svc_manager_address)
.await
}

Expand Down Expand Up @@ -474,16 +461,19 @@ impl Verifier {
&self,
quorum_number: u32,
) -> Result<u8, VerificationError> {
self.signing_client
self.client
.as_ref()
.quorum_adversary_threshold_percentages(quorum_number, self.cfg.svc_manager_addr)
.quorum_adversary_threshold_percentages(
quorum_number,
self.cfg.eigenda_svc_manager_address,
)
.await
}

async fn call_quorum_numbers_required(&self) -> Result<Vec<u8>, VerificationError> {
self.signing_client
self.client
.as_ref()
.quorum_numbers_required(self.cfg.svc_manager_addr)
.quorum_numbers_required(self.cfg.eigenda_svc_manager_address)
.await
}

Expand Down
56 changes: 22 additions & 34 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 url::Url;
use zksync_config::EigenConfig;
use zksync_types::{
url::SensitiveUrl,
web3::{Bytes, CallRequest},
Expand All @@ -15,21 +15,9 @@ use crate::eigen::{
BatchHeader, BatchMetadata, BlobHeader, BlobInfo, BlobQuorumParam, BlobVerificationProof,
G1Commitment,
},
verifier::{Verifier, VerifierClient, VerifierConfig},
verifier::{Verifier, VerifierClient},
};

fn get_verifier_config() -> VerifierConfig {
VerifierConfig {
rpc_url: SensitiveUrl::from_str("https://ethereum-holesky-rpc.publicnode.com").unwrap(),
svc_manager_addr: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
max_blob_size: 2 * 1024 * 1024,
g1_url: Url::parse("https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point").unwrap(),
g2_url: Url::parse("https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2").unwrap(),
points_dir: None,
settlement_layer_confirmation_depth: 0,
}
}

/// Mock struct for the Verifier
/// Used to avoid making actual calls to a remote disperser
/// and possible making the CI fail due to network issues.
Expand Down Expand Up @@ -107,17 +95,17 @@ impl VerifierClient for MockVerifierClient {
}
}

fn create_remote_query_client(cfg: VerifierConfig) -> Box<DynClient<L1>> {
let url = cfg.rpc_url;
fn create_remote_query_client() -> Box<DynClient<L1>> {
let url = SensitiveUrl::from_str("https://ethereum-holesky-rpc.publicnode.com").unwrap();
let query_client: Client<L1> = Client::http(url).unwrap().build();
Box::new(query_client) as Box<DynClient<L1>>
}

#[ignore = "depends on external RPC"]
#[tokio::test]
async fn test_verify_commitment() {
let cfg = get_verifier_config();
let query_client = create_remote_query_client(cfg.clone());
let cfg = EigenConfig::default();
let query_client = create_remote_query_client();
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let commitment = G1Commitment {
x: vec![
Expand All @@ -138,7 +126,7 @@ async fn test_verify_commitment() {
/// To test actual behaviour of the verifier, run the test above
#[tokio::test]
async fn test_verify_commitment_mocked() {
let cfg = get_verifier_config();
let cfg = EigenConfig::default();
let query_client = MockVerifierClient::new(HashMap::new());
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let commitment = G1Commitment {
Expand All @@ -159,8 +147,8 @@ async fn test_verify_commitment_mocked() {
#[ignore = "depends on external RPC"]
#[tokio::test]
async fn test_verify_merkle_proof() {
let cfg = get_verifier_config();
let query_client = create_remote_query_client(cfg.clone());
let cfg = EigenConfig::default();
let query_client = create_remote_query_client();
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let cert = BlobInfo {
blob_header: BlobHeader {
Expand Down Expand Up @@ -240,7 +228,7 @@ async fn test_verify_merkle_proof() {
/// To test actual behaviour of the verifier, run the test above
#[tokio::test]
async fn test_verify_merkle_proof_mocked() {
let cfg = get_verifier_config();
let cfg = EigenConfig::default();
let query_client = MockVerifierClient::new(HashMap::new());
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let cert = BlobInfo {
Expand Down Expand Up @@ -320,8 +308,8 @@ async fn test_verify_merkle_proof_mocked() {
#[ignore = "depends on external RPC"]
#[tokio::test]
async fn test_hash_blob_header() {
let cfg = get_verifier_config();
let query_client = create_remote_query_client(cfg.clone());
let cfg = EigenConfig::default();
let query_client = create_remote_query_client();
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let blob_header = BlobHeader {
commitment: G1Commitment {
Expand Down Expand Up @@ -359,7 +347,7 @@ async fn test_hash_blob_header() {
/// To test actual behaviour of the verifier, run the test above
#[tokio::test]
async fn test_hash_blob_header_mocked() {
let cfg = get_verifier_config();
let cfg = EigenConfig::default();
let query_client = MockVerifierClient::new(HashMap::new());
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let blob_header = BlobHeader {
Expand Down Expand Up @@ -397,8 +385,8 @@ async fn test_hash_blob_header_mocked() {
#[ignore = "depends on external RPC"]
#[tokio::test]
async fn test_inclusion_proof() {
let cfg = get_verifier_config();
let query_client = create_remote_query_client(cfg.clone());
let cfg = EigenConfig::default();
let query_client = create_remote_query_client();
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let proof = hex::decode("c455c1ea0e725d7ea3e5f29e9f48be8fc2787bb0a914d5a86710ba302c166ac4f626d76f67f1055bb960a514fb8923af2078fd84085d712655b58a19612e8cd15c3e4ac1cef57acde3438dbcf63f47c9fefe1221344c4d5c1a4943dd0d1803091ca81a270909dc0e146841441c9bd0e08e69ce6168181a3e4060ffacf3627480bec6abdd8d7bb92b49d33f180c42f49e041752aaded9c403db3a17b85e48a11e9ea9a08763f7f383dab6d25236f1b77c12b4c49c5cdbcbea32554a604e3f1d2f466851cb43fe73617b3d01e665e4c019bf930f92dea7394c25ed6a1e200d051fb0c30a2193c459f1cfef00bf1ba6656510d16725a4d1dc031cb759dbc90bab427b0f60ddc6764681924dda848824605a4f08b7f526fe6bd4572458c94e83fbf2150f2eeb28d3011ec921996dc3e69efa52d5fcf3182b20b56b5857a926aa66605808079b4d52c0c0cfe06923fa92e65eeca2c3e6126108e8c1babf5ac522f4d7").unwrap();
let leaf: [u8; 32] =
Expand All @@ -418,7 +406,7 @@ async fn test_inclusion_proof() {
/// To test actual behaviour of the verifier, run the test above
#[tokio::test]
async fn test_inclusion_proof_mocked() {
let cfg = get_verifier_config();
let cfg = EigenConfig::default();
let query_client = MockVerifierClient::new(HashMap::new());
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let proof = hex::decode("c455c1ea0e725d7ea3e5f29e9f48be8fc2787bb0a914d5a86710ba302c166ac4f626d76f67f1055bb960a514fb8923af2078fd84085d712655b58a19612e8cd15c3e4ac1cef57acde3438dbcf63f47c9fefe1221344c4d5c1a4943dd0d1803091ca81a270909dc0e146841441c9bd0e08e69ce6168181a3e4060ffacf3627480bec6abdd8d7bb92b49d33f180c42f49e041752aaded9c403db3a17b85e48a11e9ea9a08763f7f383dab6d25236f1b77c12b4c49c5cdbcbea32554a604e3f1d2f466851cb43fe73617b3d01e665e4c019bf930f92dea7394c25ed6a1e200d051fb0c30a2193c459f1cfef00bf1ba6656510d16725a4d1dc031cb759dbc90bab427b0f60ddc6764681924dda848824605a4f08b7f526fe6bd4572458c94e83fbf2150f2eeb28d3011ec921996dc3e69efa52d5fcf3182b20b56b5857a926aa66605808079b4d52c0c0cfe06923fa92e65eeca2c3e6126108e8c1babf5ac522f4d7").unwrap();
Expand All @@ -438,8 +426,8 @@ async fn test_inclusion_proof_mocked() {
#[ignore = "depends on external RPC"]
#[tokio::test]
async fn test_verify_batch() {
let cfg = get_verifier_config();
let query_client = create_remote_query_client(cfg.clone());
let cfg = EigenConfig::default();
let query_client = create_remote_query_client();
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let cert = BlobInfo {
blob_header: BlobHeader {
Expand Down Expand Up @@ -541,7 +529,7 @@ async fn test_verify_batch_mocked() {
);
mock_replies.insert(mock_req, mock_res);

let cfg = get_verifier_config();
let cfg = EigenConfig::default();
let query_client = MockVerifierClient::new(mock_replies);
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let cert = BlobInfo {
Expand Down Expand Up @@ -621,8 +609,8 @@ async fn test_verify_batch_mocked() {
#[ignore = "depends on external RPC"]
#[tokio::test]
async fn test_verify_security_params() {
let cfg = get_verifier_config();
let query_client = create_remote_query_client(cfg.clone());
let cfg = EigenConfig::default();
let query_client = create_remote_query_client();
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let cert = BlobInfo {
blob_header: BlobHeader {
Expand Down Expand Up @@ -745,7 +733,7 @@ async fn test_verify_securityyy_params_mocked() {
);
mock_replies.insert(mock_req, mock_res);

let cfg = get_verifier_config();
let cfg = EigenConfig::default();
let query_client = MockVerifierClient::new(mock_replies);
let verifier = Verifier::new(cfg, Arc::new(query_client)).await.unwrap();
let cert = BlobInfo {
Expand Down

0 comments on commit 5a7e533

Please sign in to comment.