Skip to content
Get App

Modern Formal Systems Approaches with Lean

FUTO speaker presents a four-step method using Lean formal verification to test software and find bugs in tries, channels, and QUIC implementations, including curl's ngtcp2.

Key Takeaways

  • Differential fuzzing against a simple formal Lean model gives a reliable oracle and surfaced dozens of real bugs.
  • LLMs make formal verification accessible enough to use alongside unit tests.
  • Formal models help LLMs reason more strictly about code they generate.
  • Bugs found by this approach were mostly implementation bugs rather than model bugs.

What the video covers

  • The talk addresses how to review and trust large volumes of LLM-generated code using formal methods.
  • The four-step method: choose a unit to test, have an LLM write a Lean model and implementation, optionally prove properties, then run differential fuzzing or property-based testing to compare implementations.
  • Formal verification was previously rare due to the skill and time required; LLMs now make it practical.
  • Case 1 (Path map, a trie-based graph database backing store): a simple sorted-list Lean model served as oracle; differential fuzzing across billions of inputs found about 40 bugs, mostly in the production code.
  • Case 2 (Mem pipe, a lock-free inter-process channel): the LLM modeled the protocol as a state machine, identified a race condition, and produced a correctness proof under the RC11 memory model.
  • Case 3 (QUIC in curl via ngtcp2): the RFC 9000 spec was translated into Lean, and three implementations were compared, yielding five bugs in ngtcp2 and five in quiche, none security-critical.
  • Lean models trade performance for clarity: the reference implementations are quadratic where production tries are near-constant time, but they serve as trustworthy oracles.
  • Maintaining proofs as libraries drift adds overhead, and LLM mistakes can be amplified when development moves fast.
  • The speaker argues that if a project has unit tests, it can now adopt formal methods, and that a model close to reality beats no model.
  • Q&A covers spec drift, deterministic reasoning, and the value of exploring implementations until confidence is high.

Answers

Questions about this video

What are the four steps of the testing method presented?

Choose a unit to test, ask an LLM to write a Lean model and implementation of it, optionally prove properties about the model, then run and compare the implementations with differential fuzzing or property-based testing. The speaker presents this as a way to check LLM-generated code.

What bugs were found in the case studies?

About 40 bugs were found in the path map trie implementation, a race condition was identified in the mem pipe channel, and five bugs each were found in ngtcp2 and quiche. None of the QUIC bugs were security issues.

Why was formal verification rarely used before?

Proving theorems requires significant skill, knowledge, and practice, and tools like Coq or Idris were hard to learn. The speaker says LLMs have made the practice much more accessible.

Full Transcript — Download SRT & Markdown

