From Proof to Product: Formal Verification's Guarantees, Its Limits, and Where LLMs Fit

eLyKseeR's archive logic is written and proved in Rocq, extracted to OCaml, model-checked in TLA+, and then used as the oracle for the C++ and Rust implementations. Here is what that buys us, what it doesn't, how far it can go, and how much of it an LLM could do.

eLyKseeR is a cryptographic data archive. It splits files into blocks, packs them into assemblies of 16 to 256 chunks of 256 KiB, encrypts each assembly with AES-256-GCM under its own random key, and writes the chunks as files whose names reveal nothing. Those chunks can go to storage you don't trust: a USB stick, an S3 bucket, someone else's disk.

A backup tool earns trust by working when you need it, which may be years after you made the backup. A restore that fails on a corrupt chunk is annoying. A restore that quietly gives you back the wrong bytes is a disaster. So from the start, eLyKseeR has been built around a formal specification. The specification isn't documentation. It is the program.

This post describes how that works across four repositories, what the proofs actually guarantee and how they relate to tests, where the gaps are, how far we think the approach can go, and how far LLMs could take over the work.

Contents


The four repositories

repository language role
elykseer-ml Rocq (formerly Coq) → OCaml the formal specification and the reference implementation, extracted from the proofs
modelling TLA+, PlantUML models of the data relations and of the multi-party network: proof of storage, payment, restore, re-replication, Sybil attacks
elykseer-cpp C++ the historical implementation, since 5.0.0 brought into line with the spec's archive format
elykseer-rs Rust the active main implementation; its version number is the version of the spec it follows

Underneath sits elykseer-crypto, which wraps the cryptographic primitives (AES-256-GCM, SHA3-256, the system CSPRNG) for all of them.

                 ┌──────────────────────────────────────┐
                 │  elykseer-ml  (Rocq)                 │
                 │  definitions + theorems              │
                 │  Assumptions.expected = trust base   │
                 └───────────────┬──────────────────────┘
                                 │ extraction (CI checks it is in sync)
                                 ▼
                 ┌──────────────────────────────────────┐
   modelling ──▶ │  lxr.ml  (extracted OCaml)            │
   TLA+ models   │  + C/C++ glue, elykseer-crypto       │
   (protocol,    │  = reference binaries lxr_*          │
   economics)    └───────┬───────────────────┬──────────┘
                         │ test vectors      │ golden tests
                         ▼                   ▼
                 ┌──────────────┐    ┌──────────────┐
                 │ elykseer-cpp │    │ elykseer-rs  │
                 │ byte-identical│   │ cross backup │
                 │ chunks       │    │ & restore    │
                 └──────────────┘    └──────────────┘

1. What has already been done

The specification is executable

elykseer-ml/theories/ holds 18 Rocq files, about 3,900 lines, covering the whole pipeline from the number of chunks per assembly (Nchunks.v) through assemblies, environments, the assembly cache and the processor to chunk distribution (Distribution.v). Rocq's extraction turns this into lxr.ml, about 4,400 lines of OCaml, which is linked with a thin layer of C/C++ and with elykseer-crypto to build the command-line tools lxr_backup, lxr_restore, lxr_distribute and friends.

Everything Rocq can't reason about is declared as an Axiom or Parameter and mapped to real code with Extract Constant: file I/O (fopen, fread, fwrite), the filesystem, buffer copies, AES-GCM encryption, random numbers, S3 requests. Some of these axioms carry a specification, for example:

Axiom add_content_spec : forall src sz pos tgt,
  0 < sz -> sz <= BufferPlain.buffer_len src ->
  pos + sz <= AssemblyPlainWritable.buffer_len tgt ->
  assembly_add_content src sz pos tgt = sz.

Others are cryptographic assumptions stated outright, such as chunk_identifier_injective (distinct assembly and chunk ids give distinct chunk names) or aid_collision_resistance.

Where a property can be built into the types, it is. The chunk count isn't an integer that hopefully lies in [16, 256]. It is a dependent type that carries the proof:

Definition t := { p : positive | (Npos min_n <= Npos p)%N /\ (Npos p <= Npos max_n)%N }.

