aboutsummaryrefslogtreecommitdiffstats
path: root/src/simtest
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 00:34:13 +0000
committertv <tv@krebsco.de>2026-11-17 01:47:54 +0100
commitf0f8c1147715b28568e9e19026f5ef7d9f5092ce (patch)
treea9c1359dbfc9bf03754b4e419c5e681b92c85bce /src/simtest
parentb79ac0fb88ad6604a87d2e72010b6a9a1a4d6fd8 (diff)
simtest: a fork whose root doesn't read as its heads do, found by who holds them
`federation_attack_33`: beside the fork a node holding the history makes, one whose root leaves out tv's write, which counts at its heads. b, holding the history, builds the one and not the other (`fork::check`). Each fork's founder starts its swarm from its root and the events it keeps, and a node of lass joins each by its ID, taking it on its operator's word, and reads what the root keeps: tv's write in the one, carried by the changes founding its swarm, nothing in the other.
Diffstat (limited to 'src/simtest')
-rw-r--r--src/simtest/holding.rs102
1 files changed, 101 insertions, 1 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 3e25f20..3ab8582 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -11,8 +11,9 @@ use std::time::Duration;
use super::{SOON, Sim, sim_key};
use crate::document::events;
use crate::federation::client::Record;
-use crate::federation::event::{Does, Event, Signed};
+use crate::federation::event::{Checkpoint, Does, Event, Signed};
use crate::federation::fold::Federation;
+use crate::federation::fork;
use crate::federation::harness::{self, Party, Spec};
use crate::federation::held::{self, Holding, Voter};
use crate::federation::jcs::Json;
@@ -778,3 +779,102 @@ async fn federation_attack_59() {
assert!(nay, "{party} voted no `false` on lass's checkpoint");
}
}
+
+/// A fork whose root doesn't read as its heads do, leaving out tv's write, which counts
+/// there, beside the fork a node holding the history builds: b, holding it, builds the
+/// one and not the other. Each fork's founder starts its swarm from its root and the
+/// events it keeps, and a node of lass joins each by its ID, taking it on its operator's
+/// word, and reads what the root keeps: tv's write in the one, nothing in the other.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn federation_attack_33() {
+ let sim = Sim::with_identity(90);
+ let (tv, lass, _) = three();
+ let (first, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"])]);
+ let nodes = started(
+ &sim,
+ &root,
+ vec![("a", holding("tv")), ("b", holding("lass"))],
+ )
+ .await;
+ let write = tv.write(&[id], "home/tv/x", s("1"));
+ let head = Id::of(&write);
+ put(&nodes[0], &[&write]).await;
+ let all = &nodes;
+ sim.wait_until("a and b hold tv's write", SOON, move || async move {
+ all.iter().all(|node| holds(node, &[head]))
+ })
+ .await;
+ // The forks' versions, after the first, naming their nodes anew.
+ let forking = |named: [&str; 2]| {
+ let mut spec = first.after(first.hash());
+ for (party, node) in spec.parties.iter_mut().zip(named) {
+ party.nodes = vec![sim_key(node).id()];
+ party.nodes_since = 1;
+ }
+ spec
+ };
+ let (honest, crafted) = (forking(["f", "j"]), forking(["g", "k"]));
+ let file = read(&nodes[0], |store| {
+ fork::make(store, &[head], &honest.json())
+ })
+ .expect("a store")
+ .expect("a fork");
+ let (honest_root, kept) = fork::read_root_file(&file);
+ assert_eq!(kept, vec![write.clone()]);
+ let crafted_root = Checkpoint {
+ at: vec![head],
+ keeps: Vec::new(),
+ version: Version::read(&crafted.json()).expect("a version"),
+ }
+ .bytes();
+ let builds = |root: &[u8]| {
+ read(&nodes[1], |store| {
+ fork::check(store, root).map(|check| check.builds)
+ })
+ };
+ assert_eq!(builds(&honest_root), Some(Ok(true)));
+ assert_eq!(builds(&crafted_root), Some(Ok(false)));
+
+ let mut forks = Vec::new();
+ for ((founder, joiner), (root, kept)) in [("f", "j"), ("g", "k")].into_iter().zip([
+ (honest_root.clone(), kept),
+ (crafted_root.clone(), Vec::new()),
+ ]) {
+ let forked = Id::of(&root);
+ let started = sim.start_with(
+ founder,
+ &[],
+ Start::FromDocument(Origin::Root),
+ move |config| {
+ of_the_store(config, forked, None, holding("tv"));
+ config.initial_doc =
+ events::started(Federation::NAME, &root, &kept).expect("a fork's root");
+ },
+ );
+ let joined = sim.start_with(joiner, &[founder], Start::Join, move |config| {
+ of_the_store(config, forked, None, holding("lass"))
+ });
+ forks.push((started, joined));
+ }
+ let forks = &forks;
+ sim.wait_until(
+ "each joiner holds its fork's store",
+ LONG,
+ move || async move {
+ forks
+ .iter()
+ .all(|(_, joined)| joined.holding.tells_members())
+ },
+ )
+ .await;
+ let reads = |node: &AppState| {
+ read(node, |store| {
+ (store.id(), store.state().value("home/tv/x").cloned())
+ })
+ };
+ assert_eq!(
+ reads(&forks[0].1),
+ Some((Id::of(&honest_root), Some(s("1"))))
+ );
+ assert_eq!(reads(&forks[1].1), Some((Id::of(&crafted_root), None)));
+}