Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eigen-client-extra-features): address PR comments #375

Merged
merged 10 commits into from
Dec 19, 2024
2 changes: 1 addition & 1 deletion core/lib/config/src/configs/da_client/eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct EigenConfig {
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
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
6 changes: 3 additions & 3 deletions core/node/da_clients/src/eigen/client_tests.rs
Original file line number Diff line number Diff line change
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,7 +70,7 @@ 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(),
wait_for_finalization: false,
Expand Down Expand Up @@ -110,7 +110,7 @@ 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(),
wait_for_finalization: false,
Expand Down
11 changes: 5 additions & 6 deletions core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tonic::{
use zksync_config::EigenConfig;
use zksync_da_client::types::DAError;
use zksync_eth_client::clients::PKSigningClient;
use zksync_types::{url::SensitiveUrl, K256PrivateKey, SLChainId, H160};
use zksync_types::{url::SensitiveUrl, Address, K256PrivateKey, SLChainId};
use zksync_web3_decl::client::{Client, DynClient, L1};

use super::{
Expand Down Expand Up @@ -58,12 +58,11 @@ impl<T: GetBlobData> RawEigenClient<T> {
.eigenda_eth_rpc
.clone()
.ok_or(anyhow::anyhow!("EigenDA ETH RPC not set"))?,
svc_manager_addr: config.eigenda_svc_manager_address.clone(),
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(),
settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth.max(0)
as u32,
settlement_layer_confirmation_depth: config.settlement_layer_confirmation_depth,
private_key: hex::encode(private_key.secret_bytes()),
chain_id: config.chain_id,
};
Expand All @@ -75,7 +74,7 @@ impl<T: GetBlobData> RawEigenClient<T> {
K256PrivateKey::from_bytes(zksync_types::H256::from_str(
&verifier_config.private_key,
)?)?,
H160::from_str(&verifier_config.svc_manager_addr)?,
verifier_config.svc_manager_addr,
Verifier::DEFAULT_PRIORITY_FEE_PER_GAS,
SLChainId(verifier_config.chain_id),
query_client,
Expand Down Expand Up @@ -185,7 +184,7 @@ impl<T: GetBlobData> RawEigenClient<T> {
let Some(data) = self.get_blob_data(blob_info.clone()).await? else {
return Err(anyhow::anyhow!("Failed to get blob data"));
};
let data_db = self.get_blob_data.call(request_id).await?;
let data_db = self.get_blob_data.get_blob_data(request_id).await?;
if let Some(data_db) = data_db {
if data_db != data {
return Err(anyhow::anyhow!(
Expand Down
21 changes: 6 additions & 15 deletions core/node/da_clients/src/eigen/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, fs::File, io::copy, path::Path, str::FromStr};
use std::{collections::HashMap, fs::File, io::copy, path::Path};

use ark_bn254::{Fq, G1Affine};
use ethabi::{encode, ParamType, Token};
Expand All @@ -9,7 +9,7 @@ use zksync_basic_types::web3::CallRequest;
use zksync_eth_client::{clients::PKSigningClient, EnrichedClientResult};
use zksync_types::{
web3::{self, BlockId, BlockNumber},
H160, U256, U64,
Address, U256, U64,
};

use super::blob_info::{BatchHeader, BlobHeader, BlobInfo, G1Commitment};
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum VerificationError {
#[derive(Debug, Clone)]
pub struct VerifierConfig {
pub rpc_url: String,
pub svc_manager_addr: String,
pub svc_manager_addr: Address,
pub max_blob_size: u32,
pub g1_url: String,
pub g2_url: String,
Expand Down Expand Up @@ -342,10 +342,7 @@ impl Verifier {
data.append(batch_id_vec.to_vec().as_mut());

let call_request = CallRequest {
to: Some(
H160::from_str(&self.cfg.svc_manager_addr)
.map_err(|_| VerificationError::ServiceManagerError)?,
),
to: Some(self.cfg.svc_manager_addr),
data: Some(zksync_basic_types::web3::Bytes(data)),
..Default::default()
};
Expand Down Expand Up @@ -445,10 +442,7 @@ impl Verifier {
let data = func_selector.to_vec();

let call_request = CallRequest {
to: Some(
H160::from_str(&self.cfg.svc_manager_addr)
.map_err(|_| VerificationError::ServiceManagerError)?,
),
to: Some(self.cfg.svc_manager_addr),
data: Some(zksync_basic_types::web3::Bytes(data)),
..Default::default()
};
Expand All @@ -474,10 +468,7 @@ impl Verifier {
let func_selector = ethabi::short_signature("quorumNumbersRequired", &[]);
let data = func_selector.to_vec();
let call_request = CallRequest {
to: Some(
H160::from_str(&self.cfg.svc_manager_addr)
.map_err(|_| VerificationError::ServiceManagerError)?,
),
to: Some(self.cfg.svc_manager_addr),
data: Some(zksync_basic_types::web3::Bytes(data)),
..Default::default()
};
Expand Down
8 changes: 3 additions & 5 deletions core/node/da_clients/src/eigen/verifier_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod test {
use zksync_types::{
url::SensitiveUrl,
web3::{BlockId, Bytes, CallRequest},
K256PrivateKey, SLChainId, H160, U64,
Address, K256PrivateKey, SLChainId, H160, U64,
};
use zksync_web3_decl::client::{Client, DynClient, L1};

Expand All @@ -21,7 +21,7 @@ mod test {
fn get_verifier_config() -> VerifierConfig {
VerifierConfig {
rpc_url: "https://ethereum-holesky-rpc.publicnode.com".to_string(),
svc_manager_addr: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".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(),
Expand Down Expand Up @@ -82,9 +82,7 @@ mod test {
)
.map_err(|_| VerificationError::ServiceManagerError)
.unwrap(),
zksync_types::H160::from_str(&cfg.svc_manager_addr)
.map_err(|_| VerificationError::ServiceManagerError)
.unwrap(),
cfg.svc_manager_addr,
Verifier::DEFAULT_PRIORITY_FEE_PER_GAS,
SLChainId(cfg.chain_id),
query_client,
Expand Down
Loading
Loading