diff options
| author | tv <tv@krebsco.de> | 2026-11-19 01:48:57 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 03:18:49 +0100 |
| commit | 03744437a5ffc36fbb5e973a0ddfd6b91945b212 (patch) | |
| tree | 227eb42b4e7cac546b857cfacb79ab890e8bb137 /src/federation/held.rs | |
| parent | f24063e90d02ef76d87401d6e74cf8c9f489ff7d (diff) | |
federation: votes on the events proposing a checkpoint above its heads
Anyone could propose a checkpoint's version again, by an event beside its heads. A node
voting by itself, and a party's client, built a vote on every event proposing what it
voted on, so every vote was beside the heads, and no version event written on them was
taken: the checkpoint could never move the store. And the voters' rule refused it once
that event was held for a while, as the heads left it out.
They vote on the events proposing it that are above the heads it names
(`State::proposing`), which `GET /events/counts` lists as `proposals`; where there are
none, `none` says so, the node casts nothing and the client says why. The voters' rule
leaves proposals and votes aside, as they lapse with the move.
Row 70 is tested (`federation_attack_70`).
Diffstat (limited to 'src/federation/held.rs')
| -rw-r--r-- | src/federation/held.rs | 112 |
1 files changed, 100 insertions, 12 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs index 66f20e9..93e2505 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -728,7 +728,6 @@ impl Holding { return Ok(Vec::new()); } let current = store.state().current().clone(); - let ballots = store.state().ballots(¤t.hash); let heads = store.heads(); let line = crate::access::sshsig::PublicKey(voter.key.verifying_key().to_bytes()).line(); let mut record = record.clone(); @@ -740,21 +739,24 @@ impl Holding { yes, nays, } => { - // On the events proposing it: above the heads it names for a - // checkpoint wherever they are, so a version event may be written on - // it, which the node's heads, holding what is beside them, may not be. - let proposing = ballots - .get(&proposal) - .map_or_else(Vec::new, |ballot| ballot.proposals.clone()); + // On the events proposing it, those above the heads it names for a + // checkpoint, so a version event may be written on it, which the + // node's heads, holding what is beside them, may not be. + let proposing = store.state().proposing(¤t.hash, &proposal); + if proposing.is_empty() { + if hand.is_some() { + return Err(format!( + "no event proposing {proposal} is above the heads it names: \ + no version event is written on a vote on it" + )); + } + continue; + } let cast = event::signed( &voter.key, party, &line, - if proposing.is_empty() { - &heads - } else { - &proposing - }, + &proposing, event::vote(current.hash, proposal, yes), ); record.cast(¤t, &cast, nays); @@ -1949,6 +1951,92 @@ mod tests { assert!(holding.vote_by_hand(next.hash(), true).is_ok()); } + /// Row 70 (`docs/federation.md`): a checkpoint's version proposed again, by an event + /// beside its heads. A node backs it all the same, as a proposal lapses with the move, + /// and votes on the event proposing it above the heads alone: a version event written + /// on such votes moves it; one on votes built on both events is beside the heads, and + /// refused. + #[test] + fn federation_attack_70() { + let (tv, lass, makefu) = ( + Party::new("tv", 1), + Party::new("lass", 2), + Party::new("makefu", 3), + ); + let first = Spec::first(&[&tv, &lass, &makefu], &[]); + let root = first.root(); + let on = first.hash(); + let head = tv.write(&[Id::of(&root)], "home/tv/a", harness::str("1")); + let mut next = first.after(on); + next.checkpoint = Some(vec![Id::of(&head)]); + let above = tv.propose(&[Id::of(&head)], &next.json()); + let beside = lass.propose(&[Id::of(&root)], &next.json()); + let mut doc = events::started(Federation::NAME, &root, &[]).unwrap(); + for event in [&head, &above, &beside] { + put(&mut doc, event); + } + let dir = crate::files::scratch_dir("held-attack-70"); + let record = dir.join("makefu.json"); + let version = Version::read(&first.json()).unwrap(); + let mut begun = Record::begin(Id::of(&root), "makefu", &version); + begun.began = Id::of(b"before the federation").to_string(); + begun.save(&record).unwrap(); + let holding = Holding::open( + None, + Arc::new(Files::default()), + None, + Some("makefu".into()), + ) + .unwrap() + .voting(Some(Voter { + key: makefu.key.clone(), + record, + // Everything held for a while: the proposal beside the heads too. + rules: Rules::default(), + })); + read(&holding, &doc, 0); + assert_eq!( + holding.with(|store| store.state().proposing(&on, &next.hash())), + Some(vec![Id::of(&above)]) + ); + let cast = holding.vote_by_hand(next.hash(), true).unwrap(); + assert!(matches!( + Event::read_taken(&cast), + Some(Event::Signed(Signed { deps, .. })) if deps == vec![Id::of(&above)] + )); + let both = [Id::of(&above), Id::of(&beside)]; + let beside_votes = [&tv, &lass].map(|party| party.vote(&both, on, next.hash(), true)); + for vote in &beside_votes { + assert!(matches!( + holding.offer(vote.clone()), + Some(Offered::Taken(_)) + )); + } + let refused = harness::version_event( + &[Id::of(&beside_votes[0]), Id::of(&beside_votes[1])], + next.hash(), + ); + assert!(matches!( + holding.offer(refused), + Some(Offered::Refused(Refusal::Judged(_))) + )); + let tv_yes = tv.vote(&[Id::of(&above)], on, next.hash(), true); + assert!(matches!( + holding.offer(tv_yes.clone()), + Some(Offered::Taken(_)) + )); + let written = harness::version_event(&[Id::of(&cast), Id::of(&tv_yes)], next.hash()); + assert!(matches!(holding.offer(written), Some(Offered::Taken(_)))); + assert_eq!( + holding.with(|store| store.state().current().hash), + Some(next.hash()) + ); + assert_ne!( + holding.with(|store| Id::of(store.checkpoint())), + Some(Id::of(&root)) + ); + } + // The store's attack rows (`docs/store.md`, Attacks) read from a document. /// tv's federation, its root, and a document started from it. |
