Skip to content

Commit b1ff7fb

Browse files
committed
Merge #66: Various modernization/cleanups and release 0.9.0
0a5a7e2 release 0.9.0 (Andrew Poelstra) 8274b29 add a few missing #derives (Andrew Poelstra) 1241bc6 cargo fmt (Andrew Poelstra) 2c84bfa ci: update contrib/test.sh for recent changes (Andrew Poelstra) a0b1a4f remove unused `unstable` feature and references to benchmarks (Andrew Poelstra) 9af7b52 rename `use-rand` feature to `rand`; remove unused `rand-core` dep (Andrew Poelstra) b016592 rename `use-serde` feature to `serde` and `bitcoin-private` to `internals` (Andrew Poelstra) 1ddc43f docsrs: label feature-gated functions (Andrew Poelstra) Pull request description: The main thing I need here is the `PartialOrd` impl on `Twek`, but this also addresses a bunch of other nits. ACKs for top commit: sanket1729: utACK 0a5a7e2. Tree-SHA512: 6111386c03c4b189aa7829de4b787c0a96c4ea48c9252c6e1829e569320426662e24b12f786b06b61bc949c1e52050afbdd24304814679258f37a33d78365f8f
2 parents 8825320 + 0a5a7e2 commit b1ff7fb

File tree

11 files changed

+46
-64
lines changed

11 files changed

+46
-64
lines changed

.github/workflows/rust.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ jobs:
2222
env:
2323
DO_ASAN: true
2424
run: ./contrib/test.sh
25-
- name: Running benchmarks
26-
env:
27-
DO_BENCH: true
28-
run: ./contrib/test.sh
2925
- name: Building docs
3026
env:
3127
DO_DOCS: true

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Unreleased
22

3+
# 0.9.0 - 2023-06-08
4+
5+
- Rename `use-serde` to `serde` and `use-rand` to `rand`
6+
- Remove unused `unstable` feature
7+
- Add `PartialOrd`, `Ord` and `Hash` back to `Tweak`
8+
39
# 0.8.0 - 2023-04-13
410

511
- Increment MSRV to 1.48.0

Cargo.toml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secp256k1-zkp"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
55
"Andrew Poelstra <apoelstra@wpsoftware.net>",
66
"Lucas Soriano <lucas@comit.network>",
@@ -16,35 +16,32 @@ edition = "2018"
1616

1717
# Should make docs.rs show all functions, even those behind non-default features
1818
[package.metadata.docs.rs]
19-
features = [ "use-rand", "rand-std", "use-serde", "recovery" ]
19+
all-features = true
20+
rustdoc-args = ["--cfg", "docsrs"]
2021

2122
[features]
22-
unstable = ["recovery", "rand-std"]
2323
default = ["std"]
2424
std = ["secp256k1-zkp-sys/std", "secp256k1/std"]
25-
rand-std = ["rand/std", "secp256k1/rand-std"]
25+
rand-std = ["actual-rand/std", "secp256k1/rand-std"]
2626
recovery = ["secp256k1-zkp-sys/recovery", "secp256k1/recovery"]
2727
lowmemory = ["secp256k1-zkp-sys/lowmemory", "secp256k1/lowmemory"]
2828
global-context = ["std", "rand-std", "secp256k1/global-context"]
2929
bitcoin_hashes = ["secp256k1/bitcoin_hashes"]
30-
use-serde = ["serde", "secp256k1/serde"]
31-
use-rand = ["rand", "secp256k1/rand"]
30+
serde = ["actual-serde", "secp256k1/serde"]
31+
rand = ["actual-rand", "secp256k1/rand"]
3232

3333
[dependencies]
34+
actual-serde = { package = "serde", version = "1.0", default-features = false, optional = true }
35+
actual-rand = { package = "rand", version = "0.8", default-features = false, optional = true }
3436
secp256k1 = "0.27.0"
3537
secp256k1-zkp-sys = { version = "0.8.0", default-features = false, path = "./secp256k1-zkp-sys" }
36-
rand = { version = "0.8", default-features = false, optional = true }
37-
serde = { version = "1.0", default-features = false, optional = true }
38-
bitcoin-private = "0.1.0"
38+
internals = { package = "bitcoin-private", version = "0.1.0" }
3939

4040
[dev-dependencies]
41-
rand = "0.8"
42-
rand_core = "0.6"
4341
serde_test = "1.0"
4442

4543
[target.wasm32-unknown-unknown.dev-dependencies]
4644
wasm-bindgen-test = "0.3"
47-
rand = { version = "0.8" }
4845
getrandom = { version = "0.2", features = ["js"] }
4946

