Skip to content

Migrate from Ethers to Alloy#887

Merged
3alpha merged 5 commits intomainfrom
migrate-to-alloy
Nov 11, 2025
Merged

Migrate from Ethers to Alloy#887
3alpha merged 5 commits intomainfrom
migrate-to-alloy

Conversation

@3alpha
Copy link
Copy Markdown
Collaborator

@3alpha 3alpha commented Nov 7, 2025

Usage related changes

Maybe bit faster performance

Development related changes

ethers-rs library has been depreciated in favour of alloy. This PR migrates from one to the other. Resolves #886.

Checklist:

  • Checked out the contribution guidelines
  • Applied formatting - ./scripts/format.sh
  • No linter errors - ./scripts/clippy_check.sh
  • No unused dependencies - ./scripts/check_unused_deps.sh
  • No spelling errors - ./scripts/check_spelling.sh
  • Performed code self-review
  • Rebased to the latest commit of the target branch (or merged it into my branch)
    • Once you make the PR reviewable, please avoid force-pushing
  • Updated the docs if needed - ./website/README.md
  • Linked the issues resolvable by this PR - linking info
  • Updated the tests if needed; all passing - execution info

Summary by CodeRabbit

  • Chores
    • Updated Ethereum integration dependencies, replacing ethers library with alloy for improved compatibility and maintainability.
    • Enhanced wallet and provider handling for Ethereum messaging operations.
    • Improved error handling with updated error type reporting for Ethereum-related failures.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 7, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key(s) in object: 'auto_resolve_threads'
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

This pull request migrates the codebase from the deprecated ethers-rs library to alloy. Changes include updating workspace dependencies (removing ethers, adding alloy and eyre), replacing Provider-based architecture with alloy's ProviderBuilder and PrivateKeySigner pattern, migrating hash types from H256 to B256, replacing contract ABI generation from abigen to sol! macros, and updating error types and type conversions throughout messaging, starknet modules, and integration tests. All public API surfaces affected by the migration have been updated accordingly.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • messaging/ethereum.rs: Substantial rewiring of provider/wallet architecture, contract deployment patterns, and RPC interaction logic; requires careful validation of provider initialization, error handling paths, and contract call semantics
  • test_messaging.rs: High density of type conversions and address/numeric literal replacements; multiple test scenarios need validation against new Alloy primitives and error messages
  • BackgroundAnvil struct refactoring: New ProviderBuilder pattern and PrivateKeySigner initialization; new get_block method adds public API surface requiring verification
  • Hash type migrations (H256 → B256): Verify byte ordering conversions (from_be_bytes / to_be_bytes) are correct in message hash handling across messaging and starknet modules
  • sol! macro contract bindings: Confirm generated contract interfaces (LogMessageToL2, MockStarknetMessaging) produce equivalent functionality to previous abigen-generated code

Possibly related PRs

  • #882: Modifies overlapping Ethereum messaging code paths (messaging/ethereum.rs and messaging/mod.rs) with related state management around last_fetched_block and message collection logic.

Suggested labels

