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