Skip to content

Commit fdded5b

Browse files
committed
Remove the global-context features
Now that we fully use the new global contexts that work both with and without `std` we can delete the `global-context` and `global-context-less-secure` features.
1 parent 3d17551 commit fdded5b

File tree

9 files changed

+9
-46
lines changed

9 files changed

+9
-46
lines changed

Cargo.toml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,9 @@ exclude = ["tests", "contrib"]
1616
[features]
1717
default = ["std"]
1818
std = ["alloc", "secp256k1-sys/std", "rand?/std", "rand?/std_rng", "rand?/thread_rng"]
19-
# allow use of Secp256k1::new and related API that requires an allocator
2019
alloc = ["secp256k1-sys/alloc"]
2120
recovery = ["secp256k1-sys/recovery"]
2221
lowmemory = ["secp256k1-sys/lowmemory"]
23-
global-context = ["std"]
24-
# disable re-randomization of the global context, which provides some
25-
# defense-in-depth against sidechannel attacks. You should only use
26-
# this feature if you expect the `rand` crate's thread_rng to panic.
27-
# (If you are sure the `rand` and `std` features will not be enabled, e.g.
28-
# if you are doing a no-std build, then this feature does nothing
29-
# and is not necessary.)
30-
global-context-less-secure = ["global-context"]
3122
arbitrary = ["dep:arbitrary"]
3223

3324
[dependencies]

contrib/test_vars.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
# shellcheck disable=SC2034
66

77
# Test all these features with "std" enabled.
8-
FEATURES_WITH_STD="global-context global-context-less-secure lowmemory rand recovery serde"
8+
FEATURES_WITH_STD="lowmemory rand recovery serde"
99

1010
# Test all these features without "std" enabled.
11-
FEATURES_WITHOUT_STD="global-context global-context-less-secure lowmemory rand recovery serde alloc"
11+
FEATURES_WITHOUT_STD="lowmemory rand recovery serde alloc"
1212

1313
# Run these examples.
1414
EXAMPLES="sign_verify:std sign_verify_recovery:std,recovery generate_keys:rand,std"

githooks/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fi
4747
git diff-index --check --cached "$against" -- || exit 1
4848

4949
# Check that code lints cleanly.
50-
cargo clippy --features=rand,std,recovery,lowmemory,global-context --all-targets -- -D warnings || exit 1
50+
cargo clippy --features=rand,std,recovery,lowmemory --all-targets -- -D warnings || exit 1
5151

5252
# Check that there are no formatting issues.
5353
cargo +nightly fmt --check || exit 1

