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

fix: add check before allocation in SimpleCoder::decode_one() #689

Merged
merged 1 commit into from
May 5, 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
7 changes: 6 additions & 1 deletion crates/consensus/src/transaction/eip4844/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use c_kzg::{KzgCommitment, KzgProof};
use alloc::vec::Vec;

use super::utils::WholeFe;
use alloy_eips::eip4844::{BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB};
use alloy_eips::eip4844::{BYTES_PER_BLOB, FIELD_ELEMENTS_PER_BLOB, MAX_BLOBS_PER_BLOCK};
use core::cmp;

/// A builder for creating a [`BlobTransactionSidecar`].
Expand Down Expand Up @@ -196,6 +196,11 @@ impl SimpleCoder {
return Ok(None);
}

// if there are too many bytes
if num_bytes > BYTES_PER_BLOB * MAX_BLOBS_PER_BLOCK {
return Err(());
}

let mut res = Vec::with_capacity(num_bytes);
while num_bytes > 0 {
let to_copy = cmp::min(31, num_bytes);
Expand Down
Loading