Skip to content

Commit

Permalink
Merge branch 'eigen-client-solve-comments' into eigen-client-solve-co…
Browse files Browse the repository at this point in the history
…mments-p2
  • Loading branch information
juan518munoz committed Dec 17, 2024
2 parents dc3db99 + 0c1aae0 commit c9d1b4a
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 158 deletions.
6 changes: 3 additions & 3 deletions core/lib/config/src/configs/da_client/eigen.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use serde::Deserialize;
use zksync_basic_types::secrets::PrivateKey;
use zksync_basic_types::{secrets::PrivateKey, Address};
/// Configuration for the EigenDA remote disperser client.
#[derive(Clone, Debug, PartialEq, Deserialize, Default)]
pub struct EigenConfig {
/// URL of the Disperser RPC server
pub disperser_rpc: String,
/// Block height needed to reach in order to consider the blob finalized
/// a value less or equal to 0 means that the disperser will not wait for finalization
pub settlement_layer_confirmation_depth: i32,
pub settlement_layer_confirmation_depth: u32,
/// URL of the Ethereum RPC server
pub eigenda_eth_rpc: Option<String>,
/// Address of the service manager contract
pub eigenda_svc_manager_address: String,
pub eigenda_svc_manager_address: Address,
/// Wait for the blob to be finalized before returning the response
pub wait_for_finalization: bool,
/// Authenticated dispersal
Expand Down
10 changes: 8 additions & 2 deletions core/lib/env_config/src/da_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ impl FromEnv for DataAvailabilitySecrets {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use zksync_basic_types::Address;
use zksync_config::{
configs::{
da_client::{
Expand Down Expand Up @@ -251,7 +254,7 @@ mod tests {
DA_DISPERSER_RPC="http://localhost:8080"
DA_SETTLEMENT_LAYER_CONFIRMATION_DEPTH=0
DA_EIGENDA_ETH_RPC="http://localhost:8545"
DA_EIGENDA_SVC_MANAGER_ADDRESS="0x123"
DA_EIGENDA_SVC_MANAGER_ADDRESS="0xD4A7E1Bd8015057293f0D0A557088c286942e84b"
DA_WAIT_FOR_FINALIZATION=true
DA_AUTHENTICATED=false
DA_G1_URL="resources1"
Expand All @@ -267,7 +270,10 @@ mod tests {
disperser_rpc: "http://localhost:8080".to_string(),
settlement_layer_confirmation_depth: 0,
eigenda_eth_rpc: Some("http://localhost:8545".to_string()),
eigenda_svc_manager_address: "0x123".to_string(),
eigenda_svc_manager_address: Address::from_str(
"0xD4A7E1Bd8015057293f0D0A557088c286942e84b"
)
.unwrap(),
wait_for_finalization: true,
authenticated: false,
g1_url: "resources1".to_string(),
Expand Down
12 changes: 8 additions & 4 deletions core/lib/protobuf_config/src/da_client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use anyhow::Context;
use zksync_config::configs::{
self,
Expand All @@ -9,6 +11,7 @@ use zksync_config::configs::{
},
};
use zksync_protobuf::{required, ProtoRepr};
use zksync_types::Address;

use crate::proto::{
da_client::{self as proto},
Expand Down Expand Up @@ -64,9 +67,10 @@ impl ProtoRepr for proto::DataAvailabilityClient {
)
.context("settlement_layer_confirmation_depth")?,
eigenda_eth_rpc: required(&conf.eigenda_eth_rpc).ok().cloned(),
eigenda_svc_manager_address: required(&conf.eigenda_svc_manager_address)
.context("eigenda_svc_manager_address")?
.clone(),
eigenda_svc_manager_address: Address::from_str(
required(&conf.eigenda_svc_manager_address)
.context("eigenda_svc_manager_address")?,
)?,
wait_for_finalization: *required(&conf.wait_for_finalization)
.context("wait_for_finalization")?,
authenticated: *required(&conf.authenticated).context("authenticated")?,
Expand Down Expand Up @@ -116,7 +120,7 @@ impl ProtoRepr for proto::DataAvailabilityClient {
config.settlement_layer_confirmation_depth,
),
eigenda_eth_rpc: config.eigenda_eth_rpc.clone(),
eigenda_svc_manager_address: Some(config.eigenda_svc_manager_address.clone()),
eigenda_svc_manager_address: Some(config.eigenda_svc_manager_address.to_string()),
wait_for_finalization: Some(config.wait_for_finalization),
authenticated: Some(config.authenticated),
g1_url: Some(config.g1_url.clone()),
Expand Down
2 changes: 1 addition & 1 deletion core/lib/protobuf_config/src/proto/config/da_client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ message CelestiaConfig {

message EigenConfig {
optional string disperser_rpc = 3;
optional int32 settlement_layer_confirmation_depth = 4;
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;
Expand Down
124 changes: 13 additions & 111 deletions core/node/da_clients/src/eigen/blob_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use super::{

#[derive(Debug)]
pub enum ConversionError {
NotPresentError,
NotPresent,
}

impl fmt::Display for ConversionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConversionError::NotPresentError => write!(f, "Failed to convert BlobInfo"),
ConversionError::NotPresent => write!(f, "Failed to convert BlobInfo"),
}
}
}
Expand All @@ -29,18 +29,6 @@ pub struct G1Commitment {
pub y: Vec<u8>,
}

impl G1Commitment {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
bytes.extend(&self.x.len().to_be_bytes());
bytes.extend(&self.x);
bytes.extend(&self.y.len().to_be_bytes());
bytes.extend(&self.y);

bytes
}
}

impl From<DisperserG1Commitment> for G1Commitment {
fn from(value: DisperserG1Commitment) -> Self {
Self {
Expand All @@ -58,18 +46,6 @@ pub struct BlobQuorumParam {
pub chunk_length: u32,
}

impl BlobQuorumParam {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
bytes.extend(&self.quorum_number.to_be_bytes());
bytes.extend(&self.adversary_threshold_percentage.to_be_bytes());
bytes.extend(&self.confirmation_threshold_percentage.to_be_bytes());
bytes.extend(&self.chunk_length.to_be_bytes());

bytes
}
}

impl From<DisperserBlobQuorumParam> for BlobQuorumParam {
fn from(value: DisperserBlobQuorumParam) -> Self {
Self {
Expand All @@ -88,34 +64,16 @@ pub struct BlobHeader {
pub blob_quorum_params: Vec<BlobQuorumParam>,
}

impl BlobHeader {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
bytes.extend(self.commitment.to_bytes());
bytes.extend(&self.data_length.to_be_bytes());
bytes.extend(&self.blob_quorum_params.len().to_be_bytes());

for quorum in &self.blob_quorum_params {
bytes.extend(quorum.to_bytes());
}

bytes
}
}

impl TryFrom<DisperserBlobHeader> for BlobHeader {
type Error = ConversionError;
fn try_from(value: DisperserBlobHeader) -> Result<Self, Self::Error> {
if value.commitment.is_none() {
return Err(ConversionError::NotPresentError);
}
let blob_quorum_params: Vec<BlobQuorumParam> = value
.blob_quorum_params
.iter()
.map(|param| BlobQuorumParam::from(param.clone()))
.collect();
Ok(Self {
commitment: G1Commitment::from(value.commitment.unwrap()),
commitment: G1Commitment::from(value.commitment.ok_or(ConversionError::NotPresent)?),
data_length: value.data_length,
blob_quorum_params,
})
Expand All @@ -130,21 +88,6 @@ pub struct BatchHeader {
pub reference_block_number: u32,
}

impl BatchHeader {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
bytes.extend(&self.batch_root.len().to_be_bytes());
bytes.extend(&self.batch_root);
bytes.extend(&self.quorum_numbers.len().to_be_bytes());
bytes.extend(&self.quorum_numbers);
bytes.extend(&self.quorum_signed_percentages.len().to_be_bytes());
bytes.extend(&self.quorum_signed_percentages);
bytes.extend(&self.reference_block_number.to_be_bytes());

bytes
}
}

impl From<DisperserBatchHeader> for BatchHeader {
fn from(value: DisperserBatchHeader) -> Self {
Self {
Expand All @@ -165,25 +108,11 @@ pub struct BatchMetadata {
pub batch_header_hash: Vec<u8>,
}

impl BatchMetadata {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
bytes.extend(self.batch_header.to_bytes());
bytes.extend(&self.signatory_record_hash);
bytes.extend(&self.confirmation_block_number.to_be_bytes());

bytes
}
}

impl TryFrom<DisperserBatchMetadata> for BatchMetadata {
type Error = ConversionError;
fn try_from(value: DisperserBatchMetadata) -> Result<Self, Self::Error> {
if value.batch_header.is_none() {
return Err(ConversionError::NotPresentError);
}
Ok(Self {
batch_header: BatchHeader::from(value.batch_header.unwrap()),
batch_header: BatchHeader::from(value.batch_header.ok_or(ConversionError::NotPresent)?),
signatory_record_hash: value.signatory_record_hash,
fee: value.fee,
confirmation_block_number: value.confirmation_block_number,
Expand All @@ -201,31 +130,15 @@ pub struct BlobVerificationProof {
pub quorum_indexes: Vec<u8>,
}

impl BlobVerificationProof {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
bytes.extend(&self.batch_id.to_be_bytes());
bytes.extend(&self.blob_index.to_be_bytes());
bytes.extend(self.batch_medatada.to_bytes());
bytes.extend(&self.inclusion_proof.len().to_be_bytes());
bytes.extend(&self.inclusion_proof);
bytes.extend(&self.quorum_indexes.len().to_be_bytes());
bytes.extend(&self.quorum_indexes);

bytes
}
}

impl TryFrom<DisperserBlobVerificationProof> for BlobVerificationProof {
type Error = ConversionError;
fn try_from(value: DisperserBlobVerificationProof) -> Result<Self, Self::Error> {
if value.batch_metadata.is_none() {
return Err(ConversionError::NotPresentError);
}
Ok(Self {
batch_id: value.batch_id,
blob_index: value.blob_index,
batch_medatada: BatchMetadata::try_from(value.batch_metadata.unwrap())?,
batch_medatada: BatchMetadata::try_from(
value.batch_metadata.ok_or(ConversionError::NotPresent)?,
)?,
inclusion_proof: value.inclusion_proof,
quorum_indexes: value.quorum_indexes,
})
Expand All @@ -238,28 +151,17 @@ pub struct BlobInfo {
pub blob_verification_proof: BlobVerificationProof,
}

impl BlobInfo {
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = vec![];
let blob_header_bytes = self.blob_header.to_bytes();
bytes.extend(blob_header_bytes.len().to_be_bytes());
bytes.extend(blob_header_bytes);
let blob_verification_proof_bytes = self.blob_verification_proof.to_bytes();
bytes.extend(blob_verification_proof_bytes);
bytes
}
}

impl TryFrom<DisperserBlobInfo> for BlobInfo {
type Error = ConversionError;
fn try_from(value: DisperserBlobInfo) -> Result<Self, Self::Error> {
if value.blob_header.is_none() || value.blob_verification_proof.is_none() {
return Err(ConversionError::NotPresentError);
}
Ok(Self {
blob_header: BlobHeader::try_from(value.blob_header.unwrap())?,
blob_header: BlobHeader::try_from(
value.blob_header.ok_or(ConversionError::NotPresent)?,
)?,
blob_verification_proof: BlobVerificationProof::try_from(
value.blob_verification_proof.unwrap(),
value
.blob_verification_proof
.ok_or(ConversionError::NotPresent)?,
)?,
})
}
Expand Down
2 changes: 1 addition & 1 deletion core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::utils::to_retriable_da_error;

#[async_trait]
pub trait GetBlobData: Clone + std::fmt::Debug + Send + Sync {
async fn call(&self, input: &str) -> anyhow::Result<Option<Vec<u8>>>;
async fn get_blob_data(&self, input: &str) -> anyhow::Result<Option<Vec<u8>>>;
}

/// EigenClient is a client for the Eigen DA service.
Expand Down
18 changes: 9 additions & 9 deletions core/node/da_clients/src/eigen/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod tests {
types::{DAError, DispatchResponse},
DataAvailabilityClient,
};
use zksync_types::secrets::PrivateKey;
use zksync_types::{secrets::PrivateKey, Address};

use crate::eigen::{blob_info::BlobInfo, EigenClient, GetBlobData};

Expand Down Expand Up @@ -59,7 +59,7 @@ mod tests {

#[async_trait::async_trait]
impl GetBlobData for MockGetBlobData {
async fn call(&self, _input: &'_ str) -> anyhow::Result<Option<Vec<u8>>> {
async fn get_blob_data(&self, _input: &'_ str) -> anyhow::Result<Option<Vec<u8>>> {
Ok(None)
}
}
Expand All @@ -70,9 +70,9 @@ mod tests {
async fn test_non_auth_dispersal() {
let config = EigenConfig {
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
settlement_layer_confirmation_depth: -1,
settlement_layer_confirmation_depth: 0,
eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
wait_for_finalization: false,
authenticated: false,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
Expand Down Expand Up @@ -110,9 +110,9 @@ mod tests {
async fn test_auth_dispersal() {
let config = EigenConfig {
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
settlement_layer_confirmation_depth: -1,
settlement_layer_confirmation_depth: 0,
eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
wait_for_finalization: false,
authenticated: true,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
Expand Down Expand Up @@ -156,7 +156,7 @@ mod tests {
g2_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g2.point.powerOf2".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(),
eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
chain_id: 17000,
};
let secrets = EigenSecrets {
Expand Down Expand Up @@ -192,7 +192,7 @@ mod tests {
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
settlement_layer_confirmation_depth: 5,
eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
eigenda_svc_manager_address:Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
wait_for_finalization: false,
authenticated: false,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
Expand Down Expand Up @@ -232,7 +232,7 @@ mod tests {
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
settlement_layer_confirmation_depth: 5,
eigenda_eth_rpc: Some("https://ethereum-holesky-rpc.publicnode.com".to_string()),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
eigenda_svc_manager_address: Address::from_str("0xD4A7E1Bd8015057293f0D0A557088c286942e84b").unwrap(),
wait_for_finalization: false,
authenticated: true,
g1_url: "https://github.com/Layr-Labs/eigenda-proxy/raw/2fd70b99ef5bf137d7bbca3461cf9e1f2c899451/resources/g1.point".to_string(),
Expand Down
Loading

0 comments on commit c9d1b4a

Please sign in to comment.