Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L1 client: ethers -> alloy #2456

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

L1 client: ethers -> alloy #2456

wants to merge 20 commits into from

Conversation

rob-maron
Copy link
Contributor

@rob-maron rob-maron commented Jan 14, 2025

This PR:

  1. Adds a second set of bindings (alloy) and the related generation logic to the existing scripts
  2. Changes the RPC client logic to use alloy instead, making minimal changes elsewhere to support it

This PR does not:

  1. Touch anything else ethers-related

Files to pay attention to:

Both l1.rss comprise the majority of the real changes in this PR

@rob-maron rob-maron changed the title ethers rpc -> alloy ethers L1 client -> alloy Jan 14, 2025
@rob-maron rob-maron changed the title ethers L1 client -> alloy L1 client: ethers -> alloy Jan 14, 2025
forge bind --contracts ./contracts/src/ --ethers --crate-name contract-bindings-ethers --bindings-path contract-bindings-ethers --select "{{REGEXP}}" --overwrite --force

# Generate the alloy bindings
# For now, to compile these, you need to fork `alloy-core` and change the `RESOLVE_LIMIT`. From there, you need to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rob-maron have we opened and issue or PR to get this change into alloy-core?

Copy link
Collaborator

@sveitser sveitser Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the value of RESOLVE_LIMIT we need? Probably quickest if we open a PR bumping it to the value we need and mention why we need the increase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I have RESOLVE_LIMIT set to 128 (from 32). Thanks for noting, I will add it to the comments for now

I will also open an issue/PR shortly - want to see why this is failing tests first

Comment on lines 24 to +28
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, Hash, PartialEq, Eq)]
pub struct L1BlockInfo {
pub number: u64,
pub timestamp: U256,
pub hash: H256,
pub timestamp: ethers::types::U256,
pub hash: ethers::types::H256,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep these as ethers types because if not it breaks header serialization

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird these types deserialize differently with alloy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. When I get to switching everything else I'll see if it could just be some endianness thing. It didn't immediately allow me to choose le or be when I had tried to fix this

@rob-maron rob-maron marked this pull request as ready for review January 16, 2025 15:44
Comment on lines +854 to +869
pub async fn is_proxy_contract(&self, proxy_address: Address) -> anyhow::Result<bool> {
// confirm that the proxy_address is a proxy
// using the implementation slot, 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc, which is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1
let hex_bytes =
hex::decode("360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc")
.expect("Failed to decode hex string");
let implementation_slot = B256::from_slice(&hex_bytes);
let storage = self
.provider
.get_storage_at(proxy_address, implementation_slot.into())
.await?;

let implementation_address = Address::from_slice(&storage.to_be_bytes::<32>()[12..]);

// when the implementation address is not equal to zero, it's a proxy
Ok(implementation_address != Address::ZERO)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was duplicated - we need one written for ethers for the contract deployer but we also need one here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants