diff --git a/substrate/tendermint/src/ext.rs b/substrate/tendermint/src/ext.rs index 8bc19f8c..94b95b61 100644 --- a/substrate/tendermint/src/ext.rs +++ b/substrate/tendermint/src/ext.rs @@ -104,7 +104,7 @@ pub enum BlockError { /// Trait representing a Block. pub trait Block: Send + Sync + Clone + PartialEq + Debug + Encode + Decode { // Type used to identify blocks. Presumably a cryptographic hash of the block. - type Id: Send + Sync + Copy + Clone + PartialEq + Debug + Encode + Decode; + type Id: Send + Sync + Copy + Clone + PartialEq + AsRef<[u8]> + Debug + Encode + Decode; /// Return the deterministic, unique ID for this block. fn id(&self) -> Self::Id; diff --git a/substrate/tendermint/src/lib.rs b/substrate/tendermint/src/lib.rs index 75f9de30..b35c56c9 100644 --- a/substrate/tendermint/src/lib.rs +++ b/substrate/tendermint/src/lib.rs @@ -301,6 +301,7 @@ impl TendermintMachine { // Check if it has gotten a sufficient amount of precommits let (participants, weight) = self .log + // Use a junk signature since message equality is irrelevant to the signature .message_instances(round, Data::Precommit(Some((block.id(), self.signer.sign(&[]))))); let threshold = self.weights.threshold(); @@ -324,7 +325,7 @@ impl TendermintMachine { msg: Message::Signature>, ) -> Result, TendermintError> { if let Data::Precommit(Some((id, sig))) = &msg.data { - if !self.signer.verify(msg.sender, &id.encode(), sig.clone()) { + if !self.signer.verify(msg.sender, id.as_ref(), sig.clone()) { Err(TendermintError::Malicious(msg.sender))?; } } @@ -433,7 +434,7 @@ impl TendermintMachine { self .broadcast(Data::Precommit(Some(( block.id(), - self.signer.sign(&block.id().encode()), + self.signer.sign(block.id().as_ref()), )))) .await, ); diff --git a/substrate/tendermint/tests/ext.rs b/substrate/tendermint/tests/ext.rs index 16bf2bce..21e35187 100644 --- a/substrate/tendermint/tests/ext.rs +++ b/substrate/tendermint/tests/ext.rs @@ -7,7 +7,7 @@ use tokio::sync::RwLock; use tendermint_machine::{ext::*, SignedMessage, TendermintMachine, TendermintHandle}; type TestValidatorId = u16; -type TestBlockId = u32; +type TestBlockId = [u8; 4]; struct TestSignatureScheme(u16); impl SignatureScheme for TestSignatureScheme { @@ -114,7 +114,7 @@ impl Network for TestNetwork { dbg!("Adding ", &block); assert!(block.valid.is_ok()); assert!(self.verify_commit(block.id(), &commit)); - TestBlock { id: block.id + 1, valid: Ok(()) } + TestBlock { id: (u32::from_le_bytes(block.id) + 1).to_le_bytes(), valid: Ok(()) } } } @@ -129,7 +129,7 @@ impl TestNetwork { TestNetwork(i, arc.clone()), i, BlockNumber(1), - TestBlock { id: 1, valid: Ok(()) }, + TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) }, )); } }