From 5d779a66a04536f08d6b9c6c797b5ed60e269bf9 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Sat, 1 Mar 2025 17:10:15 +0000 Subject: [PATCH] refactor: Merge system tx from address --- Cargo.lock | 12 ------- bin/reth/Cargo.toml | 2 -- bin/reth/src/block_ingest.rs | 31 +++++-------------- crates/ethereum/evm/src/execute.rs | 8 ++--- crates/ethereum/primitives/src/transaction.rs | 7 ++--- crates/payload/validator/src/lib.rs | 7 ++--- crates/primitives-traits/src/block/body.rs | 10 +++--- .../src/transaction/signed.rs | 5 ++- 8 files changed, 22 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe3276bd8..685ee41de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6648,7 +6648,6 @@ dependencies = [ name = "reth" version = "1.2.0" dependencies = [ - "alloy-chains", "alloy-consensus", "alloy-eips", "alloy-primitives", @@ -6717,7 +6716,6 @@ dependencies = [ "reth-trie", "reth-trie-db", "rmp-serde", - "rmpv", "serde", "serde_json", "similar-asserts", @@ -10189,16 +10187,6 @@ dependencies = [ "serde", ] -[[package]] -name = "rmpv" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58450723cd9ee93273ce44a20b6ec4efe17f8ed2e3631474387bfdecf18bb2a9" -dependencies = [ - "num-traits", - "rmp", -] - [[package]] name = "roaring" version = "0.10.10" diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index dd0cf6cbe..1bbef6495 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -92,11 +92,9 @@ similar-asserts.workspace = true parking_lot.workspace = true lz4_flex = "0.11.3" rmp-serde = "1.3.0" -rmpv = "1.3.0" serde = { workspace = true, features = ["derive"] } reth-e2e-test-utils.workspace = true once_cell.workspace = true -alloy-chains.workspace = true reth-ethereum-forks.workspace = true jsonrpsee.workspace = true reth-rpc-layer.workspace = true diff --git a/bin/reth/src/block_ingest.rs b/bin/reth/src/block_ingest.rs index 3ad261150..63ee73c32 100644 --- a/bin/reth/src/block_ingest.rs +++ b/bin/reth/src/block_ingest.rs @@ -1,10 +1,8 @@ use std::path::PathBuf; use std::sync::Arc; -use alloy_consensus::transaction::RlpEcdsaTx; use alloy_consensus::{BlockBody, BlockHeader}; -use alloy_eips::Typed2718; -use alloy_primitives::{address, Address, PrimitiveSignature, B256, U256}; +use alloy_primitives::{Address, PrimitiveSignature, B256, U256}; use alloy_rpc_types::engine::{ ExecutionPayloadEnvelopeV3, ForkchoiceState, PayloadAttributes, PayloadStatusEnum, }; @@ -16,7 +14,7 @@ use reth_node_builder::EngineTypes; use reth_node_builder::NodeTypesWithEngine; use reth_node_builder::{rpc::RethRpcAddOns, FullNode}; use reth_payload_builder::{EthBuiltPayload, EthPayloadBuilderAttributes, PayloadId}; -use reth_primitives::{Transaction, TransactionSigned}; +use reth_primitives::TransactionSigned; use reth_provider::{BlockHashReader, StageCheckpointReader}; use reth_rpc_api::EngineApiClient; use reth_rpc_layer::AuthClientService; @@ -53,23 +51,6 @@ async fn submit_payload( Ok(submission.latest_valid_hash.unwrap_or_default()) } -pub(crate) fn impersonated_hash( - this: &Transaction, - sender: Address, - signature: &PrimitiveSignature, -) -> B256 { - let mut buffer = Vec::new(); - let ty = this.ty(); - match this { - Transaction::Legacy(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer), - Transaction::Eip2930(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer), - Transaction::Eip1559(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer), - Transaction::Eip4844(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer), - Transaction::Eip7702(tx) => tx.eip2718_encode_with_type(signature, ty, &mut buffer), - } - buffer.extend_from_slice(sender.as_ref()); - B256::from_slice(alloy_primitives::utils::keccak256(&buffer).as_slice()) -} impl BlockIngest { pub(crate) fn collect_block(&self, height: u64) -> Option { let f = ((height - 1) / 1_000_000) * 1_000_000; @@ -126,7 +107,6 @@ impl BlockIngest { { let BlockBody { transactions, ommers, withdrawals } = std::mem::take(block.body_mut()); - let signer = address!("2222222222222222222222222222222222222222"); let signature = PrimitiveSignature::new( // from anvil U256::from(0x1), @@ -136,8 +116,11 @@ impl BlockIngest { let mut system_txs = vec![]; for transaction in original_block.system_txs { let typed_transaction = transaction.tx.to_reth(); - let hash = impersonated_hash(&typed_transaction, signer, &signature); - let tx = TransactionSigned::new(typed_transaction, signature, hash); + let tx = TransactionSigned::new( + typed_transaction, + signature, + Default::default(), + ); system_txs.push(tx); } let mut txs = vec![]; diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index a5a6aa0ec..90a59afcc 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -8,7 +8,7 @@ use alloc::{boxed::Box, sync::Arc, vec::Vec}; use alloy_consensus::{Header, Transaction}; use alloy_eips::{eip4895::Withdrawals, eip6110, eip7685::Requests}; use alloy_evm::FromRecoveredTx; -use alloy_primitives::{address, Address, B256}; +use alloy_primitives::{Address, B256}; use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET}; use reth_evm::{ execute::{ @@ -23,7 +23,7 @@ use reth_execution_types::BlockExecutionResult; use reth_primitives::{ EthPrimitives, Receipt, Recovered, RecoveredBlock, SealedBlock, TransactionSigned, }; -use reth_primitives_traits::NodePrimitives; +use reth_primitives_traits::{transaction::signed::HL_SYSTEM_TX_FROM_ADDR, NodePrimitives}; use reth_revm::{context_interface::result::ResultAndState, db::State, DatabaseCommit}; /// Factory for [`EthExecutionStrategy`]. @@ -190,10 +190,8 @@ where .into()); } - const HL_SYSETM_TX_FROM_ADDR: Address = address!("2222222222222222222222222222222222222222"); - let hash = tx.hash(); - let is_system_transaction = tx.signer() == HL_SYSETM_TX_FROM_ADDR; + let is_system_transaction = tx.signer() == HL_SYSTEM_TX_FROM_ADDR; // Execute transaction. let result_and_state = diff --git a/crates/ethereum/primitives/src/transaction.rs b/crates/ethereum/primitives/src/transaction.rs index bba2bb885..9196c6669 100644 --- a/crates/ethereum/primitives/src/transaction.rs +++ b/crates/ethereum/primitives/src/transaction.rs @@ -12,8 +12,7 @@ use alloy_eips::{ }; use alloy_evm::FromRecoveredTx; use alloy_primitives::{ - address, keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, - B256, U256, + keccak256, Address, Bytes, ChainId, PrimitiveSignature as Signature, TxHash, TxKind, B256, U256, }; use alloy_rlp::{Decodable, Encodable}; use core::hash::{Hash, Hasher}; @@ -22,7 +21,7 @@ use reth_primitives_traits::{ sync::OnceLock, transaction::{ error::TransactionConversionError, - signed::{is_impersonated_tx, RecoveryError}, + signed::{is_impersonated_tx, RecoveryError, HL_SYSTEM_TX_FROM_ADDR}, }, InMemorySize, SignedTransaction, }; @@ -836,8 +835,6 @@ impl SignedTransaction for TransactionSigned { } fn recover_signer(&self) -> Result { - const HL_SYSTEM_TX_FROM_ADDR: Address = - address!("2222222222222222222222222222222222222222"); let signature = self.signature(); if is_impersonated_tx(signature, self.gas_price()) { return Ok(HL_SYSTEM_TX_FROM_ADDR); diff --git a/crates/payload/validator/src/lib.rs b/crates/payload/validator/src/lib.rs index fab83b613..878f1cf21 100644 --- a/crates/payload/validator/src/lib.rs +++ b/crates/payload/validator/src/lib.rs @@ -12,10 +12,10 @@ pub mod cancun; pub mod prague; pub mod shanghai; -use alloy_primitives::{address, Address}; use alloy_rpc_types_engine::{ExecutionData, PayloadError}; use reth_chainspec::EthereumHardforks; use reth_primitives::SealedBlock; +use reth_primitives_traits::transaction::signed::HL_SYSTEM_TX_FROM_ADDR; use reth_primitives_traits::{Block, SignedTransaction}; use std::sync::Arc; @@ -90,8 +90,6 @@ impl ExecutionPayloadValidator { let expected_hash = payload.block_hash(); // First parse the block - const HL_SYSTEM_TX_FROM_ADDR: Address = - address!("2222222222222222222222222222222222222222"); let transactions = payload.as_v1().transactions.clone(); let (normal, system) = transactions.into_iter().partition(|tx| { let tx = T::decode_2718(&mut tx.iter().as_slice()); @@ -107,8 +105,7 @@ impl ExecutionPayloadValidator { block.body.transactions = system .iter() .map(|tx| { - T::decode_2718(&mut tx.iter().as_slice()) - .expect("transaction should be valid") + T::decode_2718(&mut tx.iter().as_slice()).expect("transaction should be valid") }) .chain(block.body.transactions) .collect(); diff --git a/crates/primitives-traits/src/block/body.rs b/crates/primitives-traits/src/block/body.rs index 8d5fbbb4a..75131b28c 100644 --- a/crates/primitives-traits/src/block/body.rs +++ b/crates/primitives-traits/src/block/body.rs @@ -1,14 +1,14 @@ //! Block body abstraction. use crate::{ - transaction::signed::RecoveryError, BlockHeader, FullSignedTx, InMemorySize, MaybeSerde, - MaybeSerdeBincodeCompat, SignedTransaction, + transaction::signed::{RecoveryError, HL_SYSTEM_TX_FROM_ADDR}, + BlockHeader, FullSignedTx, InMemorySize, MaybeSerde, MaybeSerdeBincodeCompat, + SignedTransaction, }; use alloc::{fmt, vec::Vec}; use alloy_consensus::{Transaction, Typed2718}; use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals}; use alloy_primitives::{Address, Bytes, B256}; -use revm_primitives::address; /// Helper trait that unifies all behaviour required by transaction to support full node operations. pub trait FullBlockBody: BlockBody + MaybeSerdeBincodeCompat {} @@ -82,12 +82,10 @@ pub trait BlockBody: /// Calculate the transaction root for the block body. fn calculate_tx_root(&self) -> B256 { - const HL_SYSETM_TX_FROM_ADDR: Address = - address!("2222222222222222222222222222222222222222"); let transactions: Vec = self .transactions() .into_iter() - .filter(|tx| !matches!(tx.recover_signer(), Ok(address) if HL_SYSETM_TX_FROM_ADDR == address)) + .filter(|tx| !matches!(tx.recover_signer(), Ok(address) if HL_SYSTEM_TX_FROM_ADDR == address)) .cloned() .collect::>(); alloy_consensus::proofs::calculate_transaction_root(transactions.as_slice()) diff --git a/crates/primitives-traits/src/transaction/signed.rs b/crates/primitives-traits/src/transaction/signed.rs index 2003b42ec..68bdf3141 100644 --- a/crates/primitives-traits/src/transaction/signed.rs +++ b/crates/primitives-traits/src/transaction/signed.rs @@ -18,6 +18,9 @@ use revm_primitives::{address, U256}; pub trait FullSignedTx: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {} impl FullSignedTx for T where T: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {} +/// Hyperliquid system transaction from address. +pub const HL_SYSTEM_TX_FROM_ADDR: Address = address!("2222222222222222222222222222222222222222"); + /// Check if the transaction is impersonated. /// Signature part is introduced in block_ingest, while the gas_price is trait of hyperliquid system transactions. pub fn is_impersonated_tx(signature: &Signature, gas_price: Option) -> bool { @@ -178,7 +181,7 @@ impl SignedTransaction for PooledTransaction { ) -> Result { let signature = self.signature(); if is_impersonated_tx(signature, self.gas_price()) { - return Ok(address!("2222222222222222222222222222222222222222")); + return Ok(HL_SYSTEM_TX_FROM_ADDR); } match self { Self::Legacy(tx) => tx.tx().encode_for_signing(buf),