Skip to content

Commit

Permalink
Update to deprecations in ed25519 1.3 (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev authored Nov 26, 2021
1 parent 9690eca commit df231ed
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 1 addition & 1 deletion tendermint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 5 additions & 11 deletions tendermint/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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![];
Expand Down Expand Up @@ -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![];
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion tendermint/src/signature.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions tendermint/src/test.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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())
}
12 changes: 7 additions & 5 deletions tendermint/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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(),
)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tendermint/src/vote/sign_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions testgen/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -130,7 +130,7 @@ impl Generator<vote::Vote> 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()))?,
};

Expand Down

0 comments on commit df231ed

Please sign in to comment.