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

fix(privval): always sign extension #857

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 17 additions & 15 deletions src/privval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,24 @@ impl SignableMsg {
pub fn extension_bytes(&self, chain_id: chain::Id) -> Result<Option<Bytes>, EncodeError> {
match self {
Self::Proposal(_) => Ok(None),
Self::Vote(vote) => {
// Only sign extension if actually present
if vote.extension.is_empty() {
return Ok(None);
Self::Vote(v) => {
match (v.vote_type, v.block_id) {
// Only sign extension if it's a precommit for a non-nil block.
// Note that extension can be empty.
(vote::Type::Precommit, Some(_)) => {
let canonical = proto::types::CanonicalVoteExtension {
extension: v.extension.clone(),
height: v.height.into(),
round: v.round.value().into(),
chain_id: chain_id.to_string(),
};

let mut bytes = BytesMut::new();
canonical.encode_length_delimited(&mut bytes)?;
Ok(Some(bytes.into()))
}
_ => Ok(None),
}

let canonical = proto::types::CanonicalVoteExtension {
extension: vote.extension.clone(),
height: vote.height.into(),
round: vote.round.value().into(),
chain_id: chain_id.to_string(),
};

let mut bytes = BytesMut::new();
canonical.encode_length_delimited(&mut bytes)?;
Ok(Some(bytes.into()))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Session {
signable_msg.add_consensus_signature(consensus_sig);
self.log_signing_request(&signable_msg, started_at).unwrap();

// Add extension signature if there are any extensions defined
// Add extension signature if the message is a precommit for a non-empty block ID.
if let Some(extension_msg) = signable_msg.extension_bytes(chain_id)? {
let started_at = Instant::now();
let extension_sig = chain.keyring.sign(public_key, &extension_msg)?;
Expand Down
Loading