ClearSplit tracks shared expenses and settlements among a group of people. Its central guarantee—the Conservation Theorem—states that the sum of all balances is always exactly zero: money cannot appear or disappear. This is not an assertion or a test; it is a mathematical theorem proved in Dafny and preserved by construction across every operation.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/metareflection/dafny-replay/llms.txt
Use this file to discover all available pages before exploring further.
Domain model
The model holds three entity types. Money values are integers (representing cents) to avoid floating-point errors.Module structure
The code is split into two Dafny modules to separate the user-facing contract from its proof:ClearSplitSpec (abstract module) — defines all types, predicates, function signatures, and the key lemma signatures as abstract declarations. This is the surface you review when you want to understand the guarantees without reading proofs.
ClearSplit (refinement module) — provides all implementations and proofs. The abstract lemma signatures are discharged here with full proof terms.
Key theorems
Conservation Theorem
The sum of all member balances is always zero. No money is created or destroyed by any sequence of expenses and settlements.AddExpense Delta Law
When an expensee is added:
- If the payer is not a share owner:
balance(payer)' = balance(payer) + amount - For each share owner (not the payer):
balance(p)' = balance(p) - shares[p] - If the payer is also a share owner:
balance(payer)' = balance(payer) + amount - shares[payer] - All other balances are unchanged.
AddSettlement Delta Law
When a settlements is recorded:
balance(s.from)' = balance(s.from) + amount(payer owes less)balance(s.to)' = balance(s.to) - amount(recipient is owed less)- All other balances are unchanged.
ExplainSumsToBalance
A person’s current balance equals the sum of all their individual transaction deltas across every expense and settlement. This provides an auditable history: you can reconstruct the exact balance from the sequence of transactions.Kernel variants
ClearSplit is proved against three kernels, covering local use, collaborative use, and cloud deployment:| Directory | Kernel | Features |
|---|---|---|
clear-split/ | Replay | Undo/redo, local state |
(via ClearSplitMultiCollaboration.dfy) | Multi-Collaboration | Offline clients, concurrent edits |
clear-split-cloud/ | Effect State Machine | Backend persistence (Supabase or Cloudflare) |
Running the app
Replay kernel
Local undo/redo with invariant preservation across all history operations.
Multi-Collaboration kernel
Server-authoritative state with offline client support and minimal rejection.
Effect State Machine
Bounded retries and pending-action preservation for the cloud variant.
Guarantees reference
Precise statement of what is proved, what is assumed, and what is trusted.