fix: prevent CREATE tx for EIP-4844 types (#8291)

Co-authored-by: joshieDo <93316087+joshieDo@users.noreply.github.com>
This commit is contained in:
Federico Gimenez
2024-05-21 10:45:23 +02:00
committed by GitHub
parent adbe1ba9b1
commit 5100ddd28e
15 changed files with 120 additions and 39 deletions

View File

@ -1,7 +1,7 @@
//! Compatibility functions for rpc `Transaction` type.
use alloy_rpc_types::request::{TransactionInput, TransactionRequest};
use reth_primitives::{BlockNumber, TransactionSignedEcRecovered, TxKind, TxType, B256};
use reth_primitives::{Address, BlockNumber, TransactionSignedEcRecovered, TxKind, TxType, B256};
use reth_rpc_types::Transaction;
use signature::from_primitive_signature;
pub use typed::*;
@ -42,9 +42,9 @@ fn fill(
let signer = tx.signer();
let signed_tx = tx.into_signed();
let to = match signed_tx.kind() {
let to: Option<Address> = match signed_tx.kind() {
TxKind::Create => None,
TxKind::Call(to) => Some(*to),
TxKind::Call(to) => Some(Address(*to)),
};
#[allow(unreachable_patterns)]

View File

@ -47,7 +47,8 @@ pub fn to_primitive_transaction(
gas_limit: tx.gas_limit.to(),
max_fee_per_gas: tx.max_fee_per_gas.to(),
max_priority_fee_per_gas: tx.max_priority_fee_per_gas.to(),
to: tx.kind,
placeholder: Some(()),
to: tx.to,
value: tx.value,
access_list: tx.access_list,
blob_versioned_hashes: tx.blob_versioned_hashes,

View File

@ -2,7 +2,7 @@
//! transaction deserialized from the json input of an RPC call. Depending on what fields are set,
//! it can be converted into the container type [`TypedTransactionRequest`].
use alloy_primitives::{Bytes, TxKind, B256, U256};
use alloy_primitives::{Address, Bytes, TxKind, B256, U256};
use alloy_rpc_types::{AccessList, BlobTransactionSidecar};
/// Container type for various Ethereum transaction requests
@ -100,8 +100,8 @@ pub struct EIP4844TransactionRequest {
pub max_fee_per_gas: U256,
/// The gas limit for the transaction
pub gas_limit: U256,
/// The kind of transaction (e.g., Call, Create)
pub kind: TxKind,
/// The recipient of the transaction
pub to: Address,
/// The value of the transaction
pub value: U256,
/// The input data for the transaction

View File

@ -979,7 +979,11 @@ where
gas_limit: U256::from(gas.unwrap_or_default()),
value: value.unwrap_or_default(),
input: data.into_input().unwrap_or_default(),
kind: to.unwrap_or(RpcTransactionKind::Create),
#[allow(clippy::manual_unwrap_or_default)] // clippy is suggesting here unwrap_or_default
to: match to {
Some(RpcTransactionKind::Call(to)) => to,
_ => Address::default(),
},
access_list: access_list.unwrap_or_default(),
// eip-4844 specific.
@ -1802,7 +1806,7 @@ pub(crate) fn build_transaction_receipt_with_block_receipts(
res_receipt.contract_address = Some(from.create(transaction.transaction.nonce()));
}
Call(addr) => {
res_receipt.to = Some(*addr);
res_receipt.to = Some(Address(*addr));
}
}