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

feat: port generate_blob_sidecar #1511

Merged
merged 1 commit into from
Oct 18, 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
28 changes: 28 additions & 0 deletions crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ impl BlobTransactionSidecar {
self.commitments.len() * BYTES_PER_COMMITMENT + // commitments
self.proofs.len() * BYTES_PER_PROOF // proofs
}

/// Tries to create a new [`BlobTransactionSidecar`] from the given blobs.
#[cfg(all(feature = "kzg", any(test, feature = "arbitrary")))]
pub fn try_from_blobs(blobs: Vec<c_kzg::Blob>) -> Result<Self, c_kzg::Error> {
use crate::eip4844::env_settings::EnvKzgSettings;
use c_kzg::{KzgCommitment, KzgProof};

let kzg_settings = EnvKzgSettings::Default;

let commitments = blobs
.iter()
.map(|blob| {
KzgCommitment::blob_to_kzg_commitment(&blob.clone(), kzg_settings.get())
.map(|blob| blob.to_bytes())
})
.collect::<Result<Vec<_>, _>>()?;

let proofs = blobs
.iter()
.zip(commitments.iter())
.map(|(blob, commitment)| {
KzgProof::compute_blob_kzg_proof(blob, commitment, kzg_settings.get())
.map(|blob| blob.to_bytes())
})
.collect::<Result<Vec<_>, _>>()?;

Ok(Self::from_kzg(blobs, commitments, proofs))
}
}

impl Encodable for BlobTransactionSidecar {
Expand Down