00:00
Speaker A
Thank you for Thank you very much for coming here. I'm happy to see such a huge number of people.
00:06
Speaker A
And today I want to talk about how to make software better, hopefully. So, the reason I'm bringing up this question is that people are producing so much more code today using LM and chatbots. But all of those all that code
00:24
Speaker A
people cannot review it. People people do not know if it's good, if it does whatever you you you're you want it to do.
00:31
Speaker A
And understandably, people who maintain large repositories have a question. Do I want to introduce LM made code into my repository?
00:42
Speaker A
And I on my projects faced with such a problem. We had a We had a high-quality code base which people crafted for years and they didn't want to introduce LM code. So, what I've done is I have introduced
00:58
Speaker A
a method which turned out to be very efficient. This is a method of testing and it involves four simple steps.
01:08
Speaker A
We are choosing a thing which is we're going to test as you would do with a unit test.
01:14
Speaker A
You ask an LM to made a a lean model and implementation of this thing.
01:22
Speaker A
Optionally, you can prove things about the model. So, you could say, "Hey, this is my function. I want to know whether these properties hold for this function." And LM will help LMs will helpfully prove anything to you.
01:40
Speaker A
Or or show you a counter example. And then fourth step, which is run and compare.
01:47
Speaker A
In this case uh So, there are two different names for the fourth step. One of the names would be a differential fuzzer, if you know what fuzzers are, or property-based testing, if you're if you come from functional programming.
02:06
Speaker A
So, why now? Until this year, it was really hard to do formal verification and formal methods using formal methods.
02:19
Speaker A
Because it takes a lot of skill, knowledge, and practice to be able to to be able to prove theorems, especially with formal formally verified software.
02:30
Speaker A
And I tried, and I failed. It was easier for me to write my own software which does formal verification than to learn Coq or Idris or something similar.
02:42
Speaker A
But I actually learned Lean and was pretty pretty good. So, before 2026, people used formal verification very sparingly.
02:53
Speaker A
They used it in critical software and they used in critical infrastructure and for military projects.
03:01
Speaker A
So, yes, let's see how I'm doing the method which I'm describing. I have three examples, and for all of them I have found um interesting bugs, and I'm pretty happy about the the result.
03:14
Speaker A
So, target first. Path map, which is a which is a backing backing storage for a graph database I'm working on, and it's based on a trie.
03:26
Speaker A
Basically, it's a prefix tree, and for example you you walk here, you're going to end up in an in.
03:33
Speaker A
You walk there, you're going to you're going to end up at a at 10. And the idea is that you're going to share prefixes, and therefore you're going to use less memory.
03:46
Speaker A
But the implementation of this trie is very difficult. It involves having lots of difficult node types and and lots lots of difficult algorithms. So, what do we do?
03:57
Speaker A
So, instead of trying to define a model for a trie, we're going to define a model for a map.
04:03
Speaker A
This is the entire This is the entire specification for our for the that data structure. Instead of a trie, we're going we're going to have a sorted list of entries.
04:14
Speaker A
Uh this is very simple to reason about. This is very simple to demonstrate if it's true.
04:21
Speaker A
And here are a few algorithms. So, here are three algorithms for a path map.
04:29
Speaker A
Uh union, intersection, and subtraction. So, again, these are obviously correct, but you wouldn't you wouldn't use them in production because they take much more space and they take way more time. So, these algorithms are quadratic in time where
04:50
Speaker A
most of the time a trie map would have had constant constant time. But, there's there's an upside because the implementation of such algorithms to be made efficient, it it has to take a lot of a lot a lot of code. So, this
05:07
Speaker A
is one of these functions in Rust. Okay, so what's the plan? We have a lean implementation and it's way you've seen it on on the screen. It's it's way more simple. We can make proofs about properties we can choose. So, for
05:24
Speaker A
example, a proof that we have done for the algorithms was that the union intersection and subtraction correspond to Boolean algebra on paths.
05:36
Speaker A
Basically, and, or, and and not. We have our implementation, which is very big and very complicated, and we run and compare them uh side side by side. So, we have a This is run and run and compare. We call
05:53
Speaker A
it a differential fuzzer. It creates random programs to construct tries and then it it's going to run both programs on Lean implementation and on our implementation.
06:07
Speaker A
With billions of inputs, we find lots of bugs. We found So, why this is useful?
06:18
Speaker A
In let's see. I have two benefits here. So, first one is that if you're doing um property-based testing, it is necessary for you to have an oracle. How do you have an oracle if you have only one implementation of your code? And Lean
06:35
Speaker A
provides a second implementation, which is hopefully easier to follow and hopefully it's going to be correct.
06:43
Speaker A
And then we can also make proofs about uh the model. As a result, we have found 40 bugs and almost all of them were bugs in the code, not in the model.
06:53
Speaker A
We had two bugs which were uh not necessarily bugs, but we had to change the how API behaves to make it more consistent. So, it wasn't necessarily a a model problem. It was a model of what we were
07:13
Speaker A
what we were trying to do. So, we had like lots and lots of bug fixes. I managed to I managed to dose our development by just submitting bug fixes.
07:25
Speaker A
Target two, which is mem pipe. Mem pipe is a a concurrency primitive. It's a lock-free channel, which allows you to send messages across different processes.
07:39
Speaker A
So, I asked Cloud, "Hey, can you prove to me that this the protocol which a mem pipe uses is decent. And what happened is that Cloud said actually there's a there's a race condition.
07:53
Speaker A
Like so it it built a model a state machine for uh it built a state machine for the client and the server. So this describes the protocol what is happening in memory not necessarily what what the code is doing
08:06
Speaker A
but what's happening in memory. And it said hey actually if you insert two pauses here and here you're going to have a race condition and your channel is going to be stuck.
08:16
Speaker A
But if you change the order of certain checks then everything is going to be correct.
08:21
Speaker A
And after that Cloud also provided me with a proof based on RC11 memory ordering model showing that this implementation is correct as in all of the messages going to are going to pass none of the pauses are none of the pauses are are going to
08:39
Speaker A
block the channel and all of the messages are are going to be received. So essentially by me by trying to show that the implementation is correct I have I've seen a bug because of that.
08:58
Speaker A
Third target which is uh uh curl and ngtcp2. Uh curl is famous for having lots and lots of attention because um having a vulnerability in curl allows you to break many many targets. So I decided to say let's see if curl is
09:19
Speaker A
broken. But I couldn't take on all of curl I only look at the implementation of quick which is HTTP3 implementation.
09:28
Speaker A
Curl delegates the implementation of uh quick to ngtcp2 library. So I took the RFC 9000 spec which is the spec for quick.
09:40
Speaker A
And asked Claude to translate the spec to lean. Basically saying all of the requirements need to be all the requirements which we which are specified in the RFC need to be made in into a lean statement. Excellent. We
09:54
Speaker A
have that. And also we have now have an implementation of quick also in lean.
10:00
Speaker A
And there is a proof that the specification corresponds to the implementation. So what happened So what happened is I checked three different implementation and a spec in the same run and compare loop.
10:12
Speaker A
What happened is is that I found five bugs in ngtcp2 and a quiche a quick quiche a different library which implements quick.
10:21
Speaker A
So uh Yeah, five bugs in ngtcp2 and five bugs in quiche. None of them are are security bugs, but they are bugs nevertheless.
10:31
Speaker A
So I posted those bugs to GitHub for respective uh projects. So I talked to my co-workers and to my friends with this specific approach and they've have had the same results. They found subtle bugs in pretty much everything they pointed
10:49
Speaker A
it at. And why does this work? I think this works because this is merely an extrapolation of the unreasonable effectiveness of mathematics in sciences.
11:04
Speaker A
And I the So my speculation is that we are giving LLMs a tool to think in a more strict way.
11:19
Speaker A
And since we give it this tool, it gives it allows it allows it allows LLMs to reason in a more strict way. So basically if I am allowed to anthropomorphize, LLM is saying, "Oh crap, now I have to
11:32
Speaker A
actually understand what what the hell is going on and I'm going to try to make it more reasonable.
11:38
Speaker A
So now to objections. I often hear objections to using a formal methods and I think it's based on the framing on how we are doing. So if the first objection is that the result is going only going to be as
11:52
Speaker A
good as the spec. Garbage speak in, garbage code out. I don't view I think this framing is a bit incorrect in this specific case. So for this specific case, the framing I use is that our lean model is our attempt at
12:11
Speaker A
understanding of what we want to do. And this attempt may be incorrect. It may give you bad results. You're going to change your model according to new if you have new observations which contradict your model, you're going to
12:26
Speaker A
change your model. I think that having a model which is close to reality is significantly better than having no model.
12:36
Speaker A
Yeah. Also like you need to understand the proof statements. Well, yes in case of lean the the type declarations for theorems are relatively easy to understand. I think you can learn to you can learn to read them pretty fast.
12:58
Speaker A
I think they're difficult. And second one second is that you can just ask a LM to translate that to English and most of the time you're going to have good results. And I understand that LMs are LMs are failing.
13:12
Speaker A
English is not such a precise language, but I think the results speak from the for itself.
13:19
Speaker A
Also you need you need to know what to prove. And answer to that is well, if you have unit tests, you can just extrapolate whatever you test is doing and that that's going to be your theorem or that that's going to be your proof.
13:30
Speaker A
Basically, my claim is that if you have unit tests, you can do formal methods now.
13:37
Speaker A
Um But yeah. Uh that's short That was a bit short, but do you have any questions? And I welcome any Thank you. So, the question was how what methods would guarantee that uh the model would be correct on a large code base,
13:55
Speaker A
right? So, what works best is having parallel implementation uh which which you can run against each other.
14:05
Speaker A
In this case, you could you could have a spec, which is going to run you all of your unit tests. So, you have a spec, which is which is hopefully a simpler implementation, and that spec is going to also run the
14:18
Speaker A
unit tests. Okay? So, if you if you have two implementations which pass unit tests, and one of the implementations has mathematical proofs attached to it, I would trust the uh the thing which has mathematical proofs.
14:32
Speaker A
Hopefully, that addresses what you're what you're asking. I'm a little more worried about Uh actually, wouldn't you So, I'm more worried about instances where if you're if you're dealing with a code base that's large enough where you have a large number of contributors and
14:48
Speaker A
the behavior's changing constantly, that means the model's changing constantly, and maybe not everyone will be as diligent about updating the the verification models, and those might change. How do you like what are some of the methods you might want to employ to
15:02
Speaker A
to prevent sort of either laziness or other problems creeping in where maybe the model says, "Well, it's just good enough to change the model so it works." What do you What do you do to address those issues?
15:12
Speaker A
We have uh we have lean checkers and lean fuzzers running in CI. Wait. Wait. Wait. wait. One second.
15:24
Speaker A
Yeah. The spec could drift from the lean proof. This Who's checking that? You mean uh so if I if I understood your question correctly, what happens if you have uh spec written in prose and that spec is going to drift from the lean lean code.
15:44
Speaker A
Yeah, or maybe even you never change the prose and you somebody just change the spec in the code and you know didn't like update the API in the spec, right?
15:54
Speaker A
So in that case, you would have to choose the single source of truth and uh in case So in case of our project, we chose our model as a single source of truth to what you are expect uh from the
16:11
Speaker A
library's behavior. So yes, there is text there is uh plain text documentation, but if you want to be more specific and more and more precise about what's happening, you're going to read the lean.
16:26
Speaker A
How do you avoid uh maintaining this like parallel code base basically of lean proofs?
16:33
Speaker A
Or do like do you only do the lean proof for something that's like this is super important, we have to nail this and then you kind of soften on the other places or I mean, similar to what he asked, but
16:44
Speaker A
Yeah, so okay. So what what happens if you want to if your library needs to drift and your library wants wants to drift. In that case, you would have to update the proofs and yes, there is overhead. In
16:56
Speaker A
practice, I don't think the overhead is large because uh LM's just can update the uh the library the library and lean pretty easily and pretty seamlessly. In like in my experience, I haven't I have not encountered where it it incurred a
17:11
Speaker A
large overhead. But also, I agree it is better to it is significantly better to run this on something which has pretty strong and pretty static spec in which in case like try maps or main pipe or quick, they're pretty static.
17:34
Speaker A
So I'm I'm wondering if would you be wanting to do more deterministic LLMs for this sort of thing because one thing that I've at least written in program now, there's always a balance between like the idea of like
17:50
Speaker A
everything's unit tested, you know, everything's you know, has integration test, etc. So if anyone messes up it won't even compile and we know exactly where. There's always a medium between that. However, when we're throwing LLMs into the mix, would it be more
18:05
Speaker A
advantageous to have it be more of the deterministic type so we could also kind of like path trace in case a glitch happens with that part of the chain because the one thing that people don't really emphasize enough sometimes is even the
18:18
Speaker A
unit test themselves can fail. So likewise, if we're adding this on top of it, then that also like is an added complexity.
18:28
Speaker A
Yeah, that's good. So I'd like to to if possible, could you rephrase the question because what what happens is that LLMs are not part of the result. So LLMs are a method to produce these artifacts and these artifacts are deterministic
18:47
Speaker A
these artifacts are not static, but the artifacts are pretty well have a well-defined runtime and LLMs are merely a method how to get there. In principle, you could you could get there uh by yourself. It's just going to take way
19:05
Speaker A
more effort. I I I don't know how to Maybe if you rephrase the question, I could answer you better.
19:11
Speaker A
Yeah, it's just in the sense of like creating these artifacts, you know, like I mean obviously just as people can also make mistakes, but then when the LLM makes a mistake and we're going much faster, these are amplified. So,
19:25
Speaker A
how do you know, how are you able to like I guess produce this fast, but also when we're getting more certain, how do we you know, make sure that the outputs good?
19:35
Speaker A
So, the way we did it is we run a fuzzer, and the fuzzer is going to exercise your code in a very deep corners. So, it's going to test every single it essentially is going to test every single branch.
19:47
Speaker A
Hopefully, but like a lot of the time it's it's going to be the case.
19:51
Speaker A
So, if you exercise enough of your code and if you exercise enough of your tests, you can have a significant um how to say, significant uh level of certainty that what it's doing is correct. You may encounter a corner case
20:08
Speaker A
where it's where it doesn't do what you want, but with enough tests and enough exploration, you can be uh you have you can have a high level of certainty that it is essentially the same. It is what you
20:24
Speaker A
want. Um I know it's not satisfying. It's not This is not a It's not a deterministic answer, but it is the best we the best method I have found so far.
20:36
Speaker A
Thank you very much. All right, do we have any other questions? Okay, we have another one.
20:49
Speaker A
Uh when it comes down to API versus implementation, how are you able to detect when there's a uh you said there was a a bad API design.
21:01
Speaker A
Um in that instance, how were you able to uh to figure that out? That's going to be case-by-case and you would have to think for yourself um because you are the only source of truth when it comes to what do you want to do with the
21:19
Speaker A
library? And uh essentially those uh examples were those two examples were asking the question, what do you want to do with the library in this case? Like as an example uh there was a there was a trivial um corner case where we have a try and
21:38
Speaker A
we need to traverse um in the by depths depth depth K. And what happened is that well, what what happens if the K is zero?
21:47
Speaker A
And different places in the library did different things. But this but the plain text of the specification was under specified. So, we had to change the specification of what happens if you try to walk with depth zero.
22:06
Speaker A
Like like you you'd have to choose you'd have to understand yourself. Um yeah, uh how and where did you learn how to do this and what's your GitHub?
22:17
Speaker A
Well, I started practicing Lean about I think in in June. And uh I stumbled up upon this specific approach because I happened to know people who do fuzzing and people who do differential fuzzing. So, I just tried it out, it worked out, and I'm talking
22:37
Speaker A
about it. And and your GitHub? GitHub is there. Actually, look at look look right behind you. The the monitor right behind you.
22:48
Speaker A
Look at that. My GitHub is m1iel. What? Yes. I'm new here, so I don't know do they share decks?
22:55
Speaker A
The the URL doesn't work. I'm going to upload it soon. All right. Uh thank you for your presentation Igor.
23:01
Speaker A
[applause] Thank you guys for coming. Thank you for Fruto. Thank you for Aaron Wolf, who makes this all possible.
Topics:Leanformal verificationLLM-generated codedifferential fuzzingproperty-based testingtrielock-free channelQUICcurlFUTO

Get More with the SozAI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries and speaker detection. 30 minutes free.

Or transcribe another YouTube video here →