aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 00:12:20 +0000
committertv <tv@krebsco.de>2026-11-17 01:45:59 +0100
commit65b826f4a5bdd6f2ae2942df4a3975255e33c48f (patch)
tree998285e2a25ebb708d479dd4c26588a7cb4cbc23
parent41e290716c9ce517597d4b2dec29c8882c36afdb (diff)
simtest: two checkpoints proposed at once, the one not backed dying by the nays
`federation_attack_59`: a for tv and b for lass, apart, each propose a checkpoint once their stores took six events, and back it; c votes for makefu, following tv; each votes `false` on a checkpoint beside the one it backs (`--store-nay-beside`). a and b, together, vote `false` on each other's: the votes split. With c, tv's passes and every node moves there; lass's is dead by the nays of tv and makefu, which their records hold.
-rw-r--r--src/federation/attacks.rs4
-rw-r--r--src/simtest/holding.rs135
2 files changed, 136 insertions, 3 deletions
diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs
index 707e0e7..531dca7 100644
--- a/src/federation/attacks.rs
+++ b/src/federation/attacks.rs
@@ -12,8 +12,8 @@ use super::store::{Fold, Id};
use super::version::Version;
/// Rows whose tests wait: what a node, a party's client or a tool does (stage 3), forks
-/// (stage 4), a rule for two checkpoints proposed at once, and flooding.
-const LATER: &[u32] = &[30, 33, 35, 36, 39, 45, 51, 58, 59, 63, 65, 68];
+/// (stage 4), and flooding.
+const LATER: &[u32] = &[30, 33, 35, 36, 39, 45, 51, 58, 63, 65, 68];
fn tv() -> Party {
Party::new("tv", 1)
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 955b2c0..f70ef0d 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -11,7 +11,7 @@ use std::time::Duration;
use super::{SOON, Sim, sim_key};
use crate::document::events;
use crate::federation::client::Record;
-use crate::federation::event::Event;
+use crate::federation::event::{Does, Event, Signed};
use crate::federation::fold::Federation;
use crate::federation::harness::{self, Party, Spec};
use crate::federation::held::{self, Holding, Voter};
@@ -192,6 +192,44 @@ fn written(node: &AppState, version: Id) -> Option<Id> {
.flatten()
}
+/// The proposal on the current version that `party` proposed, as `node`'s store holds it:
+/// its hash, and the parties voting `true` on it, and `false`.
+type Ballot = (Id, BTreeSet<String>, BTreeSet<String>);
+
+fn ballot(node: &AppState, party: &str) -> Option<Ballot> {
+ read(node, |store| {
+ let state = store.state();
+ let signed = |id: &Id| match store.get(id).and_then(Event::read_taken) {
+ Some(Event::Signed(signed)) => Some(signed),
+ _ => None,
+ };
+ state
+ .ballots(&state.current().hash)
+ .into_iter()
+ .find_map(|(hash, ballot)| {
+ let proposed = ballot
+ .proposals
+ .iter()
+ .filter_map(signed)
+ .any(|proposing| proposing.party == party);
+ let (mut yes, mut no) = (BTreeSet::new(), BTreeSet::new());
+ for vote in ballot.votes.iter().filter_map(signed) {
+ if let Does::Vote { yes: true, .. } = vote.does {
+ yes.insert(vote.party);
+ } else {
+ no.insert(vote.party);
+ }
+ }
+ proposed.then_some((hash, yes, no))
+ })
+ })
+ .flatten()
+}
+
+fn set(names: &[&str]) -> BTreeSet<String> {
+ names.iter().map(|name| (*name).to_owned()).collect()
+}
+
/// What counts, as `node`'s store reads: the current version, the values at places, and
/// the members; and the events it took after its checkpoint.
type Counts = (
@@ -645,3 +683,98 @@ async fn store_attack_10() {
// Each refuses the other's changes for good: their documents part.
assert_ne!(super::heads(twins[0]).await, super::heads(twins[1]).await);
}
+
+/// Two checkpoints proposed at once, by nodes voting by themselves: a for tv and b for
+/// lass, apart, each propose one once their stores took six events, and back it; c votes
+/// for makefu, following tv; each votes `false` on a checkpoint beside the one it backs.
+/// a and b, together, vote `false` on each other's: the votes split. With c, tv's passes
+/// and every node moves there; lass's is dead by the nays of tv and makefu, which their
+/// records hold.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn federation_attack_59() {
+ let sim = Sim::with_identity(89);
+ let (tv, lass, makefu) = three();
+ let (first, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"]), (&makefu, &["c"])]);
+ let dir = crate::files::scratch_dir("sim-attack-59");
+ let proposing = Rules {
+ propose_events: Some(6),
+ nay_beside: true,
+ ..Rules::default()
+ };
+ let following = Rules {
+ follow: vec!["tv".to_owned()],
+ nay_beside: true,
+ held_for: Duration::from_secs(3600),
+ ..Rules::default()
+ };
+ let nodes = started(
+ &sim,
+ &root,
+ vec![
+ ("a", voting(&tv, proposing.clone(), &dir, &first)),
+ ("b", voting(&lass, proposing, &dir, &first)),
+ ("c", voting(&makefu, following, &dir, &first)),
+ ],
+ )
+ .await;
+ for name in ["a", "b", "c"] {
+ sim.net.take_down(name);
+ }
+ // Six writes of each, one on the other.
+ for (node, party) in [(&nodes[0], &tv), (&nodes[1], &lass)] {
+ let mut on = id;
+ for n in 0..6 {
+ let write = party.write(&[on], &format!("home/{}/{n}", party.name), s("1"));
+ on = Id::of(&write);
+ put(node, &[&write]).await;
+ }
+ }
+ let all = &nodes;
+ sim.wait_until(
+ "a and b each back a checkpoint of their own",
+ LONG,
+ move || async move {
+ [(0, "tv"), (1, "lass")].into_iter().all(|(i, party)| {
+ ballot(&all[i], party).is_some_and(|(_, yes, _)| yes.contains(party))
+ })
+ },
+ )
+ .await;
+ sim.net.bring_up("a");
+ sim.net.bring_up("b");
+ sim.wait_until(
+ "a and b vote `false` on each other's",
+ LONG,
+ move || async move {
+ all[..2].iter().all(|node| {
+ ballot(node, "tv")
+ .is_some_and(|(_, yes, no)| yes == set(&["tv"]) && no == set(&["lass"]))
+ && ballot(node, "lass")
+ .is_some_and(|(_, yes, no)| yes == set(&["lass"]) && no == set(&["tv"]))
+ })
+ },
+ )
+ .await;
+ let (passing, _, _) = ballot(&nodes[0], "tv").expect("tv's");
+ let (other, _, _) = ballot(&nodes[0], "lass").expect("lass's");
+ sim.net.bring_up("c");
+ sim.wait_until(
+ "every node moves to tv's checkpoint",
+ LONG,
+ move || async move { all.iter().all(|node| current(node) == Some(passing)) },
+ )
+ .await;
+ for party in ["tv", "makefu"] {
+ let record = Record::load(&dir.join(format!("{party}.json"))).expect("its record");
+ let nay = record.votes.iter().any(|vote| {
+ matches!(
+ Event::read_taken(vote.as_bytes()),
+ Some(Event::Signed(Signed {
+ does: Does::Vote { proposal, yes: false, .. },
+ ..
+ })) if proposal == other
+ )
+ });
+ assert!(nay, "{party} voted no `false` on lass's checkpoint");
+ }
+}