Skip to content

Commit

Permalink
avoid allocating
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 12, 2024
1 parent c287b83 commit 7b06f04
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/optimism/primitives/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ impl SignedTransaction for OpTransactionSigned {
recover_signer(signature, signature_hash)
}

fn recover_signer_unchecked(&self) -> Option<Address> {
// Optimism's Deposit transaction does not have a signature. Directly return the
// `from` address.
if let OpTypedTransaction::Deposit(TxDeposit { from, .. }) = &self.transaction {
return Some(*from)
}

let Self { transaction, signature, .. } = self;
let signature_hash = signature_hash(transaction);
recover_signer_unchecked(signature, signature_hash)
}

fn recover_signer_unchecked_with_buf(&self, buf: &mut Vec<u8>) -> Option<Address> {
match &self.transaction {
// Optimism's Deposit transaction does not have a signature. Directly return the
Expand Down Expand Up @@ -443,7 +455,7 @@ impl<'a> arbitrary::Arbitrary<'a> for OpTransactionSigned {
}

/// Calculates the signing hash for the transaction.
pub fn signature_hash(tx: &OpTypedTransaction) -> B256 {
fn signature_hash(tx: &OpTypedTransaction) -> B256 {
match tx {
OpTypedTransaction::Legacy(tx) => tx.signature_hash(),
OpTypedTransaction::Eip2930(tx) => tx.signature_hash(),
Expand Down

0 comments on commit 7b06f04

Please sign in to comment.