Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions crates/primitives/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,21 @@ impl FoundryTxEnvelope {

/// Returns the hash if the transaction is impersonated (using a fake signature)
///
/// This appends the `address` before hashing it
/// This encodes the transaction without signature (following Ethereum standard),
/// then appends the `sender` address before hashing to ensure uniqueness for
/// impersonated transactions that share the same fake signature.
pub fn impersonated_hash(&self, sender: Address) -> B256 {
let mut buffer = Vec::new();
Encodable::encode(self, &mut buffer);
// Encode transaction data without signature (same as standard hash())
match self {
Self::Legacy(t) => t.tx().encode(&mut buffer),
Self::Eip2930(t) => t.tx().encode(&mut buffer),
Self::Eip1559(t) => t.tx().encode(&mut buffer),
Self::Eip4844(t) => t.tx().tx().encode(&mut buffer),
Self::Eip7702(t) => t.tx().encode(&mut buffer),
Self::Deposit(t) => t.inner().encode(&mut buffer),
}
// Append sender address to ensure uniqueness for impersonated transactions
buffer.extend_from_slice(sender.as_ref());
B256::from_slice(alloy_primitives::utils::keccak256(&buffer).as_slice())
}
Expand Down
Loading