For a thorough introduction to this style of programming in Rocq, where types carry proofs and programs are extracted from them, see Adam Chlipala's Certified Programming with Dependent Types (listed at the end).

What is proved

At v0.10.3 the theories contain 62 theorems and lemmas plus 21 checked examples, with zero Admitted. They cluster in three places.

Layout experiments (CheckApos.v). This file explores alternative, "non-local" index calculations that spread neighbouring bytes further apart than the production layout does. One question was whether such an index could be held in a 32-bit integer. For the 32-bit variant it is proved that the function is injective (no two bytes land on the same position), that it stays clear of the reserved regions (the random header at the start and the 16-byte GCM tag at the end), that it agrees with a closed form, and that it fits in 32 bits for up to 128 chunks. A 64-bit variant is checked on examples. Production uses neither: it stripes a byte at logical position i into chunk i mod n at offset i div n, with 64-bit indexes in C (long), OCaml (int) and Rust (u64). The spec itself uses Rocq's unbounded N.

Distribution (Distribution.v, 43 results). The planner that assigns chunks to sinks by weight and the retry scheduler that copies them are proved to behave:

  • plan_covers: if the weights add up to enough, every chunk is assigned to some sink
  • plan_only_chunks: no sink is handed something that isn't a chunk of the plan
  • attempts_bounded, tried_at_least_once: every chunk is tried at least once and never more than the retry policy allows
  • deadline_respected: no attempt starts after its deadline
  • no_retry_after_success, no_retry_permanent: success and permanent failure are final
  • ok_was_copied: a reported success really is what the copy function returned
  • ok_plan_complete, restore_ok_complete: if the run reports OK, every chunk has a successful copy

Utilities and the cache: list lemmas (take_list, drop_list) and the identity behaviour of the empty read and write queues.

The trust base is checked in CI

A proof is only as good as its assumptions. So theories/Assumptions.v runs Print Assumptions on 33 key constants, and assumptions.sh normalises the output into Assumptions.expected. The file shows, for each theorem and each top-level function, exactly which axioms it rests on. Twelve of the 33 are closed under the global context (they depend on no axiom at all), including the seven main distribution theorems and injectivity and 32-bit bounds of the experimental layout function. The rest, such as Processor.file_backup, depend on the FFI axioms listed by name. In total the system relies on 63 named assumptions, one of them the standard proof_irrelevance.

The Forgejo CI job for elykseer-ml then:

  1. checks all proofs (make),
  2. fails if the trust base changed compared to Assumptions.expected,
  3. runs the QuickChick property tests of the spec,
  4. fails if the extracted lxr.ml differs from the committed one.

Step 2 is what keeps the spec from "proving" something by quietly adding an axiom. Step 4 means the code you build is the code that was proved.

Tests on top of the proofs

  • QuickChick on the spec (theories/tests/DistributionQC.v): ten properties state the distribution theorems on random inputs, 10,000 cases each, against a simulated world with a fake clock and scripted copy results. The header comment gives the reason: a wrongly stated theorem shows up before the proof work.
  • QCheck on the extracted code (test/testPBT.ml): round trips through the real C buffer code ("get_content after add_content is identity", "all blocks in a full assembly restore correctly") at critical chunk counts such as 16, 17, 127, 128, 129, 144, 145 and 256; path containment ("restore_relpath never escapes base", 5,000 cases); block preparation covering a file exactly.
  • Alcotest, CLI and integration tests: security checks (path traversal, HTTPS-only sinks, secret files with 0600 permissions), incremental backup, and a large backup-and-restore round trip over random data, verified by checksum.

The model

The modelling repository has two layers. The first is a set of documents and PlantUML diagrams of the data relations and services (data store, assemblies, snapshot, assembly cache, processor, distribution), updated to match elykseer-ml v0.10.3.

The second layer is about 880 lines of TLA+ in six modules for the parts that can't be proved inside a single process: the network of writers, brokers, storage providers and readers.

  • PoS: proof of storage via HMAC challenges over byte ranges, reputation, partitions, and dishonest providers who lose, drop, partially keep or relay ("facade") chunks
  • Econ, EconPoS: escrow, settlement, stake and the incentive property NoGain (no deviation beats the honest profit)
  • Restore, Replicas, Sybil: paid restore, re-replication with hysteresis, and Sybil providers