maintenance

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.68% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Migrate from Ethers to Alloy' directly and concisely describes the main change: replacing the deprecated ethers-rs library with alloy throughout the codebase.
Description check ✅ Passed The PR description follows the template structure with both usage and development sections completed, includes the issue reference (#886), and has all checklist items marked as done.
Linked Issues check ✅ Passed The PR successfully addresses issue #886 by migrating all ethers-rs dependencies to alloy, including updates to workspace dependencies, error types, contract bindings, provider implementations, and test utilities.
Out of Scope Changes check ✅ Passed All code changes are directly related to the ethers-to-alloy migration: dependency updates, type replacements (H256→B256, Provider implementations), error handling, and test adjustments align with the stated objective.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@3alpha
Copy link
Copy Markdown
Collaborator Author

3alpha commented Nov 7, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 7, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/integration/common/background_anvil.rs (1)

72-75: Avoid panicking on invalid private keys

Line [73] calls PrivateKeySigner::from_str(private_key).unwrap(), so a malformed key (e.g., user typo) will panic the test harness instead of returning a structured TestError::AlloyError. Please propagate the error via map_err so the caller gets the expected RPC failure surface.

Apply this diff:

-        let provider_signer =
-            PrivateKeySigner::from_str(private_key).unwrap().with_chain_id(chain_id.into());
+        let provider_signer = PrivateKeySigner::from_str(private_key)
+            .map_err(|e| TestError::AlloyError(format!("Invalid private key: {e}")))?
+            .with_chain_id(chain_id.into());
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 09d1909 and 567a291.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • Cargo.toml (2 hunks)
  • crates/starknet-devnet-core/Cargo.toml (1 hunks)
  • crates/starknet-devnet-core/src/error.rs (1 hunks)
  • crates/starknet-devnet-core/src/messaging/ethereum.rs (14 hunks)
  • crates/starknet-devnet-core/src/messaging/mod.rs (5 hunks)
  • crates/starknet-devnet-core/src/starknet/add_l1_handler_transaction.rs (2 hunks)
  • crates/starknet-devnet-core/src/starknet/mod.rs (2 hunks)
  • tests/integration/Cargo.toml (1 hunks)
  • tests/integration/common/background_anvil.rs (6 hunks)
  • tests/integration/common/errors.rs (1 hunks)
  • tests/integration/common/utils.rs (2 hunks)
  • tests/integration/test_messaging.rs (16 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-06-16T07:35:24.725Z
Learnt from: FabijanC
Repo: 0xSpaceShard/starknet-devnet PR: 799
File: crates/starknet-devnet-core/src/starknet/mod.rs:240-246
Timestamp: 2025-06-16T07:35:24.725Z
Learning: In the Starknet devnet codebase, `get_class_hash_at` has different behaviors at different layers: at the internal state level (blockifier), it returns `Ok(ClassHash(Felt::ZERO))` for undeployed addresses, while at the RPC layer, this gets converted to `Err(Error::ContractNotFound)`. When checking if a contract is deployed at the internal state level, use `is_ok_and(|h| h.0 == Felt::ZERO)` to detect undeployed addresses.

Applied to files:

  • crates/starknet-devnet-core/src/starknet/mod.rs
  • crates/starknet-devnet-core/src/messaging/mod.rs
  • tests/integration/test_messaging.rs
📚 Learning: 2025-09-18T13:11:58.957Z
Learnt from: Abeeujah
Repo: 0xSpaceShard/starknet-devnet PR: 848
File: tests/integration/test_blocks_generation.rs:65-78
Timestamp: 2025-09-18T13:11:58.957Z
Learning: The function assert_tx_succeeded_pre_confirmed in tests/integration/common/utils.rs was not converted to return Result<(), anyhow::Error> and still returns unit type (), unlike assert_tx_succeeded_accepted which was converted to return Result.

Applied to files:

  • tests/integration/common/utils.rs
  • tests/integration/common/errors.rs
  • tests/integration/test_messaging.rs
📚 Learning: 2025-09-18T13:15:00.238Z
Learnt from: Abeeujah
Repo: 0xSpaceShard/starknet-devnet PR: 848
File: tests/integration/test_blocks_generation.rs:141-162
Timestamp: 2025-09-18T13:15:00.238Z
Learning: In tests/integration/common/utils.rs, the function assert_tx_succeeded_pre_confirmed currently contains only a TODO comment and doesn't perform any actual assertions, making it effectively unimplemented despite having its signature updated to return Result<(), anyhow::Error>.

Applied to files:

  • tests/integration/common/errors.rs
  • tests/integration/test_messaging.rs
📚 Learning: 2025-09-18T13:15:00.238Z
Learnt from: Abeeujah
Repo: 0xSpaceShard/starknet-devnet PR: 848
File: tests/integration/test_blocks_generation.rs:141-162
Timestamp: 2025-09-18T13:15:00.238Z
Learning: The function assert_tx_succeeded_pre_confirmed in tests/integration/common/utils.rs is currently unimplemented - it only contains a TODO message printed via eprintln! and has all the actual assertion logic commented out. The function still returns unit type () rather than Result<(), anyhow::Error> and essentially acts as a no-op stub.

Applied to files:

  • tests/integration/test_messaging.rs
  • crates/starknet-devnet-core/src/messaging/ethereum.rs
🔇 Additional comments (18)
crates/starknet-devnet-core/src/starknet/add_l1_handler_transaction.rs (2)

1-1: LGTM! Import updated correctly for alloy migration.

The import of B256 from alloy::primitives correctly replaces the previous H256 import as part of the ethers-rs to alloy migration.


31-38: LGTM! B256 conversion is correct and consistent across the codebase.

The conversion from L1 transaction hash to B256 using B256::new(*l1_tx_hash.as_bytes()) is the correct pattern for the alloy migration. The l1_to_l2_tx_hashes HashMap is properly defined with B256 as the key type, and the same conversion pattern is used consistently elsewhere in the codebase.

crates/starknet-devnet-core/Cargo.toml (1)

18-18: LGTM! Clean dependency migration.

The replacement of ethers with alloy is straightforward and aligns with the workspace-level dependency updates.

crates/starknet-devnet-core/src/error.rs (1)

205-206: LGTM! Error variant correctly updated.

The rename from EthersError to AlloyError is consistent with the library migration and properly updates both the variant name and error message.

tests/integration/common/utils.rs (2)

8-8: LGTM! Import updated to Alloy.

The import path correctly reflects the migration from ethers to alloy primitives.


465-467: LGTM! Conversion method correctly updated.

The change from U256::from_big_endian(&f.to_bytes_be()) to U256::from_be_bytes(f.to_bytes_be()) correctly reflects the API difference between ethers and alloy. Both methods interpret big-endian byte arrays identically, so the behavior is preserved.

tests/integration/Cargo.toml (1)

19-19: LGTM! Test dependency correctly updated.

The replacement of ethers with alloy in the integration tests aligns with the broader migration.

tests/integration/common/errors.rs (1)

21-22: LGTM! Test error variant correctly updated.

The rename from EthersError to AlloyError in the test error enum is consistent with the core library changes.

Cargo.toml (2)

74-74: LGTM! Minor version bump.

The upgrade of url from 2.4 to 2.5 is a minor version increment and should be backward compatible.


118-119: LGTM! New dependencies for migration.

The addition of alloy (1.1.0) and eyre (0.6) at the workspace level properly supports the migration from ethers-rs.

crates/starknet-devnet-core/src/starknet/mod.rs (2)

4-4: LGTM! Hash type import updated.

The import correctly switches from ethers' H256 to alloy's B256 for representing 32-byte hashes.


1564-1564: LGTM! Hash construction updated for alloy.

The change from H256(*l1_tx_hash.as_bytes()) to B256::new(*l1_tx_hash.as_bytes()) correctly reflects the API difference between ethers and alloy for constructing 32-byte hashes. The behavior is semantically equivalent.

crates/starknet-devnet-core/src/messaging/mod.rs (6)

35-35: LGTM! Hash type import updated.

The import correctly switches from ethers' H256 to alloy's B256.


50-50: LGTM! Documentation updated.

The doc comment correctly reflects the change from ethers to alloy.


59-59: LGTM! Public field type updated.

The HashMap key type correctly changes from H256 to B256 for the l2_to_l1_messages_hashes field.


63-63: LGTM! Public field type updated.

The HashMap key type correctly changes from H256 to B256 for the l1_to_l2_tx_hashes field.


165-165: LGTM! Hash construction updated.

The change from H256(...) to B256::new(...) correctly reflects alloy's API for constructing 32-byte hashes.


211-211: LGTM! Hash construction updated.

The change from H256(...) to B256::new(...) correctly reflects alloy's API for constructing 32-byte hashes.

@3alpha 3alpha merged commit 3aecdf1 into main Nov 11, 2025
2 checks passed
@3alpha 3alpha deleted the migrate-to-alloy branch November 11, 2025 14:34
3alpha added a commit that referenced this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate from ethers-rs to alloy

1 participant