Skip to content

Commit

Permalink
fix: add more rlp correctness checks (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Oct 30, 2024
1 parent 86a53f6 commit 193bcd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
22 changes: 18 additions & 4 deletions crates/consensus/src/transaction/rlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,19 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {
if !header.list {
return Err(alloy_rlp::Error::UnexpectedString);
}
let remaining_len = buf.len();
let remaining = buf.len();

if header.payload_length > remaining_len {
if header.payload_length > remaining {
return Err(alloy_rlp::Error::InputTooShort);
}

Self::rlp_decode_fields(buf)
let this = Self::rlp_decode_fields(buf)?;

if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength);
}

Ok(this)
}

/// Decodes the transaction from RLP bytes, including the signature.
Expand Down Expand Up @@ -185,7 +191,15 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {
if header.list {
return Err(alloy_rlp::Error::UnexpectedList.into());
}
Self::eip2718_decode_with_type(buf, ty)

let remaining = buf.len();
let res = Self::eip2718_decode_with_type(buf, ty)?;

if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength.into());
}

Ok(res)
}

/// Decodes the transaction from network bytes, expecting the default type
Expand Down
9 changes: 8 additions & 1 deletion crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ impl BlobTransactionSidecar {
if buf.len() < header.payload_length {
return Err(alloy_rlp::Error::InputTooShort);
}
Self::rlp_decode_fields(buf)
let remaining = buf.len();
let this = Self::rlp_decode_fields(buf)?;

if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength);
}

Ok(this)
}
}

Expand Down

0 comments on commit 193bcd8

Please sign in to comment.