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): Remove kzgpad #339

Merged
merged 2 commits into from
Nov 15, 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
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/node/da_clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pbjson-types.workspace = true
# Eigen dependencies
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
Expand Down
57 changes: 55 additions & 2 deletions core/node/da_clients/src/eigen/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ impl RawEigenClient {
is_retriable: false,
});
}
//TODO: remove zkgpad_rs
let data = kzgpad_rs::remove_empty_byte_from_padded_bytes(&get_response.data);

let data = remove_empty_byte_from_padded_bytes(&get_response.data);
Ok(Some(data))
}
}
Expand Down Expand Up @@ -383,3 +383,56 @@ fn convert_by_padding_empty_byte(data: &[u8]) -> Vec<u8> {
valid_data.truncate(valid_end);
valid_data
}

#[cfg(test)]
fn remove_empty_byte_from_padded_bytes(data: &[u8]) -> Vec<u8> {
let parse_size = DATA_CHUNK_SIZE;

// 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 - 1)];
let mut valid_end = data_len * (DATA_CHUNK_SIZE - 1);

for (i, chunk) in data.chunks(parse_size).enumerate() {
let offset = i * (DATA_CHUNK_SIZE - 1);

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

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

valid_data.truncate(valid_end);
valid_data
}

#[cfg(test)]
mod test {
#[test]
fn test_pad_and_unpad() {
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
let padded_data = super::convert_by_padding_empty_byte(&data);
let unpadded_data = super::remove_empty_byte_from_padded_bytes(&padded_data);
assert_eq!(data, unpadded_data);
}

#[test]
fn test_pad_and_unpad_large() {
let data = vec![1; 1000];
let padded_data = super::convert_by_padding_empty_byte(&data);
let unpadded_data = super::remove_empty_byte_from_padded_bytes(&padded_data);
assert_eq!(data, unpadded_data);
}

#[test]
fn test_pad_and_unpad_empty() {
let data = Vec::new();
let padded_data = super::convert_by_padding_empty_byte(&data);
let unpadded_data = super::remove_empty_byte_from_padded_bytes(&padded_data);
assert_eq!(data, unpadded_data);
}
}
Loading