Skip to content

Commit

Permalink
Merge rust-bitcoin#709: Bump MSRV to 1.63
Browse files Browse the repository at this point in the history
55c2efc Bump MSRV to 1.63 (Martin Habovstiak)

Pull request description:

  The version 1.63 satisfies our requirements for MSRV and provides significant benefits so this commit bumps it. This commit also starts using weak dependencies.

ACKs for top commit:
  tcharding:
    ACK 55c2efc

Tree-SHA512: 565fd46768384e7c026c3aa8873e321a20425a6526bcd379ba442cf2504517a435c6c14e21186b36c99185d0a8439f4de2d3ba097b91119483d1a83ab05010ba
  • Loading branch information
apoelstra committed Jul 26, 2024
2 parents 135c938 + 55c2efc commit c4c029f
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ jobs:
run: ./contrib/test.sh

MSRV:
name: Test - 1.56.1 toolchain
name: Test - MSRV toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@1.56.1
uses: dtolnay/rust-toolchain@1.63.0
- name: Running test script
env:
DO_FEATURE_MATRIX: true
Expand Down
16 changes: 6 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ description = "Rust wrapper library for Pieter Wuille's `libsecp256k1`. Implemen
keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
readme = "README.md"
edition = "2021"
rust-version = "1.56.1"
rust-version = "1.63.0"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["std"]
std = ["alloc", "secp256k1-sys/std"]
std = ["alloc", "secp256k1-sys/std", "rand?/std", "rand?/std_rng", "hashes?/std"]
# allow use of Secp256k1::new and related API that requires an allocator
alloc = ["secp256k1-sys/alloc"]
hashes-std = ["std", "hashes/std"]
rand-std = ["std", "rand", "rand/std", "rand/std_rng"]
recovery = ["secp256k1-sys/recovery"]
lowmemory = ["secp256k1-sys/lowmemory"]
global-context = ["std"]
# disable re-randomization of the global context, which provides some
# defense-in-depth against sidechannel attacks. You should only use
# this feature if you expect the `rand` crate's thread_rng to panic.
# (If you are sure the `rand-std` feature will not be enabled, e.g.
# (If you are sure the `rand` and `std` features will not be enabled, e.g.
# if you are doing a no-std build, then this feature does nothing
# and is not necessary.)
global-context-less-secure = ["global-context"]
Expand All @@ -39,8 +37,6 @@ global-context-less-secure = ["global-context"]
secp256k1-sys = { version = "0.10.0", default-features = false, path = "./secp256k1-sys" }
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
# the respective -std feature e.g., hashes-std
hashes = { package = "bitcoin_hashes", version = ">= 0.12, <= 0.14", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, optional = true }

