Skip to content
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
23 changes: 20 additions & 3 deletions anchor/common/ssv_types/src/msgid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ impl Role {
}

pub fn max_round(self) -> Option<u64> {
// as per https://github.com/ssvlabs/ssv/blob/6382d4b52ea5e0efd9378a5a00ef481f39d6234f/message/validation/consensus_validation.go#L370
// Caps both the incoming consensus-message round gate and the local QBFT
// instance round limit. Values mirror go-ssv's maxRound:
// https://github.com/ssvlabs/ssv/blob/d2352a3dba3e7b309ef090b7a23f4cac1d9002d1/message/validation/consensus_validation.go#L434-L443
match self {
Role::Committee | Role::Aggregator | Role::AggregatorCommittee => Some(12),
Role::Proposer | Role::SyncCommittee => Some(6),
Role::EnvelopeProposer => Some(2),
Role::Proposer | Role::EnvelopeProposer => Some(2),
Role::SyncCommittee => Some(6),
// These roles don't use QBFT consensus
Role::ValidatorRegistration
| Role::VoluntaryExit
Expand Down Expand Up @@ -519,4 +521,19 @@ mod tests {
"EnvelopeProposer resolves to a validator-scoped duty executor"
);
}

/// Pins the proposer QBFT and sync-committee round caps.
#[test]
fn proposer_and_sync_committee_max_rounds_are_pinned() {
assert_eq!(
Role::Proposer.max_round(),
Some(2),
"`Role::Proposer` must cap QBFT at round 2"
);
assert_eq!(
Role::SyncCommittee.max_round(),
Some(6),
"`Role::SyncCommittee` must maintain its round 6 cap"
);
}
}
55 changes: 55 additions & 0 deletions anchor/message_validator/src/consensus_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,61 @@ mod tests {
);
}

/// A proposer consensus message above the round 2 cap is rejected.
#[test]
fn test_proposer_consensus_message_round_three_too_high() {
// Create proposer QBFT message with round 3 (exceeds round 2 cap).
let committee_info = create_committee_info(SINGLE_NODE_COMMITTEE);
let qbft_message = QbftMessageBuilder::new(Role::Proposer, QbftMessageType::Prepare)
.with_round(3)
.build();
let signed_msg = create_signed_consensus_message(
qbft_message.clone(),
vec![OperatorId(1)],
vec![],
vec![],
);
let map = create_operator_pub_keys(committee_info.committee_members.clone(), vec![]);

// Validate consensus message.
let result =
validate_consensus_message_semantics(&signed_msg, &qbft_message, &committee_info, &map);

// Should reject with RoundTooHigh error.
assert_validation_error(
result,
|failure| matches!(failure, ValidationFailure::RoundTooHigh),
"RoundTooHigh",
);
}

/// A proposer consensus message at the round 2 cap is still accepted.
#[test]
fn test_proposer_consensus_message_round_two_accepted() {
// Create a proposer QBFT message with round 2 (at the cap boundary).
let committee_info = create_committee_info(SINGLE_NODE_COMMITTEE);
let qbft_message = QbftMessageBuilder::new(Role::Proposer, QbftMessageType::Prepare)
.with_round(2)
.build();
let signed_msg = create_signed_consensus_message(
qbft_message.clone(),
vec![OperatorId(1)],
vec![],
vec![],
);
let map = create_operator_pub_keys(committee_info.committee_members.clone(), vec![]);

// Validate consensus message.
let result =
validate_consensus_message_semantics(&signed_msg, &qbft_message, &committee_info, &map);

// Expect successful validation (round 2 is the maximum allowed).
assert!(
result.is_ok(),
"Proposer consensus message at round 2 cap should validate successfully, got: {result:?}"
);
}

#[test]
fn test_consensus_message_mismatched_identifier() {
let committee_info = create_committee_info(SINGLE_NODE_COMMITTEE);
Expand Down
Loading