5047
[lib]

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Continuous integration](https://github.com/ElementsProject/rust-secp256k1-zkp/workflows/Continuous%20integration/badge.svg)
22

3-
### rust-secp256k1-zkp
3+
# rust-secp256k1-zkp
44

55
`rust-secp256k1-zkp` is a wrapper around [libsecp256k1-zkp](https://github.com/ElementsProject/secp256k1-zkp) that also
66
re-exports all bindings from [`rust-secp256k1`](https://github.com/rust-bitcoin/rust-secp256k1).
@@ -13,11 +13,12 @@ In addition to everything from `rust-secp256k1`, this library adds type-safe Rus
1313
- pedersen commitments
1414
- adaptor signatures
1515

16-
### Contributing
16+
# Contributing
1717

1818
Contributions to this library are welcome. A few guidelines:
1919

2020
- Any breaking changes must have an accompanied entry in CHANGELOG.md
2121
- No new dependencies, please.
2222
- No crypto should be implemented in Rust, with the possible exception of hash functions. Cryptographic contributions should be directed upstream to libsecp256k1.
2323
- This library should always compile with any combination of features on **Rust 1.41.1**.
24+

contrib/test.sh

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#!/bin/sh -ex
22

3-
FEATURES="bitcoin_hashes global-context lowmemory use-rand rand-std recovery use-serde"
4-
5-
# Use toolchain if explicitly specified
6-
if [ -n "$TOOLCHAIN" ]
7-
then
8-
alias cargo="cargo +$TOOLCHAIN"
9-
fi
3+
FEATURES="bitcoin_hashes global-context lowmemory rand rand-std recovery serde"
104

115
cargo --version
126
rustc --version
@@ -34,15 +28,13 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
3428
done
3529

3630
# Other combos
37-
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all
38-
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS=$RUSTFLAGS cargo test --all --features="$FEATURES"
31+
RUSTFLAGS='--cfg=rust_secp_fuzz' cargo test --all
32+
RUSTFLAGS='--cfg=rust_secp_fuzz' cargo test --all --features="$FEATURES"
3933
cargo test --all --features="rand rand-std"
4034
cargo test --all --features="rand serde"
4135

42-
if [ "$DO_BENCH" = true ]; then # proxy for us having a nightly compiler
43-
cargo test --all --all-features
44-
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS='--cfg=rust_secp_fuzz' cargo test --all --all-features
45-
fi
36+
cargo test --all --all-features
37+
RUSTFLAGS='--cfg=rust_secp_fuzz' RUSTDOCFLAGS='--cfg=rust_secp_fuzz' cargo test --all --all-features
4638
fi
4739

4840
# Docs
@@ -67,16 +59,10 @@ if [ "$DO_ASAN" = true ]; then
6759
cargo test --lib --all --features="$FEATURES" -Zbuild-std --target x86_64-unknown-linux-gnu
6860
fi
6961

70-
# Bench
71-
if [ "$DO_BENCH" = true ]; then
72-
cargo bench --all --features="unstable"
73-
fi
74-
7562
# Lint if told to
7663
if [ "$DO_LINT" = true ]
7764
then
7865
(
79-
rustup component add rustfmt
8066
cargo fmt --all -- --check
8167
)
8268
fi

src/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
//!
3030
3131
// Coding conventions
32+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3233
#![warn(missing_docs)]
3334
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
34-
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
3535

3636
/// Re-export of the internal FFI bindings crate
3737
pub extern crate secp256k1_zkp_sys;
@@ -42,20 +42,16 @@ extern crate secp256k1;
4242

4343
#[cfg(feature = "bitcoin_hashes")]
4444
pub use secp256k1::hashes;
45-
#[cfg(any(test, feature = "std"))]
46-
extern crate core;
4745
/// Re-export of the `rand` crate
48-
#[cfg(any(test, feature = "rand"))]
49-
pub extern crate rand;
50-
#[cfg(test)]
51-
extern crate rand_core;
46+
#[cfg(feature = "actual-rand")]
47+
pub extern crate actual_rand as rand;
5248
/// Re-export of the `serde` crate
5349
#[cfg(feature = "serde")]
54-
pub extern crate serde;
50+
pub extern crate actual_serde as serde;
51+
#[cfg(any(test, feature = "std"))]
52+
extern crate core;
5553
#[cfg(all(test, feature = "serde"))]
5654
extern crate serde_test;
57-
#[cfg(all(test, feature = "unstable"))]
58-
extern crate test;
5955
#[cfg(all(test, target_arch = "wasm32"))]
6056
#[macro_use]
6157
extern crate wasm_bindgen_test;

src/zkp/ecdsa_adaptor.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
//!
99
1010
use crate::ffi::{self, CPtr, ECDSA_ADAPTOR_SIGNATURE_LENGTH};
11+
#[cfg(feature = "rand-std")]
12+
use crate::rand::thread_rng;
13+
#[cfg(feature = "actual-rand")]
14+
use crate::rand::{CryptoRng, Rng};
1115
use crate::{constants, PublicKey, Secp256k1, SecretKey};
1216
use crate::{ecdsa::Signature, Verification};
1317
use crate::{from_hex, Error};
1418
use crate::{Message, Signing};
1519
use core::{fmt, ptr, str};
16-
#[cfg(any(test, feature = "rand-std"))]
17-
use rand::thread_rng;
18-
#[cfg(any(test, feature = "rand"))]
19-
use rand::{CryptoRng, Rng};
2020

2121
/// Represents an adaptor signature and dleq proof.
2222
#[derive(Debug, PartialEq, Clone, Copy, Eq)]
@@ -131,7 +131,7 @@ impl EcdsaAdaptorSignature {
131131
/// The nonce derivation process is strengthened against side channel
132132
/// attacks by providing auxiliary randomness using the ThreadRng random number generator.
133133
/// Requires compilation with "rand-std" feature.
134-
#[cfg(any(test, feature = "rand-std"))]
134+
#[cfg(feature = "rand-std")]
135135
pub fn encrypt<C: Signing>(
136136
secp: &Secp256k1<C>,
137137
msg: &Message,
@@ -147,7 +147,7 @@ impl EcdsaAdaptorSignature {
147147
/// The nonce derivation process is strengthened against side channel
148148
/// attacks by providing auxiliary randomness using the provided random number generator.
149149
/// Requires compilation with "rand" feature.
150-
#[cfg(any(test, feature = "rand"))]
150+
#[cfg(feature = "actual-rand")]
151151
pub fn encrypt_with_rng<C: Signing, R: Rng + CryptoRng>(
152152
secp: &Secp256k1<C>,
153153
msg: &Message,
@@ -291,9 +291,9 @@ impl EcdsaAdaptorSignature {
291291
mod tests {
292292
use super::Message;
293293
use super::*;
294-
use crate::SECP256K1;
295294
#[cfg(not(rust_secp_fuzz))]
296-
use rand::{rngs::ThreadRng, thread_rng, RngCore};
295+
use crate::rand::{rngs::ThreadRng, thread_rng, RngCore};
296+
use crate::SECP256K1;
297297

298298
#[cfg(not(rust_secp_fuzz))]
299299
fn test_ecdsa_adaptor_signature_helper(

src/zkp/generator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::ffi::{self, CPtr};
22
use crate::{constants, from_hex, Error, Secp256k1, Signing, Tag};
33
use core::{fmt, str};
4-
#[cfg(feature = "rand")]
4+
#[cfg(feature = "actual-rand")]
55
use rand::Rng;
66

77
/// Represents a blinding factor/Tweak on secp256k1 curve
88
///
99
/// Contrary to a [`crate::SecretKey`], the value 0 is also a valid tweak.
1010
/// Values outside secp curve order are invalid tweaks.
1111
#[derive(Default, Copy, Clone)]
12-
#[cfg_attr(not(fuzzing), derive(Eq, PartialEq))]
12+
#[cfg_attr(not(fuzzing), derive(Eq, PartialEq, PartialOrd, Ord))]
1313
pub struct Tweak([u8; constants::SECRET_KEY_SIZE]);
1414
secp256k1_zkp_sys::impl_array_newtype!(Tweak, u8, constants::SECRET_KEY_SIZE);
1515

@@ -56,7 +56,7 @@ impl str::FromStr for Tweak {
5656

5757
impl Tweak {
5858
/// Generate a new random Tweak
59-
#[cfg(feature = "rand")]
59+
#[cfg(feature = "actual-rand")]
6060
pub fn new<R: Rng + ?Sized>(rng: &mut R) -> Tweak {
6161
let mut ret = [0u8; constants::SECRET_KEY_SIZE];
6262
rng.fill_bytes(&mut ret);
@@ -110,7 +110,7 @@ impl Tweak {
110110
/// Represents a generator on the secp256k1 curve.
111111
///
112112
/// A generator is a public key internally but has a slightly different serialization with the first byte being tweaked.
113-
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
113+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
114114
pub struct Generator(ffi::PublicKey);
115115

116116
impl Generator {

src/zkp/rangeproof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl RangeProof {
206206
#[cfg(feature = "bitcoin_hashes")]
207207
impl ::core::fmt::Display for RangeProof {
208208
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
209-
use bitcoin_private::hex::display::DisplayHex;
209+
use internals::hex::display::DisplayHex;
210210

211211
write!(f, "{:x}", &self.serialize().as_slice().as_hex())
212212
}

src/zkp/surjection_proof.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct SurjectionProof {
1111
inner: ffi::SurjectionProof,
1212
}
1313

14-
#[cfg(feature = "rand")]
14+
#[cfg(feature = "actual-rand")]
1515
mod with_rand {
1616
use super::*;
1717
use crate::{Signing, Tag, Tweak};
@@ -193,7 +193,7 @@ impl SurjectionProof {
193193
#[cfg(feature = "bitcoin_hashes")]
194194
impl ::core::fmt::Display for SurjectionProof {
195195
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
196-
use bitcoin_private::hex::display::DisplayHex;
196+
use internals::hex::display::DisplayHex;
197197

198198
write!(f, "{:x}", &self.serialize().as_slice().as_hex())
199199
}

0 commit comments

Comments
 (0)