Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 1 addition & 8 deletions crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,7 @@ impl<T: Decodable2718 + Send + Sync + Debug + Unpin + 'static> PayloadBuilderAtt
.unwrap_or_default()
.into_iter()
.map(|data| {
let mut buf = data.as_ref();
let tx = Decodable2718::decode_2718(&mut buf).map_err(alloy_rlp::Error::from)?;

if !buf.is_empty() {
return Err(alloy_rlp::Error::UnexpectedLength);
}

Ok(WithEncoded::new(data, tx))
Decodable2718::decode_2718_exact(data.as_ref()).map(|tx| WithEncoded::new(data, tx))
})
.collect::<Result<_, _>>()?;

Expand Down
9 changes: 6 additions & 3 deletions crates/rpc/rpc-eth-types/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ use std::future::Future;
/// This is a helper function that returns the appropriate RPC-specific error if the input data is
/// malformed.
///
/// See [`alloy_eips::eip2718::Decodable2718::decode_2718`]
pub fn recover_raw_transaction<T: SignedTransaction>(mut data: &[u8]) -> EthResult<Recovered<T>> {
/// This function uses [`alloy_eips::eip2718::Decodable2718::decode_2718_exact`] to ensure
/// that the entire input buffer is consumed and no trailing bytes are allowed.
///
/// See [`alloy_eips::eip2718::Decodable2718::decode_2718_exact`]
pub fn recover_raw_transaction<T: SignedTransaction>(data: &[u8]) -> EthResult<Recovered<T>> {
if data.is_empty() {
return Err(EthApiError::EmptyRawTransactionData)
}

let transaction =
T::decode_2718(&mut data).map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;
T::decode_2718_exact(data).map_err(|_| EthApiError::FailedToDecodeSignedTransaction)?;

SignedTransaction::try_into_recovered(transaction)
.or(Err(EthApiError::InvalidTransactionSignature))
Expand Down
9 changes: 5 additions & 4 deletions crates/transaction-pool/src/maintain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,11 @@ where
tx_backups
.into_iter()
.filter_map(|backup| {
let tx_signed = <P::Transaction as PoolTransaction>::Consensus::decode_2718(
&mut backup.rlp.as_ref(),
)
.ok()?;
let tx_signed =
<P::Transaction as PoolTransaction>::Consensus::decode_2718_exact(
backup.rlp.as_ref(),
)
.ok()?;
let recovered = tx_signed.try_into_recovered().ok()?;
let pool_tx =
<P::Transaction as PoolTransaction>::try_from_consensus(recovered).ok()?;
Expand Down