Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 28, 2024
1 parent ca36137 commit 010399e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ impl PooledTransactionsElement {
// decode the type byte, only decode BlobTransaction if it is a 4844 transaction
let tx_type = *data.first().ok_or(RlpError::InputTooShort)?;

// First, we advance the buffer past the type byte
data.advance(1);

if tx_type == EIP4844_TX_TYPE_ID {
// Recall that the blob transaction response `TransactionPayload` is encoded like
// this: `rlp([tx_payload_body, blobs, commitments, proofs])`
Expand All @@ -232,21 +235,17 @@ impl PooledTransactionsElement {
//
// This makes the full encoding:
// `tx_type (0x03) || rlp([[chain_id, nonce, ...], blobs, commitments, proofs])`
//
// First, we advance the buffer past the type byte
data.advance(1);

// Now, we decode the inner blob transaction:
// `rlp([[chain_id, nonce, ...], blobs, commitments, proofs])`
let blob_tx = BlobTransaction::decode_inner(data)?;
Ok(Self::BlobTransaction(blob_tx))
} else {
// DO NOT advance the buffer for the type, since we want the enveloped decoding to
// decode it again and advance the buffer on its own.
let typed_tx = TransactionSigned::decode_2718(data).map_err(|err| match err {
Eip2718Error::RlpError(err) => err,
_ => RlpError::Custom("failed to decode EIP-2718 transaction"),
})?;
let typed_tx =
TransactionSigned::typed_decode(tx_type, data).map_err(|err| match err {
Eip2718Error::RlpError(err) => err,
_ => RlpError::Custom("failed to decode EIP-2718 transaction"),
})?;

// because we checked the tx type, we can be sure that the transaction is not a
// blob transaction or legacy
Expand Down

0 comments on commit 010399e

Please sign in to comment.