Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ specification.workspace = true
once_cell = { version = "1.19", default-features = false, features = ["alloc"] }

# ecRecover
rust_secp256k1 = { version = "0.22", package = "secp256k1", default-features = false, features = [
"alloc",
"recovery",
]}
k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] }
secp256k1 = { version = ">=0.28, <=0.29", default-features = false, features = [
"alloc",
Expand Down
13 changes: 8 additions & 5 deletions crates/precompile/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,23 @@ mod secp256k1 {
#[allow(clippy::module_inception)]
mod secp256k1 {
use primitives::{alloy_primitives::B512, keccak256, B256};
use secp256k1::{
use rust_secp256k1::{
Copy link
Member

Choose a reason for hiding this comment

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

Hey @stevencartavia, the idea is not to replace it but to add a new option with a feature flag for rust_secp256k1.

I would see to try cfg_if (there are a few examples of its usage in the repo)

ecdsa::{RecoverableSignature, RecoveryId},
Message, SECP256K1,
Message, Secp256k1,
};

// Silence the unused crate dependency warning.
use k256 as _;
use secp256k1 as _;

pub fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result<B256, rust_secp256k1::Error> {
let engine = Secp256k1::new();
Copy link
Member

Choose a reason for hiding this comment

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

does rust_secp256k1 have something as a static context? for secp256k1 this was one of the performance degradation and that is why we use SECP256K1.recover_ecdsa as it is faster


pub fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result<B256, secp256k1::Error> {
let recid = RecoveryId::from_i32(recid as i32).expect("recovery ID is valid");
let sig = RecoverableSignature::from_compact(sig.as_slice(), recid)?;

let msg = Message::from_digest(msg.0);
let public = SECP256K1.recover_ecdsa(&msg, &sig)?;
let msg = Message::from_slice(msg.as_ref())?;
let public = engine.recover_ecdsa(&msg, &sig)?;

let mut hash = keccak256(&public.serialize_uncompressed()[1..]);
hash[..12].fill(0);
Expand Down
Loading