aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/vote.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-18 17:23:18 +0000
committertv <tv@krebsco.de>2026-11-18 18:30:32 +0100
commitf261a80b88c1fb640f4c892934809e15a7e05a95 (patch)
treeb899d8994ab6fd320d0094c8e6e56487c73cc53d /src/federation/vote.rs
parentd130c0612b4c63f2d30da65ebcc231018c1f2606 (diff)
attacks: rows 45, 58 and 65 tested beside the code they test
The check that every attack row of the federation has its test looks beside the code a row is about too: a node's (`held`), a party's client's (`client`), and a node voting by itself (`vote`). Rows 45 (a version written on the side a node doesn't read, refused as its own and reported apart, the change that put it taken), 58 (a node following on checkpoints only, unless its operator chose any version) and 65 (a client keeping the nays that freed its `true`) have their tests there, and wait no more.
Diffstat (limited to 'src/federation/vote.rs')
-rw-r--r--src/federation/vote.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/federation/vote.rs b/src/federation/vote.rs
index 9bf7a1c..d4968be 100644
--- a/src/federation/vote.rs
+++ b/src/federation/vote.rs
@@ -512,6 +512,54 @@ mod tests {
assert!(decide(&seen(&store, &held), &rules, &record).is_empty());
}
+ /// Row 58 (`docs/federation.md`): a party the node follows backs, or votes `false` on,
+ /// a version that changes more than moving to a checkpoint: by default the node follows
+ /// neither; one following on any version, as its operator chose, follows both.
+ #[test]
+ fn federation_attack_58() {
+ let (tv, _, _, first, mut store) = three();
+ let root = store.id();
+ let mut backed = first.after(first.hash());
+ backed
+ .rules
+ .push(("names/x".to_owned(), harness::str("tv")));
+ let mut opposed = first.after(first.hash());
+ opposed
+ .rules
+ .push(("names/y".to_owned(), harness::str("tv")));
+ let one = taken(&mut store, tv.propose(&[root], &backed.json()));
+ let two = taken(&mut store, tv.propose(&[root], &opposed.json()));
+ taken(
+ &mut store,
+ tv.vote(&[one], first.hash(), backed.hash(), true),
+ );
+ taken(
+ &mut store,
+ tv.vote(&[two], first.hash(), opposed.hash(), false),
+ );
+ let rules = Rules {
+ follow: vec!["tv".to_owned()],
+ ..Rules::default()
+ };
+ let long = |_: &Id| Some(Duration::from_secs(3600));
+ let record = record(&store, "makefu");
+ assert!(decide(&seen(&store, &long), &rules, &record).is_empty());
+ let any = Rules {
+ follow_any: true,
+ ..rules
+ };
+ let acts = decide(&seen(&store, &long), &any, &record);
+ assert_eq!(acts.len(), 2);
+ assert!(acts.iter().any(|act| matches!(
+ act,
+ Act::Vote { proposal, yes: true, .. } if *proposal == backed.hash()
+ )));
+ assert!(acts.iter().any(|act| matches!(
+ act,
+ Act::Vote { proposal, yes: false, .. } if *proposal == opposed.hash()
+ )));
+ }
+
#[test]
fn a_vote_by_hand_keeps_to_the_record() {
let (tv, _, _, first, mut store) = three();