-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use alloy::{ | ||
network::Network, | ||
primitives::{b256, Address, B256}, | ||
providers::Provider, | ||
}; | ||
|
||
use crate::{error::DetectProxyResult, utils::storage_slot_as_address}; | ||
|
||
const OPEN_ZEPPELIN_PREFIX: B256 = | ||
b256!("0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3"); | ||
|
||
pub(crate) async fn detect_open_zeppelin_proxy<N, P: Provider<N>>( | ||
address: Address, | ||
provider: P, | ||
) -> DetectProxyResult<Option<Address>> | ||
where | ||
N: Network, | ||
{ | ||
if let Ok(Some(addr)) = storage_slot_as_address(&provider, address, OPEN_ZEPPELIN_PREFIX).await | ||
{ | ||
return Ok(Some(addr)); | ||
} | ||
|
||
Ok(None) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use alloy::{ | ||
network::Network, | ||
primitives::{Address, Bytes, B256, U256}, | ||
providers::Provider, | ||
}; | ||
|
||
use crate::error::DetectProxyResult; | ||
|
||
pub(crate) async fn storage_slot_as_address<N, P: Provider<N>>( | ||
provider: P, | ||
address: Address, | ||
slot: B256, | ||
) -> DetectProxyResult<Option<Address>> | ||
where | ||
N: Network, | ||
{ | ||
let slot = provider | ||
.get_storage_at(address, slot.into()) | ||
.latest() | ||
.await?; | ||
|
||
if !slot.is_zero() { | ||
return Ok(Some(u256_to_address(slot))); | ||
} | ||
|
||
Ok(None) | ||
} | ||
|
||
pub(crate) fn u256_to_address(u256: U256) -> Address { | ||
let bytes: Bytes = u256.to_be_bytes::<32>().into(); | ||
Address::from_slice(&bytes[12..]) | ||
} |