Verified Garbage: An experimental formally verified cryptography library
30 points by nelhage
30 points by nelhage
just self-aware enough for me to not dismiss it as slop. i will not use it, but good luck!
the issue is, i do not believe/understand formal verification enough: to me, lean is (just) a kind of programming language and it's implementation(s) or the lean code being verified may have bugs, like any other program, even if it compiles or is tested. even if itself is "bug free", it may be built on fundamentally incorrect assumptions such as how some particular cpu microcode or ISA works and interacts (in this case) - to perfectly model it would require something close to re-implementaiton, no?
feel free to correct me and explain it better, please!
lean is (just) a kind of programming language and it's implementation(s) or the lean code being verified may have bugs, like any other program, even if it compiles or is tested
Of course! Every program may have bugs, including the implementation of Lean. The Lean community has partially mitigated this problem by reducing the "trusted base" to a (relatively) small checker "kernel" (preceded by parser/preprocessor/macro-expander); subsequently, they've written multiple, supposedly independent implementations of this kernel. They've also made it relatively easy to pass arbitrary Lean code through a bunch of those implementations.
I believe even with those multiple checker kernels, you still depend at least on a large swath of the main Lean codebase in order to compile the theorem statement to the core language. But at least the proof, afterwards, is rather tight (since whatever happens before the lowering of the proof into the core language, it's checked afterwards by a battery of tested kernels).
EDIT: More generally, though, formal verification rests on the assumption that while the prover may of course have bugs, it's hopefully used in more than one project, so the more it's used the lower the probability of bugs in the prover as compared to the probability of bugs in the thing you're trying to verify. Furthermore, bugs in provers tend to be (but are not always) of a kind that intentionally written proof code tends not to hit; you typically need to write contrived proof code to exploit such a bug. Of course, 1. this is not a guarantee, and 2. if you LLM-generate your proof, who knows what "intentionally" even means.
I think this is pretty neat. LLMs are great at producing stuff that is mostly right but not always, in large quantities. For most purposes this is problematic since it means you need to code-review slop and get depressed etc. Once you have a specification of what you want, and you can formally, and automatically, check generated code against that spec, you can use LLMs for what they're good at without having to deal much with the things they're not. (Pending, I guess, increased trust in their trusted computing base.)
If we're going to have LLMs, let's use them in this kind of way.
That’s what makes me nervous about this kind of thing. I didn’t read the whole article but the difficulty in doing this typically is that you need to have a formal model of the ISA and the microarchitectural guarantees to reason about. LLMs cannot wish that model into existence.
These have existed for a long time, though.
Sem86 and LibLISA: https://liblisa.nl/ Picinae: https://personal.utdallas.edu/~hamlen/hamlen19feast.pdf https://github.com/CharlesAverill/Picinae Even Ghidra's SLEIGH could be considered a step in this direction: https://ghidra.re/ghidra_docs/languages/html/sleigh.html
There are almost certainly bugs in all of these (esp. in weirder architectures), but they'll only come out with increased use.
As for timing properties, that's way way way harder. Even within an ISA, different CPUs (or microcode revisions) will have different timing properties. You need exact timing info to make exact timing proofs work. Afaik this is basically only available for softcores.
The key trick is that you don't need to prove very much about the timing: you just need the timing not to leak any secret information. They describe their (standard) notion of constant-time in a footnote:
the instruction trace does not depend on any secret inputs, and no instruction that handles secret data has data-dependent timing
The first half means you execute identical instructions no matter what the value of the secret inputs is. Primarily, that means you never do a conditional branch based on secret data.
The second half does need details about the hardware's timing, but only about one flag per instruction: might that instruction's timing ever depend on the values of its inputs?
For some architectures, that's actually published as an official part of the ISA spec. For others, you do have to make some amount of "educated guess" and/or experimental determination, but many cases are easy -- e.g. it's never safe to leak secret information into the address of a memory access.
I think the annoyance starts once you ask how sure you are there is at least one constant-time multiplication operation, and can you find out which one it is.
Would it be possible in principle to prove properties based on assumptions about the precise timings, and then fill out which assumptions hold based on the specific CPU at hand? Or proofs that hold regardless of precise timings, similar to how cache-oblivious algorithms work independently on the cache size.
Would it be possible in principle to prove properties based on assumptions about the precise timings, and then fill out which assumptions hold based on the specific CPU at hand?
The difficulty is in getting the data with which to fill out the assumptions. You need precise descriptions of branch prediction, the pipeline, the cache, timing-data dependencies within instructions (e.g., xor rax, rax is faster than xor rax, rbx), etc.
Or proofs that hold regardless of precise timings, similar to how cache-oblivious algorithms work independently on the cache size.
I'm not sure! My intuition is that as soon as you have a branch, you need to prove that the two sides have the same running time, which requires an exact timing specification.
My intuition is that as soon as you have a branch, you need to prove that the two sides have the same running time, which requires an exact timing specification.
I suppose that people writing timing-sensitive code would have some intuition of why they think their code is robust. So you not necessarily need the data. It would be valuable also to just point out to wrong assumptions, like “look, your assumptions are not enough to guarantee your code is robust, because this counterexample may happen”
There may be something there. I'd personally like to shoot for the stronger proof goal of "the code is correct given a specification of the CPU" rather than "the code is correct given some set of programmer assumptions."
Yet, providing assumptions about your system is what you do when you model it for model checking and other formal methods techniques. Also, usually the strongest kind of proof is out of reach either for computational limits or for other issues. Something to understand about formal methods is that it doesn’t have to be all or nothing. There’s plenty of value to extract from what looks like an intermediate result.
The article states that they have in fact written a formal model of the ISA, including both semantics and whether instructions have data-dependent timing. They've generated this model (in Lean) with an LLM (of course), and then checked it by hand. Their stated intention is to eventually migrate this ISA spec to something community-maintained and (optionally) human-written.
It's not perfect, but this stance is better than I've seen in many other places. :P
Indeed, they need to encode which promises of instruction constant-timeness are credible going forward, which is sometimes more of a political act of «will they dare to make this non-constant-time in next generation» than even a technical act of interpreting published documentation.
The writing though is inscrutable. LLM generated text is sterile. It would me interesting it the text added anything beyond asking an LLM to tell me what the code is about. The post could be a link to the source code and instructions to generate the post.
I'm sorry to be the bearer of bad news, but if you don't like the writing, that's human writing you don't like.
The idea of the post is to have specifications of cryptographic functions that you trust, and then let LLMs go wild writing bespoke assembly code for each platform to optimize them aggressively. Given this idea, the key component is the specification -- and, in particular, what actually it captures of the environment, acknowledging how much of side-channel issues it captures.
I don't understand how people would then consider reasonable to not even write the specifications themselves:
Our specifications were also written by LLMs, and then reviewed by humans.
Come on. Specifications are the key point of your entire system, they should be order-of-magnitudes easier to write than the code, and it is essential that you understand them very well to make accurate security claims. Why not write them yourself?
Second, we want to find ways to bolster trust in our TCB. We’re interested in a number of possible approaches to do this, including potentially replacing our LLM authored specifications with community maintained, human authored, specifications for cryptographic algorithms.
Okay, so the one hard problem in your work is left for later? What actually is achieved here?
Maybe people will just ignore this effort because of the absence of verifiable effort to get well-understood specifications. In this case I view this as a waste of compute: it demonstrates feasibility of something, which is arguably not something that people find very doubtful right now (that LLMs can write optimized assembly from specifications), without doing the most important/hard/valuable part. Or maybe people will start using this and assume that it is "correct" (without knowing exactly what that means), which would be fairly dangerous for those users.
The authors of the piece seem to be reasonable people (in particular they do not appear to put this in production). I wonder why they went to the extent of this demo. Maybe they just ignore the externalities of LLM usage, and did it because they could (at little human effort).
Okay, so the one hard problem in your work is left for later? What actually is achieved here?
Even if you’re right, there’s value to getting all the easy stuff finished. Now they can both focus on and invite others to help with the hard part.
This is fabulous work. I've started working on a way of augmenting programs with borrow-checker style guarantees, contracts, and detailed type information for variables. My goal is to make code much easier to understand and verify.
I'm definitely going to look at how these ideas can be adopted "under the hood" as it were.
Is there documentation on how the ISA specifications were generated/tested? It would be great to have a torture test suite to really hammer the CPUs to flush out behavioural quirks and differences. That would give a lot of confidence to the ISA side, and be generally useful for anyone adopting this technique.