diff --git a/Cargo.lock b/Cargo.lock index fb955a9f9..1b9a9b25f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2390,7 +2390,6 @@ dependencies = [ "op-alloy-registry", "op-alloy-rpc-types-engine", "proptest", - "serde", "serde_json", "spin", "thiserror 2.0.3", diff --git a/bin/host/src/fetcher/mod.rs b/bin/host/src/fetcher/mod.rs index 07557348e..18f777222 100644 --- a/bin/host/src/fetcher/mod.rs +++ b/bin/host/src/fetcher/mod.rs @@ -7,7 +7,11 @@ use crate::{ util, }; use alloy_consensus::{Header, TxEnvelope, EMPTY_ROOT_HASH}; -use alloy_eips::{eip2718::Encodable2718, eip4844::FIELD_ELEMENTS_PER_BLOB, BlockId}; +use alloy_eips::{ + eip2718::Encodable2718, + eip4844::{IndexedBlobHash, FIELD_ELEMENTS_PER_BLOB}, + BlockId, +}; use alloy_primitives::{address, keccak256, map::HashMap, Address, Bytes, B256}; use alloy_provider::{Provider, ReqwestProvider}; use alloy_rlp::{Decodable, EMPTY_STRING_CODE}; @@ -16,7 +20,6 @@ use alloy_rpc_types::{ Transaction, }; use anyhow::{anyhow, Result}; -use kona_derive::sources::IndexedBlobHash; use kona_preimage::{PreimageKey, PreimageKeyType}; use kona_proof::HintType; use op_alloy_protocol::BlockInfo; @@ -187,7 +190,7 @@ where let timestamp = u64::from_be_bytes(timestamp_data_bytes); let partial_block_ref = BlockInfo { timestamp, ..Default::default() }; - let indexed_hash = IndexedBlobHash { index: index as usize, hash }; + let indexed_hash = IndexedBlobHash { index, hash }; // Fetch the blob sidecar from the blob provider. let mut sidecars = self diff --git a/bin/host/src/providers/beacon.rs b/bin/host/src/providers/beacon.rs index 0447b9290..9f6b84748 100644 --- a/bin/host/src/providers/beacon.rs +++ b/bin/host/src/providers/beacon.rs @@ -1,8 +1,8 @@ //! Contains an online implementation of the `BeaconClient` trait. +use alloy_eips::eip4844::IndexedBlobHash; use alloy_rpc_types_beacon::sidecar::{BeaconBlobBundle, BlobData}; use async_trait::async_trait; -use kona_derive::sources::IndexedBlobHash; use reqwest::Client; /// The config spec engine api method. @@ -128,7 +128,7 @@ impl BeaconClient for OnlineBeaconClient { let mut sidecars = Vec::with_capacity(hashes.len()); hashes.iter().for_each(|hash| { if let Some(sidecar) = - raw_response.data.iter().find(|sidecar| sidecar.index == hash.index as u64) + raw_response.data.iter().find(|sidecar| sidecar.index == hash.index) { sidecars.push(sidecar.clone()); } diff --git a/bin/host/src/providers/blob.rs b/bin/host/src/providers/blob.rs index a8a96d7cb..f719537b3 100644 --- a/bin/host/src/providers/blob.rs +++ b/bin/host/src/providers/blob.rs @@ -1,10 +1,10 @@ //! Contains an online implementation of the `BlobProvider` trait. use crate::providers::{BeaconClient, OnlineBeaconClient}; -use alloy_eips::eip4844::{Blob, BlobTransactionSidecarItem}; +use alloy_eips::eip4844::{Blob, BlobTransactionSidecarItem, IndexedBlobHash}; use alloy_rpc_types_beacon::sidecar::BlobData; use async_trait::async_trait; -use kona_derive::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider}; +use kona_derive::{errors::BlobProviderError, traits::BlobProvider}; use op_alloy_protocol::BlockInfo; use tracing::warn; @@ -103,10 +103,10 @@ impl OnlineBlobProvider { let sidecars = self.fetch_sidecars(slot, blob_hashes).await?; // Filter blob sidecars that match the indicies in the specified list. - let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::>(); + let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::>(); let filtered = sidecars .into_iter() - .filter(|s| blob_hash_indicies.contains(&(s.index as usize))) + .filter(|s| blob_hash_indicies.contains(&s.index)) .collect::>(); // Validate the correct number of blob sidecars were retrieved. @@ -156,10 +156,7 @@ where let hash = blob_hashes .get(i) .ok_or(BlobProviderError::Backend("Missing blob hash".to_string()))?; - match sidecar.verify_blob(&alloy_eips::eip4844::IndexedBlobHash { - hash: hash.hash, - index: hash.index as u64, - }) { + match sidecar.verify_blob(&IndexedBlobHash { hash: hash.hash, index: hash.index }) { Ok(_) => Ok(sidecar.blob), Err(e) => Err(BlobProviderError::Backend(e.to_string())), } @@ -253,7 +250,7 @@ impl OnlineBlobProviderWithFallback>(); let filtered = sidecars .into_iter() - .filter(|s| blob_hash_indicies.contains(&(s.index as usize))) + .filter(|s| blob_hash_indicies.contains(&s.index)) .collect::>(); // Validate the correct number of blob sidecars were retrieved. @@ -312,10 +309,9 @@ where let hash = blob_hashes.get(i).ok_or(BlobProviderError::Backend( "fallback: failed to get blob hash".to_string(), ))?; - match sidecar.verify_blob(&alloy_eips::eip4844::IndexedBlobHash { - hash: hash.hash, - index: hash.index as u64, - }) { + match sidecar + .verify_blob(&IndexedBlobHash { hash: hash.hash, index: hash.index }) + { Ok(_) => Ok(sidecar.blob), Err(e) => Err(BlobProviderError::Backend(e.to_string())), } diff --git a/crates/derive/Cargo.toml b/crates/derive/Cargo.toml index e9c27c7b1..a24305053 100644 --- a/crates/derive/Cargo.toml +++ b/crates/derive/Cargo.toml @@ -30,9 +30,6 @@ tracing.workspace = true async-trait.workspace = true thiserror.workspace = true -# `serde` feature dependencies -serde = { workspace = true, optional = true, features = ["derive"] } - # `test-utils` feature dependencies spin = { workspace = true, optional = true } tracing-subscriber = { workspace = true, optional = true, features = ["fmt"] } @@ -47,9 +44,8 @@ tracing-subscriber = { workspace = true, features = ["fmt"] } alloy-primitives = { workspace = true, features = ["rlp", "k256", "map", "arbitrary"] } [features] -default = ["serde"] +default = [] serde = [ - "dep:serde", "alloy-primitives/serde", "alloy-consensus/serde", "op-alloy-consensus/serde", diff --git a/crates/derive/src/sources/blob_hash.rs b/crates/derive/src/sources/blob_hash.rs deleted file mode 100644 index 18008936b..000000000 --- a/crates/derive/src/sources/blob_hash.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! Contains the `BlobHash` type and related types. - -use alloy_primitives::B256; - -/// A Blob hash -#[derive(Default, Clone, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct IndexedBlobHash { - /// The index of the blob - pub index: usize, - /// The hash of the blob - pub hash: B256, -} - -impl PartialEq for IndexedBlobHash { - fn eq(&self, other: &Self) -> bool { - self.index == other.index && self.hash == other.hash - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_indexed_blob_hash() { - let hash = B256::from([1; 32]); - let indexed_blob_hash = IndexedBlobHash { index: 1, hash }; - - assert_eq!(indexed_blob_hash.index, 1); - assert_eq!(indexed_blob_hash.hash, hash); - } - - #[test] - #[cfg(feature = "serde")] - fn test_indexed_blob_hash_serde_roundtrip() { - let hash = B256::from([1; 32]); - let indexed_blob_hash = IndexedBlobHash { index: 1, hash }; - - let serialized = serde_json::to_string(&indexed_blob_hash).unwrap(); - let deserialized: IndexedBlobHash = serde_json::from_str(&serialized).unwrap(); - - assert_eq!(indexed_blob_hash, deserialized); - } -} diff --git a/crates/derive/src/sources/blobs.rs b/crates/derive/src/sources/blobs.rs index 87bb97b56..f97b41d01 100644 --- a/crates/derive/src/sources/blobs.rs +++ b/crates/derive/src/sources/blobs.rs @@ -2,12 +2,13 @@ use crate::{ errors::{BlobProviderError, PipelineError}, - sources::{BlobData, IndexedBlobHash}, + sources::BlobData, traits::{BlobProvider, ChainProvider, DataAvailabilityProvider}, types::PipelineResult, }; use alloc::{boxed::Box, string::ToString, vec::Vec}; use alloy_consensus::{Transaction, TxEip4844Variant, TxEnvelope, TxType}; +use alloy_eips::eip4844::IndexedBlobHash; use alloy_primitives::{Address, Bytes}; use async_trait::async_trait; use op_alloy_protocol::BlockInfo; @@ -56,7 +57,7 @@ where } fn extract_blob_data(&self, txs: Vec) -> (Vec, Vec) { - let mut number: u64 = 0; + let mut index: u64 = 0; let mut data = Vec::new(); let mut hashes = Vec::new(); for tx in txs { @@ -78,11 +79,11 @@ where let Some(to) = tx_kind else { continue }; if to != self.batcher_address { - number += blob_hashes.map_or(0, |h| h.len() as u64); + index += blob_hashes.map_or(0, |h| h.len() as u64); continue; } if tx.recover_signer().unwrap_or_default() != self.signer { - number += blob_hashes.map_or(0, |h| h.len() as u64); + index += blob_hashes.map_or(0, |h| h.len() as u64); continue; } if tx.tx_type() != TxType::Eip4844 { @@ -105,11 +106,11 @@ where } else { continue; }; - for blob in blob_hashes { - let indexed = IndexedBlobHash { hash: blob, index: number as usize }; + for hash in blob_hashes { + let indexed = IndexedBlobHash { hash, index }; hashes.push(indexed); data.push(BlobData::default()); - number += 1; + index += 1; } } (data, hashes) diff --git a/crates/derive/src/sources/mod.rs b/crates/derive/src/sources/mod.rs index 7ddd4b33a..e0c9772d3 100644 --- a/crates/derive/src/sources/mod.rs +++ b/crates/derive/src/sources/mod.rs @@ -7,9 +7,6 @@ //! [DataAvailabilityProvider]: crate::traits::DataAvailabilityProvider //! [BlockInfo]: op_alloy_protocol::BlockInfo -mod blob_hash; -pub use blob_hash::IndexedBlobHash; - mod blob_data; pub use blob_data::BlobData; diff --git a/crates/derive/src/test_utils/blob_provider.rs b/crates/derive/src/test_utils/blob_provider.rs index b8cfe74fa..f5c2e19db 100644 --- a/crates/derive/src/test_utils/blob_provider.rs +++ b/crates/derive/src/test_utils/blob_provider.rs @@ -1,8 +1,8 @@ //! An implementation of the [BlobProvider] trait for tests. -use crate::{errors::BlobProviderError, sources::IndexedBlobHash, traits::BlobProvider}; +use crate::{errors::BlobProviderError, traits::BlobProvider}; use alloc::{boxed::Box, vec::Vec}; -use alloy_eips::eip4844::Blob; +use alloy_eips::eip4844::{Blob, IndexedBlobHash}; use alloy_primitives::{map::HashMap, B256}; use async_trait::async_trait; use op_alloy_protocol::BlockInfo; diff --git a/crates/derive/src/traits/data_sources.rs b/crates/derive/src/traits/data_sources.rs index 027e42186..18e51bf99 100644 --- a/crates/derive/src/traits/data_sources.rs +++ b/crates/derive/src/traits/data_sources.rs @@ -1,9 +1,9 @@ //! Contains traits that describe the functionality of various data sources used in the derivation //! pipeline's stages. -use crate::{errors::PipelineErrorKind, sources::IndexedBlobHash, types::PipelineResult}; +use crate::{errors::PipelineErrorKind, types::PipelineResult}; use alloc::{boxed::Box, fmt::Debug, string::ToString, vec::Vec}; -use alloy_eips::eip4844::Blob; +use alloy_eips::eip4844::{Blob, IndexedBlobHash}; use alloy_primitives::Bytes; use async_trait::async_trait; use core::fmt::Display; diff --git a/crates/proof-sdk/proof/src/l1/blob_provider.rs b/crates/proof-sdk/proof/src/l1/blob_provider.rs index 57dd967c9..5d66d7f92 100644 --- a/crates/proof-sdk/proof/src/l1/blob_provider.rs +++ b/crates/proof-sdk/proof/src/l1/blob_provider.rs @@ -3,10 +3,10 @@ use crate::{errors::OracleProviderError, HintType}; use alloc::{boxed::Box, sync::Arc, vec::Vec}; use alloy_consensus::Blob; -use alloy_eips::eip4844::FIELD_ELEMENTS_PER_BLOB; +use alloy_eips::eip4844::{IndexedBlobHash, FIELD_ELEMENTS_PER_BLOB}; use alloy_primitives::keccak256; use async_trait::async_trait; -use kona_derive::{sources::IndexedBlobHash, traits::BlobProvider}; +use kona_derive::traits::BlobProvider; use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType}; use op_alloy_protocol::BlockInfo;