[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"eknGGvsxcT":3},"# leanp2p\n\n> leanp2p is a project by [Invisible Garden](https://invisible.garden).\n\nlibp2p for Lean 4: the implementation repository.\n\n**Status: bootstrap.** W0 landed: the package tree builds, the import\nlint and the test runner are green, and the vector infrastructure is\nin place (ARCHITECTURE.md §6). Code arrives package by package,\nbottom-up, in the order of [`docs/PLAN.md`](docs/PLAN.md). W1 starts\n`base/conc` and `base/bytes`.\n\n## What it is\n\nA libp2p stack in Lean 4. Its first target is the **Ethereum consensus\nlayer**: `tcp + /noise + /yamux`, identify, req/resp (`ssz_snappy`), and\ngossipsub v1.1. Everything else that libp2p offers stays a deferred\nseam behind the interfaces. ARCHITECTURE.md §8 gives the full priority\nlist.\n\nDependency strategy: **FFI first**. Some dependencies have a mature\nimplementation in another language: OpenSSL today, snappy and QUIC\nstacks later. The stack binds each one through a small C shim behind a\nLean interface. A native Lean implementation may replace it later,\nbehind the same interface.\n\n## Layout\n\n```\npackages/\n  base/     conc (concurrency primitives), bytes (byte model)\n  codec/    varint, multiformats (multihash/multibase/base58/cid/multiaddr),\n            proto (protobuf wire codec)\n  crypto/   Crypto facade; pure (pure-Lean digests, proved),\n            backend (OpenSSL 3 via C shim); secp256k1, P-256, SHA-256,\n            and keccak route to the etheorem hazmat packages\n  net/      streams (Connection/BufReader/Framing/tcp), yamux\n  libp2p/   identity, core (seam types), security, mux, negotiate, host, protocols\n  cli/      demo node, ping node, interop harness\n```\n\nDependency rule: in `cli → libp2p → net → crypto → codec → base`, a\ngroup imports only the groups to its right. No package left of\n`libp2p/` mentions libp2p, so other projects can use those packages.\n\n## Documents\n\n- [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md): the package layout,\n  how the parts connect (seams, classes, cores, loops), the contracts\n  of each package, the cross-cutting invariants, the verification\n  strategy, and the consensus-layer priorities. It is authoritative for\n  **what** and **why**.\n- [`docs/PLAN.md`](docs/PLAN.md): the work units, the dependency graph,\n  and the build order. It is authoritative for **order**. Claim a unit\n  there before you implement it.\n- [`docs/PRINCIPLES.md`](docs/PRINCIPLES.md): the engineering\n  discipline in detail. It explains what each rule means in practice,\n  and which incidents led to it.\n- `packages/\u003Cgroup>/\u003Cpkg>/docs/ARCHITECTURE.md` and `docs/PLAN.md`:\n  every package writes these as its first work unit. They refine the\n  root documents and never contradict them.\n- [`CONTRIBUTING.md`](CONTRIBUTING.md): the pull request and issue\n  workflow, the toolchain setup, and pointers to the code style.\n- [`SECURITY.md`](SECURITY.md): the vulnerability disclosure policy.\n- [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md): the community guidelines.\n\n## The reference implementation\n\nThe **`spike` branch** of this repository holds a working libp2p spike.\nTheorems prove its wire formats, and fuzz tests pin them. Its captured\nvectors (`VECTORS.lock`, `Tests/vectors/`, `vendor/`) moved onto `main`\nwith W0.3; the branch keeps the reference implementation, a\n3148-check suite, and a live go interop cell. Read it before you\nimplement anything, because its tests and vectors are the source of\nthe contracts. Treat the spike as a reference and\n`docs/ARCHITECTURE.md` as the spec. Where they\ndiffer, the architecture wins. ARCHITECTURE.md §3 also fixes the code\nshape.\n\n## Toolchain\n\nLean 4 (v4.34; see `lean-toolchain`) and OpenSSL 3\nfor `crypto/backend` (arrives with W3.2). `lake test` runs the suite.\nThe suite must pass\nunder `+RTS -N1`, the criterion for concurrency starvation.\n\n## License\n\nLGPL-3.0-or-later; see [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE).\nEvery contribution falls under the contributor agreement in\n[`CLA`](CLA).\n",1794686164713]