Skip to content

Commit

Permalink
Validation on decoding NewPooledTransactions68 (#6090)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Jan 23, 2024
1 parent 2b97e0c commit e1e8105
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion crates/net/eth-wire/src/types/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,22 @@ pub struct NewPooledTransactionHashes68 {
/// 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
/// string when decoding.
#[cfg_attr(
any(test, feature = "arbitrary"),
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<u8>(), 100)")
)]
pub types: Vec<u8>,
/// 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>,
/// 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>,
}

Expand Down Expand Up @@ -342,7 +354,26 @@ impl Decodable for NewPooledTransactionHashes68 {
}

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)
}
}

Expand Down

0 comments on commit e1e8105

Please sign in to comment.