Skip to content

Commit 04098f8

Browse files
committed
Upgrade to bincode v2
And increase MSRV to use workspace dependency feature
1 parent 292dab2 commit 04098f8

File tree

27 files changed

+184
-137
lines changed

27 files changed

+184
-137
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Tests
22

3-
43
on:
54
push:
65
branches:
@@ -9,11 +8,10 @@ on:
98

109
# Make sure CI fails on all warnings, including Clippy lints
1110
env:
12-
RUSTFLAGS: "-Dwarnings"
13-
RUSTDOCFLAGS: "-Dwarnings"
11+
RUSTFLAGS: "-Dwarnings"
12+
RUSTDOCFLAGS: "-Dwarnings"
1413

1514
jobs:
16-
1715
fmt:
1816
name: Rustfmt
1917
runs-on: ubuntu-latest
@@ -38,7 +36,7 @@ jobs:
3836
runs-on: ubuntu-latest
3937
steps:
4038
- uses: actions/checkout@v4
41-
- uses: dtolnay/rust-toolchain@1.63.0
39+
- uses: dtolnay/rust-toolchain@1.64.0
4240
- uses: Swatinem/rust-cache@v2
4341
- run: |
4442
cargo update -p proptest --precise "1.2.0"
@@ -66,9 +64,9 @@ jobs:
6664
- name: test-on-target
6765
uses: actions-rs/cargo@v1
6866
with:
69-
use-cross: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }}
67+
use-cross: ${{ matrix.target != 'x86_64-unknown-linux-gnu' }}
7068
command: test
71-
args: --all-features --release --target ${{ matrix.target }}
69+
args: --all-features --release --target ${{ matrix.target }}
7270

7371
# test nightly build/test
7472
test-nightly:
@@ -84,31 +82,29 @@ jobs:
8482
runs-on: ubuntu-latest
8583
strategy:
8684
matrix:
87-
package: [ "secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun" ]
85+
package: ["secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun"]
8886
steps:
8987
- uses: actions/checkout@v4
9088
- uses: dtolnay/rust-toolchain@stable
9189
- uses: Swatinem/rust-cache@v2.0.0
9290
- run: cargo test --release --no-default-features -p ${{ matrix.package }}
9391

94-
9592
# test with alloc feature only
9693
test-alloc:
9794
runs-on: ubuntu-latest
9895
strategy:
9996
matrix:
100-
package: [ "secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun" ]
97+
package: ["secp256kfun", "sigma_fun", "ecdsa_fun", "schnorr_fun"]
10198
steps:
10299
- uses: actions/checkout@v4
103100
- uses: dtolnay/rust-toolchain@stable
104101
- uses: Swatinem/rust-cache@v2.0.0
105102
- run: cargo test --release --no-default-features --features alloc -p ${{ matrix.package }}
106103

107-
108104
doc-build:
109-
name: doc-build
110-
runs-on: ubuntu-latest
111-
steps:
112-
- uses: actions/checkout@v4
113-
- uses: dtolnay/rust-toolchain@stable
114-
- run: cargo doc --no-deps --workspace --all-features
105+
name: doc-build
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v4
109+
- uses: dtolnay/rust-toolchain@stable
110+
- run: cargo doc --no-deps --workspace --all-features

CHANGELOG.md

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

3+
## Unreleased
4+
5+
- Upgrade to bincode v2
6+
- MSRV 1.63 -> 1.64
7+
38
## v0.11.0
49

510
- Added `prelude` module for convenient importing

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ members = [
88
"arithmetic_macros"
99
]
1010
resolver = "2"
11+
12+
[workspace.dependencies]
13+
bincode = { version = "2", default-features = false, features = ["derive"] }

ecdsa_fun/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "ecdsa_fun"
33
version = "0.11.0"
44
authors = ["LLFourn <lloyd.fourn@gmail.com>"]
55
edition = "2021"
6-
rust-version = "1.63"
6+
rust-version = "1.64"
77
license = "0BSD"
88
homepage = "https://github.com/LLFourn/secp256kfun/tree/master/ecdsa_fun"
99
repository = "https://github.com/LLFourn/secp256kfun"
@@ -17,7 +17,7 @@ keywords = ["bitcoin", "ecdsa", "secp256k1"]
1717
secp256kfun = { path = "../secp256kfun", version = "0.11", default-features = false }
1818
sigma_fun = { path = "../sigma_fun", version = "0.8", features = ["secp256k1"], default-features = false, optional = true }
1919
rand_chacha = { version = "0.3", optional = true } # needed for adaptor signatures atm but would be nice to get rid of
20-
bincode = { version = "1.0", optional = true }
20+
bincode = { workspace = true, optional = true }
2121

