Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: require destination for 7702 #1262

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion crates/consensus/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ impl<'a> arbitrary::Arbitrary<'a> for Header {

#[cfg(test)]
mod tests {
use super::*;
mattsse marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(feature = "serde")]
#[test]
Expand Down
14 changes: 6 additions & 8 deletions crates/consensus/src/transaction/eip7702.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -263,7 +261,7 @@ impl TxEip7702 {
mem::size_of::<u64>() + // gas_limit
mem::size_of::<u128>() + // max_fee_per_gas
mem::size_of::<u128>() + // max_priority_fee_per_gas
self.to.size() + // to
mem::size_of::<Address>() + // to
mattsse marked this conversation as resolved.
Show resolved Hide resolved
mem::size_of::<U256>() + // value
self.access_list.size() + // access_list
self.input.len() + // input
Expand Down Expand Up @@ -305,7 +303,7 @@ impl Transaction for TxEip7702 {
}

fn to(&self) -> TxKind {
self.to
self.to.into()
}

fn value(&self) -> U256 {
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl TryFrom<Transaction> for Signed<TxEip7702> {
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
Expand Down
9 changes: 7 additions & 2 deletions crates/rpc-types-eth/src/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ impl TransactionRequest {
fn build_7702(self) -> Result<TxEip7702, &'static str> {
let checked_to = self.to.ok_or("Missing 'to' field for Eip7702 transaction.")?;

let to_address = match checked_to {
mattsse marked this conversation as resolved.
Show resolved Hide resolved
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.")?,
Expand All @@ -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(),
Expand Down Expand Up @@ -808,7 +813,7 @@ impl From<TxEip4844Variant> for TransactionRequest {
impl From<TxEip7702> 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),
Expand Down
Loading