Start here

Overview

crdtlib is a Lean 4 library of operation-based CRDTs. A small set of combinators builds complex CRDTs out of simpler ones, and each combinator proves that its result converges. Anything you assemble from them is therefore a CRDT by construction: verified in Lean and executable.

The building blocks

Every CRDT in the library is assembled from primitives and principal and derived combinators. The same colors mark them throughout the documentation.

  • Principal combinator
  • Derived combinator
  • Primitive CRDT

The primitive CRDTs are written by hand, with a hand-written commutativity proof. The combinators each preserve commutativity:

The derived combinators are defined in terms of the principal ones, so they do not need their own proof:

Reading the source

Code excerpts in this documentation are taken from the library. To follow along in the repository:

PathContents
Crdtlib/CRDT/Basic.leanCRDT and CRDTₜ, and the conversion between them
Crdtlib/CRDT/Pkg.lean, Concurrent.leanEvents, timestamps and concurrency
Crdtlib/CRDT/Primitive/The primitive families: ac_fun and mv_regₜ
Crdtlib/Combinator/Principal/Product, MapState, Associate, Traverse, MapInterpretation
Crdtlib/Combinator/Derived/MapOp, DisjointProduct, JointProduct, TaggedUnion
Crdtlib/CRDT/Std/The catalog: registers, counters, sets and lists