2222
[dev-dependencies]
2323
rand = "0.8"
@@ -42,8 +42,8 @@ libsecp_compat_0_30 = ["secp256kfun/libsecp_compat_0_30"]
4242
std = ["alloc"]
4343
alloc = ["secp256kfun/alloc", "sigma_fun?/alloc" ]
4444
serde = ["secp256kfun/serde","sigma_fun?/serde"]
45-
adaptor = ["dep:sigma_fun", "dep:bincode", "dep:rand_chacha"]
46-
bincode = [ "secp256kfun/bincode", "dep:bincode" ]
45+
adaptor = ["dep:sigma_fun", "bincode", "dep:rand_chacha"]
46+
bincode = [ "secp256kfun/bincode", "dep:bincode", "sigma_fun?/bincode" ]
4747
proptest = ["secp256kfun/proptest"]
4848

4949

ecdsa_fun/src/adaptor/encrypted_signature.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ secp256kfun::impl_display_debug_serialize! {
2929
}
3030
}
3131

32-
#[derive(Clone, Debug, PartialEq)]
32+
#[derive(Clone, Debug, PartialEq, bincode::Encode, bincode::Decode)]
3333
#[cfg_attr(
3434
feature = "serde",
3535
derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize),
@@ -52,20 +52,19 @@ pub(crate) struct EncryptedSignatureInternal {
5252
#[derive(Clone, PartialEq)]
5353
pub struct EncryptedSignature(pub(crate) EncryptedSignatureInternal);
5454

55-
#[cfg(feature = "serde")]
5655
secp256kfun::impl_display_debug_serialize! {
5756
fn to_bytes(es: &EncryptedSignature) -> [u8;162] {
5857
let mut bytes = [0u8;162];
59-
bytes.copy_from_slice(bincode::serialize(&es.0).unwrap().as_slice());
58+
let size = bincode::encode_into_slice(&es.0, &mut bytes[..], bincode::config::legacy()).expect("infallible");
59+
assert_eq!(size, 162);
6060
bytes
6161
}
6262
}
6363

64-
#[cfg(feature = "serde")]
6564
secp256kfun::impl_fromstr_deserialize! {
6665
name => "ECDSA adaptor signature",
6766
fn from_bytes(bytes: [u8;162]) -> Option<EncryptedSignature> {
68-
bincode::deserialize(&bytes[..]).ok().map(EncryptedSignature)
67+
bincode::decode_from_slice(&bytes[..], bincode::config::legacy()).ok().map(|(v,_)| EncryptedSignature(v))
6968
}
7069
}
7170

@@ -104,10 +103,18 @@ mod test {
104103
&encryption_key,
105104
b"hello world you are beautiful!!!",
106105
);
107-
let serialized = bincode::serialize(&encrypted_signature).unwrap();
106+
let serialized = bincode::encode_to_vec(
107+
bincode::serde::Compat(&encrypted_signature),
108+
bincode::config::standard(),
109+
)
110+
.unwrap();
108111
assert_eq!(serialized.len(), 33 + 33 + 32 + 64);
109-
let deseriazed = bincode::deserialize::<EncryptedSignature>(&serialized[..]).unwrap();
112+
let (deseriazed, _) = bincode::decode_from_slice::<
113+
bincode::serde::Compat<EncryptedSignature>,
114+
_,
115+
>(&serialized[..], bincode::config::standard())
116+
.unwrap();
110117

111-
assert_eq!(deseriazed, encrypted_signature);
118+
assert_eq!(deseriazed.0, encrypted_signature);
112119
}
113120
}

ecdsa_fun/tests/adaptor_test_vectors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct Serialization {
4646
}
4747

