Skip to content

Comments

feat: Add dynamic crypto backend for ecrecover#2634

Merged
mattsse merged 18 commits intoalloy-rs:mainfrom
kevaundray:kw/add-dyn-crypto-rs
Jul 1, 2025
Merged

feat: Add dynamic crypto backend for ecrecover#2634
mattsse merged 18 commits intoalloy-rs:mainfrom
kevaundray:kw/add-dyn-crypto-rs

Conversation

@kevaundray
Copy link
Contributor

Motivation

One motivation for this is to allow downstream users to plug in their own implementation of certain functions. The downstream user we have in mind are zkVM guest program implementers where they could add precompiles using this strategy.

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@kevaundray kevaundray changed the title chore: Add dynamic crypto backend chore: Add dynamic crypto backend for ecdsa Jun 29, 2025
@kevaundray kevaundray changed the title chore: Add dynamic crypto backend for ecdsa chore: Add dynamic crypto backend for ecrecover Jun 29, 2025
@kevaundray kevaundray changed the title chore: Add dynamic crypto backend for ecrecover feat: Add dynamic crypto backend for ecrecover Jun 29, 2025
@kevaundray kevaundray force-pushed the kw/add-dyn-crypto-rs branch from 71a385a to 59fbb2f Compare June 29, 2025 16:17
@kevaundray kevaundray force-pushed the kw/add-dyn-crypto-rs branch from 59fbb2f to e5114be Compare June 29, 2025 16:18
@kevaundray kevaundray marked this pull request as ready for review June 29, 2025 16:32
Comment on lines +179 to +182
#[cfg(feature = "crypto-backend")]
if let Some(provider) = super::backend::try_get_provider() {
return provider.recover_signer_unchecked(&sig, &hash.0);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If crypto-baackend feature-flag is set, then this will call whatever backend is set here.

To install your own backend, you can call install_default_provider in your own codebase. install_default_provider can only be called once, calling it more than once will return an error

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

only have nits, otherwise this lgtm

but we can add some additional docs for the backend type

Comment on lines +178 to +182
// Try dynamic backend first when crypto-backend feature is enabled
#[cfg(feature = "crypto-backend")]
if let Some(provider) = super::backend::try_get_provider() {
return provider.recover_signer_unchecked(&sig, &hash.0);
}
Copy link
Member

Choose a reason for hiding this comment

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

this seems okay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A different strategy would be to make it such that the crypto-backend was exactly like the other two backends. It would need to have a recover_signer_unchecked function instead of a method.

The downside of this approach is that the fallback would need to be defined in the crypto-backend module or we could just return an error, if no backend has been installed

Copy link
Member

@mattsse mattsse Jun 30, 2025

Choose a reason for hiding this comment

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

if no backend has been installed

this I'd like to avoid because this will be very unpleasant for users that just want to do some simple rpc stuff

@github-project-automation github-project-automation bot moved this to In Progress in Alloy Jun 29, 2025
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

this lgtm

mind taking a look at this as well @klkvr @DaniPopes

@github-project-automation github-project-automation bot moved this from In Progress to Reviewed in Alloy Jun 30, 2025
@mattsse mattsse merged commit e15ed74 into alloy-rs:main Jul 1, 2025
28 checks passed
@github-project-automation github-project-automation bot moved this from Reviewed to Done in Alloy Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants