Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
gadget: verify SignedCommitment message signature (#142)
Browse files Browse the repository at this point in the history
* gadget: verify SignedCommitment message signature

* gadget: log messages with bad sigs

* gadget: move todo comment
  • Loading branch information
andresilva committed Apr 8, 2021
1 parent 69f1f46 commit 1d94b0f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/beefy/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,25 @@ impl<B, P> GossipValidator<B> for BeefyGossipValidator<B, P>
where
B: Block,
P: Pair,
P::Public: Decode,
P::Signature: Decode,
P::Public: Debug + Decode,
P::Signature: Debug + Decode,
{
fn validate(
&self,
_context: &mut dyn GossipValidatorContext<B>,
_sender: &sc_network::PeerId,
sender: &sc_network::PeerId,
mut data: &[u8],
) -> GossipValidationResult<B::Hash> {
if VoteMessage::<MmrRootHash, NumberFor<B>, P::Public, P::Signature>::decode(&mut data).is_ok() {
GossipValidationResult::ProcessAndKeep(self.topic)
} else {
GossipValidationResult::Discard
if let Ok(msg) = VoteMessage::<MmrRootHash, NumberFor<B>, P::Public, P::Signature>::decode(&mut data) {
if P::verify(&msg.signature, &msg.commitment.encode(), &msg.id) {
return GossipValidationResult::ProcessAndKeep(self.topic);
} else {
// TODO: report peer
debug!(target: "beefy", "🥩 Bad signature on message: {:?}, from: {:?}", msg, sender);
}
}

GossipValidationResult::Discard
}

fn message_expired<'a>(&'a self) -> Box<dyn FnMut(B::Hash, &[u8]) -> bool + 'a> {
Expand Down Expand Up @@ -406,7 +411,6 @@ where
fn handle_vote(&mut self, round: (MmrRootHash, NumberFor<B>), vote: (P::Public, P::Signature)) {
self.gossip_validator.note_round(round.1);

// TODO: validate signature
let vote_added = self.rounds.add_vote(round, vote);

if vote_added && self.rounds.is_done(&round) {
Expand Down

0 comments on commit 1d94b0f

Please sign in to comment.