Skip to content

Commit

Permalink
Make the -sys crate optional
Browse files Browse the repository at this point in the history
Downstream projects, such as `bitcoin` are using types from this crate
and need to compile the C code even if they only use the types for
checking validity of the data and don't perform cryptographic
operations. Compiling C code is slow and unreliable so there was desire
to avoid this.

This commit introduces pure Rust implementation of basic
non-cryptographic operations (is point on the curve, decompression of
point, secret key constant time comparisons) and feature-gates
cryptographic operations on `secp256k1-sys` which is now optional. To
make use of this, downstream crates will have to deactivate the feature
and possibly feature gate themselves.

The implementation requires a U256 type which was copied from the
`bitcoin` crate. We don't depend on a common crate to avoid needless
compilation when the feature is turned on.

This is a breaking change because users who did cryptographic operations
with `default-features = false` will get compilation errors until they
enable the feature.
  • Loading branch information
Kixunil committed Jul 2, 2024
1 parent 6648126 commit aa4ffa9
Show file tree
Hide file tree
Showing 12 changed files with 1,379 additions and 354 deletions.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
std = ["alloc", "secp256k1-sys/std"]
default = ["sys-std"]
std = ["alloc"]
alloc = []
sys-std = ["std", "sys-alloc", "secp256k1-sys/std"]
# allow use of Secp256k1::new and related API that requires an allocator
alloc = ["secp256k1-sys/alloc"]
sys-alloc = ["secp256k1-sys/alloc"]
hashes-std = ["std", "hashes/std"]
rand-std = ["std", "rand", "rand/std", "rand/std_rng"]
recovery = ["secp256k1-sys/recovery"]
Expand All @@ -36,7 +38,7 @@ global-context = ["std"]
global-context-less-secure = ["global-context"]

[dependencies]
secp256k1-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-sys" }
secp256k1-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-sys", optional = true }
serde = { version = "1.0.103", default-features = false, optional = true }

# You likely only want to enable these if you explicitly do not want to use "std", otherwise enable
Expand Down
2 changes: 1 addition & 1 deletion contrib/_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -ex

REPO_DIR=$(git rev-parse --show-toplevel)
FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std"
FEATURES="hashes global-context lowmemory rand recovery serde std alloc hashes-std rand-std secp256k1-sys"

cargo --version
rustc --version
Expand Down
Loading

0 comments on commit aa4ffa9

Please sign in to comment.