chadtmiller.com/group-host
atmosphere group host
atproto: the MST, CAR files, signed commits and commit proofs
MergedThis adds the MST, CARv1 reading and writing, and v3 signed commits. I read all three new files (mst.rs, car.rs, commit.rs). I did not read the data-model files this pull includes, or the tests. I could not read the repo's AGENTS.md at the base branch, because the tool errored.
One thing needs fixing before this merges. Tree::read is meant for untrusted input such as imported repos and CARs, and it can be made to run for an effectively unbounded time. read_node follows every link without remembering which nodes it has visited. A crafted block set can make a node's l and every entry's t link to the same child, and repeat that for up to 64 layers. The traversal then visits the child once per link, so the work grows exponentially. Each node is only a few hundred bytes, so the input stays small. The final rebuild-and-compare check would reject such a tree, but the walk never gets that far. Keep a set of visited CIDs, or reject a CID seen twice. A valid MST never references one node from two places, so refusing a repeat loses nothing.
Smaller points that do not block the merge:
read_nodedoes not check that a key looks likecollection/rkey. Since the rebuilt root has to match, this only matters if callers assume the keys are well-formed.Commit::from_bytesaccepts extra fields. They would be dropped, so re-encoding the commit would give a different CID. Rejecting unknown fields would be stricter.
crates/atproto/src/mst.rsline 335Outdated
}; | |
let subtree = |v: &Value, records: &mut BTreeMap<String, Cid>| match v { | |
Value::Null => Ok(()), | |
Value::Link(c) => read_node(*c, blocks, records, layer + 1), |
The descent has no visited set, so a block set whose nodes link repeatedly to the same child costs time exponential in depth, even though MAX_LAYERS bounds the depth. Track visited CIDs and refuse a node reached twice.
Fixed: read_node keeps the CIDs it has visited and refuses one reached twice ("node … is reached twice"), tested with a node linked from both l and an entry's t. Also took the second point: Commit::from_bytes refuses a commit with fields beyond its six. Key shape is left to the rebuild check, as you say.
Both points from my earlier review are done. read_node now keeps a seen set and refuses a node reached twice, so the exponential walk is gone. A valid MST never reaches one node from two places, so this rejects nothing legitimate. Commit::from_bytes now requires exactly six fields, so a commit with extra fields is refused and re-encoding gives the same CID. I re-read mst.rs and commit.rs at the new head and found nothing new. I did not re-read car.rs, the tests or the data-model files this pull includes.
One point from last time is still open and does not block the merge. read_node doesn't check that a key looks like collection/rkey. The rebuilt-root check keeps the tree itself consistent, so this only matters if callers assume well-formed keys.

What changes
crates/atprotogets the repo, the second of step 2's parts indocs/design/README.md:mst: the Merkle search tree, built whole from a repo's keys and their records' CIDs (Tree::build), with the nodes a commit adds since an earlier tree (new_since) and the covering proof of a key (covering_proof), worked out as the reference implementation'sgetCoveringProofdoes, so that the firehose's commits carry the same blocks.Tree::readreads a tree from blocks, refusing a node that is missing, malformed, or not where its key's depth puts it, by rebuilding the tree from its keys and requiring the same root.car: CARv1 written and read, each block checked against its CID.commit: version 3 commits, signed, written, read and verified.Why
The host's repos,
sync.getRepo, the firehose and importing an account all stand on these. A tree built whole, rather than changed in place, is the smallest thing that is right: a group's repo holds its profile, roles, rules and what it publishes, hundreds of records rather than millions, and the vectors check its shape exactly.How it was checked
Against atproto's interop vectors: every key height and common prefix, and all six of the firehose's commit-proof vectors. Each builds the tree before, checks its root, applies the adds and deletes, checks the root after, and requires the proof (new nodes and each changed key's covering proof) to be exactly
blocksInProof. The empty tree's root is the well-knownbafyreie5737…. A test for each tree, CAR and commit refused. Locally,cargo llvm-covat 100% of lines and functions, clippy clean.Shortcomings
Stacked on the data model's pull, which it includes until that lands. Building the tree whole costs a hash of every node on each commit, which is fine at a group's size but not at an account's of millions. Changing it in place can come once a repo needs it, behind the same
Tree. Nothing in the host uses these yet.Review
src/mst.rs:build, the threeproof_for_*, andread_node.