From e85bf540462cd3e3cd9349681ad9284482c3773b Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Fri, 26 Nov 2021 19:12:03 +0200 Subject: [PATCH 1/2] Update to deprecations in ed25519 1.3 (#1024) --- .../improvements/1023-ed25519-deprecations.md | 3 +++ tendermint/Cargo.toml | 2 +- tendermint/src/proposal.rs | 16 +++++----------- tendermint/src/signature.rs | 5 ++++- tendermint/src/test.rs | 7 +++++++ tendermint/src/vote.rs | 12 +++++++----- tendermint/src/vote/sign_vote.rs | 4 ++-- testgen/src/vote.rs | 4 ++-- 8 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 .changelog/unreleased/improvements/1023-ed25519-deprecations.md diff --git a/.changelog/unreleased/improvements/1023-ed25519-deprecations.md b/.changelog/unreleased/improvements/1023-ed25519-deprecations.md new file mode 100644 index 000000000..375daa0e4 --- /dev/null +++ b/.changelog/unreleased/improvements/1023-ed25519-deprecations.md @@ -0,0 +1,3 @@ +- `[tendermint]` Deprecated `signature::ED25519_SIGNATURE_SIZE` + in favor of `Ed25519Signature::BYTE_SIZE` + ([#1023](https://github.com/informalsystems/tendermint-rs/issues/1023)) \ No newline at end of file diff --git a/tendermint/Cargo.toml b/tendermint/Cargo.toml index a6f80f4d3..0bf4f19dd 100644 --- a/tendermint/Cargo.toml +++ b/tendermint/Cargo.toml @@ -36,7 +36,7 @@ crate-type = ["cdylib", "rlib"] async-trait = { version = "0.1", default-features = false } bytes = { version = "1.0", default-features = false } chrono = { version = "0.4.19", default-features = false, features = ["serde"] } -ed25519 = { version = "1", default-features = false } +ed25519 = { version = "1.3", default-features = false } ed25519-dalek = { version = "1", default-features = false, features = ["u64_backend"] } futures = { version = "0.3", default-features = false } num-traits = { version = "0.2", default-features = false } diff --git a/tendermint/src/proposal.rs b/tendermint/src/proposal.rs index 3140f3248..4f266a9b9 100644 --- a/tendermint/src/proposal.rs +++ b/tendermint/src/proposal.rs @@ -121,8 +121,8 @@ mod tests { use crate::hash::{Algorithm, Hash}; use crate::prelude::*; use crate::proposal::SignProposalRequest; - use crate::signature::{Ed25519Signature, ED25519_SIGNATURE_SIZE}; - use crate::{proposal::Type, Proposal, Signature}; + use crate::test::dummy_signature; + use crate::{proposal::Type, Proposal}; use chrono::{DateTime, Utc}; use core::str::FromStr; use tendermint_proto::Protobuf; @@ -152,9 +152,7 @@ mod tests { .unwrap(), }), timestamp: Some(dt.into()), - signature: Some(Signature::from(Ed25519Signature::new( - [0; ED25519_SIGNATURE_SIZE], - ))), + signature: Some(dummy_signature()), }; let mut got = vec![]; @@ -236,9 +234,7 @@ mod tests { .unwrap(), }), timestamp: Some(dt.into()), - signature: Some(Signature::from(Ed25519Signature::new( - [0; ED25519_SIGNATURE_SIZE], - ))), + signature: Some(dummy_signature()), }; let mut got = vec![]; @@ -322,9 +318,7 @@ mod tests { ) .unwrap(), }), - signature: Some(Signature::from(Ed25519Signature::new( - [0; ED25519_SIGNATURE_SIZE], - ))), + signature: Some(dummy_signature()), }; let want = SignProposalRequest { proposal, diff --git a/tendermint/src/signature.rs b/tendermint/src/signature.rs index 63b5e1327..d4cfb8162 100644 --- a/tendermint/src/signature.rs +++ b/tendermint/src/signature.rs @@ -1,6 +1,6 @@ //! Cryptographic (a.k.a. digital) signatures -pub use ed25519::{Signature as Ed25519Signature, SIGNATURE_LENGTH as ED25519_SIGNATURE_SIZE}; +pub use ed25519::Signature as Ed25519Signature; pub use signature::{Signer, Verifier}; #[cfg(feature = "secp256k1")] @@ -12,6 +12,9 @@ use tendermint_proto::Protobuf; use crate::error::Error; +#[deprecated(since = "0.23.1", note = "use Ed25519Signature::BYTE_SIZE instead")] +pub const ED25519_SIGNATURE_SIZE: usize = Ed25519Signature::BYTE_SIZE; + /// The expected length of all currently supported signatures, in bytes. pub const SIGNATURE_LENGTH: usize = 64; diff --git a/tendermint/src/test.rs b/tendermint/src/test.rs index fc8c868bb..ef6a6eac8 100644 --- a/tendermint/src/test.rs +++ b/tendermint/src/test.rs @@ -1,6 +1,8 @@ use core::fmt::Debug; use serde::{de::DeserializeOwned, Serialize}; +use crate::signature::{Ed25519Signature, Signature}; + /// Test that a struct `T` can be: /// /// - parsed out of the provided JSON data @@ -25,3 +27,8 @@ where assert_eq!(parsed0, parsed1); } + +/// Produces a dummy signature value for use as a placeholder in tests. +pub fn dummy_signature() -> Signature { + Signature::from(Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap()) +} diff --git a/tendermint/src/vote.rs b/tendermint/src/vote.rs index a888b0b37..1c364df07 100644 --- a/tendermint/src/vote.rs +++ b/tendermint/src/vote.rs @@ -15,8 +15,6 @@ use core::fmt; use core::str::FromStr; use bytes::BufMut; -use ed25519::Signature as Ed25519Signature; -use ed25519::SIGNATURE_LENGTH as ED25519_SIGNATURE_LENGTH; use serde::{Deserialize, Serialize}; use tendermint_proto::types::Vote as RawVote; @@ -27,6 +25,7 @@ use crate::consensus::State; use crate::error::Error; use crate::hash; use crate::prelude::*; +use crate::signature::Ed25519Signature; use crate::{account, block, Signature, Time}; /// Votes are signed messages from validators for a particular block which @@ -159,6 +158,7 @@ impl Vote { } /// Default trait. Used in tests. +// FIXME: Does it need to be in public crate API? If not, replace with a helper fn in crate::test? impl Default for Vote { fn default() -> Self { Vote { @@ -169,9 +169,11 @@ impl Default for Vote { timestamp: Some(Time::unix_epoch()), validator_address: account::Id::new([0; account::LENGTH]), validator_index: ValidatorIndex::try_from(0_i32).unwrap(), - signature: Some(Signature::from(Ed25519Signature::new( - [0; ED25519_SIGNATURE_LENGTH], - ))), + // Could have reused crate::test::dummy_signature, except that + // this Default impl is defined outside of #[cfg(test)]. + signature: Some(Signature::from( + Ed25519Signature::from_bytes(&[0; Ed25519Signature::BYTE_SIZE]).unwrap(), + )), } } } diff --git a/tendermint/src/vote/sign_vote.rs b/tendermint/src/vote/sign_vote.rs index 28347a2b7..a048c8b92 100644 --- a/tendermint/src/vote/sign_vote.rs +++ b/tendermint/src/vote/sign_vote.rs @@ -98,7 +98,7 @@ mod tests { use crate::chain::Id as ChainId; use crate::hash::Algorithm; use crate::prelude::*; - use crate::signature::{Signature, ED25519_SIGNATURE_SIZE}; + use crate::signature::{Ed25519Signature, Signature}; use crate::vote::{CanonicalVote, ValidatorIndex}; use crate::vote::{SignVoteRequest, Type}; use crate::Hash; @@ -429,7 +429,7 @@ mod tests { ) .unwrap(), }), - signature: Signature::new(vec![1; ED25519_SIGNATURE_SIZE]).unwrap(), + signature: Signature::new(vec![1; Ed25519Signature::BYTE_SIZE]).unwrap(), }; let want = SignVoteRequest { vote, diff --git a/testgen/src/vote.rs b/testgen/src/vote.rs index ed46ce0fe..4b5ad8d03 100644 --- a/testgen/src/vote.rs +++ b/testgen/src/vote.rs @@ -5,7 +5,7 @@ use simple_error::*; use std::convert::TryFrom; use tendermint::{ block::{self, parts::Header as PartSetHeader}, - signature::{Signature, Signer, ED25519_SIGNATURE_SIZE}, + signature::{Ed25519Signature, Signature, Signer}, vote, vote::ValidatorIndex, }; @@ -130,7 +130,7 @@ impl Generator for Vote { timestamp: Some(timestamp), validator_address: block_validator.address, validator_index: ValidatorIndex::try_from(validator_index as u32).unwrap(), - signature: Signature::new(vec![0_u8; ED25519_SIGNATURE_SIZE]) + signature: Signature::new(vec![0_u8; Ed25519Signature::BYTE_SIZE]) .map_err(|e| SimpleError::new(e.to_string()))?, }; From 82a0eacc4292858c68e8bb9e53f85cccb86507a3 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Fri, 26 Nov 2021 20:04:05 +0200 Subject: [PATCH 2/2] Fix up deprecation for ED25519_SIGNATURE_SIZE 0.23.1 was released before #1023 or its backport to v0.23.x were merged. --- tendermint/src/signature.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tendermint/src/signature.rs b/tendermint/src/signature.rs index d4cfb8162..603745237 100644 --- a/tendermint/src/signature.rs +++ b/tendermint/src/signature.rs @@ -12,7 +12,7 @@ use tendermint_proto::Protobuf; use crate::error::Error; -#[deprecated(since = "0.23.1", note = "use Ed25519Signature::BYTE_SIZE instead")] +#[deprecated(since = "0.23.2", note = "use Ed25519Signature::BYTE_SIZE instead")] pub const ED25519_SIGNATURE_SIZE: usize = Ed25519Signature::BYTE_SIZE; /// The expected length of all currently supported signatures, in bytes.