r/sqlite • u/neprotivo • 5d ago
Belay - formal verification for SQLite statements
https://vihren.dev/belay/Hi,
I am working on a tool that allows you to do formal verification of your SQLite statements, queries and transactions. Basically this means that you can prove something about your statement and then this means that the statement will always work as expected, no matter what data your database has. This is much better than tests which can only verify the behaviour of a statement for a specific database state.
For example now you can state: Migration M preserves the output of a query Q. Then you can ask your agent to write a proof of this statement. The proof can be checked by the Lean proof checker, and if it is correct, you know that the claim will hold for any database you run it on.
This approach can work on basically any claim you can think of. For example right now I'm implementing UX to claim that a certain transaction is idempotent.
The core of this project is a semantic model of Sqlite in Lean. Essentially thes is a rewrite of part of sqlite in lean. As long as this semantic model matches actual sqlite behaviour we can trust that our claims will hold. The model is currently checked against SQLite using a large number of tests, most of which taken from the sqlite test suite.
This is a very early proof-of-concept. I need feedback from the community how to make it better. Tell me what checks you would like to run on your DB statements and I'll make it easy to do them with Belay.
1
u/Discordbothost 3d ago
A soft-delete table rebuild would make a good example. I'd check that the active IDs stay the same and that a second active row with the same email still fails. That catches a dropped partial unique index.