pub fn get_implementation<DB, INSP>(
evm: &mut TraceEvm<DB, INSP>,
proxy: Address,
) -> Result<Option<Address>, EvmError>where
DB: Database,Expand description
Attempts to find the implementation address for a proxy contract
Checks multiple proxy patterns to find the implementation contract address. Supports the following proxy patterns:
- EIP-1967 Transparent Proxy
- EIP-1967 Beacon Proxy
- OpenZeppelin Legacy Proxy
- EIP-1822 Universal Upgradeable Proxy (UUPS)
§Arguments
evm- Configured EVM instance for state accesscontract- Address of the potential proxy contract
§Returns
Ok(Some(Address))- Implementation address if foundOk(None)- If no implementation is found (might not be a proxy)Err(_)- If there’s an error accessing contract state
§Example
use revm_trace::utils::proxy_utils::get_implementation;
use revm_trace::create_evm;
use alloy::primitives::address;
let mut evm = create_evm("https://eth.llamarpc.com").await?;
// USDT proxy contract
let proxy = address!("dac17f958d2ee523a2206206994597c13d831ec7");
if let Some(implementation) = get_implementation(&mut evm, proxy)? {
println!("Implementation found at: {}", implementation);
} else {
println!("No implementation found (not a proxy)");
}§Implementation Details
The function:
- Checks each known implementation slot in order
- For non-zero values, attempts to convert to an address
- Verifies the address has deployed code
- Returns the first valid implementation found
§Common Proxy Patterns
- EIP-1967: Modern transparent proxy pattern
- EIP-1822: Universal Upgradeable Proxy Standard (UUPS)
- OpenZeppelin: Legacy proxy implementation
- Beacon: Proxy pattern for multiple contracts sharing same implementation