1//! Commonly used constants.
23use alloy_consensus::Typed2718;
4use alloy_network::AnyTxEnvelope;
5use alloy_primitives::{address, Address, Signature, B256};
6use std::time::Duration;
78/// The dev chain-id, inherited from hardhat
9pub const DEV_CHAIN_ID: u64 = 31337;
1011/// The first four bytes of the call data for a function call specifies the function to be called.
12pub const SELECTOR_LEN: usize = 4;
1314/// Maximum size in bytes (0x6000) that a contract can have.
15pub const CONTRACT_MAX_SIZE: usize = 24576;
1617/// Default request timeout for http requests
18///
19/// Note: this is only used so that connections, that are discarded on the server side won't stay
20/// open forever. We assume some nodes may have some backoff baked into them and will delay some
21/// responses. This timeout should be a reasonable amount of time to wait for a request.
22pub const REQUEST_TIMEOUT: Duration = Duration::from_secs(45);
2324/// Alchemy free tier cups: <https://docs.alchemy.com/reference/pricing-plans>
25pub const ALCHEMY_FREE_TIER_CUPS: u64 = 330;
2627/// Logged when an error is indicative that the user is trying to fork from a non-archive node.
28pub const NON_ARCHIVE_NODE_WARNING: &str = "\
29It looks like you're trying to fork from an older block with a non-archive node which is not \
30supported. Please try to change your RPC url to an archive node if the issue persists.";
3132/// Arbitrum L1 sender address of the first transaction in every block.
33/// `0x00000000000000000000000000000000000a4b05`
34pub const ARBITRUM_SENDER: Address = address!("0x00000000000000000000000000000000000a4b05");
3536/// The system address, the sender of the first transaction in every block:
37/// `0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001`
38///
39/// See also <https://github.com/ethereum-optimism/optimism/blob/65ec61dde94ffa93342728d324fecf474d228e1f/specs/deposits.md#l1-attributes-deposited-transaction>
40pub const OPTIMISM_SYSTEM_ADDRESS: Address = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
4142/// Transaction identifier of System transaction types
43pub const SYSTEM_TRANSACTION_TYPE: u8 = 126;
4445/// Default user agent set as the header for requests that don't specify one.
46pub const DEFAULT_USER_AGENT: &str = concat!("foundry/", env!("CARGO_PKG_VERSION"));
4748/// Returns whether the sender is a known system sender that is the first tx in every block.
49///
50/// Transactions from these senders usually don't have a any fee information OR set absurdly high fees that exceed the gas limit (See: <https://github.com/foundry-rs/foundry/pull/10608>)
51///
52/// See: [ARBITRUM_SENDER], [OPTIMISM_SYSTEM_ADDRESS] and [Address::ZERO]
53#[inline]
54pub fn is_known_system_sender(sender: Address) -> bool {
55 [ARBITRUM_SENDER, OPTIMISM_SYSTEM_ADDRESS, Address::ZERO].contains(&sender)
56}
5758pub fn is_impersonated_tx(tx: &AnyTxEnvelope) -> bool {
59if let AnyTxEnvelope::Ethereum(tx) = tx {
60return is_impersonated_sig(tx.signature(), tx.ty());
61 }
62false
63}
6465pub fn is_impersonated_sig(sig: &Signature, ty: u8) -> bool {
66let impersonated_sig =
67 Signature::from_scalars_and_parity(B256::with_last_byte(1), B256::with_last_byte(1), false);
68if ty != SYSTEM_TRANSACTION_TYPE && sig == &impersonated_sig {
69return true;
70 }
71false
72}
7374#[cfg(test)]
75mod tests {
76use super::*;
7778#[test]
79fn test_constant_sender() {
80let arb = address!("0x00000000000000000000000000000000000a4b05");
81assert_eq!(arb, ARBITRUM_SENDER);
82let base = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
83assert_eq!(base, OPTIMISM_SYSTEM_ADDRESS);
84 }
85}