Skip to content

feat: add eth1wrap#87

Merged
emlautarom1 merged 6 commits into
mainfrom
emlautarom1/eth1wrap
Dec 18, 2025
Merged

feat: add eth1wrap#87
emlautarom1 merged 6 commits into
mainfrom
emlautarom1/eth1wrap

Conversation

@emlautarom1
Copy link
Copy Markdown
Collaborator

@emlautarom1 emlautarom1 commented Dec 8, 2025

Solves #40
Solves #27


The existing Go implementation adds an interface that wraps a ethclient.Client from go-ethereum. Here, we do something similar by wrapping an alloy::providers::Provider from the Alloy family of crates, while adding methods required specifically by Charon (ex. VerifySmartContractBasedSignature).

Alloy uses reqwest as the underlying HTTP client. Adding retries in a general fashion to this client is tricky since "standard" solutions like reqwest-middleware are incompatible with Alloy.

The proposed solution for now is to use the retry mechanism provided directly by Alloy: https://docs.rs/alloy-transport/latest/alloy_transport/layers/struct.RetryBackoffLayer.html . An other option (and I think the most suitable) is to use tower's Exponential Backoff, which is the underlying mechanism used by Alloy itself.

I'd like to separate PRs into one for eth1wrap (this one) and other for expbackoff and retry modules as defined in the original Go implementation, and then make the required changes to use the appropriate retry mechanism.

Copilot AI review requested due to automatic review settings December 8, 2025 19:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces the eth1wrap module, providing an Ethereum execution layer RPC client interface that wraps Alloy's Provider. Similar to how the Go implementation wraps go-ethereum's ethclient.Client, this implementation adds Charon-specific functionality like ERC-1271 smart contract signature verification with built-in retry support for rate limiting.

Key Changes

  • New EthClient struct wrapping Alloy's DynProvider with automatic retry/backoff for rate limiting
  • Integration of ERC-1271 contract signature verification via verify_smart_contract_based_signature method
  • Addition of Alloy, thiserror, and url dependencies to the workspace

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
crates/charon/src/eth1wrap/mod.rs Core implementation of EthClient with error types, retry configuration, and ERC-1271 signature verification
crates/charon/src/eth1wrap/build/IERC1271.abi ABI definition for ERC-1271 isValidSignature function
crates/charon/src/lib.rs Module export for eth1wrap
crates/charon/Cargo.toml Dependency additions for alloy, thiserror, and url
Cargo.toml Workspace-level dependency definitions
flake.nix Added protobuf to nix development dependencies
Cargo.lock Dependency lock file updates for Alloy ecosystem and transitive dependencies

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs Outdated
Comment thread crates/charon/src/eth1wrap/mod.rs Outdated
Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 8, 2025

Coverage (base → head): 61.04% → 60.76% ⬇️ 0.28 pp
Only posts when PR coverage is lower than the base branch's latest push (or freshly computed base).

This was linked to issues Dec 9, 2025
Copy link
Copy Markdown
Collaborator

@varex83 varex83 left a comment

Choose a reason for hiding this comment

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

LGTM!

One question: do you plan to add tests in the future for this?

@varex83
Copy link
Copy Markdown
Collaborator

varex83 commented Dec 9, 2025

Also, can you rename the PR so it will have the same style as other PRs

@emlautarom1 emlautarom1 changed the title Add eth1wrap feat: Add eth1wrap Dec 9, 2025
@emlautarom1 emlautarom1 changed the title feat: Add eth1wrap feat: add eth1wrap Dec 9, 2025
Copilot AI review requested due to automatic review settings December 18, 2025 19:21
@emlautarom1
Copy link
Copy Markdown
Collaborator Author

One question: do you plan to add tests in the future for this?

I think this was discussed during our dailies but for the time being there are no tests since the original Go tests are pretty much testing mocks. The only relevant tests that they have is to ensure that the magic value used in VerifySmartContractBasedSignature is correct.

If you have any suggestion for particular tests then I'm happy to add them in a later PR.

@emlautarom1 emlautarom1 merged commit 1ab5315 into main Dec 18, 2025
12 checks passed
@emlautarom1 emlautarom1 deleted the emlautarom1/eth1wrap branch December 18, 2025 19:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs
let instance = IERC1271::new(address, &self.0);

let call = instance
.isValidSignature(hash.into(), sig.to_vec().into())
Copy link

Copilot AI Dec 18, 2025

Choose a reason for hiding this comment

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

The sig.to_vec() call creates an unnecessary allocation by copying the slice into a new Vec. Since Alloy types typically accept references or slices, consider checking if the generated binding accepts Cow<[u8]> or a slice reference directly to avoid the allocation.

Suggested change
.isValidSignature(hash.into(), sig.to_vec().into())
.isValidSignature(hash.into(), sig.into())

Copilot uses AI. Check for mistakes.
Comment thread crates/charon/src/eth1wrap/mod.rs
Comment thread crates/charon/src/eth1wrap/mod.rs
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.

Implement app/eth1wrap Implement app/eth1wrap/generated

3 participants