Skip to content

Commit

Permalink
Merge branch 'main' into klkvr/wip-bool-parity
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Oct 31, 2024
2 parents fabd775 + 273d784 commit 4ad8918
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
37 changes: 16 additions & 21 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{SignableTransaction, Signed, Transaction, TxType};
use alloc::vec::Vec;
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 alloy_rlp::{BufMut, Decodable, Encodable, Header};
use core::mem;

#[doc(inline)]
Expand Down Expand Up @@ -290,22 +290,17 @@ impl RlpEcdsaTx for TxEip4844Variant {
}

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

let res = Self::rlp_decode_fields(buf)?;

let chunk = &mut &buf[..header.length_with_payload()];
let res = Self::rlp_decode_fields(chunk)?;
if !chunk.is_empty() {
if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength);
}
buf.advance(header.length_with_payload());
Ok(res)
}

Expand Down Expand Up @@ -850,6 +845,12 @@ impl RlpEcdsaTx for TxEip4844WithSidecar {
self.sidecar.rlp_encode_fields(out);
}

fn rlp_header_signed(&self, signature: &Signature) -> Header {
let payload_length = self.tx.rlp_encoded_length_with_signature(signature)
+ self.sidecar.rlp_encoded_fields_length();
Header { list: true, payload_length }
}

fn rlp_encode_signed(&self, signature: &Signature, out: &mut dyn BufMut) {
self.rlp_header_signed(signature).encode(out);
self.tx.rlp_encode_signed(signature, out);
Expand All @@ -867,20 +868,14 @@ impl RlpEcdsaTx for TxEip4844WithSidecar {
if !header.list {
return Err(alloy_rlp::Error::UnexpectedString);
}
let remaining_len = buf.len();
if header.payload_length > remaining_len {
return Err(alloy_rlp::Error::InputTooShort);
}
let remaining = buf.len();

let chunk = &mut &buf[..remaining_len];
let (tx, signature) = TxEip4844::rlp_decode_with_signature(chunk)?;
let sidecar = BlobTransactionSidecar::rlp_decode_fields(chunk)?;
let (tx, signature) = TxEip4844::rlp_decode_with_signature(buf)?;
let sidecar = BlobTransactionSidecar::rlp_decode_fields(buf)?;

// Decoding did not consume the entire payload specified by the header
if !chunk.is_empty() {
if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength);
}
buf.advance(header.payload_length);

Ok((Self { tx, sidecar }, signature))
}
Expand Down
22 changes: 18 additions & 4 deletions crates/consensus/src/transaction/rlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,19 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {
if !header.list {
return Err(alloy_rlp::Error::UnexpectedString);
}
let remaining_len = buf.len();
let remaining = buf.len();

if header.payload_length > remaining_len {
if header.payload_length > remaining {
return Err(alloy_rlp::Error::InputTooShort);
}

Self::rlp_decode_fields(buf)
let this = Self::rlp_decode_fields(buf)?;

if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength);
}

Ok(this)
}

/// Decodes the transaction from RLP bytes, including the signature.
Expand Down Expand Up @@ -180,7 +186,15 @@ pub trait RlpEcdsaTx: SignableTransaction<Signature> + Sized {
if header.list {
return Err(alloy_rlp::Error::UnexpectedList.into());
}
Self::eip2718_decode_with_type(buf, ty)

let remaining = buf.len();
let res = Self::eip2718_decode_with_type(buf, ty)?;

if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength.into());
}

Ok(res)
}

/// Decodes the transaction from network bytes, expecting the default type
Expand Down
9 changes: 8 additions & 1 deletion crates/eips/src/eip4844/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,14 @@ impl BlobTransactionSidecar {
if buf.len() < header.payload_length {
return Err(alloy_rlp::Error::InputTooShort);
}
Self::rlp_decode_fields(buf)
let remaining = buf.len();
let this = Self::rlp_decode_fields(buf)?;

if buf.len() + header.payload_length != remaining {
return Err(alloy_rlp::Error::UnexpectedLength);
}

Ok(this)
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/rpc-types-trace/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ pub struct InternalIssuance {
/// Custom `Block` struct that includes transaction count for Otterscan responses
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OtsBlock<T = Transaction> {
pub struct OtsBlock<T = Transaction, H = Header> {
/// The block information.
#[serde(flatten)]
pub block: Block<T>,
pub block: Block<T, H>,
/// The number of transactions in the block.
#[doc(alias = "tx_count")]
pub transaction_count: usize,
}

impl<T> From<Block<T>> for OtsBlock<T> {
fn from(block: Block<T>) -> Self {
impl<T, H> From<Block<T, H>> for OtsBlock<T, H> {
fn from(block: Block<T, H>) -> Self {
Self { transaction_count: block.transactions.len(), block }
}
}
Expand Down Expand Up @@ -215,9 +215,9 @@ pub struct OtsReceipt {

/// Custom struct for otterscan `getBlockTransactions` RPC response
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct OtsBlockTransactions<T = Transaction> {
pub struct OtsBlockTransactions<T = Transaction, H = Header> {
/// The full block information with transaction count.
pub fullblock: OtsBlock<T>,
pub fullblock: OtsBlock<T, H>,
/// The list of transaction receipts.
pub receipts: Vec<OtsTransactionReceipt>,
}
Expand Down

0 comments on commit 4ad8918

Please sign in to comment.