There are 53 TLC configurations, and 28 of them are negative tests: they must violate a named property, which shows that the property isn't vacuously true. CI runs all of them on every change, except two larger _big configurations that take minutes.

The model has already earned its keep. Some findings:

  • A facade provider is caught only if the deadline lies strictly between an honest provider's latency and the cost of relaying.
  • Checking that every chunk was answered is not enough. A provider that keeps half of every chunk gets the proof whenever the probes hit the kept half (PoS_partial).
  • The stake must cover the broker's fee, or a failed proof costs the writer money.
  • Two kinds of cheating stay profitable under the current rules: a facade inside a lax deadline, and dropping a chunk after its last probe.

These are design results, found before any code was written.

Back-validation of the implementations

C++ (elykseer-cpp 5.0.0). Since 5.0.0 the archive format follows the spec. A generator (tests/conformance/gen_vectors.ml) runs the extracted reference code with fixed keys, IVs and deterministic content and writes the results as C++ test vectors. utConformance checks that elykseer-cpp writes byte-identical chunks. A second script has elykseer-ml (from a pinned Docker image) back up a set of files, after which the C++ LXRrestore and LXRverify must restore them bit for bit. Regenerated vectors must match the committed ones, so a change in the reference is noticed.

Rust (elykseer-rs 0.10.3). The Rust modules mirror the theory files one to one (common::nchunks ↔ Nchunks.v, assembly ↔ Assembly.v, and so on), and about 225 unit tests cover them. The golden test tests/test_golden.sh runs in both directions against the reference image elykseer-ml:v0.10.3-1: ml backs up and Rust restores and verifies, then Rust backs up and ml restores and verifies, for sizes from 120 bytes to several assemblies and for 16 and 29 chunks per assembly, all checked by SHA-256. The two implementations store metadata differently (an Irmin git store versus JSON files), and the script moves the values between them, so even the metadata semantics have to agree.


2. Which proofs are possible, and how they relate to tests

A spectrum of assurance

Each technique in the pipeline answers a different question:

technique covers relative to catches
Rocq proof all inputs the axioms in Assumptions.expected logic errors in the spec, for the properties that were stated
QuickChick on the spec many random inputs the same definitions wrongly stated theorems, before the proof effort
TLA+ model checking all states of a small instance the model's abstractions protocol and incentive flaws, races, unwanted interleavings
negative TLA+ configs one known bad behaviour the model vacuous properties (a mutation test for the specification)
QCheck on extracted code many random inputs the real FFI and C glue errors below the axioms: buffers, layout code, the OS
conformance vectors a few fixed points, byte for byte the reference binary format divergence in another implementation
golden cross-tests realistic files, end to end two independent implementations semantic divergence, metadata, CLI behaviour

The key relationship: a proof replaces testing of the logic it covers, but only that logic, and only up to the axioms. Tests are still needed for everything outside a proof: the axiomatised FFI, the extraction step, the build, the OS, and above all the properties nobody stated.

Two bugs that tell the story

The GCM tag bug (fixed in 0.10.1). Data is striped over the chunks, and the GCM tag sits in the last 16 bytes of the last chunk. In a full assembly, the tag could overwrite up to 15 bytes of data in the last rows. This was data loss, and no theorem covered it, because the striping was done in C behind an axiom. The fix reserves the last 16 rows: Environment.v now subtracts 16 × nchunks from the free space of an assembly. That reservation is in the spec, but no theorem states it yet. The layout theorems in CheckApos.v show that the property can be proved, but they cover an experimental index calculation, not the production striping. Proving it for the production code is the first item in section 3.

The partial-write bug (fixed in 0.10.3). A code audit of v0.10.2 found that EnvironmentWritable counted writing a full assembly as successful when any byte had been written (0 < n). With half the chunk directories read-only, backup wrote 4 of 16 chunks, printed done. and exited 0. This was in the Rocq specification itself, so it was "verified" code. But no theorem said "a key is stored only if all chunks were written", so the proofs had nothing to say about it. The fix checks N.eqb n (assemblysize …). The same audit found that restore used the chunk count from the command line rather than the stored localnchunks, which is also fixed in 0.10.3.

