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