foundry_common/
constants.rs1use alloy_eips::Typed2718;
4use alloy_network::AnyTxEnvelope;
5use alloy_primitives::{Address, B256, Signature, address};
6use std::time::Duration;
7
8pub const DEV_CHAIN_ID: u64 = 31337;
10
11pub const SELECTOR_LEN: usize = 4;
13
14pub const CONTRACT_MAX_SIZE: usize = 24576;
16
17pub const REQUEST_TIMEOUT: Duration = Duration::from_secs(45);
23
24pub const ALCHEMY_FREE_TIER_CUPS: u64 = 330;
26
27pub 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.";
31
32pub const ARBITRUM_SENDER: Address = address!("0x00000000000000000000000000000000000a4b05");
35
36pub const OPTIMISM_SYSTEM_ADDRESS: Address = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
41
42pub const MONAD_SYSTEM_ADDRESS: Address = address!("0x6f49a8F621353f12378d0046E7d7e4b9B249DC9e");
44
45pub const SYSTEM_TRANSACTION_TYPE: u8 = 126;
47
48pub const DEFAULT_USER_AGENT: &str = concat!("foundry/", env!("CARGO_PKG_VERSION"));
50
51pub const TYPE_BINDING_PREFIX: &str = "string constant schema_";
53
54pub fn is_known_system_sender(sender: Address) -> bool {
60 [ARBITRUM_SENDER, OPTIMISM_SYSTEM_ADDRESS, MONAD_SYSTEM_ADDRESS, Address::ZERO]
61 .contains(&sender)
62}
63
64pub fn is_impersonated_tx(tx: &AnyTxEnvelope) -> bool {
65 if let AnyTxEnvelope::Ethereum(tx) = tx {
66 return is_impersonated_sig(tx.signature(), tx.ty());
67 }
68 false
69}
70
71pub fn is_impersonated_sig(sig: &Signature, ty: u8) -> bool {
72 let impersonated_sig =
73 Signature::from_scalars_and_parity(B256::with_last_byte(1), B256::with_last_byte(1), false);
74 if ty != SYSTEM_TRANSACTION_TYPE
75 && (sig == &impersonated_sig || sig.r() == impersonated_sig.r())
76 {
77 return true;
78 }
79 false
80}
81
82#[cfg(test)]
83mod tests {
84 use super::*;
85
86 #[test]
87 fn test_constant_sender() {
88 let arb = address!("0x00000000000000000000000000000000000a4b05");
89 assert_eq!(arb, ARBITRUM_SENDER);
90 let base = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
91 assert_eq!(base, OPTIMISM_SYSTEM_ADDRESS);
92 }
93}