diff --git a/crates/optimism/payload/src/payload.rs b/crates/optimism/payload/src/payload.rs index ef692ade1b76..a7ead167d768 100644 --- a/crates/optimism/payload/src/payload.rs +++ b/crates/optimism/payload/src/payload.rs @@ -53,12 +53,17 @@ impl PayloadBuilderAttributes for OptimismPayloadBuilderAttributes { .unwrap_or_default() .into_iter() .map(|data| { - TransactionSigned::decode_2718(&mut data.as_ref()) - .map_err(|err| match err { - Eip2718Error::RlpError(err) => err, - _ => alloy_rlp::Error::Custom("invalid transaction"), - }) - .map(|tx| WithEncoded::new(data, tx)) + let mut buf = data.as_ref(); + let tx = TransactionSigned::decode_2718(&mut buf).map_err(|err| match err { + Eip2718Error::RlpError(err) => err, + _ => alloy_rlp::Error::Custom("invalid transaction"), + })?; + + if !buf.is_empty() { + return Err(alloy_rlp::Error::UnexpectedLength); + } + + Ok(WithEncoded::new(data, tx)) }) .collect::>()?; diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index fffba9f658de..3b49fe8258ae 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1982,30 +1982,4 @@ mod tests { assert!(res.is_err()); } - - #[test] - fn decode_envelope_fails_on_trailing_bytes_legacy() { - let data = [201, 3, 56, 56, 128, 43, 36, 27, 128, 3, 192]; - - let result = TransactionSigned::decode_2718(&mut data.as_ref()); - - assert!(result.is_err()); - let Err(Eip2718Error::RlpError(err)) = result else { - panic!("Expected RlpError, got {:?}", result); - }; - assert_eq!(err, RlpError::UnexpectedLength); - } - - #[test] - fn decode_envelope_fails_on_trailing_bytes_eip2718() { - let data = hex!("02f872018307910d808507204d2cb1827d0094388c818ca8b9251b393131c08a736a67ccb19297880320d04823e2701c80c001a0cf024f4815304df2867a1a74e9d2707b6abda0337d2d54a4438d453f4160f190a07ac0e6b3bc9395b5b9c8b9e6d77204a236577a5b18467b9175c01de4faa208d900"); - - let result = TransactionSigned::decode_2718(&mut data.as_ref()); - - assert!(result.is_err()); - let Err(Eip2718Error::RlpError(err)) = result else { - panic!("Expected RlpError, got {:?}", result); - }; - assert_eq!(err, RlpError::UnexpectedLength); - } } diff --git a/crates/rpc/rpc-types-compat/src/engine/payload.rs b/crates/rpc/rpc-types-compat/src/engine/payload.rs index 758523630ea3..734cfe46a5fd 100644 --- a/crates/rpc/rpc-types-compat/src/engine/payload.rs +++ b/crates/rpc/rpc-types-compat/src/engine/payload.rs @@ -28,10 +28,18 @@ pub fn try_payload_v1_to_block(payload: ExecutionPayloadV1) -> Result err, _ => alloy_rlp::Error::Custom("invalid transaction"), - }) + })?; + + if !buf.is_empty() { + return Err(alloy_rlp::Error::UnexpectedLength); + } + + Ok(tx) }) .collect::, _>>()?; let transactions_root = proofs::calculate_transaction_root(&transactions);