Skip to content
Closed
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
3 changes: 3 additions & 0 deletions code/crates/core-types/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ where

/// Address of the validator who issued this proposal
fn validator_address(&self) -> &Ctx::Address;

/// Return a copy of this proposal with a different value.
fn with_value(self, value: Ctx::Value) -> Self;
}

/// Whether or not a proposal is valid.
Expand Down
4 changes: 4 additions & 0 deletions code/crates/core-types/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ where

/// The ID of the value.
fn id(&self) -> Self::Id;

/// Return a dummy/sentinel value for testing purposes.
/// Must differ from any real value produced by the system.
fn dummy() -> Self;
}

/// The possible messages used to deliver proposals
Expand Down
3 changes: 3 additions & 0 deletions code/crates/core-types/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ where

/// Extend this vote with an extension, overriding any existing extension.
fn extend(self, extension: SignedExtension<Ctx>) -> Self;

/// Return a copy of this vote with a different value.
fn with_value(self, value: NilOrVal<<Ctx::Value as Value>::Id>) -> Self;
}
34 changes: 31 additions & 3 deletions code/crates/engine/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
Effect, LivenessMsg, PeerId, Resumable, Resume, SignedConsensusMsg, VoteExtensionError,
};
use malachitebft_core_types::{
Context, Proposal, Round, Timeout, TimeoutKind, Timeouts, ValidatorSet, Validity, Value,
ValueId, ValueOrigin, ValueResponse as CoreValueResponse, Vote,
Context, NilOrVal, Proposal, Round, Timeout, TimeoutKind, Timeouts, ValidatorSet, Validity,
Value, ValueId, ValueOrigin, ValueResponse as CoreValueResponse, Vote,
};
use malachitebft_metrics::Metrics;
use malachitebft_signing::{SigningProvider, SigningProviderExt};
Expand Down Expand Up @@ -1140,9 +1140,37 @@
self.tx_event.send(|| Event::Published(msg.clone()));

self.network
.cast(NetworkMsg::PublishConsensusMsg(msg))
.cast(NetworkMsg::PublishConsensusMsg(msg.clone()))
.map_err(|e| eyre!("Error when broadcasting consensus message: {e:?}"))?;

// TESTING ONLY: send conflicting messages to trigger equivocation detection
if std::env::var("TEST_ONLY_MALICIOUS_NODE").as_deref() == Ok("true") {
match &msg {
SignedConsensusMsg::Vote(signed_vote) => {

Check warning on line 1149 in code/crates/engine/src/consensus.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/malachite/malachite/code/crates/engine/src/consensus.rs

Check warning on line 1149 in code/crates/engine/src/consensus.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/malachite/malachite/code/crates/engine/src/consensus.rs

Check warning on line 1149 in code/crates/engine/src/consensus.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/malachite/malachite/code/crates/engine/src/consensus.rs
// Send a conflicting nil vote to trigger vote equivocation
if signed_vote.message.value().is_val() {
let conflicting = signed_vote.message.clone().with_value(NilOrVal::Nil);
if let Ok(signed) = self.signing_provider.sign_vote(conflicting).await {
let _ = self.network.cast(NetworkMsg::PublishConsensusMsg(
SignedConsensusMsg::Vote(signed),
));
}
}
}
SignedConsensusMsg::Proposal(signed_proposal) => {

Check warning on line 1160 in code/crates/engine/src/consensus.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/malachite/malachite/code/crates/engine/src/consensus.rs

Check warning on line 1160 in code/crates/engine/src/consensus.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/malachite/malachite/code/crates/engine/src/consensus.rs

Check warning on line 1160 in code/crates/engine/src/consensus.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/malachite/malachite/code/crates/engine/src/consensus.rs
// Send a conflicting proposal with a dummy value to trigger
// double proposal detection on honest nodes.
let bad_proposal = signed_proposal.message.clone()
.with_value(<<Ctx as Context>::Value as Value>::dummy());
if let Ok(signed) = self.signing_provider.sign_proposal(bad_proposal).await {
let _ = self.network.cast(NetworkMsg::PublishConsensusMsg(
SignedConsensusMsg::Proposal(signed),
));
}
}
}
}

Ok(r.resume_with(()))
}

Expand Down
10 changes: 10 additions & 0 deletions code/crates/starknet/p2p-types/src/context/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ impl common::Proposal<MockContext> for Proposal {
fn validator_address(&self) -> &Address {
&self.proposer
}

fn with_value(mut self, value: Hash) -> Self {
self.value_id = value;
self
}
}

impl common::Vote<MockContext> for Vote {
Expand Down Expand Up @@ -79,6 +84,11 @@ impl common::Vote<MockContext> for Vote {
fn take_extension(&mut self) -> Option<SignedExtension<MockContext>> {
None
}

fn with_value(mut self, value: NilOrVal<Hash>) -> Self {
self.block_hash = value;
self
}
}

impl common::ValidatorSet<MockContext> for ValidatorSet {
Expand Down
4 changes: 4 additions & 0 deletions code/crates/starknet/p2p-types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ impl malachitebft_core_types::Value for BlockHash {
fn id(&self) -> Self::Id {
*self
}

fn dummy() -> Self {
Self::new([0xBA; 32])
}
}

#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down
5 changes: 5 additions & 0 deletions code/crates/test/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ impl malachitebft_core_types::Proposal<TestContext> for Proposal {
fn validator_address(&self) -> &Address {
&self.validator_address
}

fn with_value(mut self, value: Value) -> Self {
self.value = value;
self
}
}

impl Protobuf for Proposal {
Expand Down
4 changes: 4 additions & 0 deletions code/crates/test/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ impl malachitebft_core_types::Value for Value {
fn id(&self) -> ValueId {
self.id()
}

fn dummy() -> Self {
Self::new(u64::MAX)
}
}

impl Protobuf for Value {
Expand Down
5 changes: 5 additions & 0 deletions code/crates/test/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ impl malachitebft_core_types::Vote<TestContext> for Vote {
..self
}
}

fn with_value(mut self, value: NilOrVal<ValueId>) -> Self {
self.value = value;
self
}
}

impl Protobuf for Vote {
Expand Down
Loading