diff --git a/crates/consensus/src/transaction/legacy.rs b/crates/consensus/src/transaction/legacy.rs index fc8f4acd5af..262d9d066c5 100644 --- a/crates/consensus/src/transaction/legacy.rs +++ b/crates/consensus/src/transaction/legacy.rs @@ -228,6 +228,10 @@ impl Transaction for TxLegacy { } impl SignableTransaction for TxLegacy { + fn use_eip155(&self) -> bool { + self.chain_id.is_some() + } + fn set_chain_id(&mut self, chain_id: ChainId) { self.chain_id = Some(chain_id); } diff --git a/crates/consensus/src/transaction/mod.rs b/crates/consensus/src/transaction/mod.rs index 6d6c3755190..6b6df0c9139 100644 --- a/crates/consensus/src/transaction/mod.rs +++ b/crates/consensus/src/transaction/mod.rs @@ -59,6 +59,11 @@ pub trait Transaction: any::Any + Send + Sync + 'static { /// types, or in other networks. For example, in Optimism, the deposit transaction signature is the /// unit type `()`. pub trait SignableTransaction: Transaction { + /// True if the transaction uses EIP-155 signatures. + fn use_eip155(&self) -> bool { + false + } + /// Sets `chain_id`. /// /// Prefer [`set_chain_id_checked`](Self::set_chain_id_checked). diff --git a/crates/signer-wallet/src/lib.rs b/crates/signer-wallet/src/lib.rs index 1a482e2e9bb..f567e00bc9b 100644 --- a/crates/signer-wallet/src/lib.rs +++ b/crates/signer-wallet/src/lib.rs @@ -118,11 +118,7 @@ impl> SignerSync for Wallet #[inline] fn sign_hash_sync(&self, hash: &B256) -> Result { let (recoverable_sig, recovery_id) = self.signer.sign_prehash(hash.as_ref())?; - let mut sig = Signature::from_signature_and_parity(recoverable_sig, recovery_id)?; - if let Some(chain_id) = self.chain_id { - sig = sig.with_chain_id(chain_id); - } - Ok(sig) + Ok(Signature::from_signature_and_parity(recoverable_sig, recovery_id)?) } #[inline] diff --git a/crates/signer/src/lib.rs b/crates/signer/src/lib.rs index c03c1a8d6df..1f3b33c410e 100644 --- a/crates/signer/src/lib.rs +++ b/crates/signer/src/lib.rs @@ -48,8 +48,10 @@ macro_rules! sign_transaction_with_chain_id { let mut sig = $sign.map_err(alloy_signer::Error::other)?; - if let Some(chain_id) = $signer.chain_id().or_else(|| $tx.chain_id()) { - sig = sig.with_chain_id(chain_id); + if $tx.use_eip155() { + if let Some(chain_id) = $signer.chain_id().or_else(|| $tx.chain_id()) { + sig = sig.with_chain_id(chain_id); + } } Ok(sig)