Skip to content

Commit db9cb21

Browse files
tony-iqlusionromac
andauthored
Bump ed25519 to v2, k256 to v0.13, signature to v2 (#1285)
* Bump `ed25519` => v2; `k256` => v0.13; `signature` => v2 Bumps all of the above dependencies to their latest versions, which use the new `signature` v2 release: RustCrypto/traits#1211 * Add `patch.crates-io` for fizyk20/generic-array#133 The `generic-array` crate's docs won't build without this, which breaks the docs build in CI * Remove workaround for docs build in CI * Pin docs build to nightly-2023-03-01 It fails on newer versions: https://github.com/informalsystems/tendermint-rs/actions/runs/4602897393/jobs/8132365869?pr=1285 * Add changelog entry --------- Co-authored-by: Romain Ruetschi <[email protected]>
1 parent 797bee1 commit db9cb21

File tree

11 files changed

+26
-24
lines changed

11 files changed

+26
-24
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* `[tendermint, tendermint-p2p]` Bump `ed25519` to v2, `k256` to v0.13, and `signature` to v2

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- uses: actions/checkout@v2
6969
- uses: actions-rs/toolchain@v1
7070
with:
71-
toolchain: nightly
71+
toolchain: nightly-2023-03-01 # regression prevents docs from building
7272
override: true
7373
- uses: actions-rs/cargo@v1
7474
env:

p2p/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ sha2 = { version = "0.10", default-features = false }
3939
subtle = { version = "2", default-features = false }
4040
x25519-dalek = { version = "1.1", default-features = false, features = ["u64_backend"] }
4141
zeroize = { version = "1", default-features = false }
42-
signature = { version = "1", default-features = false }
42+
signature = { version = "2", default-features = false }
4343
aead = { version = "0.4.1", default-features = false }
4444
flex-error = { version = "0.4.4", default-features = false }
4545

tendermint/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ rustdoc-args = ["--cfg", "docsrs"]
3131
[dependencies]
3232
bytes = { version = "1.2", default-features = false, features = ["serde"] }
3333
digest = { version = "0.10", default-features = false }
34-
ed25519 = { version = "1.5", default-features = false }
34+
ed25519 = { version = "2", default-features = false, features = ["alloc"] }
3535
futures = { version = "0.3", default-features = false }
3636
num-traits = { version = "0.2", default-features = false }
3737
once_cell = { version = "1.3", default-features = false }
@@ -41,7 +41,7 @@ serde = { version = "1", default-features = false, features = ["derive"] }
4141
serde_json = { version = "1", default-features = false, features = ["alloc"] }
4242
serde_bytes = { version = "0.11", default-features = false }
4343
serde_repr = { version = "0.1", default-features = false }
44-
signature = { version = "1", default-features = false }
44+
signature = { version = "2", default-features = false, features = ["alloc"] }
4545
subtle = { version = "2", default-features = false }
4646
subtle-encoding = { version = "0.5", default-features = false, features = ["bech32-preview"] }
4747
tendermint-proto = { version = "0.30.0", default-features = false, path = "../proto" }
@@ -50,7 +50,7 @@ zeroize = { version = "1.1", default-features = false, features = ["zeroize_deri
5050
flex-error = { version = "0.4.4", default-features = false }
5151
ed25519-consensus = { version = "2", optional = true, default-features = false }
5252
sha2 = { version = "0.10", optional = true, default-features = false }
53-
k256 = { version = "0.11", optional = true, default-features = false, features = ["ecdsa"] }
53+
k256 = { version = "0.13", optional = true, default-features = false, features = ["alloc", "ecdsa"] }
5454
ripemd = { version = "0.1.3", optional = true, default-features = false }
5555

5656
[features]
@@ -61,7 +61,7 @@ secp256k1 = ["k256", "ripemd"]
6161
rust-crypto = ["sha2", "ed25519-consensus"]
6262

6363
[dev-dependencies]
64-
k256 = { version = "0.11", default-features = false, features = ["ecdsa"] }
64+
k256 = { version = "0.13", default-features = false, features = ["ecdsa"] }
6565
pretty_assertions = "1.3.0"
6666
proptest = { version = "0.10.1", default-features = false, features = ["std"] }
6767
tendermint-pbt-gen = { path = "../pbt-gen", default-features = false, features = ["time"] }

tendermint/src/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ mod key_conversions {
117117
fn from(pk: Secp256k1) -> Id {
118118
use ripemd::Ripemd160;
119119

120-
let sha_digest = Sha256::digest(pk.to_bytes());
120+
let sha_digest = Sha256::digest(pk.to_sec1_bytes());
121121
let ripemd_digest = Ripemd160::digest(&sha_digest[..]);
122122
let mut bytes = [0u8; LENGTH];
123123
bytes.copy_from_slice(&ripemd_digest[..LENGTH]);

tendermint/src/crypto/default/signature.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ mod tests {
283283
_ => panic!("expected public key to be secp256k1: {:?}", public_key),
284284
}
285285
let der_sig = k256::ecdsa::Signature::from_der(sig).unwrap();
286-
let sig = der_sig.as_ref();
287-
let sig = Signature::try_from(sig).unwrap();
286+
let sig = der_sig.to_bytes();
287+
let sig = Signature::try_from(sig.as_slice()).unwrap();
288288
Verifier::verify(public_key, msg, &sig)
289289
.unwrap_or_else(|_| panic!("signature should be valid for test vector {}", i));
290290
}

tendermint/src/public_key.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ tendermint_pb_modules! {
153153
#[cfg(feature = "secp256k1")]
154154
PublicKey::Secp256k1(ref pk) => RawPublicKey {
155155
sum: Some(Sum::Secp256k1(
156-
pk.to_bytes().to_vec(),
156+
pk.to_sec1_bytes().into(),
157157
)),
158158
},
159159
}
@@ -200,7 +200,7 @@ impl PublicKey {
200200
match self {
201201
PublicKey::Ed25519(pk) => pk.as_bytes().to_vec(),
202202
#[cfg(feature = "secp256k1")]
203-
PublicKey::Secp256k1(pk) => pk.to_bytes().to_vec(),
203+
PublicKey::Secp256k1(pk) => pk.to_sec1_bytes().into(),
204204
}
205205
}
206206

@@ -215,7 +215,7 @@ impl PublicKey {
215215
#[cfg(feature = "secp256k1")]
216216
PublicKey::Secp256k1(ref pk) => {
217217
let mut key_bytes = vec![0xEB, 0x5A, 0xE9, 0x87, 0x21];
218-
key_bytes.extend(pk.to_bytes());
218+
key_bytes.extend(pk.to_sec1_bytes().as_ref());
219219
key_bytes
220220
},
221221
};
@@ -373,7 +373,7 @@ fn serialize_secp256k1_base64<S>(pk: &Secp256k1, serializer: S) -> Result<S::Ok,
373373
where
374374
S: ser::Serializer,
375375
{
376-
String::from_utf8(base64::encode(pk.to_bytes()))
376+
String::from_utf8(base64::encode(pk.to_sec1_bytes()))
377377
.unwrap()
378378
.serialize(serializer)
379379
}

tendermint/src/signature.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Cryptographic (a.k.a. digital) signatures
22
3-
use core::convert::TryFrom;
4-
53
pub use ed25519::Signature as Ed25519Signature;
64
#[cfg(feature = "secp256k1")]
75
pub use k256::ecdsa::Signature as Secp256k1Signature;
6+
87
use tendermint_proto::Protobuf;
98

109
use crate::{error::Error, prelude::*};
@@ -83,7 +82,7 @@ impl AsRef<[u8]> for Signature {
8382

8483
impl From<Ed25519Signature> for Signature {
8584
fn from(sig: Ed25519Signature) -> Signature {
86-
Self(sig.as_ref().to_vec())
85+
Self(sig.to_vec())
8786
}
8887
}
8988

@@ -96,7 +95,7 @@ impl From<ed25519_consensus::Signature> for Signature {
9695

9796
#[cfg(feature = "secp256k1")]
9897
impl From<Secp256k1Signature> for Signature {
99-
fn from(pk: Secp256k1Signature) -> Signature {
100-
Self(pk.as_ref().to_vec())
98+
fn from(sig: Secp256k1Signature) -> Signature {
99+
Self(sig.to_vec())
101100
}
102101
}

tendermint/src/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ where
3131

3232
/// Produces a dummy signature value for use as a placeholder in tests.
3333
pub fn dummy_signature() -> Signature {
34-
Signature::from(Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap())
34+
Signature::from(Ed25519Signature::from_bytes(
35+
&[0; Ed25519Signature::BYTE_SIZE],
36+
))
3537
}

tendermint/src/vote.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ impl Default for Vote {
171171
validator_index: ValidatorIndex::try_from(0_i32).unwrap(),
172172
// Could have reused crate::test::dummy_signature, except that
173173
// this Default impl is defined outside of #[cfg(test)].
174-
signature: Some(Signature::from(
175-
Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap(),
176-
)),
174+
signature: Some(Signature::from(Ed25519Signature::from_bytes(
175+
&[0; Ed25519Signature::BYTE_SIZE],
176+
))),
177177
}
178178
}
179179
}

tendermint/tests/alt_crypto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! for a chain environment that provides its own cryptographic API.
33
#![cfg(all(feature = "secp256k1", feature = "rust-crypto"))]
44

5-
use ::signature::{DigestVerifier, Signature as _};
5+
use ::signature::DigestVerifier;
66
use digest::Digest;
77

88
use tendermint::crypto::signature::{self, Verifier};
@@ -23,7 +23,7 @@ impl Verifier for SubstrateSignatureVerifier {
2323
) -> Result<(), signature::Error> {
2424
match pubkey {
2525
PublicKey::Secp256k1(pk) => {
26-
let sig = k256::ecdsa::Signature::from_bytes(signature.as_bytes())
26+
let sig = k256::ecdsa::Signature::try_from(signature.as_bytes())
2727
.map_err(|_| signature::Error::MalformedSignature)?;
2828
let mut hasher = sha2::Sha256::new();
2929
Digest::update(&mut hasher, msg);

0 commit comments

Comments
 (0)