Skip to content

Commit

Permalink
fix: hash handling (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Nov 1, 2024
1 parent ab78ea0 commit 8399c86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 32 deletions.
37 changes: 9 additions & 28 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,10 @@ impl RlpEcdsaTx for TxEip4844Variant {
}
}

fn rlp_encoded_length(&self) -> usize {
match self {
Self::TxEip4844(inner) => inner.rlp_encoded_length(),
Self::TxEip4844WithSidecar(inner) => inner.rlp_encoded_length(),
}
}

fn rlp_encoded_length_with_signature(&self, signature: &Signature) -> usize {
fn rlp_header_signed(&self, signature: &Signature) -> Header {
match self {
Self::TxEip4844(inner) => inner.rlp_encoded_length_with_signature(signature),
Self::TxEip4844WithSidecar(inner) => inner.rlp_encoded_length_with_signature(signature),
Self::TxEip4844(inner) => inner.rlp_header_signed(signature),
Self::TxEip4844WithSidecar(inner) => inner.rlp_header_signed(signature),
}
}

Expand Down Expand Up @@ -289,21 +282,6 @@ impl RlpEcdsaTx for TxEip4844Variant {
TxEip4844::rlp_decode_fields(buf).map(Into::into)
}

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

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

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

fn rlp_decode_with_signature(buf: &mut &[u8]) -> alloy_rlp::Result<(Self, Signature)> {
// We need to determine if this has a sidecar tx or not. The needle ref
// is consumed to look for headers.
Expand Down Expand Up @@ -334,8 +312,10 @@ impl RlpEcdsaTx for TxEip4844Variant {
}

fn tx_hash_with_type(&self, signature: &Signature, ty: u8) -> alloy_primitives::TxHash {
// eip4844 tx_hash is always based on the non-sidecar encoding
self.tx().tx_hash_with_type(signature, ty)
match self {
Self::TxEip4844(inner) => inner.tx_hash_with_type(signature, ty),
Self::TxEip4844WithSidecar(inner) => inner.tx_hash_with_type(signature, ty),
}
}
}

Expand Down Expand Up @@ -779,7 +759,7 @@ impl SignableTransaction<Signature> for TxEip4844WithSidecar {
let signature = signature.with_parity_bool();

// important: must hash the tx WITHOUT the sidecar
let hash = self.tx.tx_hash(&signature);
let hash = self.tx_hash(&signature);

Signed::new_unchecked(self, signature, hash)
}
Expand Down Expand Up @@ -895,6 +875,7 @@ impl RlpEcdsaTx for TxEip4844WithSidecar {
}

fn tx_hash_with_type(&self, signature: &Signature, ty: u8) -> alloy_primitives::TxHash {
// eip4844 tx_hash is always based on the non-sidecar encoding
self.tx.tx_hash_with_type(signature, ty)
}
}
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloy_consensus::{
Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEip7702, TxEnvelope, TxLegacy,
};
use alloy_eips::eip7702::SignedAuthorization;
use alloy_eips::{eip2718::Encodable2718, eip7702::SignedAuthorization};
use alloy_network_primitives::TransactionResponse;
use alloy_primitives::{Address, BlockHash, Bytes, ChainId, TxKind, B256, U256};

Expand Down Expand Up @@ -237,10 +237,9 @@ impl<T: TransactionTrait> TransactionTrait for Transaction<T> {
}
}

impl<T: TransactionTrait> TransactionResponse for Transaction<T> {
impl<T: TransactionTrait + Encodable2718> TransactionResponse for Transaction<T> {
fn tx_hash(&self) -> B256 {
Default::default()
// self.hash
self.inner.trie_hash()
}

fn block_hash(&self) -> Option<BlockHash> {
Expand Down

0 comments on commit 8399c86

Please sign in to comment.