Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify consensus message author matches with the sender #15386

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions consensus/consensus-types/src/proof_of_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ impl SignedBatchInfoMsg {
pub fn take(self) -> Vec<SignedBatchInfo> {
self.signed_infos
}

pub fn author(&self) -> Option<PeerId> {
self.signed_infos
.first()
.map(|signed_info| signed_info.author())
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
39 changes: 39 additions & 0 deletions consensus/src/epoch_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
BlockStage::EPOCH_MANAGER_RECEIVED,
);
}
self.check_author(peer_id, &consensus_msg)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this should be part of the UnverifiedEvent.verify check to keep them all in one place @zekun000 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the sender verification checks to individual verify functions.

// we can't verify signatures from a different epoch
let maybe_unverified_event = self.check_epoch(peer_id, consensus_msg).await?;

Expand Down Expand Up @@ -1512,6 +1513,44 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
Ok(())
}

fn check_author(&mut self, peer_id: AccountAddress, msg: &ConsensusMsg) -> anyhow::Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this a bug fix, how about a test that verifies the bug is actually fixed ?

let author = match msg {
ConsensusMsg::CommitMessage(commit) => commit.author(),
ConsensusMsg::ProposalMsg(proposal) => proposal.proposal().author(),
ConsensusMsg::VoteMsg(vote) => Some(vote.vote().author()),
ConsensusMsg::OrderVoteMsg(order_vote) => Some(order_vote.order_vote().author()),
ConsensusMsg::CommitVoteMsg(commit_vote) => Some(commit_vote.author()),
ConsensusMsg::BatchMsg(batch) => batch.author(),
ConsensusMsg::RoundTimeoutMsg(round_timeout) => Some(round_timeout.author()),
ConsensusMsg::BatchResponse(batch_response) => Some(batch_response.author()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works too, even this doesn't go through this path (it goes through rpc), this is the batch author which is not necessarily the responser.

ConsensusMsg::BatchRequestMsg(batch_request) => Some(batch_request.source()),
ConsensusMsg::SignedBatchInfo(sign_batch_info) => sign_batch_info.author(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it also feels awkward to only check the first author, probably better to have this check to individual verify function instead of here

Copy link
Contributor Author

@vusirikala vusirikala Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The verify function already checks the author here for each individual signed batch info. So, I originally ignored the author check here by setting author to None. Should I revert it back?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean instead of having this giant check_author function, check the author inside each individual message's verify function or the UnverifiedEvent::verify function as Balaji mentioned above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the sender verification checks to individual verify functions.


ConsensusMsg::CommitDecisionMsg(_)
| ConsensusMsg::DAGMessage(_)
| ConsensusMsg::EpochChangeProof(_)
| ConsensusMsg::EpochRetrievalRequest(_)
| ConsensusMsg::ProofOfStoreMsg(_)
| ConsensusMsg::SyncInfo(_)
| ConsensusMsg::RandGenMessage(_)
| ConsensusMsg::BatchResponseV2(_)
| ConsensusMsg::BlockRetrievalRequest(_)
| ConsensusMsg::BlockRetrievalResponse(_) => None,
};

if let Some(author) = author {
ensure!(
author == peer_id,
"Received {:?} message from peer {} with different author {}",
discriminant(msg),
peer_id,
author
);
}

Ok(())
}

async fn check_epoch(
&mut self,
peer_id: AccountAddress,
Expand Down
7 changes: 7 additions & 0 deletions consensus/src/pipeline/commit_reliable_broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ impl CommitMessage {
_ => None,
}
}

pub fn author(&self) -> Option<PeerId> {
match self {
CommitMessage::Vote(vote) => Some(vote.author()),
_ => None,
}
}
}

impl RBMessage for CommitMessage {}
Expand Down
3 changes: 2 additions & 1 deletion consensus/src/quorum_store/network_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ impl NetworkListener {
counters::QUORUM_STORE_MSG_COUNT
.with_label_values(&["NetworkListener::batchmsg"])
.inc();
let author = batch_msg.author();
// Batch msg verify function alreay ensures that the batch_msg is not empty.
let author = batch_msg.author().expect("Empty batch message");
let batches = batch_msg.take();
counters::RECEIVED_BATCH_MSG_COUNT.inc();

Expand Down
4 changes: 2 additions & 2 deletions consensus/src/quorum_store/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ impl BatchMsg {
Ok(epoch)
}

pub fn author(&self) -> PeerId {
self.batches[0].author()
pub fn author(&self) -> Option<PeerId> {
self.batches.first().map(|batch| batch.author())
}

pub fn take(self) -> Vec<Batch> {
Expand Down
Loading