Skip to content

feat(eip7702): add secp256k1 feature for ECDSA recovery - #87

Merged
DaniPopes merged 3 commits into
alloy-rs:mainfrom
decofe:feat/secp256k1-feature
May 14, 2026
Merged

DaniPopes merged 3 commits into
alloy-rs:mainfrom
decofe:feat/secp256k1-feature

Conversation

@decofe

@decofe decofe commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an optional secp256k1 feature to alloy-eip7702 that uses the secp256k1 C library bindings (via the secp256k1 crate) for ECDSA public key recovery instead of the pure-Rust k256 implementation.

Details

  • Feature is disabled by default — no impact on existing users
  • When both secp256k1 and k256 are enabled, secp256k1 is preferred for recovery operations (recover_authority, into_recovered, and the From impls)
  • The k256 feature continues to work exactly as before when secp256k1 is not enabled

Changes

File Change
Cargo.toml Add secp256k1 = { version = "0.31", features = ["recovery", "alloc"] } as workspace dep
crates/eip7702/Cargo.toml Add optional secp256k1 dep and feature flag
crates/eip7702/src/auth_list.rs Add secp256k1-backed recovery impl; gate k256 impl with not(feature = "secp256k1"); update From impls to any(k256, secp256k1)
crates/eip7702/src/error.rs Add Secp256k1(secp256k1::Error) variant behind feature gate

Usage

# Use secp256k1 C library for faster recovery
alloy-eip7702 = { version = "0.6", features = ["secp256k1"] }

# Use pure-Rust k256 (existing behavior, unchanged)
alloy-eip7702 = { version = "0.6", features = ["k256"] }

# Both enabled — secp256k1 is preferred
alloy-eip7702 = { version = "0.6", features = ["secp256k1", "k256"] }

Tested

  • cargo check with each feature combo: secp256k1, k256, both, neither ✅
  • cargo test --all-features ✅
  • cargo clippy --all-features -- -Dwarnings ✅
  • cargo build --target wasm32-unknown-unknown (default features, no secp256k1) ✅

@decofe
decofe force-pushed the feat/secp256k1-feature branch 2 times, most recently from 8d00419 to 321851d Compare May 14, 2026 01:42
Add an optional `secp256k1` feature to `alloy-eip7702` that uses
alloy-primitives' secp256k1 backend for ECDSA public key recovery.

The feature is disabled by default. When both `secp256k1` and `k256`
features are enabled, `secp256k1` is preferred (handled by
alloy-primitives internally via `cfg_if!`).

This avoids importing k256 or secp256k1 directly for recovery —
the backend selection is fully delegated to alloy-primitives'
`Signature::recover_address_from_prehash`.

Changes:
- Add `secp256k1` feature to eip7702 that forwards to
  `alloy-primitives/secp256k1`
- Unify recovery impl under `#[cfg(any(feature = "k256", feature = "secp256k1"))]`
  instead of separate impl blocks
- Patch alloy-primitives to decofe/core#feat/secp256k1-backend
  (alloy-rs/core#1104) until merged and released

Depends on: alloy-rs/core#1104

Amp-Thread-ID: https://ampcode.com/threads/T-019e23bb-1e32-718f-8ec4-5f3b7bef33e2
@decofe
decofe force-pushed the feat/secp256k1-feature branch from 321851d to 744e135 Compare May 14, 2026 01:44
@github-project-automation github-project-automation Bot moved this to Reviewed in Alloy May 14, 2026
Comment thread Cargo.toml Resolved
@DaniPopes
DaniPopes merged commit c4a0c74 into alloy-rs:main May 14, 2026
24 of 25 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in Alloy May 14, 2026
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