Skip to content

Commit

Permalink
chore(derive): remove indexed blob hash (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Nov 27, 2024
1 parent 89ed209 commit 443dad9
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 85 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

9 changes: 6 additions & 3 deletions bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/host/src/providers/beacon.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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());
}
Expand Down
22 changes: 9 additions & 13 deletions bin/host/src/providers/blob.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -103,10 +103,10 @@ impl<B: BeaconClient> OnlineBlobProvider<B> {
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::<Vec<usize>>();
let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::<Vec<u64>>();
let filtered = sidecars
.into_iter()
.filter(|s| blob_hash_indicies.contains(&(s.index as usize)))
.filter(|s| blob_hash_indicies.contains(&s.index))
.collect::<Vec<_>>();

// Validate the correct number of blob sidecars were retrieved.
Expand Down Expand Up @@ -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())),
}
Expand Down Expand Up @@ -253,7 +250,7 @@ impl<B: BeaconClient, F: BlobSidecarProvider> OnlineBlobProviderWithFallback<B,
let blob_hash_indicies = blob_hashes.iter().map(|b| b.index).collect::<Vec<_>>();
let filtered = sidecars
.into_iter()
.filter(|s| blob_hash_indicies.contains(&(s.index as usize)))
.filter(|s| blob_hash_indicies.contains(&s.index))
.collect::<Vec<_>>();

// Validate the correct number of blob sidecars were retrieved.
Expand Down Expand Up @@ -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())),
}
Expand Down
6 changes: 1 addition & 5 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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",
Expand Down
45 changes: 0 additions & 45 deletions crates/derive/src/sources/blob_hash.rs

This file was deleted.

15 changes: 8 additions & 7 deletions crates/derive/src/sources/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +57,7 @@ where
}

fn extract_blob_data(&self, txs: Vec<TxEnvelope>) -> (Vec<BlobData>, Vec<IndexedBlobHash>) {
let mut number: u64 = 0;
let mut index: u64 = 0;
let mut data = Vec::new();
let mut hashes = Vec::new();
for tx in txs {
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions crates/derive/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions crates/derive/src/test_utils/blob_provider.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions crates/derive/src/traits/data_sources.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions crates/proof-sdk/proof/src/l1/blob_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 443dad9

Please sign in to comment.