Skip to content

Commit

Permalink
avoid possible panic when forming blobs bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed May 6, 2024
1 parent a6c2a3a commit 175c4ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mev-build-rs/src/auctioneer/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn prepare_submission(
Fork::Deneb => SignedBidSubmission::Deneb(block_submission::deneb::SignedBidSubmission {
message,
execution_payload,
blobs_bundle: to_blobs_bundle(payload.sidecars()),
blobs_bundle: to_blobs_bundle(payload.sidecars())?,
signature,
}),
other => unreachable!("fork {other} is not reachable from this type"),
Expand Down
25 changes: 18 additions & 7 deletions mev-build-rs/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
pub mod compat {
use crate::Error;
use ethereum_consensus::{
deneb::polynomial_commitments::{KzgCommitment, KzgProof},
primitives::{Bytes32, ExecutionAddress},
ssz::prelude::{ByteList, ByteVector, List, U256},
ssz::prelude::{ByteList, ByteVector, SimpleSerializeError, U256},
};
use mev_rs::types::{BlobsBundle, ExecutionPayload};
use reth::primitives::{Address, BlobTransactionSidecar, Bloom, SealedBlock, B256};
Expand Down Expand Up @@ -68,12 +69,11 @@ pub mod compat {
ExecutionPayload::Deneb(payload)
}

pub fn to_blobs_bundle(sidecars: &[BlobTransactionSidecar]) -> BlobsBundle {
let mut commitments = List::default();
let mut proofs = List::default();
let mut blobs = List::default();
pub fn to_blobs_bundle(sidecars: &[BlobTransactionSidecar]) -> Result<BlobsBundle, Error> {
let mut commitments = vec![];
let mut proofs = vec![];
let mut blobs = vec![];

// TODO: perform length checks to avoid panic on `push`
for sidecar in sidecars {
for commitment in &sidecar.commitments {
let commitment = KzgCommitment::try_from(commitment.as_slice()).unwrap();
Expand All @@ -89,6 +89,17 @@ pub mod compat {
}
}

BlobsBundle { commitments, proofs, blobs }
Ok(BlobsBundle {
commitments: commitments
.try_into()
.map_err(|(_, err): (_, SimpleSerializeError)| Error::Consensus(err.into()))?,
proofs: proofs
.try_into()
.map_err(|(_, err): (_, SimpleSerializeError)| Error::Consensus(err.into()))?,

blobs: blobs
.try_into()
.map_err(|(_, err): (_, SimpleSerializeError)| Error::Consensus(err.into()))?,
})
}
}

0 comments on commit 175c4ef

Please sign in to comment.