4848
#[test]
49-
fn run_test_vectors() {
49+
fn run_ecdsa_adaptor_test_vectors() {
5050
let ecdsa_adaptor = Adaptor::<HashTranscript<Sha256>, _>::verify_only();
5151
let test_vectors = serde_json::from_str::<Vec<TestVector>>(DLC_SPEC_JSON).unwrap();
5252
for t in test_vectors {

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
edition = "2021"
1+
edition = "2024"
22
condense_wildcard_suffixes = true
33
format_macro_matchers = true
44
imports_granularity="Crate"

schnorr_fun/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name = "schnorr_fun"
44
version = "0.11.0"
55
authors = ["LLFourn <lloyd.fourn@gmail.com>"]
66
edition = "2021"
7-
rust-version = "1.63"
7+
rust-version = "1.64"
88
license = "0BSD"
99
homepage = "https://github.com/LLFourn/secp256kfun/tree/master/schnorr_fun"
1010
repository = "https://github.com/LLFourn/secp256kfun"
@@ -16,12 +16,12 @@ keywords = ["bitcoin", "schnorr"]
1616
[dependencies]
1717
secp256kfun = { path = "../secp256kfun", version = "0.11", default-features = false }
1818
bech32 = { version = "0.11", optional = true, default-features = false, features = ["alloc"] }
19+
bincode = { workspace = true, optional = true }
1920

2021
[dev-dependencies]
2122
secp256kfun = { path = "../secp256kfun", version = "0.11", features = ["proptest", "bincode", "alloc"] }
2223
rand = { version = "0.8" }
2324
lazy_static = "1.4"
24-
bincode = "1.0"
2525
sha2 = "0.10"
2626
serde_json = "1"
2727
rand_chacha = { version = "0.3" }
@@ -40,7 +40,7 @@ required-features = ["libsecp_compat"]
4040
default = ["std"]
4141
alloc = ["secp256kfun/alloc" ]
4242
std = ["alloc", "secp256kfun/std"]
43-
bincode = ["secp256kfun/bincode"]
43+
bincode = [ "dep:bincode", "secp256kfun/bincode"]
4444
serde = ["secp256kfun/serde"]
4545
libsecp_compat = ["libsecp_compat_0_30", "secp256kfun/libsecp_compat"]
4646
libsecp_compat_0_27 = ["secp256kfun/libsecp_compat_0_27"]

schnorr_fun/src/adaptor/encrypted_signature.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ use secp256kfun::{marker::*, Point, Scalar};
1010
derive(crate::fun::serde::Deserialize, crate::fun::serde::Serialize),
1111
serde(crate = "crate::fun::serde")
1212
)]
13-
#[cfg_attr(
14-
feature = "bincode",
15-
derive(crate::fun::bincode::Encode, crate::fun::bincode::Decode),
16-
bincode(crate = "crate::fun::bincode")
17-
)]
13+
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
1814
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
1915
pub struct EncryptedSignature<S = Public> {
2016
/// The `R` point in the signature
@@ -56,9 +52,18 @@ mod test {
5652
&encryption_key,
5753
Message::<Public>::plain("test", b"foo"),
5854
);
59-
let serialized = bincode::serialize(&encrypted_signature).unwrap();
55+
let serialized = bincode::encode_to_vec(
56+
bincode::serde::Compat(&encrypted_signature),
57+
bincode::config::standard(),
58+
)
59+
.unwrap();
6060
assert_eq!(serialized.len(), 65);
61-
let deserialized = bincode::deserialize::<EncryptedSignature>(&serialized).unwrap();
62-
assert_eq!(encrypted_signature, deserialized);
61+
let deserialized = bincode::decode_from_slice::<
62+
bincode::serde::Compat<EncryptedSignature>,
63+
_,
64+
>(&serialized, bincode::config::standard())
65+
.unwrap()
66+
.0;
67+
assert_eq!(encrypted_signature, deserialized.0);
6368
}
6469
}

schnorr_fun/src/adaptor/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ where
191191
g!(decryption_key * G).normalize()
192192
}
193193

194-
#[must_use]
195194
fn verify_encrypted_signature(
196195
&self,
197196
verification_key: &Point<EvenY, impl Secrecy>,

0 commit comments

Comments
 (0)