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 SYSTEM_TRANSACTION_TYPE: u8 = 126;
44
45pub const DEFAULT_USER_AGENT: &str = concat!("foundry/", env!("CARGO_PKG_VERSION"));
47
48pub const TYPE_BINDING_PREFIX: &str = "string constant schema_";
50
51pub fn is_known_system_sender(sender: Address) -> bool {
57 [ARBITRUM_SENDER, OPTIMISM_SYSTEM_ADDRESS, Address::ZERO].contains(&sender)
58}
59
60pub fn is_impersonated_tx(tx: &AnyTxEnvelope) -> bool {
61 if let AnyTxEnvelope::Ethereum(tx) = tx {
62 return is_impersonated_sig(tx.signature(), tx.ty());
63 }
64 false
65}
66
67pub fn is_impersonated_sig(sig: &Signature, ty: u8) -> bool {
68 let impersonated_sig =
69 Signature::from_scalars_and_parity(B256::with_last_byte(1), B256::with_last_byte(1), false);
70 if ty != SYSTEM_TRANSACTION_TYPE
71 && (sig == &impersonated_sig || sig.r() == impersonated_sig.r())
72 {
73 return true;
74 }
75 false
76}
77
78#[cfg(test)]
79mod tests {
80 use super::*;
81
82 #[test]
83 fn test_constant_sender() {
84 let arb = address!("0x00000000000000000000000000000000000a4b05");
85 assert_eq!(arb, ARBITRUM_SENDER);
86 let base = address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddead0001");
87 assert_eq!(base, OPTIMISM_SYSTEM_ADDRESS);
88 }
89}