Skip to content

Commit

Permalink
fix: corrected RLP decoding of eip4844 variant
Browse files Browse the repository at this point in the history
  • Loading branch information
prestwich committed Oct 24, 2024
1 parent a7aba88 commit 72169eb
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use crate::{SignableTransaction, Signed, Transaction, TxType};

use alloc::vec::Vec;
use alloy_eips::{
eip2930::AccessList,
eip4844::{BYTES_PER_BLOB, DATA_GAS_PER_BLOB},
eip7702::SignedAuthorization,
};
use alloy_eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB, eip7702::SignedAuthorization};
use alloy_primitives::{Address, Bytes, ChainId, Signature, TxKind, B256, U256};
use alloy_rlp::{Buf, BufMut, Decodable, Encodable, Header};
use core::mem;
Expand Down Expand Up @@ -295,21 +291,23 @@ impl RlpEcdsaTx for TxEip4844Variant {
}

fn rlp_decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
let header = Header::decode(buf)?;
let needle = &mut &**buf;
let header = Header::decode(needle)?;
if !header.list {
return Err(alloy_rlp::Error::UnexpectedString);
}
let remaining_len = buf.len();

let remaining_len = needle.len();
if header.payload_length > remaining_len {
return Err(alloy_rlp::Error::InputTooShort);
}

if header.payload_length > BYTES_PER_BLOB {
TxEip4844WithSidecar::rlp_decode(buf).map(Into::into)
} else {
TxEip4844::rlp_decode(buf).map(Into::into)
let chunk = &mut &buf[..header.length_with_payload()];
let res = Self::rlp_decode_fields(chunk)?;
if !chunk.is_empty() {
return Err(alloy_rlp::Error::UnexpectedLength);
}
buf.advance(header.length_with_payload());
Ok(res)
}

fn rlp_decode_with_signature(buf: &mut &[u8]) -> alloy_rlp::Result<(Self, Signature)> {
Expand Down Expand Up @@ -759,12 +757,6 @@ impl TxEip4844WithSidecar {
pub fn into_parts(self) -> (TxEip4844, BlobTransactionSidecar) {
(self.tx, self.sidecar)
}

/// Get the network-encoded fields length of the transaction.
pub fn network_encoded_fields_length(&self, signature: &Signature) -> usize {
self.tx.rlp_encoded_length_with_signature(signature)
+ self.sidecar.rlp_encoded_fields_length()
}
}

impl SignableTransaction<Signature> for TxEip4844WithSidecar {
Expand Down

0 comments on commit 72169eb

Please sign in to comment.