From 52be0031e8e9bb3790ae36ccc96244c8e690cae8 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 26 May 2025 15:12:29 +0200 Subject: [PATCH] fix: check encoded size (#16473) --- crates/transaction-pool/src/traits.rs | 4 +++- crates/transaction-pool/src/validate/eth.rs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 0e010845de..e55fad15b5 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -1151,7 +1151,6 @@ impl PoolTransaction for EthPooledTransaction { } fn from_pooled(tx: Recovered) -> Self { - let encoded_length = tx.encode_2718_len(); let (tx, signer) = tx.into_parts(); match tx { PooledTransactionVariant::Eip4844(tx) => { @@ -1161,11 +1160,14 @@ impl PoolTransaction for EthPooledTransaction { let tx = Signed::new_unchecked(tx, sig, hash); let tx = TransactionSigned::from(tx); let tx = Recovered::new_unchecked(tx, signer); + // we only need the encoded length of the transaction, excluding the blob sidecar + let encoded_length = tx.encode_2718_len(); let mut pooled = Self::new(tx, encoded_length); pooled.blob_sidecar = EthBlobTransactionSidecar::Present(blob); pooled } tx => { + let encoded_length = tx.encode_2718_len(); // no blob sidecar let tx = Recovered::new_unchecked(tx.into(), signer); Self::new(tx, encoded_length) diff --git a/crates/transaction-pool/src/validate/eth.rs b/crates/transaction-pool/src/validate/eth.rs index 866a28d33f..577f9d9c08 100644 --- a/crates/transaction-pool/src/validate/eth.rs +++ b/crates/transaction-pool/src/validate/eth.rs @@ -318,11 +318,11 @@ where }; // Reject transactions over defined size to prevent DOS attacks - let tx_input_len = transaction.input().len(); - if tx_input_len > self.max_tx_input_bytes { + let tx_len = transaction.encoded_length(); + if tx_len > self.max_tx_input_bytes { return Err(TransactionValidationOutcome::Invalid( transaction, - InvalidPoolTransactionError::OversizedData(tx_input_len, self.max_tx_input_bytes), + InvalidPoolTransactionError::OversizedData(tx_len, self.max_tx_input_bytes), )) }