by turbinerneiter · 6y ago · 0 comments
What I wonder is how this formal verification works. seL4 is written in C and apparently the formal verification is done in a different language. Is it possible to have a programming language where the compiler does the formal verification?
Curiously it involves Haskell for its specification. [0]
They've also done some very impressive work verifying that the ARM machine code corresponds to the verified C code. They did this not by using a formally verified compiler, but by using GCC and then verifying the correspondence afterwards.
> Is it possible to have a programming language where the compiler does the formal verification?
Yes, but these languages are not all that approachable.
There's SPARK, which is Ada-based and has seen real-world use in various life-or-death applications like military aviation.
There's also ZZ, which is in early days, and which aims to be closer to C. [2] [3]
There's also Perfect Developer, a proprietary payware product, which does impressive things adding formal verification machinery to C and C++. [4]
[0] https://en.wikipedia.org/wiki/L4_microkernel_family#High_ass...
[1] https://en.wikipedia.org/wiki/SPARK_(programming_language)
For the unfamiliar, see http://frama-c.com/ and https://en.wikipedia.org/wiki/Frama-C
It is possible, but using separate languages (as seL4 does) has certain benefits. For example:
- Kernel developers tend to have C experience. If the OS is writen in C, they have a much larger pool to hire from.
- Any such language would have to be acceptable both for the people who develop the OS and for the people who do the verification: I suspect it's not easy to find something that pleases both crowds.
- C compilers get better all the time. Every time someone improves the gcc code generator, seL4 automatically gets a bit faster. Less mainstream programming languages get better only if you maintain an expensive in-house team working on the compiler.
Doesn't SeL4 need -O1 codegen to make their extraction from the generated code (and the thus the rest of the formal proof) work out?
Also, it's not like code generation is the only advantage of using a well-supported, externally developed compiler. It's just the one I picked as an illustrative example. GCC releases improve code generation, general usability, diagnostic format support, profilers, etc., at a rate that would be hard to match for a niche language, especially without hiring a dedicated compiler development team.
[1] https://ts.data61.csiro.au/publications/nicta_full_text/6449...
If you are trying to solve an old problem a new way, is it necessarily true that having a large pool of applicants is an advantage? It could be a liability.
On the one hand, there could be more variance in a large pool, so you might find a lot of unconventional thinkers who think like you. On the other hand, large groups have social mores, and so the dogma might be difficult to overcome, like the old "people can write fortran in any language" problem.
> Less mainstream programming languages get better only if you have an expensive in-house team working on the compiler.
Not if you defer optimisation to an external (and actively maintained) backend like LLVM. Rust and Zig do this.
From my naive standpoint: input, output, side-effect, time
[no_sideffect, 1ms]
fn increment(int i) -> int:
return i + 1
What this is missing is a formal statement that says "increases the value of the input by one" -> except you accept the function body as formal statement.Thanks for all the answers here, I guess I'm going to look for some more reading material.
Normally, you wouldn't take the function body as a formal statement, and would have a separate formal specification instead. In the example of increment, the formal specification is no simpler and no more useful than the implementation itself, but this is usually not the case.
Imagine e.g. that the following specification describes the desired behavior of a function f:
f(x) <= √x and (f(x) + 1) > √x
The OS developer would write something the code below to implement this specification. int f(int x) {
int r1 = 0;
int r2 = 1;
while (x >= r2) {
r1++;
r2 = r2 + r1 + r1 + 1;
}
return r1;
}
Does this C implementation conform to the specification? It's not all that easy to tell. But if the program is actually correct, then Floyd-Hoare logic [1] allows you to go through the program line-by-line and produce a proof that for any integer i and variable x', the following holds: lemma f_implements_spec: "
{ valueOf(x') = i \<and> i > 0 }
x' = f(x')
{ valueOf(x') <= \<sqrt>(i) \<and> valueOf(x') - 1 > \<sqrt>(i) }"
meaning that if the statement x'=f(x') is ever executed in an environment where x' has an integer value i > 0, then after this line is executed, the result stored in x' will satisfy the specification above. theory Scratch
imports Main
begin
fun increment :: "int ⇒ int" where
"increment x = x + 1"
lemma increment_increments:
shows "increment x = x + 1"
by simp
lemma double_increment_adds_two:
shows "increment (increment x) = x + 2"
by simp
lemma increment_sub_1_is_x:
shows "increment x - 1 = x"
by simpSuch compiler would require solving halting problem. Most problems related to search of formal proofs are undecidable.
In the case of SPARK, it's necessary to use timeouts on the prover. Ugly, sure enough, but real work can still be done with it.
https://docs.adacore.com/spark2014-docs/html/ug/en/tutorial....
Still, the only impact this has in practice is that it tells you languages or programming styles amenable to automatic verification must be very limited in their expresiveness/flexibility.
This is a consequence of the state of current tooling, rather than an inescapable consequence of the relevant math.
A concrete example: the SPARK language is a subset of Ada, but with each release it gets less claustrophobic.
You can even go to the other end of the programming language spectrum, and use formal methods with functional programming languages. I don't think anyone develops real critical systems this way, but I believe it's an active area of research.
I don't think so. As long as false-negative results are acceptable. (i.e. it is ok if for some programs no proof if found even though they fulfill the specification)
Occasional false-negatives seem perfectly fine for real-world use.
So you're not arguing with my post.
Yes, proof search is undecidable. But that's not what we're talking about in this thread. seL4 isn't verified by proof search. The proofs were provided by humans (with limited automation).
Wrong: Because of the finite memory instead of an unbounded tape (among other reasons), computers are strictly less expressive than Turing machines.
If you remove infinite tape, you go from undecidable to "just" exponentially complex.
Which is a huge leap - we got from "impossible" to "possible in principle" and we now can do research how to make it even "sufficiently fast" for problems of practical relevance.
That said, the Halting problem on physical computers is still of extremely high computational complexity, which can be just as high a barrier as incomputability.
Otherwise the number of possible states of the Turing machine T that we want to check whether it halts or not is finite and we just have to "simulate" the program and see whether it terminates or it reaches again a state that it was already in.
nobody needs systemd. nobody but RedHat. it is a step backwards, net net.