The lesson is simple and worth repeating: formal verification guarantees the properties you write down. Tests, audits and models are how you find the ones you forgot.

What can be proved here

Already proved: combinatorial and scheduling properties (distribution coverage, retry bounds, deadlines; injectivity and bounds for the experimental layout).

Provable with moderate effort, not done yet:

  • The round trip: restoring a backed-up file gives back the original file, relative to the buffer and cipher axioms. This is the property of an archive. It requires giving the buffer axioms a functional model, for example "a buffer is a list of bytes", instead of opaque types.
  • Key discipline: every key encrypts exactly one assembly, and a key is stored only when all its chunks were written. doc/07_Keys_and_Nonces.md already argues the first in prose, and it could become a theorem about finalise_assembly.
  • Integrity: a manipulated chunk or a wrong assembly id makes restore fail rather than return data, relative to an axiom stating GCM's authenticity.
  • Containment: restored paths never leave the output directory. Today this is a 5,000-case QCheck property, and it is a natural theorem.
  • Deduplication: an unchanged block isn't stored twice, and the blocks of a file cover it exactly.

Provable only relative to assumptions: confidentiality and integrity of AES-GCM, collision resistance of SHA3-256, quality of randomness. Rocq can state these as axioms, and a computational proof (in the style of EasyCrypt or SSProve) could go further, but the primitives themselves are best taken from verified libraries (see below).

Not provable in this setting: that a storage provider is honest, that the OS writes what it says it writes, that there are no timing side channels in the C glue. These are modelled (TLA+), tested, or written down as part of the threat model.


3. How we can improve, and how far we can go

Near term

  1. Prove the production layout. The functions proved in CheckApos.v are experiments with alternative index calculations. The striping actually used (chunk = i mod n, offset = i div n) lives in assembly.cxx (and in striped() in Rust), behind the add_content_spec axiom. Define this striping in Rocq, over N, and prove three things: it is a bijection onto the assembly, it never touches the header or the tag rows, and it stays below 2⁶⁴ (it actually stays below 2²⁶). Then either extract it, or keep the C and Rust loops and test them against the extracted function. The proof techniques from CheckApos.v carry over directly.
  2. Theorems for Environment and Processor. These modules currently have no theorems, and that is where the partial-write bug was. Candidates: "key stored ⇒ all chunks written", "one key per encryption", and the round trip.
  3. Give the buffer axioms a model. Replace opaque buffer types with a reference model (a list of bytes) in a separate theory, prove the *_spec axioms consistent against it, and test the C implementation against the same model with QCheck. This makes the axioms falsifiable.
  4. Track the trust base as a metric. 63 named assumptions today. Every release should report the number, and the CI diff already forces a human to look at every change.
  5. Share the conformance vectors. C++ checks byte-identical chunks with vectors from the spec, while Rust checks interoperability end to end. Rust should check the same vectors, and both should check vectors for metadata as well.
  6. Differential fuzzing. Run cargo-fuzz on the Rust implementation with the extracted OCaml as the oracle, on the same inputs, comparing outputs and error behaviour. This is cheap, and it catches divergence that fixed vectors miss.

Medium term

  1. Link TLA+ and the code. The Rocq Distribution and the TLA+ Replicas/PoS describe neighbouring things. With trace validation, the implementation logs its actions and TLC checks that the log is a behaviour of the spec. That ties the model to what the code actually does.
  2. Verified primitives. Replace hand-wrapped crypto with verified implementations where available: the HACL*/EverCrypt family and libcrux provide verified AES-GCM, SHA-3 and, for the post-quantum transition discussed in our first paper, ML-KEM. The cryptographic axioms then point to verified code instead of a library we trust.
  3. Rust refinement. Tools now exist that translate Rust into a proof assistant (Aeneas, coq-of-rust/rocq-of-rust, hax) or verify Rust in place (Verus, Kani, Creusot). The realistic target is the Rust core, meaning layout, assembly state transitions, the key store and the round trip, proved equivalent to the Rocq definitions. The CLI and I/O shell stay tested.
  4. Trust the extraction less. Rocq's extraction is not itself verified. MetaRocq's verified erasure and CertiCoq address this. Until then, differential tests and the "committed extraction must match" check are the guard.

