From 438d4f06103ba7ae17a80f48aa589219c7d8dd61 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 00:25:41 +0000 Subject: federation: a fork's root made, and checked by a node holding its history `federation::fork`: a node holding a federation's history makes the root of a fork at heads it holds by a version, with the events the root keeps, as the file the fork's founders start its swarm from (`make`, `root_file`, which `--store-root` reads); and checks a fork's root it is given (`check`): whether it builds that root at its heads, byte for byte, what it holds that those heads lack, and, party by party, the keys the fork's version gives where they aren't those the party had there. The attack rows 35 and 36 have their tests. --- src/federation/attacks.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'src/federation/attacks.rs') diff --git a/src/federation/attacks.rs b/src/federation/attacks.rs index 531dca7..e1d2936 100644 --- a/src/federation/attacks.rs +++ b/src/federation/attacks.rs @@ -5,15 +5,16 @@ use super::event::Checkpoint; use super::fold::Federation; +use super::fork; use super::harness::{self, Party, Spec}; use super::jcs::Json; use super::store::memory::{Offered, Refusal, Store}; 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), and flooding. -const LATER: &[u32] = &[30, 33, 35, 36, 39, 45, 51, 58, 63, 65, 68]; +/// Rows whose tests wait: what a node, a party's client or a tool does (stage 3), a fork +/// whose root differs, simulated (stage 4), and flooding. +const LATER: &[u32] = &[30, 33, 39, 45, 51, 58, 63, 65, 68]; fn tv() -> Party { Party::new("tv", 1) @@ -688,6 +689,47 @@ fn federation_attack_34() { assert!(fed.store.fork(&[here], &elsewhere.json().bytes()).is_err()); } +/// A fork at heads of its founder's choosing, leaving out a write of lass's: a node +/// holding the federation builds its root, and is told what those heads lack. +#[test] +fn federation_attack_35() { + let mut fed = three(); + let root = fed.root(); + let here = fed.take(tv().write(&[root], "home/tv/a", s("1"))); + let beside = fed.take(lass().write(&[root], "home/lass/b", s("1"))); + let mut forking = fed.first.after(fed.first.hash()); + forking.parties[0].nodes_since = 1; + let file = fork::make(&fed.store, &[here], &forking.json()).expect("a fork"); + let (fork_root, _) = fork::read_root_file(&file); + let check = fork::check(&fed.store, &fork_root).expect("checked"); + assert!(check.builds); + assert_eq!(check.lacking, vec![beside]); +} + +/// A fork's version giving lass, who didn't go, a key of its founder's: a node holding +/// the federation is told, party by party. +#[test] +fn federation_attack_36() { + let mut fed = three(); + let root = fed.root(); + let here = fed.take(tv().write(&[root], "home/tv/a", s("1"))); + let mut forking = fed.first.after(fed.first.hash()); + forking.parties[1].keys = vec![harness::key_line(9)]; + forking.parties[1].keys_since = 1; + let file = fork::make(&fed.store, &[here], &forking.json()).expect("a fork"); + let (fork_root, _) = fork::read_root_file(&file); + let check = fork::check(&fed.store, &fork_root).expect("checked"); + assert!(check.builds); + assert_eq!( + check.keys, + vec![( + "lass".to_owned(), + vec![lass().key_line()], + vec![harness::key_line(9)] + )] + ); +} + #[test] fn federation_attack_37() { let mut fed = three(); -- cgit v1.3.1