src/context/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ mod alloc_only {
179179
not(target_arch = "wasm32"),
180180
feature = "rand",
181181
feature = "std",
182-
not(feature = "global-context-less-secure")
183182
))]
184183
{
185184
ctx.randomize(&mut rand::rng());

src/ecdsa/recovery.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ impl RecoverableSignature {
128128
/// Determines the public key for which this [`Signature`] is valid for `msg`. Requires a
129129
/// verify-capable context.
130130
#[inline]
131-
#[cfg(feature = "global-context")]
132131
pub fn recover(&self, msg: impl Into<Message>) -> Result<key::PublicKey, Error> {
133132
self.recover_ecdsa(msg)
134133
}

src/key/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ impl PublicKey {
117117

118118
/// Creates a new public key from a [`SecretKey`].
119119
#[inline]
120-
#[cfg(feature = "global-context")]
121120
#[deprecated(since = "TBD", note = "use from_secret_key instead")]
122121
pub fn from_secret_key_global(sk: &SecretKey) -> PublicKey { PublicKey::from_secret_key(sk) }
123122

@@ -460,7 +459,7 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
460459
///
461460
/// # Serde support
462461
///
463-
/// Implements de/serialization with the `serde` and `global-context` features enabled. Serializes
462+
/// Implements de/serialization with the `serde` and feature enabled. Serializes
464463
/// the secret bytes only. We treat the byte value as a tuple of 32 `u8`s for non-human-readable
465464
/// formats. This representation is optimal for some formats (e.g. [`bincode`]) however other
466465
/// formats may be less optimal (e.g. [`cbor`]). For human-readable formats we use a hex string.
@@ -606,7 +605,7 @@ impl Keypair {
606605

607606
/// Generates a new random secret key.
608607
#[inline]
609-
#[cfg(all(feature = "global-context", feature = "rand"))]
608+
#[cfg(feature = "rand")]
610609
#[deprecated(since = "TBD", note = "use Keypair::new instead")]
611610
pub fn new_global<R: ::rand::Rng + ?Sized>(rng: &mut R) -> Keypair { Keypair::new(rng) }
612611

@@ -1934,7 +1933,7 @@ mod test {
19341933
}
19351934

19361935
#[test]
1937-
#[cfg(all(feature = "global-context", feature = "serde"))]
1936+
#[cfg(feature = "serde")]
19381937
fn test_serde_keypair() {
19391938
use serde::{Deserialize, Deserializer, Serialize, Serializer};
19401939
use serde_test::{assert_tokens, Configure, Token};
@@ -2109,7 +2108,7 @@ mod test {
21092108

21102109
#[test]
21112110
#[cfg(not(secp256k1_fuzz))]
2112-
#[cfg(all(feature = "global-context", feature = "serde"))]
2111+
#[cfg(feature = "serde")]
21132112
fn test_serde_x_only_pubkey() {
21142113
use serde_test::{assert_tokens, Configure, Token};
21152114

src/lib.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,6 @@
4949
//! # }
5050
//! ```
5151
//!
52-
//! If the "global-context" feature is enabled you have access to an alternate API.
53-
//!
54-
//! ```rust
55-
//! # #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] {
56-
//! use secp256k1::{rand, Message};
57-
//!
58-
//! // See previous example regarding this constant.
59-
//! const HELLO_WORLD_SHA2: [u8; 32] = [
60-
//! 0x31, 0x5f, 0x5b, 0xdb, 0x76, 0xd0, 0x78, 0xc4, 0x3b, 0x8a, 0xc0, 0x06, 0x4e, 0x4a, 0x01, 0x64,
61-
//! 0x61, 0x2b, 0x1f, 0xce, 0x77, 0xc8, 0x69, 0x34, 0x5b, 0xfc, 0x94, 0xc7, 0x58, 0x94, 0xed, 0xd3,
62-
//! ];
63-
//!
64-
//! let (secret_key, public_key) = secp256k1::generate_keypair(&mut rand::rng());
65-
//! let message = Message::from_digest(HELLO_WORLD_SHA2);
66-
//!
67-
//! let sig = secret_key.sign_ecdsa(message);
68-
//! assert!(sig.verify(message, &public_key).is_ok());
69-
//! # }
70-
//! ```
71-
//!
7252
//! The above code requires `rust-secp256k1` to be compiled with the `rand`, `hashes`, and `std`
7353
//! feature enabled, to get access to [`generate_keypair`](struct.Secp256k1.html#method.generate_keypair)
7454
//! Alternately, keys and messages can be parsed from slices, like
@@ -139,7 +119,6 @@
139119
//! * `hashes` - use the `hashes` library.
140120
//! * `recovery` - enable functions that can compute the public key from signature.
141121
//! * `lowmemory` - optimize the library for low-memory environments.
142-
//! * `global-context` - enable use of global secp256k1 context (implies `std`).
143122
//! * `serde` - implements serialization and deserialization for types in this crate using `serde`.
144123
//! **Important**: `serde` encoding is **not** the same as consensus encoding!
145124
//!
@@ -422,12 +401,12 @@ pub fn generate_keypair<R: rand::Rng + ?Sized>(rng: &mut R) -> (key::SecretKey,
422401
/// Constructor for unit testing. (Calls `generate_keypair` if all
423402
/// the relevant features are on to get coverage of that functoin.)
424403
#[cfg(test)]
425-
#[cfg(all(feature = "global-context", feature = "rand", feature = "std"))]
404+
#[cfg(all(feature = "rand", feature = "std"))]
426405
fn test_random_keypair() -> (key::SecretKey, key::PublicKey) { generate_keypair(&mut rand::rng()) }
427406

428407
/// Constructor for unit testing.
429408
#[cfg(test)]
430-
#[cfg(not(all(feature = "global-context", feature = "rand", feature = "std")))]
409+
#[cfg(not(all(feature = "rand", feature = "std")))]
431410
fn test_random_keypair() -> (key::SecretKey, key::PublicKey) {
432411
let sk = SecretKey::test_random();
433412
let pk = key::PublicKey::from_secret_key(&sk);
@@ -963,7 +942,6 @@ mod tests {
963942
assert_tokens(&sig.readable(), &[Token::String(SIG_STR)]);
964943
}
965944

966-
#[cfg(feature = "global-context")]
967945
#[test]
968946
fn test_global_context() {
969947
let sk_data = hex!("e6dd32f8761625f105c39a39f19370b3521d845a12456d60ce44debd0a362641");

src/schnorr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ impl Signature {
103103

104104
/// Verifies a schnorr signature for `msg` using `pk`.
105105
#[inline]
106-
#[cfg(feature = "global-context")]
107106
pub fn verify(&self, msg: &[u8], pk: &XOnlyPublicKey) -> Result<(), Error> {
108107
verify(self, msg, pk)
109108
}

tests/serde.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ extern crate bincode;
44
extern crate secp256k1;
55
extern crate serde_cbor;
66

7-
#[cfg(feature = "global-context")]
87
use secp256k1::Keypair;
98
use secp256k1::{musig, PublicKey, SecretKey, XOnlyPublicKey};
109

@@ -95,7 +94,6 @@ fn bincode_public_key() {
9594
}
9695

9796
#[test]
98-
#[cfg(feature = "global-context")]
9997
fn bincode_keypair() {
10098
let kp = Keypair::from_seckey_byte_array(SK_BYTES).expect("failed to create keypair");
10199
let ser = bincode::serialize(&kp).unwrap();

0 commit comments

Comments
 (0)