diff --git a/crates/consensus/src/header.rs b/crates/consensus/src/header.rs index 3c086b8b045..c5b9f2da681 100644 --- a/crates/consensus/src/header.rs +++ b/crates/consensus/src/header.rs @@ -641,7 +641,6 @@ impl<'a> arbitrary::Arbitrary<'a> for Header { #[cfg(test)] mod tests { - use super::*; #[cfg(feature = "serde")] #[test] diff --git a/crates/consensus/src/transaction/eip7702.rs b/crates/consensus/src/transaction/eip7702.rs index c2e704a4df8..12307fcc073 100644 --- a/crates/consensus/src/transaction/eip7702.rs +++ b/crates/consensus/src/transaction/eip7702.rs @@ -1,6 +1,6 @@ use crate::{EncodableSignature, SignableTransaction, Signed, Transaction, TxType}; use alloy_eips::eip2930::AccessList; -use alloy_primitives::{keccak256, Bytes, ChainId, Signature, TxKind, B256, U256}; +use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, TxKind, B256, U256}; use alloy_rlp::{BufMut, Decodable, Encodable, Header}; use core::mem; @@ -50,10 +50,8 @@ pub struct TxEip7702 { /// This is also known as `GasTipCap` #[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))] pub max_priority_fee_per_gas: u128, - /// The 160-bit address of the message call’s recipient or, for a contract creation - /// transaction, ∅, used here to denote the only member of B0 ; formally Tt. - #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "TxKind::is_create"))] - pub to: TxKind, + /// The 160-bit address of the message call’s recipient. + pub to: Address, /// A scalar value equal to the number of Wei to /// be transferred to the message call’s recipient or, /// in the case of contract creation, as an endowment @@ -263,7 +261,7 @@ impl TxEip7702 { mem::size_of::() + // gas_limit mem::size_of::() + // max_fee_per_gas mem::size_of::() + // max_priority_fee_per_gas - self.to.size() + // to + mem::size_of::
() + // to mem::size_of::() + // value self.access_list.size() + // access_list self.input.len() + // input @@ -305,7 +303,7 @@ impl Transaction for TxEip7702 { } fn to(&self) -> TxKind { - self.to + self.to.into() } fn value(&self) -> U256 { @@ -430,7 +428,7 @@ mod tests { max_fee_per_gas: 0x4a817c800, max_priority_fee_per_gas: 0x3b9aca00, gas_limit: 2, - to: TxKind::Create, + to: Address::default(), value: U256::ZERO, input: vec![1, 2].into(), access_list: Default::default(), diff --git a/crates/consensus/src/transaction/envelope.rs b/crates/consensus/src/transaction/envelope.rs index fc5c324e983..339b37523f1 100644 --- a/crates/consensus/src/transaction/envelope.rs +++ b/crates/consensus/src/transaction/envelope.rs @@ -823,7 +823,7 @@ mod tests { gas_limit: 3, max_fee_per_gas: 4, max_priority_fee_per_gas: 5, - to: Address::left_padding_from(&[5]).into(), + to: Address::left_padding_from(&[5]), value: U256::from(6_u64), input: vec![7].into(), access_list: AccessList(vec![AccessListItem { diff --git a/crates/rpc-types-eth/src/transaction/mod.rs b/crates/rpc-types-eth/src/transaction/mod.rs index 6d6262cdd0f..1700bcf33bd 100644 --- a/crates/rpc-types-eth/src/transaction/mod.rs +++ b/crates/rpc-types-eth/src/transaction/mod.rs @@ -269,7 +269,7 @@ impl TryFrom for Signed { max_priority_fee_per_gas: tx .max_priority_fee_per_gas .ok_or(ConversionError::MissingMaxPriorityFeePerGas)?, - to: tx.to.into(), + to: tx.to.ok_or(ConversionError::MissingTo)?, value: tx.value, access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, authorization_list: tx diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index aacd3f3af70..24a886fc2d9 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -314,6 +314,11 @@ impl TransactionRequest { fn build_7702(self) -> Result { let checked_to = self.to.ok_or("Missing 'to' field for Eip7702 transaction.")?; + let to_address = match checked_to { + TxKind::Create => return Err("The field `to` can only be of type TxKind::Call(Account). Please change it accordingly."), + TxKind::Call(to) => to, + }; + Ok(TxEip7702 { chain_id: self.chain_id.unwrap_or(1), nonce: self.nonce.ok_or("Missing 'nonce' field for Eip7702 transaction.")?, @@ -324,7 +329,7 @@ impl TransactionRequest { max_priority_fee_per_gas: self .max_priority_fee_per_gas .ok_or("Missing 'max_priority_fee_per_gas' field for Eip7702 transaction.")?, - to: checked_to, + to: to_address, value: self.value.unwrap_or_default(), input: self.input.into_input().unwrap_or_default(), access_list: self.access_list.unwrap_or_default(), @@ -808,7 +813,7 @@ impl From for TransactionRequest { impl From for TransactionRequest { fn from(tx: TxEip7702) -> Self { Self { - to: if let TxKind::Call(to) = tx.to { Some(to.into()) } else { None }, + to: Some(tx.to.into()), gas: Some(tx.gas_limit), max_fee_per_gas: Some(tx.max_fee_per_gas), max_priority_fee_per_gas: Some(tx.max_priority_fee_per_gas),