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 d9c7bd5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 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

0 comments on commit d9c7bd5

Please sign in to comment.