| ▲ | So You Want to Build a Mainstream Formally Verifiable Language(danilafe.com) |
| 69 points by mpweiher 8 hours ago | 44 comments |
| |
|
| ▲ | smj-edison 3 hours ago | parent | next [-] |
| I think there's a pretty big conceptual difference between programming and math, which is that in programming we think about building up something over time by applying successive steps. In math though we have to think about the whole thing simultaneously, forwards and backwards. So when we prove a program, we're actually proving it forwards and backwards, with all possible inputs and outputs, at the same time. And either it's all true, or it blows up in your face. Another difficulty is with programming, we succeed by making abstractions that don't leak, where with math we're constantly opening up mathematical objects and messing around with their internals, chaining together the internals with theorems to get to our desired outcome. Since we so often need access to the guts of the objects we're working with to prove facts, it makes it really hard to interoperate with other systems, because either we have to make assumptions about those systems which can compromise correctness or we have to be able to plug in all the way. Signed, an undergrad in math with decent coding experience. |
| |
| ▲ | random3 2 hours ago | parent | next [-] | | As a computer scientist with 20 years experience in software and last 3 shifting on math, I think I agree with how you describe the approach in SWE. I collected a ton of notes on the same process myself. I'd sum it up as starting to code before/without trying to get a proper* understanding of the end-to-end problem, and then incrementally adjusting along the way. This often solves a chicken and egg problem, of not being able to advance understanding before building. The problem is not rewriting or fully refactoring the code once your understanding persist. Often this is too late (aka "shipping the prototype"). Then everything expands into more complexity over more or less** time. I think this whole process can actually be described formally. I'm not sure how much it matters anymore, but I suspect agent generated code suffers from the same issue, just with different measures due to speed/memory advantages agents have. ---- * I say "proper" assuming "full" is likely unachievable in most settings ** the difference between many software projects can be reduced to how fast they become dead ends based on how fast complexity explodes. | |
| ▲ | latentsea 9 minutes ago | parent | prev [-] | | > Another difficulty is with programming, we succeed by making abstractions that don't leak So, we basically fail then. |
|
|
| ▲ | nylonstrung 2 hours ago | parent | prev | next [-] |
| We don't need a new verifiable language, everyone trying to build new ones is suffering from NIH in my opinion. Lean is already an extremely powerful and performant FP whose capability is essentially a superset of all other FPs and which has the most powerful metaprogramming and DSL building features outside of Racket It has massive, likely insurmountable network effects in terms of the lemmas already written for it which can be reused in general purpose contexts What we need is more libraries, frameworks, contributions to Core and Batteries which make it more useful outside of the domain of pure proofs and mathematics which has obviously been the focus so far. |
| |
| ▲ | jeremyjh an hour ago | parent | next [-] | | The author acknowledged that. I recently discovered this on my own and was surprised to learn that: * Lean 4 is self-hosting * Lean has monadic I/O, do notation, type classes and other Haskell inspired syntax and language features. * There is at least one guy building infrastructure fundamentals for web app development: https://github.com/paulbutcher?tab=repositories&q=&type=&lan... * If you know and like Haskell, Lean is quite approachable (at least initially). * Dependent types can be much easier to understand than the capabilities possible with the many different type extensions in Haskell. For example, lean-pq has compile time verification of usage of table schemas (that are defined in code) and the machinery for that is very simple to understand compared to the various Haskell libraries that achieve this (click the Try it link at the bottom of the README section on this at https://github.com/typednotes/lean-pq#compile-time-column-ve...) | | | |
| ▲ | danilafe an hour ago | parent | prev | next [-] | | I agree with you in part, as I have lightly alluded to in my article. There's a lot to love! Lean's typeclasses + inference, metaprogramming, custom notation, "X implemented as Y" support, and much more are fantastic. It's not clear to me, however, that the space is completely filled. I find it hard to imagine using Lean for software that deeply interacts with the OS or hardware, or even just "doesn't refcount". Am I unaware of progress in this area? In a similar vein, in terms of practical software success, I think we've seen the most with model checking, yet Lean is not particularly amenable to this. It remains to be seen whether tactics and proofs (+ some sort of repair) will beat out the incumbent. | | |
| ▲ | nylonstrung an hour ago | parent | next [-] | | Great article BTW, I think it was incredibly detailed and well written > I find it hard to imagine using Lean for software that deeply interacts with the OS or hardware, or even just "doesn't refcount". This is true: my thought is that the path to using Lean for "practical software" looks like delegating a lot of stuff like I/O to Rust libs. Lean will soon be able to compile to LLVM IR instead of just C and IMO it makes more sense to think about how to fill the gaps with the smartest cross-lang approaches rather than to rebuild a lot of basic stuff as pure Lean | | |
| ▲ | danilafe 29 minutes ago | parent [-] | | Thank you for your kind words! > my thought is that the path to using Lean for "practical software" looks like delegating a lot of stuff like I/O to Rust libs. Lean will soon be able to compile to LLVM IR instead of just C and IMO it makes more sense to think about how to fill the gaps with the smartest cross-lang approaches rather than to rebuild a lot of basic stuff as pure Lean I think this is the sort of approach we should pursue to make progress towards verification as an industry. But every time I write low-level code, and have to think through complicated cases, I feel that it is there that I need the most help. That's when I dream of a tool that can meet me at my level of abstraction and help me lean on rigor and verification. This is part of why mainstream verifiable languages have been on my mind personally, and I admit this implicit bias may affect the focus of the article and original claims. |
| |
| ▲ | jeremyjh an hour ago | parent | prev | next [-] | | I really liked your article, and I haven't read or absorbed all of it yet but I agreed with your points on this topic. I think Lean could perhaps serve in most server application use cases (and many others - roughly any use case where you could use Haskell), and Aeneas or something like it could leverage Lean only for verification. https://lean-lang.org/use-cases/aeneas/ | | |
| ▲ | danilafe an hour ago | parent [-] | | Absolutely. Libraries like servant in Haskell, too, relied on extensions to the language (was it data kinds and GADTs?) to make for some very, very sleek abstractions. Lean comes with these language features, but in a single unified type system, and it has even more goodies! | | |
| ▲ | jeremyjh an hour ago | parent [-] | | What was surprising to me is that (at least some) Lean code is easier to understand than the machinery behind Servant, since you are just using normal code to operate on types. | | |
| ▲ | nylonstrung 35 minutes ago | parent [-] | | This to me is the single most mindblowing part of Lean that has not been fully taken advantage of yet: that types themselves are first class and fully programmable in a way indistinct from normal code And it compounds with Lean's dependent type system and the ability for proofs to be "bundled" into said dependent types and then erase at elab time |
|
|
| |
| ▲ | erichocean an hour ago | parent | prev [-] | | I'm doing Lean 4 certificates for Armv9 assembly. It's doable. Update: Google did something similar here: https://deepmind.google/blog/introducing-alphaproof-code/ |
| |
| ▲ | dnautics an hour ago | parent | prev [-] | | > capability is essentially a superset of all other FPs Is that what we really want? For SW verification you mostly want "just plain logic" and really "set theory" is enough. Sure, the result will be more verbose, but do we care anymore now that the LLMs are writing so much of things? We should pivot to one where these two properties hold: 1. The bridge between the code and the proof is obvious 2. The proof is easily checkable by a human. That could mean more verbose, if you don't elide logical step or steps where the prover goes and looks for a theorem that satisfies the assertion. | | |
| ▲ | jeremyjh an hour ago | parent | next [-] | | The article addresses this - there are two different models and they have different pros and cons - probably there is not a single model that is best for every use case. Lean - used alone - would be the intrinsic model. Lean, or another formal language, bridged to a programming language (like the Aeneas project with Rust https://lean-lang.org/use-cases/aeneas/) would be the extrinsic. I haven't gotten far enough into this to really speak knowledgeably about this, but my intuition suggests that the intrinsic model has some significant advantages - specifically it encourages/forces you to model all your invariants in a dependent type system in the first place, and then you can prove things about the interaction of those invariants in a higher abstraction layer that is continuously checked as the program evolves. A language without a dependent type system is significantly constrained in the invariants it can prove in its type system alone - perhaps there are properties you'd have to prove with (pure) unit tests to supplement the type system, and this further constrains design. | | |
| ▲ | dnautics 24 minutes ago | parent [-] | | > A language without a dependent type system is significantly constrained in the invariants it can prove in its type system alone I mean, no? Sure, you can't prove that some user function doesn't make a syscall that under the hood allocates on page, for example, but you can certainly derive invariants (like safety guarantees) based on stdlib usage, and report if a stray syscall or ffi occurs for manual review. You could also maintain a list of "cleared" syscalls/ffis that the prover should just ignore moving forward. As for other things, you're going to have to annotate your software in general. Be that in comments, some sort of metadata tag, even some in-tree manifest file. For example rust does not encode "this is a database call" in its type system. So if you want to instrument your code to verify that no consistency errors can occur (for example, not wrapping a read-modify-write in a transaction) you can't just do it by analyzing the language, you'll have to write your "own plugin". That's why having access to the IR (versus the asm) is better, because you have access to metadata that gets chucked out the window when it goes to asm. |
| |
| ▲ | nylonstrung 40 minutes ago | parent | prev [-] | | My personal thesis and hope is that Lean's real value is being an extremely useful general purpose pure functional language a that, unlike Haskell etc, has a genuine "wedge" and superpower in the form of proof solving I think all the capability it has to verify software and improve correctness are realized far more fully and elegantly if the software itself is built with Lean. Ironically, much of the of software verification by proof it's known for can be rendered unnecessary IMO because for example typechecker itself can enforce correctness by construction "Come for the verification, stay for the type system and metaprogramming." At the very least the proof/verification usecase has resulted in hundreds of millions poured into Lean-centric startups like Harmonic and LLM post-training which gives it an advantage no other existing functional language has had or will ever have. |
|
|
|
| ▲ | tiffanyh 5 hours ago | parent | prev | next [-] |
| I’m surprised SPARK programing language was never mentioned. https://en.wikipedia.org/wiki/SPARK_(programming_language) https://www.adacore.com/languages/spark |
| |
| ▲ | danilafe 5 hours ago | parent [-] | | Thanks, it's a case of low cognitive ease :) I was aware of SPARK but not particularly familiar, and dropped it from my enumeration of relevant technologies unintentionally (though, the purpose of the post was not specifically to enumerate relevant tech). I really should read up on SPARK! | | |
|
|
| ▲ | kccqzy 5 hours ago | parent | prev | next [-] |
| > I believe that one crucial distinction is preventing the meteoric ascent of AI in software of the formally verified kind: the everpresence of change. This is actually also what I realized after a year or so in industry. (I was quite enamored of formal verification in college.) |
|
| ▲ | dnautics an hour ago | parent | prev | next [-] |
| One of the most interesting things is how Sel4 works -- IIUC they compile to arm64 assembler, and then run verification proofs on that. Inspired by that, I think that an interesting place to patch verification in to an existing language is at the IR level. At the IR level, you have usually (effectively) a highly-regularized schema for all operations, that is usually still embued with semantic information (for example: the function you called is "malloc") that can be used to generate invariants that you'd like to prove (or refute). Of course you still have to trust that the IR->ASM part of the compiler is good, but at least the program logic has been verified. |
| |
| ▲ | danilafe 6 minutes ago | parent | next [-] | | This is an interesting idea. At its core, IRs tend to be smaller and have better defined semantics. Of course, you'd have to use something other than the IR itself as the metalanguage (not a problem, though). Perhaps the reason this hasn't been attempted as often (I read the sibling Sel4 discussion about refinements) is twofold: 1. The mechanical effort required to show that the IR satisfies some abstract specification. Sel4 requires several refinement proofs (I am trusting the sibling comment on this), which suggests a great deal of effort. Perhaps LLMs (taken as "smart heuristics for proof code generation") can be of use here. 2. IR serves a secondary purpose as a target for compiler transformations. I've written myself about formally verifying compiler analyses[1] and I've proven a rudimentary LICM optimization in Lean based on these analyses (I haven't had a chance to write that one up), but it took a great deal of effort. We may then be forced either not to optimize or to trust something like LLVM (but...here be dragons? :P ). So there is a tension between "simple core language" and "mutable substrate for optimization". And that doesn't even bring into question MLIR dialects and progressive lowering! [1]: https://danilafe.com/series/static-program-analysis-in-agda/ | |
| ▲ | saithound an hour ago | parent | prev [-] | | You write: > One of the most interesting things is how Sel4 works -- IIUC they compile to arm64 assembler, and then run verification proofs on that But that's not how seL4 works. The seL4 proofs are refinement proofs. No assembly is involved, and the verification work is done on the abstract mathematical spec, and the C implementation. Here's how it works: 1. They write a mathematical specification in Isabelle. 2. They prove good security properties about the mathematical specification. They show that a correct implementation of the specification wouls prevent applications running on top of it from modifying data without authorisation (integrity), from interfering with resource access of other applications (availability), and from learning information from other applications without explicit authorisation (confidentiality). 3. They prove (in Isabelle, an interacrive theorem prover) that a Haskell program refines an abstract Isabelle specification, then prove that the C implementation of seL4 refines the Haskell program. 4. They compile the C program using gcc, then prove (using an automated tool) that the machine code was compiled correctly. This works on ARM and RISC-V. Assembly is not involved in the proof, only machine code and C code. 5. Together, the chain of refinements in 3,4 imply that the running binary correctly implements the mathematical specification. Sincw the specification satisfies the good properties, so does the implementation. In other words, the seL4 KERNEL prevents applications running on top of seL4 from modifying data without authorisation (integrity), from interfering with resource access of other applications (availability), and from learning information from other applications without explicit authorisation (confidentiality). Together these security properties enforce the isolation of components running on top of the kernel, allowing critical components to securely run alongside untrusted software. | | |
| ▲ | dnautics 17 minutes ago | parent [-] | | thanks for the correction! I do maintain that checking the IR is better than checking the code. For C, for example, not having to deal with #defines is by itself enough to make it a reasonable target. In a way I'm glad I got the seL4 methodology wrong. |
|
|
|
| ▲ | blacksqr an hour ago | parent | prev | next [-] |
| Eiffel was designed from the start to be formally provable. A subset of Ada (SPARK) is formally provable. Both are relatively easy to learn and use. Options to produce better code have been available for a long time. The more interesting and perplexing question to me is why weren't they brought into the mainstream decades ago? And what will have to change for them to get serious consideration? It seems to me that even total evisceration of existing code by LLMs has not been enough to prompt meaningful reconsideration in the mainstream of how programs are developed. |
| |
| ▲ | dnautics an hour ago | parent [-] | | for spark, it was probably that ada compilers were closed source for a long time when c/c++ was already in its gcc era. |
|
|
| ▲ | rrook 5 hours ago | parent | prev | next [-] |
| I'd boil away all of the article's thoughts on "object" vs "meta" languages, and instead point out that all languages are expression of graphs. Once the language is built from this perspective, object language and meta language (using the articles terms) can exist happily together. This is actually the core thesis of my language project; all computation is situated in a global hypergraph. |
| |
| ▲ | danilafe 5 hours ago | parent [-] | | Say more! I'm familiar with expression graphs, and I know languages that are built on this, but it's not clear to me how this applies to formal proofs. Do you have more details? | | |
| ▲ | rrook 4 hours ago | parent [-] | | Imagine like a graph with typed edges: A ──f──> B ──g──> C Any single proof can first be thought of as proving an assertion about the graph. "There exists a path from A to C that traverses g." From there, the proof is bog standard graph maths. In the abstract, all expressions of logic are graphs, like...statements of graph state, mutation, comparison, relation, differentiation, etc. An expression of language can be an incomplete expression of a graph, and other expressions can fill in the missing pieces or assert things about it. The language can express both the computation and the logic we use to reason about that computation. In a sense, proof languages typically operate this way. They build a graph, assert something about it, and prove it in the mathy-graphy-sense. Mainstream programming languages have not yet put the graph structures front-and-center in the language design, and in the gap between the two we feel friction. | | |
| ▲ | soulofmischief 4 hours ago | parent [-] | | Nice, I'm also doing this to a degree with the language I've been building over the last year, proving as many facts as I can about the structure of the code, but my goal is to empower the compiler while allowing for terse, ergonomic code. Formal verification is in the back of my mind, but it isn't a language goal at this time. Instead, I'm focusing on more narrow validation, adopting Rust's "if it compiles it probably runs" ethos. |
|
|
|
|
| ▲ | imtringued 21 minutes ago | parent | prev | next [-] |
| This is a pretty bad article because it starts with irrelevant technical details and doesn't even spend a minute asking itself what a developer might even want to prove about their software. Instead, the assumption is that you want tomprove everything about the program, which leads to going down irrelevant rabbit holes and completely failing to live up to the title. If you want to go mainstream you need to be able to convince users that they can prove useful properties about their software and so far the article has managed to entirely avoid that topic. |
| |
|
| ▲ | Ericson2314 3 hours ago | parent | prev [-] |
| Lean has already gone mainstream. |
| |
| ▲ | kzrdude 3 hours ago | parent | next [-] | | Why did Lean win over Rocq/Coq? It was popular first, then Lean overtook it. | | |
| ▲ | armchairhacker 23 minutes ago | parent | next [-] | | IME Rocq has more legacy quirks. For example, proof automation is done in LTac (very not composable and “spaghetti” but more support and documentation) and LTac2 (newer, confusing, still hard to compose). Inconsistent syntax and behavior, tactics unexpectedly failing (because they’re spaghetti). And maybe this was my poor skill, but even simple tasks were slow, just finding the right lemma, tactic, or syntax to apply them. Lean:Rust::Rocq:C++ | |
| ▲ | logicchains 3 hours ago | parent | prev [-] | | A more polished/user friendly design, and more suitable to formalizing math (built in quotients support). Also more efficient/faster. |
| |
| ▲ | danilafe 3 hours ago | parent | prev [-] | | It's not a bad choice! But I am yet to see any "real world software" written in it, in public or in private. | | |
| ▲ | nylonstrung 2 hours ago | parent | next [-] | | I'm very focused on the "real world software" use case for Lean. Right now it's pretty thin but Nick Palladinos has done some great work IMO https://github.com/palladin/lean-linq
https://github.com/palladin/lean-cloud | |
| ▲ | Ciantic 2 hours ago | parent | prev | next [-] | | It definitely isn't bad choice, it reads a lot like Haskell. I've been exploring this myself too, haven't tried performance, but there are some Postgres / HTTP libraries for it. Its macro capabilities make it very nice for SQL driven apps. I've been working one small invocing schema, and you can derive the Insert, Patch etc types with just macros with `deriving Patch` at the end of your type. Also, one of my reasoning is that if these AI LLMs are tuned to work with millions of lines of Lean, it probably is very efficient for it. | |
| ▲ | Ericson2314 3 hours ago | parent | prev [-] | | I wrote tic tac toe for the terminal in it :) | | |
|
|