Skip to content

Commit

Permalink
fix decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 26, 2024
1 parent f3822d4 commit 230f53c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ impl Decodable for PooledTransactionsElement {
let tx_type = *buf.first().ok_or(RlpError::InputTooShort)?;
let remaining_len = buf.len();

// Aadvance the buffer past the type byte
buf.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 @@ -604,11 +607,8 @@ impl Decodable for 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
buf.advance(1);

// Now, we decode the inner blob transaction:
// Decode the inner blob transaction:
// `rlp([[chain_id, nonce, ...], blobs, commitments, proofs])`
let blob_tx = BlobTransaction::decode_inner(buf)?;

Expand All @@ -620,12 +620,11 @@ impl Decodable for PooledTransactionsElement {

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(buf).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, buf).map_err(|err| match err {
Eip2718Error::RlpError(err) => err,
_ => RlpError::Custom("failed to decode EIP-2718 transaction"),
})?;

// check that the bytes consumed match the payload length
let bytes_consumed = remaining_len - buf.len();
Expand Down

0 comments on commit 230f53c

Please sign in to comment.