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): Verifier #326

Merged
merged 28 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
226834f
initial commit
juan518munoz Oct 31, 2024
27413ac
Merge branch 'eigen-client-extra-features' into eigen-client-non-auth…
gianbelinche Nov 1, 2024
0dd2289
Merge branch 'eigen-client-extra-features' into eigen-client-non-auth…
gianbelinche Nov 1, 2024
7f5d01e
Add tests
gianbelinche Nov 1, 2024
ab03654
Add memstore
gianbelinche Nov 1, 2024
c565e84
Add assert to tests
gianbelinche Nov 1, 2024
f15932c
Merge branch 'eigen-client-non-auth-dispersal' into eigen-client-mems…
gianbelinche Nov 1, 2024
dc5b721
Add rest of memstore
gianbelinche Nov 1, 2024
46838fc
Address pr comments
gianbelinche Nov 1, 2024
d450f8a
Merge branch 'eigen-client-extra-features' into eigen-client-memstore
gianbelinche Nov 1, 2024
ec1a65a
Remove to retriable error
gianbelinche Nov 1, 2024
7864534
Merge branch 'eigen-client-extra-features' into eigen-client-memstore
gianbelinche Nov 4, 2024
edafcff
Fix conflicts
gianbelinche Nov 4, 2024
64226d8
Add verifier
gianbelinche Nov 4, 2024
f75bbad
Fix verifier
gianbelinche Nov 4, 2024
862329b
Add path to points to config
gianbelinche Nov 4, 2024
f892e99
Merge branch 'eigen-client-extra-features' into eigen-client-memstore
gianbelinche Nov 4, 2024
be8c975
Merge branch 'eigen-client-memstore' into eigen-client-verifier
gianbelinche Nov 4, 2024
794bef8
Fix typo
gianbelinche Nov 4, 2024
1c1bc02
Fix eigenda env test
gianbelinche Nov 4, 2024
6b463d3
Fix verifier test
gianbelinche Nov 4, 2024
7f94fed
Move eigendaservicemanager to generated
gianbelinche Nov 4, 2024
a1e2028
Remove unneeded imports
gianbelinche Nov 4, 2024
fa1a6a4
Document verifier
gianbelinche Nov 4, 2024
15ceab3
Modify errors
gianbelinche Nov 5, 2024
db0f14e
Address comments
gianbelinche Nov 5, 2024
ff490f9
Merge branch 'eigen-client-extra-features' into eigen-client-verifier
gianbelinche Nov 5, 2024
a0a044a
Fix conflicts
gianbelinche Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,322 changes: 1,263 additions & 59 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion core/lib/config/src/configs/da_client/eigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ pub struct DisperserConfig {
pub eth_confirmation_depth: i32,
pub eigenda_eth_rpc: String,
pub eigenda_svc_manager_address: String,
pub blob_size_limit: u64,
pub blob_size_limit: u32,
juanbono marked this conversation as resolved.
Show resolved Hide resolved
pub status_query_timeout: u64,
pub status_query_interval: u64,
pub wait_for_finalization: bool,
pub authenticated: bool,
pub verify_cert: bool,
pub path_to_points: String,
}

#[derive(Clone, Debug, PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions core/lib/env_config/src/da_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ mod tests {
DA_STATUS_QUERY_INTERVAL=3
DA_WAIT_FOR_FINALIZATION=true
DA_AUTHENTICATED=false
DA_VERIFY_CERT=false
DA_PATH_TO_POINTS="resources"
"#;
lock.set_env(config);

Expand All @@ -315,6 +317,8 @@ mod tests {
status_query_interval: 3,
wait_for_finalization: true,
authenticated: false,
verify_cert: false,
path_to_points: "resources".to_string(),
}))
);
}
Expand Down
8 changes: 8 additions & 0 deletions core/lib/protobuf_config/src/da_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ impl ProtoRepr for proto::DataAvailabilityClient {
authenticated: required(&conf.authenticated)
.context("authenticated")?
.clone(),
verify_cert: required(&conf.verify_cert)
.context("verify_cert")?
.clone(),
path_to_points: required(&conf.path_to_points)
.context("path_to_points")?
.clone(),
})
}
};
Expand Down Expand Up @@ -176,6 +182,8 @@ impl ProtoRepr for proto::DataAvailabilityClient {
status_query_interval: Some(config.status_query_interval),
wait_for_finalization: Some(config.wait_for_finalization),
authenticated: Some(config.authenticated),
verify_cert: Some(config.verify_cert),
path_to_points: Some(config.path_to_points.clone()),
},
)),
})
Expand Down
4 changes: 3 additions & 1 deletion core/lib/protobuf_config/src/proto/config/da_client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ message DisperserConfig {
optional int32 eth_confirmation_depth = 4;
optional string eigenda_eth_rpc = 5;
optional string eigenda_svc_manager_address = 6;
optional uint64 blob_size_limit = 7;
optional uint32 blob_size_limit = 7;
optional uint64 status_query_timeout = 8;
optional uint64 status_query_interval = 9;
optional bool wait_for_finalization = 10;
optional bool authenticated = 11;
optional bool verify_cert = 12;
optional string path_to_points = 13;
}

