From 04e5e6c55a77baa7df5d8d6cb18296664a7527db Mon Sep 17 00:00:00 2001 From: refcell Date: Fri, 18 Oct 2024 19:58:38 -0400 Subject: [PATCH] feat: indexed blob hash --- crates/eips/src/eip4844/sidecar.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/eips/src/eip4844/sidecar.rs b/crates/eips/src/eip4844/sidecar.rs index 2db41652f89..1ce899d99e3 100644 --- a/crates/eips/src/eip4844/sidecar.rs +++ b/crates/eips/src/eip4844/sidecar.rs @@ -16,6 +16,16 @@ use alloc::vec::Vec; #[cfg(feature = "kzg")] pub(crate) const VERSIONED_HASH_VERSION_KZG: u8 = 0x01; +/// A Blob hash +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct IndexedBlobHash { + /// The index of the blob + pub index: u64, + /// The hash of the blob + pub hash: B256, +} + /// This represents a set of blobs, and its corresponding commitments and proofs. /// /// This type encodes and decodes the fields without an rlp header. @@ -105,9 +115,12 @@ impl BlobTransactionSidecarItem { result.then_some(()).ok_or(BlobTransactionValidationError::InvalidProof) } - /// Verify the blob sidecar against its [crate::NumHash]. - pub fn verify_blob(&self, hash: &crate::NumHash) -> Result<(), BlobTransactionValidationError> { - if self.index != hash.number { + /// Verify the blob sidecar against its [IndexedBlobHash]. + pub fn verify_blob( + &self, + hash: &IndexedBlobHash, + ) -> Result<(), BlobTransactionValidationError> { + if self.index != hash.index { let blob_hash_part = B256::from_slice(&self.blob[0..32]); return Err(BlobTransactionValidationError::WrongVersionedHash { have: blob_hash_part,