A complete Lean 4 formalization of the paper "Heterogeneous trust in reliable broadcast via modal logic and history structures". This repository contains mechanically verified proofs of three broadcast algorithms using history structures and modal logic.
This formalization includes:
- Foundations (Section 2-3): History structures, prehistories, event-tuples, semifilters, and Kripke-style modal semantics
- Modal Logic Framework (Section 4-5): Box/diamond modalities, quorum intersection properties, sequentiality, and liveness reasoning
- Three Broadcast Algorithms:
- ThyHBB1 (Section 6): Basic heterogeneous broadcast with unique proposals
- ThyHBB2 (Section 7): Improved protocol with non-equivocation
- ThyHBB3 (Section 8): Full protocol with correlation axioms
- Correctness Proofs: Agreement, Liveness 1, and Liveness 2 properties for all three algorithms
ModalDistribution/
├── Core/ # Foundation: prehistories, histories, semifilters, models
│ ├── Prehistory.lean
│ ├── History.lean
│ ├── Semifilter.lean
│ └── Model.lean
├── Logic/ # Modal logic syntax, semantics, and axiom system
│ ├── Syntax.lean
│ ├── Semantics.lean
│ ├── AxiomSystem.lean
│ └── Properties/ # Modality properties, sequentiality, quorums
├── Examples/ # Includes the three broadcast algorithms and their proofs
│ ├── HistoryStructures.lean # Common history structure definitions
│ ├── ThyLive.lean # Liveness (Section 5.2)
│ ├── ThyHBB1/ # Section 6
│ │ ├── Axioms.lean
│ │ ├── Agreement.lean
│ │ ├── Liveness_One.lean
│ │ └── Liveness_Two.lean
│ ├── ThyHBB2/ # Section 7
│ │ └── [similar structure]
│ └── ThyHBB3/ # Section 8
│ └── [similar structure]
See PAPER_MAPPING.md for a detailed mapping between paper definitions/theorems and their Lean implementations.
You need:
- Lean 4 - A theorem prover and functional programming language
- elan - The Lean version manager
- lake - Lean's build tool (installed with Lean)
On Linux/macOS:
curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | shOn Windows, download and run elan-init.exe.
After installation, restart your terminal or run:
source ~/.profile # or source ~/.bashrcgit clone https://github.com/anoma/hbb-lean.git
cd hbb-lean(Or unpack the zip archive of this repository, if you have downloaded it from a DOI or other source.)
# EITHER type
lake build
# OR (for informative verification announcements as each protocol is verified during the build) type
./build_with_accouncements.shThis builds the project and verifies all proofs. It will:
- Automatically install the correct Lean version (v4.24.0-rc1)
- Download and build Mathlib4 (the standard mathematical library)
- Build and verify all formalized correctness proofs for ThyHBB1, ThyHBB2, and ThyHBB3
What to expect during the build:
- The first build takes several minutes to several hours depending on system specs, as it compiles Mathlib4
- You'll see messages like "✔ [2440/3111] Built Mathlib.Topology.UniformSpace.Completion (31s)" as modules are being processed
- The build compiles roughly 3100 files total, which can be used to gauge build progress
- When you see modules from
ModalDistribution.Examples.ThyHBB1,ThyHBB2, andThyHBB3being processed, that's when the correctness properties (Agreement, Liveness 1, and Liveness 2) for each protocol are being verified - Subsequent builds are much faster
If the build completes without errors, all proofs are mechanically verified correct. This means the correctness properties of all three broadcast protocols have been formally proven.
For the best experience viewing and stepping through proofs:
- Install Visual Studio Code
- Open this repository in VS Code by running
code .from the terminal in the repository directory - Install the "Lean 4" extension:
- Click the "Extensions" icon in the VS Code sidebar (or press Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Lean 4"
- Install the extension published by "leanprover"
- Note: You may see a warning about installing extensions from unverified publishers. This is normal for first-time installation. The Lean 4 extension is the official extension from the Lean development team. You can verify this at the official Lean installation page
- Open any
.leanfile (e.g.,ModalDistribution.lean) to see syntax highlighting and proof states- If prompted about opening in Restricted mode, you can choose either option
If you're reading the paper and want to see how something is formalized:
- Open PAPER_MAPPING.md
- Find the definition/theorem from the paper (e.g., "Definition 2.3.5")
- Follow the file path to see the Lean code
Example: To see the Agreement proof for ThyHBB1 (Proposition 6.3.1), open ModalDistribution/Examples/ThyHBB1/Agreement.lean, or you may find the entry for that proposition in PAPER_MAPPING.md and click on its link, which will take you to the same place.
- Open a
.leanfile (e.g.,ModalDistribution.lean) - Click anywhere in a proof
- The "Lean Infoview" panel shows the proof state at that point
- Hover over identifiers to see their types
- Ctrl+click (or Cmd+click) on names to jump to definitions
- Right click on terms to get a list of interactions
This work is licensed under CC-BY 4.0.