Validation on decoding NewPooledTransactions68 (#6090)

This commit is contained in:
Emilia Hane
2024-01-23 12:06:28 +01:00
committed by GitHub
parent 2b97e0cb9f
commit e1e81059fe

View File

@ -283,10 +283,22 @@ pub struct NewPooledTransactionHashes68 {
/// instead use the [`Encodable`](alloy_rlp::Encodable) and [`Decodable`](alloy_rlp::Decodable) /// instead use the [`Encodable`](alloy_rlp::Encodable) and [`Decodable`](alloy_rlp::Decodable)
/// implementations for `&[u8]` instead, which encodes into a RLP string, and expects an RLP /// implementations for `&[u8]` instead, which encodes into a RLP string, and expects an RLP
/// string when decoding. /// string when decoding.
#[cfg_attr(
any(test, feature = "arbitrary"),
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<u8>(), 100)")
)]
pub types: Vec<u8>, pub types: Vec<u8>,
/// Transaction sizes for new transactions that have appeared on the network. /// Transaction sizes for new transactions that have appeared on the network.
#[cfg_attr(
any(test, feature = "arbitrary"),
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<usize>(), 100)")
)]
pub sizes: Vec<usize>, pub sizes: Vec<usize>,
/// Transaction hashes for new transactions that have appeared on the network. /// Transaction hashes for new transactions that have appeared on the network.
#[cfg_attr(
any(test, feature = "arbitrary"),
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<B256>(), 100)")
)]
pub hashes: Vec<B256>, pub hashes: Vec<B256>,
} }
@ -342,7 +354,26 @@ impl Decodable for NewPooledTransactionHashes68 {
} }
let encodable = EncodableNewPooledTransactionHashes68::decode(buf)?; let encodable = EncodableNewPooledTransactionHashes68::decode(buf)?;
Ok(Self { types: encodable.types.into(), sizes: encodable.sizes, hashes: encodable.hashes }) let msg = Self {
types: encodable.types.into(),
sizes: encodable.sizes,
hashes: encodable.hashes,
};
if msg.hashes.len() != msg.types.len() {
return Err(alloy_rlp::Error::ListLengthMismatch {
expected: msg.hashes.len(),
got: msg.types.len(),
})
}
if msg.hashes.len() != msg.sizes.len() {
return Err(alloy_rlp::Error::ListLengthMismatch {
expected: msg.hashes.len(),
got: msg.sizes.len(),
})
}
Ok(msg)
} }
} }