Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions crates/common/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Commonly used constants.

use alloy_consensus::Typed2718;
use alloy_network::AnyTxEnvelope;
use alloy_primitives::{address, Address, Signature, B256};
use alloy_primitives::{address, Address};
use std::time::Duration;

/// The dev chain-id, inherited from hardhat
Expand Down Expand Up @@ -58,24 +56,6 @@ pub fn is_known_system_sender(sender: Address) -> bool {
[ARBITRUM_SENDER, OPTIMISM_SYSTEM_ADDRESS, Address::ZERO].contains(&sender)
}

pub fn is_impersonated_tx(tx: &AnyTxEnvelope) -> bool {
if let AnyTxEnvelope::Ethereum(tx) = tx {
return is_impersonated_sig(tx.signature(), tx.ty());
}
false
}

pub fn is_impersonated_sig(sig: &Signature, ty: u8) -> bool {
let impersonated_sig =
Signature::from_scalars_and_parity(B256::with_last_byte(1), B256::with_last_byte(1), false);
if ty != SYSTEM_TRANSACTION_TYPE &&
(sig == &impersonated_sig || sig.r() == impersonated_sig.r())
{
return true;
}
false
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
5 changes: 2 additions & 3 deletions crates/evm/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use alloy_network::{AnyTxEnvelope, TransactionResponse};
use alloy_primitives::{Address, Selector, TxKind, B256, U256};
use alloy_provider::{network::BlockResponse, Network};
use alloy_rpc_types::{Transaction, TransactionRequest};
use foundry_common::is_impersonated_tx;
use foundry_config::NamedChain;
pub use revm::state::EvmState as StateChangeset;

Expand Down Expand Up @@ -86,9 +85,9 @@ pub fn get_function<'a>(
/// Configures the env for the given RPC transaction.
/// Accounts for an impersonated transaction by resetting the `env.tx.caller` field to `tx.from`.
pub fn configure_tx_env(env: &mut EnvMut<'_>, tx: &Transaction<AnyTxEnvelope>) {
let impersonated_from = is_impersonated_tx(&tx.inner).then_some(tx.from());
let from = tx.from();
if let AnyTxEnvelope::Ethereum(tx) = &tx.inner.inner() {
configure_tx_req_env(env, &tx.clone().into(), impersonated_from).expect("cannot fail");
configure_tx_req_env(env, &tx.clone().into(), Some(from)).expect("cannot fail");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I didn't change the configure_tx_req_env function signature or implementation to avoid having to change logic in other places where it is used such as:

I could easily change the argument name from impersonated_from to something like overwrite_from though to indicate that this value is not only used for impersonated tx's anymore.

}
}

Expand Down