diff --git a/substrate/tendermint/src/ext.rs b/substrate/tendermint/src/ext.rs index e2f047eb..383376f1 100644 --- a/substrate/tendermint/src/ext.rs +++ b/substrate/tendermint/src/ext.rs @@ -46,7 +46,7 @@ pub trait SignatureScheme: Send + Sync { fn sign(&self, msg: &[u8]) -> Self::Signature; /// Verify a signature from the validator in question. #[must_use] - fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: Self::Signature) -> bool; + fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: &Self::Signature) -> bool; /// Aggregate signatures. fn aggregate(sigs: &[Self::Signature]) -> Self::AggregateSignature; @@ -54,8 +54,8 @@ pub trait SignatureScheme: Send + Sync { #[must_use] fn verify_aggregate( &self, - msg: &[u8], signers: &[Self::ValidatorId], + msg: &[u8], sig: &Self::AggregateSignature, ) -> bool; } @@ -142,8 +142,8 @@ pub trait Network: Send + Sync { commit: &Commit, ) -> bool { if !self.signature_scheme().verify_aggregate( - &commit_msg(commit.round, id.as_ref()), &commit.validators, + &commit_msg(commit.round, id.as_ref()), &commit.signature, ) { return false; diff --git a/substrate/tendermint/src/lib.rs b/substrate/tendermint/src/lib.rs index 5472ce6d..5b65b3b9 100644 --- a/substrate/tendermint/src/lib.rs +++ b/substrate/tendermint/src/lib.rs @@ -278,7 +278,7 @@ impl TendermintMachine { loop { match msg_recv.try_recv() { Ok(msg) => { - if !machine.signer.verify(msg.msg.sender, &msg.msg.encode(), msg.sig) { + if !machine.signer.verify(msg.msg.sender, &msg.msg.encode(), &msg.sig) { continue; } machine.queue.push((false, msg.msg)); @@ -345,7 +345,7 @@ impl TendermintMachine { ) -> Result, TendermintError> { // Verify the signature if this is a precommit if let Data::Precommit(Some((id, sig))) = &msg.data { - if !self.signer.verify(msg.sender, &commit_msg(msg.round, id.as_ref()), sig.clone()) { + if !self.signer.verify(msg.sender, &commit_msg(msg.round, id.as_ref()), sig) { // Since we verified this validator actually sent the message, they're malicious Err(TendermintError::Malicious(msg.sender))?; } diff --git a/substrate/tendermint/tests/ext.rs b/substrate/tendermint/tests/ext.rs index 51751d9e..6f489f7a 100644 --- a/substrate/tendermint/tests/ext.rs +++ b/substrate/tendermint/tests/ext.rs @@ -1,8 +1,11 @@ -use std::{sync::Arc, time::SystemTime}; +use std::{ + sync::Arc, + time::{SystemTime, Duration}, +}; use parity_scale_codec::{Encode, Decode}; -use tokio::sync::RwLock; +use tokio::{sync::RwLock, time::sleep}; use tendermint_machine::{ext::*, SignedMessage, TendermintMachine, TendermintHandle}; @@ -23,7 +26,7 @@ impl SignatureScheme for TestSignatureScheme { } #[must_use] - fn verify(&self, validator: u16, msg: &[u8], sig: [u8; 32]) -> bool { + fn verify(&self, validator: u16, msg: &[u8], sig: &[u8; 32]) -> bool { (sig[.. 2] == validator.to_le_bytes()) && (&sig[2 ..] == &[msg, &[0; 30]].concat()[.. 30]) } @@ -34,13 +37,13 @@ impl SignatureScheme for TestSignatureScheme { #[must_use] fn verify_aggregate( &self, - msg: &[u8], signers: &[TestValidatorId], + msg: &[u8], sigs: &Vec<[u8; 32]>, ) -> bool { assert_eq!(signers.len(), sigs.len()); for sig in signers.iter().zip(sigs.iter()) { - assert!(self.verify(*sig.0, msg, *sig.1)); + assert!(self.verify(*sig.0, msg, sig.1)); } true } @@ -140,7 +143,7 @@ impl TestNetwork { #[tokio::test] async fn test() { TestNetwork::new(4).await; - for _ in 0 .. 100 { - tokio::task::yield_now().await; + for _ in 0 .. 10 { + sleep(Duration::from_secs(1)).await; } }