Make impersonated tx rule more strict

This commit is contained in:
sprites0
2025-02-26 03:24:14 +00:00
parent ae262b6d5a
commit 7a81e16702
2 changed files with 19 additions and 9 deletions

View File

@ -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 {