mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 02:49:55 +00:00
Make impersonated tx rule more strict
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
use alloc::vec::Vec;
|
||||
pub use alloy_consensus::{transaction::PooledTransaction, TxType};
|
||||
use alloy_consensus::{
|
||||
transaction::RlpEcdsaTx, BlobTransactionSidecar, SignableTransaction, Signed, TxEip1559,
|
||||
TxEip2930, TxEip4844, TxEip4844Variant, TxEip4844WithSidecar, TxEip7702, TxEnvelope, TxLegacy,
|
||||
Typed2718, TypedTransaction,
|
||||
transaction::RlpEcdsaTx, BlobTransactionSidecar, SignableTransaction, Signed, Transaction as _,
|
||||
TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEip4844WithSidecar, TxEip7702, TxEnvelope,
|
||||
TxLegacy, Typed2718, TypedTransaction,
|
||||
};
|
||||
use alloy_eips::{
|
||||
eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718},
|
||||
@ -20,7 +20,10 @@ use core::hash::{Hash, Hasher};
|
||||
use reth_primitives_traits::{
|
||||
crypto::secp256k1::{recover_signer, recover_signer_unchecked},
|
||||
sync::OnceLock,
|
||||
transaction::{error::TransactionConversionError, signed::RecoveryError},
|
||||
transaction::{
|
||||
error::TransactionConversionError,
|
||||
signed::{is_impersonated_tx, RecoveryError},
|
||||
},
|
||||
InMemorySize, SignedTransaction,
|
||||
};
|
||||
use revm_context::TxEnv;
|
||||
@ -836,8 +839,7 @@ impl SignedTransaction for TransactionSigned {
|
||||
const HL_SYSTEM_TX_FROM_ADDR: Address =
|
||||
address!("2222222222222222222222222222222222222222");
|
||||
let signature = self.signature();
|
||||
if signature.r() == U256::from(1) && signature.s() == U256::from(1) && signature.v() == true
|
||||
{
|
||||
if is_impersonated_tx(signature, self.gas_price()) {
|
||||
return Ok(HL_SYSTEM_TX_FROM_ADDR);
|
||||
}
|
||||
let signature_hash = self.signature_hash();
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::{
|
||||
use alloc::{fmt, vec::Vec};
|
||||
use alloy_consensus::{
|
||||
transaction::{PooledTransaction, Recovered},
|
||||
SignableTransaction,
|
||||
SignableTransaction, Transaction,
|
||||
};
|
||||
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
|
||||
use alloy_primitives::{keccak256, Address, PrimitiveSignature as Signature, TxHash, B256};
|
||||
@ -18,6 +18,15 @@ use revm_primitives::{address, U256};
|
||||
pub trait FullSignedTx: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
||||
impl<T> FullSignedTx for T where T: SignedTransaction + MaybeCompact + MaybeSerdeBincodeCompat {}
|
||||
|
||||
/// 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<u128>) -> bool {
|
||||
signature.r() == U256::from(1)
|
||||
&& signature.s() == U256::from(1)
|
||||
&& signature.v() == true
|
||||
&& gas_price == Some(0u128)
|
||||
}
|
||||
|
||||
/// A signed transaction.
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait SignedTransaction:
|
||||
@ -168,8 +177,7 @@ impl SignedTransaction for PooledTransaction {
|
||||
buf: &mut Vec<u8>,
|
||||
) -> Result<Address, RecoveryError> {
|
||||
let signature = self.signature();
|
||||
if signature.r() == U256::from(1) && signature.s() == U256::from(1) && signature.v() == true
|
||||
{
|
||||
if is_impersonated_tx(signature, self.gas_price()) {
|
||||
return Ok(address!("2222222222222222222222222222222222222222"));
|
||||
}
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user