From 385c4c46bd678774a81c83251847cc48652a167d Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 20 Dec 2024 21:42:06 +0000 Subject: [PATCH] can read eigenda v1 cert --- Cargo.lock | 2 + bin/client/justfile | 4 +- bin/host/Cargo.toml | 1 + bin/host/src/eigenda_fetcher/mod.rs | 9 ++++ crates/eigenda/Cargo.toml | 1 + crates/eigenda/src/certificate.rs | 76 +++++++++++++++++++++++++++++ crates/eigenda/src/lib.rs | 4 ++ 7 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 crates/eigenda/src/certificate.rs diff --git a/Cargo.lock b/Cargo.lock index 171dfe4..80614e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1723,6 +1723,7 @@ name = "hokulea-eigenda" version = "0.1.0" dependencies = [ "alloy-primitives", + "alloy-rlp", "async-trait", "kona-derive", "op-alloy-protocol", @@ -1740,6 +1741,7 @@ dependencies = [ "async-trait", "clap", "hokulea-client", + "hokulea-eigenda", "hokulea-proof", "kona-host", "kona-preimage", diff --git a/bin/client/justfile b/bin/client/justfile index 9ac832d..de993ed 100644 --- a/bin/client/justfile +++ b/bin/client/justfile @@ -69,7 +69,7 @@ run-client-native-against-devnet verbosity='' block_number='' rollup_config_path L1_BEACON_RPC="http://127.0.0.1:5052" L2_RPC="http://127.0.0.1:9545" ROLLUP_NODE_RPC="http://127.0.0.1:7545" - ROLLUP_CONFIG_PATH="../../../optimism/.devnet/rollup.json" + ROLLUP_CONFIG_PATH="/home/ubuntu/op-main-repo/.devnet/rollup.json" if [ -z "{{block_number}}" ]; then BLOCK_NUMBER=$(cast block finalized --json --rpc-url $L2_RPC | jq -r .number | cast 2d) @@ -120,7 +120,7 @@ run-client-native block_number l1_rpc l1_beacon_rpc l2_rpc rollup_node_rpc rollu cd $(git rev-parse --show-toplevel) echo "Running host program with native client program..." - cargo r --bin hokulea-host --release -- \ + cargo r --bin hokulea-host -- \ --l1-head $L1_HEAD \ --agreed-l2-head-hash $AGREED_L2_HEAD_HASH \ --claimed-l2-output-root $CLAIMED_L2_OUTPUT_ROOT \ diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index e286988..69820d0 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" # Workspace hokulea-proof.workspace = true hokulea-client.workspace = true +hokulea-eigenda.workspace = true # Kona kona-preimage = { workspace = true, features = ["std"] } diff --git a/bin/host/src/eigenda_fetcher/mod.rs b/bin/host/src/eigenda_fetcher/mod.rs index 643785d..976e78c 100644 --- a/bin/host/src/eigenda_fetcher/mod.rs +++ b/bin/host/src/eigenda_fetcher/mod.rs @@ -12,6 +12,8 @@ use kona_preimage::{PreimageKey, PreimageKeyType}; use std::sync::Arc; use tokio::sync::RwLock; use tracing::{error, info, trace, warn}; +use hokulea_eigenda::BlobInfo; +use alloy_rlp::{Decodable}; /// The [FetcherWithEigenDASupport] struct wraps and extends kona's [Fetcher] struct with the ability /// to fetch preimages from EigenDA. @@ -136,6 +138,13 @@ where trace!(target: "fetcher_with_eigenda_support", "Fetching hint: {hint_type} {hint_data}"); if hint_type == ExtendedHintType::EigenDACommitment { + + let item_slice= hint_data.as_ref(); + + // the fourth because 0x01010000 in the beginnin is metadata + let cert_blob_info = BlobInfo::decode(&mut &item_slice[4..])?; + info!("cert_blob_info {:?}", cert_blob_info); + let cert = hint_data; info!(target: "fetcher_with_eigenda_support", "Fetching AltDACommitment cert: {:?}", cert); // Fetch the blob sidecar from the blob provider. diff --git a/crates/eigenda/Cargo.toml b/crates/eigenda/Cargo.toml index 258342d..baa1f5f 100644 --- a/crates/eigenda/Cargo.toml +++ b/crates/eigenda/Cargo.toml @@ -9,6 +9,7 @@ kona-derive.workspace = true # Op Alloy op-alloy-protocol.workspace = true alloy-primitives.workspace = true +alloy-rlp.workspace = true tracing.workspace = true async-trait.workspace = true diff --git a/crates/eigenda/src/certificate.rs b/crates/eigenda/src/certificate.rs new file mode 100644 index 0000000..1ecdcaa --- /dev/null +++ b/crates/eigenda/src/certificate.rs @@ -0,0 +1,76 @@ +// data struct copied from https://github.com/Layr-Labs/eigenda-client-rs/blob/3ac1f62ae3d99aedf3de7a2fe827fab17db7b874/src/blob_info.rs +use core::fmt; + +use alloy_primitives::Bytes; +use alloy_rlp::{RlpDecodable, RlpEncodable}; + +use alloc::vec::Vec; + + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct G1Commitment { + pub x: [u8; 32], + pub y: [u8; 32], +} + + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct BlobQuorumParam { + pub quorum_number: u32, + pub adversary_threshold_percentage: u32, + pub confirmation_threshold_percentage: u32, + pub chunk_length: u32, +} + +impl BlobQuorumParam { + pub fn to_bytes(&self) -> Vec { + let mut bytes = Vec::new(); + 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 + } +} + + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct BlobHeader { + pub commitment: G1Commitment, + pub data_length: u32, + pub blob_quorum_params: Vec, +} + + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct BatchHeader { + pub batch_root: Bytes, + pub quorum_numbers: Bytes, + pub quorum_signed_percentages: Bytes, + pub reference_block_number: u32, +} + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct BatchMetadata { + pub batch_header: BatchHeader, + pub signatory_record_hash: Bytes, + pub fee: Bytes, + pub confirmation_block_number: u32, + pub batch_header_hash: Bytes, +} + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct BlobVerificationProof { + pub batch_id: u32, + pub blob_index: u32, + pub batch_medatada: BatchMetadata, + pub inclusion_proof: Bytes, + pub quorum_indexes: Bytes, +} + +#[derive(Debug, PartialEq, Clone, RlpEncodable, RlpDecodable)] +pub struct BlobInfo { + pub blob_header: BlobHeader, + pub blob_verification_proof: BlobVerificationProof, +} diff --git a/crates/eigenda/src/lib.rs b/crates/eigenda/src/lib.rs index b62f3f5..e457bbf 100644 --- a/crates/eigenda/src/lib.rs +++ b/crates/eigenda/src/lib.rs @@ -26,3 +26,7 @@ pub use eigenda_blobs::EigenDABlobSource; mod eigenda_data; pub use eigenda_data::EigenDABlobData; + +mod certificate; +pub use certificate::BlobInfo; +