Skip to content

Commit f2fb12c

Browse files
authored
feat(eigen-client-extra-features): Remove kzgpad (#339)
* Remove kzgpad * Add empty pad and unpad test
1 parent f55a424 commit f2fb12c

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

Cargo.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/node/da_clients/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pbjson-types.workspace = true
5656
# Eigen dependencies
5757
tokio-stream.workspace = true
5858
rlp.workspace = true
59-
kzgpad-rs = { git = "https://github.com/Layr-Labs/kzgpad-rs.git", tag = "v0.1.0" }
6059
rand.workspace = true
6160
sha3.workspace = true
6261
tiny-keccak.workspace = true

core/node/da_clients/src/eigen/sdk.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ impl RawEigenClient {
344344
is_retriable: false,
345345
});
346346
}
347-
//TODO: remove zkgpad_rs
348-
let data = kzgpad_rs::remove_empty_byte_from_padded_bytes(&get_response.data);
347+
348+
let data = remove_empty_byte_from_padded_bytes(&get_response.data);
349349
Ok(Some(data))
350350
}
351351
}
@@ -383,3 +383,56 @@ fn convert_by_padding_empty_byte(data: &[u8]) -> Vec<u8> {
383383
valid_data.truncate(valid_end);
384384
valid_data
385385
}
386+
387+
#[cfg(test)]
388+
fn remove_empty_byte_from_padded_bytes(data: &[u8]) -> Vec<u8> {
389+
let parse_size = DATA_CHUNK_SIZE;
390+
391+
// Calculate the number of chunks
392+
let data_len = (data.len() + parse_size - 1) / parse_size;
393+
394+
// Pre-allocate `valid_data` with enough space for all chunks
395+
let mut valid_data = vec![0u8; data_len * (DATA_CHUNK_SIZE - 1)];
396+
let mut valid_end = data_len * (DATA_CHUNK_SIZE - 1);
397+
398+
for (i, chunk) in data.chunks(parse_size).enumerate() {
399+
let offset = i * (DATA_CHUNK_SIZE - 1);
400+
401+
let copy_end = offset + chunk.len() - 1;
402+
valid_data[offset..copy_end].copy_from_slice(&chunk[1..]);
403+
404+
if i == data_len - 1 && chunk.len() < parse_size {
405+
valid_end = offset + chunk.len() - 1;
406+
}
407+
}
408+
409+
valid_data.truncate(valid_end);
410+
valid_data
411+
}
412+
413+
#[cfg(test)]
414+
mod test {
415+
#[test]
416+
fn test_pad_and_unpad() {
417+
let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
418+
let padded_data = super::convert_by_padding_empty_byte(&data);
419+
let unpadded_data = super::remove_empty_byte_from_padded_bytes(&padded_data);
420+
assert_eq!(data, unpadded_data);
421+
}
422+
423+
#[test]
424+
fn test_pad_and_unpad_large() {
425+
let data = vec![1; 1000];
426+
let padded_data = super::convert_by_padding_empty_byte(&data);
427+
let unpadded_data = super::remove_empty_byte_from_padded_bytes(&padded_data);
428+
assert_eq!(data, unpadded_data);
429+
}
430+
431+
#[test]
432+
fn test_pad_and_unpad_empty() {
433+
let data = Vec::new();
434+
let padded_data = super::convert_by_padding_empty_byte(&data);
435+
let unpadded_data = super::remove_empty_byte_from_padded_bytes(&padded_data);
436+
assert_eq!(data, unpadded_data);
437+
}
438+
}

0 commit comments

Comments
 (0)