← All projects
Project record1 mention
Originally shared on Hacker News

Belay

Belay is a Lean 4 library for formal verification of SQLite queries and migrations. It implements a semantic model of a subset of SQLite, validated by differential tests against native SQLite. During migration authoring, an agent can run #sql_check to search small databases for counterexamples to a claim; once a migration is settled, the agent writes proofs of claims such as that the migration preserves the results of existing queries and succeeds on valid data. It supports a subset of SQLite 3.51.0, cross-checked against native SQLite on 5,768 differential test cases.

Last shared
01 / The problem

What it addresses

Formal verification is typically too hard for everyday development tasks; Belay aims to make verifying SQLite migrations and queries as routine as testing, by having an agent write proofs while the developer only reads the claims.

02 / Source history

Shared over time

Each entry reflects what was shared on that date. Details may have changed since then.

  1. Belay

    Belay is a Lean 4 library for formal verification of SQLite queries and migrations. It implements a semantic model of a subset of SQLite, validated by differential tests against native SQLite. During migration authoring, an agent can run #sql_check to search small databases for counterexamples to a claim; once a migration is settled, the agent writes proofs of claims such as that the migration preserves the results of existing queries and succeeds on valid data. It supports a subset of SQLite 3.51.0, cross-checked against native SQLite on 5,768 differential test cases.

    Problem: Formal verification is typically too hard for everyday development tasks; Belay aims to make verifying SQLite migrations and queries as routine as testing, by having an agent write proofs while the developer only reads the claims.

    Posted by @neprotivo · Original source ↗

    Story title · @neprotivo · · Source ↗

    Show HN: Belay – formal verification for SQLite migrations and queries in Lean 4

    Submitted URL · @neprotivo · · Source ↗

    https://github.com/vihren-dev/belay

    Source text · @neprotivo · · Source ↗

    Belay is a Lean 4 library for doing formal verification of SQLite queries and migrations. It implements a semantic model of a subset of SQLite, validated by differential tests that compare the output against native SQLite.

    Source text · @neprotivo · · Source ↗

    With Belay I wanted to see how difficult it is to use formal verification for everyday development tasks. It turns out it can be made not much harder than writing an integration test: you state the claim, the agent writes the proof, and Lean's kernel checks it, so the only thing you have to read is the claim

    Source text · @neprotivo · · Source ↗

    Once the migration is settled, the agent writes a proof of the claims you need, for example that the migration preserves the results of existing queries and succeeds on valid data.

    Source text · @neprotivo · · Source ↗

    While a migration is being written, your agent can run #sql_check, which searches small databases for counterexamples to a claim, and is as easy to run as a linter.

    Source text · @neprotivo · · Source ↗

    Currently Belay supports a subset of SQLite 3.51.0, cross-checked against native SQLite on 5,768 differential test cases, most of which come from SQLite's own test suite.

    Source text · @neprotivo · · Source ↗

    longer write-up on the motivation and agent workflow: https://vihren.dev/blog/20261112-belay/