Repository navigation
feat: add optional secp256k1 backend for ECDSA operations - #1104
Merged
Merged
Conversation
decofe
pushed a commit
to decofe/eips
that referenced
this pull request
May 14, 2026
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
pushed a commit
to decofe/eips
that referenced
this pull request
May 14, 2026
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
pushed a commit
to decofe/eips
that referenced
this pull request
May 14, 2026
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
DaniPopes
approved these changes
May 14, 2026
mattsse
approved these changes
May 14, 2026
Add an optional `secp256k1` feature (disabled by default) to `alloy-primitives` and `alloy-core` that uses the `secp256k1` C library bindings as an alternative to the pure-Rust `k256` crate for secp256k1 curve operations. When both `k256` and `secp256k1` features are enabled, the `secp256k1` backend is preferred for address recovery operations. Changes: - Add `secp256k1 = "0.31"` workspace dependency with `recovery` feature - Add `secp256k1` optional dep and feature to alloy-primitives - Forward `secp256k1` feature through alloy-core - Add `From<secp256k1::ecdsa::RecoverableSignature>` for Signature - Add `to_secp256k1()`, `secp256k1_recid()` methods on Signature - Add `recover_from_prehash_secp256k1()` and `recover_from_msg_secp256k1()` - Use secp256k1 backend in `recover_address_from_prehash` when enabled - Add `Address::from_secp256k1_public_key()` and `Address::from_secp256k1_secret_key()` - Add `SignatureError::Secp256k1` variant Amp-Thread-ID: https://ampcode.com/threads/T-019e23c4-b4d3-772c-81d0-b858df960e84
decofe
force-pushed
the
feat/secp256k1-backend
branch
from
May 14, 2026 13:46
2ec50b3 to
21e2a77
Compare
- Add alloc feature to secp256k1 workspace dep so context creation works in no_std environments - Fix formatting of matches! expression - Add CC0-1.0 license exceptions for secp256k1, secp256k1-sys, bitcoin_hashes, and bitcoin-io in deny.toml Amp-Thread-ID: https://ampcode.com/threads/T-019e23c4-b4d3-772c-81d0-b858df960e84
DaniPopes
enabled auto-merge (squash)
May 14, 2026 14:07
decofe
pushed a commit
to decofe/eips
that referenced
this pull request
May 14, 2026
alloy-core 1.6.0 includes native secp256k1 backend support (alloy-rs/core#1104), so the temporary git patch is no longer needed. Amp-Thread-ID: https://ampcode.com/threads/T-019e23bb-1e32-718f-8ec4-5f3b7bef33e2
DaniPopes
pushed a commit
to alloy-rs/eips
that referenced
this pull request
May 14, 2026
* feat(eip7702): add `secp256k1` feature for ECDSA recovery 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 * chore: bump alloy-primitives to 1.6.0 and remove patch alloy-core 1.6.0 includes native secp256k1 backend support (alloy-rs/core#1104), so the temporary git patch is no longer needed. Amp-Thread-ID: https://ampcode.com/threads/T-019e23bb-1e32-718f-8ec4-5f3b7bef33e2 * chore: revert temporary deny.toml changes and fix trailing whitespace Amp-Thread-ID: https://ampcode.com/threads/T-019e23bb-1e32-718f-8ec4-5f3b7bef33e2 --------- Co-authored-by: Centaur AI <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a
secp256k1feature (disabled by default) toalloy-primitivesandalloy-corethat uses the C libsecp256k1 bindings (secp256k1v0.31) as an alternative to the pure-Rustk256crate for elliptic curve operations.When both
k256andsecp256k1features are enabled,secp256k1is preferred for address recovery operations.Changes
Feature wiring
secp256k1 = { version = "0.31", default-features = false }alloy-primitives: optional dep withalloc+recoveryfeatures;global-contextenabled understdalloy-core: forwardssecp256k1feature toalloy-primitivesBackend-neutral recovery
recover_address_from_msgandrecover_address_from_prehashnow compile under#[cfg(any(feature = "k256", feature = "secp256k1"))]and usecfg_if!to select the preferred backend:secp256k1(if enabled) — usesSecp256k1::recover_ecdsa+RecoverableSignaturek256(fallback) — usesVerifyingKey::recover_from_prehashNew secp256k1-specific API surface
Signature::to_secp256k1()/to_secp256k1_recoverable()Signature::from_secp256k1_signature_and_parity()Signature::recover_secp256k1_from_prehash()Address::from_secp256k1_public_key()/from_secp256k1_secret_key()From<(RecoverableSignature, RecoveryId)> for SignatureTryFrom<Signature> for secp256k1::ecdsa::SignatureSignatureError::Secp256k1variantPreserved
All existing
k256-gated API is untouched — no breaking changes.Testing
Tested with all feature combinations:
--features secp256k1✅--features k256✅--features k256,secp256k1✅--no-default-features --features secp256k1✅Recovery tests (
can_recover_tx_sender_not_normalized,recover_web3_signature) broadened to run under both backends.