Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: integrate rust-secp256k1 #1915

Merged
merged 7 commits into from
Dec 31, 2024
Merged

Conversation

stevencartavia
Copy link
Contributor

should close #1914

@@ -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)

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

@stevencartavia
Copy link
Contributor Author

I haven't found a way to fix that warning, if I add use libsecp256k1 as _; then it doesn't build it :(

@@ -78,7 +79,7 @@ serde_json = "1.0"
serde_derive = "1.0"

[features]
default = ["std", "c-kzg", "secp256k1", "portable", "blst"]
default = ["std", "c-kzg", "secp256k1", "portable", "blst", "libsecp256k1"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
default = ["std", "c-kzg", "secp256k1", "portable", "blst", "libsecp256k1"]
default = ["std", "c-kzg", "secp256k1", "portable", "blst"]

@rakita
Copy link
Member

rakita commented Dec 31, 2024

Have restructured the code a little, and left comments for visibility. Will merge after ci

pub mod bitcoin_secp256k1;
pub mod k256;
#[cfg(feature = "libsecp256k1")]
pub mod parity_libsecp256k1;
Copy link
Member

Choose a reason for hiding this comment

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

Moved it to a separate file so it is easier to navigate. and all of them can be enabled in same time

let res = parity_libsecp256k1::ecrecover(sig, recid, msg);
} else {
let res = k256::ecrecover(sig, recid, msg);
}
Copy link
Member

Choose a reason for hiding this comment

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

This is were switch is happening, priority is secp256k1 (bitcoin lib), parity (if enabled) and by default k256.

Copy link

codspeed-hq bot commented Dec 31, 2024

CodSpeed Performance Report

Merging #1915 will not alter performance

Comparing stevencartavia:rust-secp256k1 (9afbfbd) with main (60ce865)

Summary

✅ 8 untouched benchmarks

@rakita rakita merged commit d2a3b5b into bluealloy:main Dec 31, 2024
28 checks passed
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.

Integrate rust-secp256k1
2 participants