Expand All @@ -59,15 +55,15 @@ unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(secp256k1_fu

[[example]]
name = "sign_verify_recovery"
required-features = ["recovery", "hashes-std"]
required-features = ["recovery", "hashes", "std"]

[[example]]
name = "sign_verify"
required-features = ["hashes-std"]
required-features = ["hashes", "std"]

[[example]]
name = "generate_keys"
required-features = ["rand-std"]
required-features = ["rand", "std"]

[workspace]
members = ["secp256k1-sys"]
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.56.1"
msrv = "1.63.0"
16 changes: 8 additions & 8 deletions 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"

cargo --version
rustc --version
Expand Down Expand Up @@ -62,17 +62,17 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
fi

# Examples
cargo run --locked --example sign_verify --features=hashes-std
cargo run --locked --example sign_verify_recovery --features=recovery,hashes-std
cargo run --locked --example generate_keys --features=rand-std
cargo run --locked --example sign_verify --features=hashes,std
cargo run --locked --example sign_verify_recovery --features=recovery,hashes,std
cargo run --locked --example generate_keys --features=rand,std
fi

if [ "$DO_LINT" = true ]
then
cargo clippy --locked --all-features --all-targets -- -D warnings
cargo clippy --locked --example sign_verify --features=hashes-std -- -D warnings
cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes-std -- -D warnings
cargo clippy --locked --example generate_keys --features=rand-std -- -D warnings
cargo clippy --locked --example sign_verify --features=hashes,std -- -D warnings
cargo clippy --locked --example sign_verify_recovery --features=recovery,hashes,std -- -D warnings
cargo clippy --locked --example generate_keys --features=rand,std -- -D warnings
fi

# Build the docs if told to (this only works with the nightly toolchain)
Expand Down Expand Up @@ -120,7 +120,7 @@ fi
# Bench if told to, only works with non-stable toolchain (nightly, beta).
if [ "$DO_BENCH" = true ]
then
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand-std
RUSTFLAGS='--cfg=bench' cargo bench --features=recovery,rand,std
fi

exit 0
2 changes: 1 addition & 1 deletion githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fi
git diff-index --check --cached $against -- || exit 1

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

# Check that there are no formatting issues.
cargo +nightly fmt --check || exit 1
2 changes: 1 addition & 1 deletion secp256k1-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
build = "build.rs"
links = "rustsecp256k1_v0_10_0"
edition = "2021"
rust-version = "1.56.1"
rust-version = "1.63.0"

[package.metadata.docs.rs]
all-features = true
Expand Down
47 changes: 29 additions & 18 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ pub mod global {

/// A global static context to avoid repeatedly creating contexts.
///
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
///
/// ```
/// # #[cfg(all(feature = "global-context", feature = "rand-std"))] {
/// # #[cfg(all(feature = "global-context", feature = "rand", feature = "std"))] {
/// use secp256k1::{PublicKey, SECP256K1};
/// let _ = SECP256K1.generate_keypair(&mut rand::thread_rng());
/// # }
Expand All @@ -40,15 +41,16 @@ pub mod global {
impl Deref for GlobalContext {
type Target = Secp256k1<All>;

#[allow(unused_mut)] // Unused when `rand-std` is not enabled.
#[allow(unused_mut)] // Unused when `rand` + `std` is not enabled.
fn deref(&self) -> &Self::Target {
static ONCE: Once = Once::new();
static mut CONTEXT: Option<Secp256k1<All>> = None;
ONCE.call_once(|| unsafe {
let mut ctx = Secp256k1::new();
#[cfg(all(
not(target_arch = "wasm32"),
feature = "rand-std",
feature = "rand",
feature = "std",
not(feature = "global-context-less-secure")
))]
{
Expand Down Expand Up @@ -181,10 +183,12 @@ mod alloc_only {
impl<C: Context> Secp256k1<C> {
/// Lets you create a context in a generic manner (sign/verify/all).
///
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
/// If `rand-std` feature is not enabled please consider randomizing the context as follows:
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context as
/// follows:
/// ```
/// # #[cfg(feature = "rand-std")] {
/// # #[cfg(all(feature = "rand", feature = "std"))] {
/// # use secp256k1::Secp256k1;
/// # use secp256k1::rand::{thread_rng, RngCore};
/// let mut ctx = Secp256k1::new();
Expand All @@ -195,7 +199,10 @@ mod alloc_only {
/// ctx.seeded_randomize(&seed);
/// # }
/// ```
#[cfg_attr(not(feature = "rand-std"), allow(clippy::let_and_return, unused_mut))]
#[cfg_attr(
not(all(feature = "rand", feature = "std")),
allow(clippy::let_and_return, unused_mut)
)]
pub fn gen_new() -> Secp256k1<C> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();
Expand All @@ -214,7 +221,8 @@ mod alloc_only {

#[cfg(all(
not(target_arch = "wasm32"),
feature = "rand-std",
feature = "rand",
feature = "std",
not(feature = "global-context-less-secure")
))]
{
Expand All @@ -229,27 +237,30 @@ mod alloc_only {
impl Secp256k1<All> {
/// Creates a new Secp256k1 context with all capabilities.
///
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
/// If `rand-std` feature is not enabled please consider randomizing the context (see docs
/// for `Secp256k1::gen_new()`).
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
/// docs for `Secp256k1::gen_new()`).
pub fn new() -> Secp256k1<All> { Secp256k1::gen_new() }
}

impl Secp256k1<SignOnly> {
/// Creates a new Secp256k1 context that can only be used for signing.
///
/// If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
/// If `rand-std` feature is not enabled please consider randomizing the context (see docs
/// for `Secp256k1::gen_new()`).
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
/// docs for `Secp256k1::gen_new()`).
pub fn signing_only() -> Secp256k1<SignOnly> { Secp256k1::gen_new() }
}

impl Secp256k1<VerifyOnly> {
/// Creates a new Secp256k1 context that can only be used for verification.
///
/// * If `rand-std` feature is enabled, context will have been randomized using `thread_rng`.
/// * If `rand-std` feature is not enabled please consider randomizing the context (see docs
/// for `Secp256k1::gen_new()`).
/// If `rand` and `std` feature is enabled, context will have been randomized using
/// `thread_rng`.
/// If `rand` or `std` feature is not enabled please consider randomizing the context (see
/// docs for `Secp256k1::gen_new()`).
pub fn verification_only() -> Secp256k1<VerifyOnly> { Secp256k1::gen_new() }
}

Expand Down
10 changes: 5 additions & 5 deletions src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SHARED_SECRET_SIZE: usize = constants::SECRET_KEY_SIZE;
/// # Examples
///
/// ```
/// # #[cfg(feature = "rand-std")] {
/// # #[cfg(all(feature = "rand", feature = "std"))] {
/// # use secp256k1::{rand, Secp256k1};
/// # use secp256k1::ecdh::SharedSecret;
/// let s = Secp256k1::new();
Expand Down Expand Up @@ -110,7 +110,7 @@ impl AsRef<[u8]> for SharedSecret {
///
/// # Examples
/// ```
/// # #[cfg(all(feature = "hashes-std", feature = "rand-std"))] {
/// # #[cfg(all(feature = "hashes", feature = "rand", feature = "std"))] {
/// # use secp256k1::{ecdh, rand, Secp256k1, PublicKey, SecretKey};
/// # use secp256k1::hashes::{Hash, sha512};
///
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
use crate::Secp256k1;

#[test]
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
fn ecdh() {
let s = Secp256k1::signing_only();
let (sk1, pk1) = s.generate_keypair(&mut rand::thread_rng());
Expand Down Expand Up @@ -225,7 +225,7 @@ mod tests {

#[test]
#[cfg(not(secp256k1_fuzz))]
#[cfg(all(feature = "hashes-std", feature = "rand-std"))]
#[cfg(all(feature = "hashes", feature = "rand", feature = "std"))]
fn hashes_and_sys_generate_same_secret() {
use hashes::{sha256, Hash, HashEngine};

Expand Down Expand Up @@ -275,7 +275,7 @@ mod tests {
}

#[cfg(bench)]
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
#[cfg(all(feature = "rand", feature = "std"))] // Currently only a single bench that requires "rand" + "std".
mod benches {
use test::{black_box, Bencher};

Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<C: Verification> Secp256k1<C> {
/// verify-capable context.
///
/// ```rust
/// # #[cfg(feature = "rand-std")] {
/// # #[cfg(all(feature = "rand", feature = "std"))] {
/// # use secp256k1::{rand, Secp256k1, Message, Error};
/// #
/// # let secp = Secp256k1::new();
Expand Down
16 changes: 8 additions & 8 deletions src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ mod tests {
use crate::{Error, Message, Secp256k1, SecretKey};

#[test]
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
fn capabilities() {
let sign = Secp256k1::signing_only();
let vrfy = Secp256k1::verification_only();
Expand Down Expand Up @@ -251,7 +251,7 @@ mod tests {

#[test]
#[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
#[rustfmt::skip]
fn sign() {
let mut s = Secp256k1::new();
Expand All @@ -276,7 +276,7 @@ mod tests {

#[test]
#[cfg(not(secp256k1_fuzz))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
#[rustfmt::skip]
fn sign_with_noncedata() {
let mut s = Secp256k1::new();
Expand All @@ -301,7 +301,7 @@ mod tests {
}

#[test]
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
fn sign_and_verify_fail() {
let mut s = Secp256k1::new();
s.randomize(&mut rand::thread_rng());
Expand All @@ -323,7 +323,7 @@ mod tests {
}

#[test]
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
fn sign_with_recovery() {
let mut s = Secp256k1::new();
s.randomize(&mut rand::thread_rng());
Expand All @@ -339,7 +339,7 @@ mod tests {
}

#[test]
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
fn sign_with_recovery_and_noncedata() {
let mut s = Secp256k1::new();
s.randomize(&mut rand::thread_rng());
Expand All @@ -357,7 +357,7 @@ mod tests {
}

#[test]
#[cfg(feature = "rand-std")]
#[cfg(all(feature = "rand", feature = "std"))]
fn bad_recovery() {
let mut s = Secp256k1::new();
s.randomize(&mut rand::thread_rng());
Expand Down Expand Up @@ -423,7 +423,7 @@ mod tests {
}

#[cfg(bench)]
#[cfg(feature = "rand-std")] // Currently only a single bench that requires "rand-std".
#[cfg(all(feature = "rand", feature = "std"))] // Currently only a single bench that requires "rand" + "std".
mod benches {
use test::{black_box, Bencher};

Expand Down
Loading

0 comments on commit c4c029f

Please sign in to comment.