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

Byzantine test for spamming bad proposals #3486

Merged
merged 8 commits into from
Jul 31, 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
44 changes: 44 additions & 0 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ where

let mut results = state.send_handler(&msg).await;

results.reverse();

while let Some(event) = results.pop() {
let _ = sender_to_network.broadcast(event.into()).await;
}
Expand All @@ -330,6 +332,8 @@ where

let mut results = state.recv_handler(&msg).await;

results.reverse();

while let Some(event) = results.pop() {
let _ = original_sender.broadcast(event.into()).await;
}
Expand All @@ -342,6 +346,46 @@ where
}
}

#[derive(Debug)]
/// An `EventTransformerState` that multiplies `QuorumProposalSend` events, incrementing the view number of the proposal
pub struct BadProposalViewDos {
/// The number of times to duplicate a `QuorumProposalSend` event
pub multiplier: u64,
/// The view number increment each time it's duplicated
pub increment: u64,
}

#[async_trait]
impl<TYPES: NodeType, I: NodeImplementation<TYPES>> EventTransformerState<TYPES, I>
for BadProposalViewDos
{
async fn recv_handler(&mut self, event: &HotShotEvent<TYPES>) -> Vec<HotShotEvent<TYPES>> {
vec![event.clone()]
}

async fn send_handler(&mut self, event: &HotShotEvent<TYPES>) -> Vec<HotShotEvent<TYPES>> {
match event {
HotShotEvent::QuorumProposalSend(proposal, signature) => {
let mut result = Vec::new();

for n in 0..self.multiplier {
let mut modified_proposal = proposal.clone();

modified_proposal.data.view_number += n * self.increment;

result.push(HotShotEvent::QuorumProposalSend(
modified_proposal,
signature.clone(),
));
}

result
}
_ => vec![event.clone()],
}
}
}

#[derive(Debug)]
/// An `EventHandlerState` that doubles the `QuorumVoteSend` and `QuorumProposalSend` events
pub struct DoubleProposeVote;
Expand Down
38 changes: 36 additions & 2 deletions crates/testing/tests/tests_1/test_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ use hotshot_testing::{
test_builder::TestDescription,
};
#[cfg(async_executor_impl = "async-std")]
use {hotshot::tasks::DoubleProposeVote, hotshot_testing::test_builder::Behaviour, std::rc::Rc};
use {
hotshot::tasks::{BadProposalViewDos, DoubleProposeVote},
hotshot_testing::test_builder::Behaviour,
std::rc::Rc,
};

cross_tests!(
TestName: test_success,
Expand All @@ -33,7 +37,7 @@ cross_tests!(

#[cfg(async_executor_impl = "async-std")]
cross_tests!(
TestName: twins_test_success,
TestName: double_propose_vote,
Impls: [MemoryImpl],
Types: [TestTypes],
Ignore: false,
Expand All @@ -55,3 +59,33 @@ cross_tests!(
}
},
);

// Test where node 4 sends out the correct quorum proposal and additionally spams the network with an extra 99 malformed proposals
#[cfg(async_executor_impl = "async-std")]
cross_tests!(
TestName: multiple_bad_proposals,
Impls: [MemoryImpl],
Types: [TestTypes],
Ignore: false,
Metadata: {
let behaviour = Rc::new(|node_id| { match node_id {
4 => Behaviour::Byzantine(Box::new(BadProposalViewDos { multiplier: 100, increment: 1 })),
_ => Behaviour::Standard,
} });

let mut metadata = TestDescription {
// allow more time to pass in CI
completion_task_description: CompletionTaskDescription::TimeBasedCompletionTaskBuilder(
TimeBasedCompletionTaskDescription {
duration: Duration::from_secs(60),
},
),
behaviour,
..TestDescription::default()
};

metadata.overall_safety_properties.num_failed_views = 0;

metadata
},
);