Skip to content

Commit

Permalink
Merge branch 'eigen-client-solve-comments-p4' into eigen-client-solve…
Browse files Browse the repository at this point in the history
…-comments-p5
  • Loading branch information
juan518munoz committed Dec 18, 2024
2 parents 7a393d0 + 7183a92 commit 8d97116
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 43 deletions.
18 changes: 17 additions & 1 deletion core/lib/config/src/configs/da_client/eigen.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::Deserialize;
use zksync_basic_types::secrets::PrivateKey;
/// Configuration for the EigenDA remote disperser client.
#[derive(Clone, Debug, PartialEq, Deserialize, Default)]
#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct EigenConfig {
/// URL of the Disperser RPC server
pub disperser_rpc: String,
Expand All @@ -24,6 +24,22 @@ pub struct EigenConfig {
pub chain_id: u64,
}

impl Default for EigenConfig {
fn default() -> Self {
Self {
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
settlement_layer_confirmation_depth: 0,
eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
wait_for_finalization: false,
authenticated: false,
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(),
chain_id: 19000,
}
}
}

#[derive(Clone, Debug, PartialEq)]
pub struct EigenSecrets {
pub private_key: PrivateKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX idx_blob_id_l1_batch_number ON data_availability (blob_id, l1_batch_number);
5 changes: 3 additions & 2 deletions core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tonic::{
transport::{Channel, ClientTlsConfig, Endpoint},
Streaming,
};
use url::Url;
use zksync_config::EigenConfig;
use zksync_da_client::types::DAError;
use zksync_eth_client::clients::PKSigningClient;
Expand Down Expand Up @@ -72,8 +73,8 @@ impl RawEigenClient {
.ok_or(anyhow::anyhow!("EigenDA ETH RPC not set"))?,
svc_manager_addr: Address::from_str(&config.eigenda_svc_manager_address)?,
max_blob_size: Self::BLOB_SIZE_LIMIT as u32,
g1_url: config.g1_url.clone(),
g2_url: config.g2_url.clone(),
g1_url: Url::parse(&config.g1_url)?,
g2_url: Url::parse(&config.g2_url)?,
settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth,
private_key: hex::encode(private_key.secret_bytes()),
chain_id: config.chain_id,
Expand Down
54 changes: 16 additions & 38 deletions core/node/da_clients/src/eigen/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ pub struct VerifierConfig {
pub rpc_url: String,
pub svc_manager_addr: Address,
pub max_blob_size: u32,
pub g1_url: String,
pub g2_url: String,
pub g1_url: Url,
pub g2_url: Url,
pub settlement_layer_confirmation_depth: u32,
pub private_key: String,
pub chain_id: u64,
Expand Down Expand Up @@ -104,8 +104,8 @@ impl Verifier {
pub const G2POINT: &'static str = "g2.point.powerOf2";
pub const POINT_SIZE: u32 = 32;

async fn save_point(url: String, point: String) -> Result<(), VerificationError> {
let url = Url::parse(&url).map_err(|_| VerificationError::LinkError)?;
async fn save_point(url: Url, point: String) -> Result<(), VerificationError> {
//let url = Url::parse(&url).map_err(|_| VerificationError::LinkError)?;
let response = reqwest::get(url)
.await
.map_err(|_| VerificationError::LinkError)?;
Expand All @@ -124,9 +124,9 @@ impl Verifier {
.map_err(|_| VerificationError::LinkError)?;
Ok(())
}
async fn save_points(url_g1: String, url_g2: String) -> Result<String, VerificationError> {
Self::save_point(url_g1.clone(), Self::G1POINT.to_string()).await?;
Self::save_point(url_g2.clone(), Self::G2POINT.to_string()).await?;
async fn save_points(url_g1: Url, url_g2: Url) -> Result<String, VerificationError> {
Self::save_point(url_g1, Self::G1POINT.to_string()).await?;
Self::save_point(url_g2, Self::G2POINT.to_string()).await?;

Ok(".".to_string())
}
Expand Down Expand Up @@ -373,38 +373,16 @@ impl Verifier {
}

fn decode_bytes(&self, encoded: Vec<u8>) -> Result<Vec<u8>, String> {
// Ensure the input has at least 64 bytes (offset + length)
if encoded.len() < 64 {
return Err("Encoded data is too short".to_string());
let output_type = [ParamType::Bytes];
let tokens: Vec<Token> = ethabi::decode(&output_type, &encoded)
.map_err(|_| "Incorrect result on contract call")?;
let token = tokens
.get(0)
.ok_or_else(|| "Incorrect result on contract call")?;
match token {
Token::Bytes(data) => Ok(data.to_vec()),
_ => Err("Incorrect result on contract call".to_string()),
}

// Read the offset (first 32 bytes)
let offset = usize::from_be_bytes(
encoded[24..32]
.try_into()
.map_err(|_| "Offset is too large")?,
);

// Check if offset is valid
if offset + 32 > encoded.len() {
return Err("Offset points outside the encoded data".to_string());
}

// Read the length (32 bytes at the offset position)
let length = usize::from_be_bytes(
encoded[offset + 24..offset + 32]
.try_into()
.map_err(|_| "Length is too large")?,
);

// Check if the length is valid
if offset + 32 + length > encoded.len() {
return Err("Length extends beyond the encoded data".to_string());
}

// Extract the bytes data
let data = encoded[offset + 32..offset + 32 + length].to_vec();
Ok(data)
}

async fn get_quorum_adversary_threshold(
Expand Down
5 changes: 3 additions & 2 deletions core/node/da_clients/src/eigen/verifier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
mod test {
use std::{collections::HashMap, str::FromStr};

use url::Url;
use zksync_eth_client::{clients::PKSigningClient, EnrichedClientResult};
use zksync_types::{
url::SensitiveUrl,
Expand All @@ -23,8 +24,8 @@ mod test {
rpc_url: "https://ethereum-holesky-rpc.publicnode.com".to_string(),
svc_manager_addr: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
max_blob_size: 2 * 1024 * 1024,
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(),
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(),
settlement_layer_confirmation_depth: 0,
private_key: "0xd08aa7ae1bb5ddd46c3c2d8cdb5894ab9f54dec467233686ca42629e826ac4c6"
.to_string(),
Expand Down

0 comments on commit 8d97116

Please sign in to comment.