message EigenConfig {
Expand Down
8 changes: 8 additions & 0 deletions core/node/da_clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ pbjson-types.workspace = true
tokio-stream.workspace = true
rlp.workspace = true
kzgpad-rs = { git = "https://github.com/Layr-Labs/kzgpad-rs.git", tag = "v0.1.0" }
rand.workspace = true
sha3.workspace = true
tiny-keccak.workspace = true
alloy = { version = "0.3", features = ["full"] }
ethabi = "16.0.0"
rust-kzg-bn254 = {git = "https://github.com/lambdaclass/rust-kzg-bn254", branch = "bump-ark"}
ark-bn254 = "0.5.0-alpha.0"
num-bigint = "0.4.6"
14 changes: 7 additions & 7 deletions core/node/da_clients/src/eigen/blob_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl fmt::Display for ConversionError {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct G1Commitment {
pub x: Vec<u8>,
pub y: Vec<u8>,
Expand Down Expand Up @@ -69,7 +69,7 @@ impl From<DisperserG1Commitment> for G1Commitment {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BlobQuorumParam {
pub quorum_number: u32,
pub adversary_threshold_percentage: u32,
Expand Down Expand Up @@ -121,7 +121,7 @@ impl From<DisperserBlobQuorumParam> for BlobQuorumParam {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BlobHeader {
pub commitment: G1Commitment,
pub data_length: u32,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl TryFrom<DisperserBlobHeader> for BlobHeader {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BatchHeader {
pub batch_root: Vec<u8>,
pub quorum_numbers: Vec<u8>,
Expand Down Expand Up @@ -241,7 +241,7 @@ impl From<DisperserBatchHeader> for BatchHeader {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BatchMetadata {
pub batch_header: BatchHeader,
pub signatory_record_hash: Vec<u8>,
Expand Down Expand Up @@ -302,7 +302,7 @@ impl TryFrom<DisperserBatchMetadata> for BatchMetadata {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BlobVerificationProof {
pub batch_id: u32,
pub blob_index: u32,
Expand Down Expand Up @@ -365,7 +365,7 @@ impl TryFrom<DisperserBlobVerificationProof> for BlobVerificationProof {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct BlobInfo {
pub blob_header: BlobHeader,
pub blob_verification_proof: BlobVerificationProof,
Expand Down
90 changes: 61 additions & 29 deletions core/node/da_clients/src/eigen/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,27 @@ use zksync_da_client::{
DataAvailabilityClient,
};

use super::{blob_info::BlobInfo, sdk::RawEigenClient};
use super::{blob_info::BlobInfo, memstore::MemStore, sdk::RawEigenClient, Disperser};
use crate::utils::to_non_retriable_da_error;

#[derive(Debug, Clone)]
pub struct EigenClient {
client: Arc<RawEigenClient>,
client: Disperser,
}

impl EigenClient {
pub async fn new(config: EigenConfig, secrets: EigenSecrets) -> anyhow::Result<Self> {
let private_key = SecretKey::from_str(secrets.private_key.0.expose_secret().as_str())
.map_err(|e| anyhow::anyhow!("Failed to parse private key: {}", e))?;

match config {
let disperser: Disperser = match config.clone() {
EigenConfig::Disperser(config) => {
// TODO: add complete config
let client = RawEigenClient::new(
config.disperser_rpc,
config.status_query_interval,
private_key,
config.authenticated,
)
.await?;
Ok(EigenClient {
client: Arc::new(client),
})
let client = RawEigenClient::new(private_key, config).await?;
Disperser::Remote(Arc::new(client))
}
EigenConfig::MemStore(_) => {
todo!()
}
}
EigenConfig::MemStore(config) => Disperser::Memory(MemStore::new(config)),
};
Ok(Self { client: disperser })
}
}

Expand All @@ -51,11 +41,17 @@ impl DataAvailabilityClient for EigenClient {
_: u32, // batch number
data: Vec<u8>,
) -> Result<DispatchResponse, DAError> {
let blob_id = self
.client
.dispatch_blob(data)
.await
.map_err(to_non_retriable_da_error)?;
let blob_id = match &self.client {
Disperser::Remote(remote_disperser) => remote_disperser
.dispatch_blob(data)
.await
.map_err(to_non_retriable_da_error)?,
Disperser::Memory(memstore) => memstore
.clone()
.put_blob(data)
.await
.map_err(to_non_retriable_da_error)?,
};

Ok(DispatchResponse::from(blob_id))
}
Expand Down Expand Up @@ -87,16 +83,15 @@ impl DataAvailabilityClient for EigenClient {
#[cfg(test)]
impl EigenClient {
pub async fn get_blob_data(&self, blob_id: &str) -> anyhow::Result<Option<Vec<u8>>, DAError> {
self.client.get_blob_data(blob_id).await
/*match &self.disperser {
match &self.client {
Disperser::Remote(remote_client) => remote_client.get_blob_data(blob_id).await,
Disperser::Memory(memstore) => memstore.clone().get_blob_data(blob_id).await,
}*/
}
}
}
#[cfg(test)]
mod tests {
use zksync_config::configs::da_client::eigen::DisperserConfig;
use zksync_config::configs::da_client::eigen::{DisperserConfig, MemStoreConfig};
use zksync_types::secrets::PrivateKey;

use super::*;
Expand All @@ -108,13 +103,15 @@ mod tests {
custom_quorum_numbers: None,
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
eth_confirmation_depth: -1,
eigenda_eth_rpc: String::default(),
eigenda_eth_rpc: "https://ethereum-holesky-rpc.publicnode.com".to_string(),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
blob_size_limit: 2 * 1024 * 1024, // 2MB
status_query_timeout: 1800, // 30 minutes
status_query_interval: 5, // 5 seconds
wait_for_finalization: false,
authenticated: false,
verify_cert: true,
path_to_points: "../../../resources".to_string(),
});
let secrets = EigenSecrets {
private_key: PrivateKey::from_str(
Expand Down Expand Up @@ -145,13 +142,15 @@ mod tests {
custom_quorum_numbers: None,
disperser_rpc: "https://disperser-holesky.eigenda.xyz:443".to_string(),
eth_confirmation_depth: -1,
eigenda_eth_rpc: String::default(),
eigenda_eth_rpc: "https://ethereum-holesky-rpc.publicnode.com".to_string(),
eigenda_svc_manager_address: "0xD4A7E1Bd8015057293f0D0A557088c286942e84b".to_string(),
blob_size_limit: 2 * 1024 * 1024, // 2MB
status_query_timeout: 1800, // 30 minutes
status_query_interval: 5, // 5 seconds
wait_for_finalization: false,
authenticated: true,
verify_cert: true,
path_to_points: "../../../resources".to_string(),
});
let secrets = EigenSecrets {
private_key: PrivateKey::from_str(
Expand All @@ -175,4 +174,37 @@ mod tests {
let retrieved_data = client.get_blob_data(&result.blob_id).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}

#[tokio::test]
async fn test_eigenda_memory_disperser() {
let config = EigenConfig::MemStore(MemStoreConfig {
max_blob_size_bytes: 2 * 1024 * 1024, // 2MB,
blob_expiration: 60 * 2,
get_latency: 0,
put_latency: 0,
});
let secrets = EigenSecrets {
private_key: PrivateKey::from_str(
"d08aa7ae1bb5ddd46c3c2d8cdb5894ab9f54dec467233686ca42629e826ac4c6",
)
.unwrap(),
};
let client = EigenClient::new(config, secrets).await.unwrap();
let data = vec![1u8; 100];
let result = client.dispatch_blob(0, data.clone()).await.unwrap();

let blob_info: BlobInfo =
rlp::decode(&hex::decode(result.blob_id.clone()).unwrap()).unwrap();
let expected_inclusion_data = blob_info.blob_verification_proof.inclusion_proof;
let actual_inclusion_data = client
.get_inclusion_data(&result.blob_id)
.await
.unwrap()
.unwrap()
.data;
assert_eq!(expected_inclusion_data, actual_inclusion_data);

let retrieved_data = client.get_blob_data(&result.blob_id).await.unwrap();
assert_eq!(retrieved_data.unwrap(), data);
}
}
Loading
Loading