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(eips): Blob Sidecar Item Serde #1441

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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
21 changes: 18 additions & 3 deletions crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl IntoIterator for BlobTransactionSidecar {
.zip(self.proofs)
.enumerate()
.map(|(index, ((blob, commitment), proof))| BlobTransactionSidecarItem {
index,
index: index as u64,
blob: Box::new(blob),
kzg_commitment: commitment,
kzg_proof: proof,
Expand All @@ -64,7 +64,8 @@ impl IntoIterator for BlobTransactionSidecar {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlobTransactionSidecarItem {
/// The index of this item within the [BlobTransactionSidecar].
pub index: usize,
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub index: u64,
/// The blob in this sidecar item.
#[cfg_attr(feature = "serde", serde(deserialize_with = "super::deserialize_blob"))]
pub blob: Box<Blob>,
Expand Down Expand Up @@ -107,7 +108,7 @@ impl BlobTransactionSidecarItem {

/// Verify the blob sidecar against its [crate::NumHash].
pub fn verify_blob(&self, hash: &crate::NumHash) -> Result<(), BlobTransactionValidationError> {
if self.index != hash.number as usize {
if self.index != hash.number {
let blob_hash_part = B256::from_slice(&self.blob[0..32]);
return Err(BlobTransactionValidationError::WrongVersionedHash {
have: blob_hash_part,
Expand Down Expand Up @@ -410,4 +411,18 @@ mod tests {
let mut unstructured = arbitrary::Unstructured::new(b"unstructured blob");
let _blob = BlobTransactionSidecar::arbitrary(&mut unstructured).unwrap();
}

#[test]
fn test_blob_item_serde_roundtrip() {
let blob_item = BlobTransactionSidecarItem {
index: 0,
blob: Box::new(Blob::default()),
kzg_commitment: Bytes48::default(),
kzg_proof: Bytes48::default(),
};

let s = serde_json::to_string(&blob_item).unwrap();
let deserialized: BlobTransactionSidecarItem = serde_json::from_str(&s).unwrap();
assert_eq!(blob_item, deserialized);
}
}