How far can it go?

A ladder, with where we stand:

level meaning status
0 tests only passed long ago
1 executable spec, implementations tested against it ✅ C++ and Rust
2 proofs of selected properties, trust base tracked ✅ distribution, layout experiments
3 functional correctness of the core (round trip, integrity, key discipline) relative to a small set of axioms next
4 axioms discharged by verified primitives and a buffer model feasible
5 Rust core proved to refine the spec feasible for the core, expensive
6 verified extraction, compiler and OS research, not our battle

Our honest ceiling is level 5 for the core: a Rust archive engine whose central functions are proved equivalent to a Rocq specification whose correctness theorems depend only on verified cryptography and a few documented assumptions about the OS. The network and the economics stay at the level of model checking, plus monitoring in production. That is far beyond what backup software usually offers, and it is reachable.


4. Can LLMs do this?

The question asked: could an LLM write the formal specification and the models, then implement the code, then check it back against the spec? Taking the four steps one by one:

step how well LLMs do today typical failure guard in this pipeline human role
write the spec (definitions) good at drafting, and at transcribing existing code into Rocq a spec that is wrong but consistent QuickChick before proving; review decide what the system should do
state theorems fair; they suggest the obvious ones missing the important property; vacuous or trivially true statements review against the threat model; negative tests own the list of properties
prove increasingly good, and the effort is tedious exactly where LLMs are patient Admitted, a new Axiom, weakening the statement the kernel, the Assumptions.expected diff, zero-Admitted policy review statement and trust-base diffs, not the proof
write the models (TLA+) good at plausible specs a model that can't fail; abstractions that hide the bug negative configs that must fail choose the abstractions and the adversary
implement strong, especially with a module-to-theory mapping as in elykseer-rs tests written by the same model agree with the code by construction vectors and golden tests generated by the spec, not by the implementer look at failures, not at every line
check back (refinement) promising; refinement proofs are long and mechanical the same as for proofs the kernel again keep the refinement relation honest

The striking point is that formal methods are the ideal setting for LLMs, because the checker doesn't care who wrote the proof. A proof assistant is an adversarial reviewer that can't be talked round. If the kernel accepts the proof, the trust base hasn't changed and nothing is Admitted, then the result is as good as a human-written one. This is why the trust-base check in elykseer-ml's CI matters so much: the shortcut an LLM is most likely to take when stuck is to "assume" the lemma, and that shortcut is exactly what the diff catches.

The weak point is the same as for humans, only faster: specifying the wrong thing. The partial-write bug above is the pattern. Every line was in the spec, the spec was consistent, and no theorem asked the right question. An LLM can write a hundred theorems that pass, and none of them may be the one that matters. The defences are the ones this project already uses:

  • properties tested by QuickChick before anyone spends time proving them,
  • negative tests that show a property can fail,
  • implementations checked against vectors generated from the spec, so the implementer can't grade its own work,
  • independent audits that look for what nobody stated.

Our assessment

  • Implementation from a spec is ready now. Given the Rocq theories, a module map and the golden tests, a capable model can produce and maintain a conforming implementation in another language, and the spec-derived tests tell you when it is wrong.
  • Proofs are increasingly realistic for the kind of results in this codebase (list combinatorics, scheduler invariants, arithmetic bounds) and will improve quickly, because the feedback loop is perfect.
  • TLA+ models are good at producing candidate models and configurations, and only trustworthy with negative tests.
  • Choosing what to prove, the axioms and the adversary stays a human responsibility. It's where the real knowledge of the system lives, and it's the one step no checker can validate.

The likely future isn't "the LLM writes verified software". It is a division of labour: humans own the statements (properties, axioms, threat model, abstractions), and machines produce the evidence (proofs, implementations, refinements, tests), with a kernel, a model checker and spec-derived tests as the referees. eLyKseeR's pipeline was designed for human developers, and it turns out to be very close to what that division of labour needs.


Where to look

Further reading

  • Adam Chlipala, Certified Programming with Dependent Types, MIT Press, 2013. A practical introduction to programming and proving in Rocq (Coq), with dependent types, proof automation and extraction. It is freely available online as PDF and HTML.

Figures in this post refer to elykseer-ml v0.10.3 (November 2026).