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

fix(da-clients): add padding to the data within EigenDA blob #3203

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion core/node/da_clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sha2.workspace = true
prost.workspace = true
bech32.workspace = true
ripemd.workspace = true
tonic = { workspace = true, features = ["tls", "tls-roots", "prost", "codegen"] }
tonic = { workspace = true, features = ["tls-roots", "prost", "codegen"] }
pbjson-types.workspace = true

# Eigen dependencies
Expand Down
31 changes: 30 additions & 1 deletion core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct RawEigenClient {
account_id: String,
}

pub(crate) const DATA_CHUNK_SIZE: usize = 32;

impl RawEigenClient {
pub(crate) const BUFFER_SIZE: usize = 1000;

Expand Down Expand Up @@ -55,9 +57,10 @@ impl RawEigenClient {
let (tx, rx) = mpsc::channel(Self::BUFFER_SIZE);

let response_stream = client_clone.disperse_blob_authenticated(ReceiverStream::new(rx));
let padded_data = convert_by_padding_empty_byte(&data);

// 1. send DisperseBlobRequest
self.disperse_data(data, &tx).await?;
self.disperse_data(padded_data, &tx).await?;

// this await is blocked until the first response on the stream, so we only await after sending the `DisperseBlobRequest`
let mut response_stream = response_stream.await?.into_inner();
Expand Down Expand Up @@ -215,3 +218,29 @@ fn get_account_id(secret_key: &SecretKey) -> String {

format!("0x{}", hex)
}

fn convert_by_padding_empty_byte(data: &[u8]) -> Vec<u8> {
let parse_size = DATA_CHUNK_SIZE - 1;

// Calculate the number of chunks
let data_len = (data.len() + parse_size - 1) / parse_size;

// Pre-allocate `valid_data` with enough space for all chunks
let mut valid_data = vec![0u8; data_len * DATA_CHUNK_SIZE];
let mut valid_end = data_len * DATA_CHUNK_SIZE;

for (i, chunk) in data.chunks(parse_size).enumerate() {
let offset = i * DATA_CHUNK_SIZE;
valid_data[offset] = 0x00; // Set first byte of each chunk to 0x00 for big-endian compliance

let copy_end = offset + 1 + chunk.len();
valid_data[offset + 1..copy_end].copy_from_slice(chunk);

if i == data_len - 1 && chunk.len() < parse_size {
valid_end = offset + 1 + chunk.len();
}
}

valid_data.truncate(valid_end);
valid_data
}
Loading