11 ms·
This has been done so many times. The Stanford Pascal Verifier was probably the first[1] The Pascal-F Verifier, a project I headed around 1980,[2][3] used prec
by Animats 8y ago
This has been done so many times.
The Stanford Pascal Verifier was probably the first[1] The Pascal-F Verifier, a project I headed around 1980,[2][3] used preconditions and postconditions very similar to what this guy is doing in Rust. "Specifically, full functional correctness with properties like arithmetic correctness, in-bounds array accesses, state machines correctness, functional correctness with respect to an abstract specification or security properties." - we had all that in 1983. Look at the example starting at page 56 in [2].
DEC did a lot of work on this for Modula, and later Java, in the late 1980s.[4] Modula went down with DEC. The work was mostly lost. Dafny is probably the most modern system in this line.
Memory safety by proof was coming along well in the early 1980s. Working systems existed. Automatic prover technology was working. Then came C.
The "array is a pointer" mindset of C set programming back by decades. In Pascal, there were no buffer overflows. Pascal, Modula, Ada, and on to Rust - no buffer overflows. Everything carried along size information. Subscript checking optimizations had been figured out by the 1980s, so the performance penalty was coming down.
The author mentions Sapiens, an attempt to apply machine learning to the problem of null pointers in C. (Anyone have a reference? It's hard to find.) Massive amounts of effort are being applied to try to infer information that C just can't express. This would be a lot more worthwhile if it resulted in translation of C to something better.
Forty years, and this still isn't fixed.
[1] http://i.stanford.edu/pub/cstr/reports/cs/tr/79/731/CS-TR-79-731.pdf http://i.stanford.edu/pub/cstr/reports/cs/tr/79/731/CS-TR-79...
[2] http://www.animats.com/papers/verifier/verifiermanual.pdf http://www.animats.com/papers/verifier/verifiermanual.pdf
[3] https://github.com/John-Nagle/pasv https://github.com/John-Nagle/pasv
[4] https://link.springer.com/content/pdf/10.1007/BFb0026441.pdf https://link.springer.com/content/pdf/10.1007/BFb0026441.pdf
- skywhopper 8y agoFormal methods and "proving" "correctness" have not taken off because while they seem like a great idea, it's insanely expensive to do it for non-trivial software, and you end up with a provably correct piece of software that is still full of business logic bugs and which inevitably fails to keep up with ever-changing business processes. I agree that software is terrible, and programming language choice plays a big role in what sorts of mistakes you can make, but I'm skeptical that attempting to write provably correct programs is a remotely realistic goal. Sure, it's possible to prove an algorithm, but the real world software systems that need the help--certainly anything that involves more than one process on a single CPU--have complexity that goes well beyond what can be modeled or reasoned about, much less be proven.
- Animats 8y agoIt's not that hard to automatically prove that a large piece of software has no buffer overflows and no null pointer dereferences. We had that working decades ago. Unless the code is in C. Then it's really hard.
- OnlyOneCannolo 8y agoDifficult, yes, but solved [1]. There exist sound static analyzers for C and C++. "Sound" meaning no false-negatives. [1] https://github.com/NASA-SW-VnV/ikos/blob/master/analyzer/README.md#checks https://github.com/NASA-SW-VnV/ikos/blob/master/analyzer/REA...
- jakevn 8y agoIf this has solved the issue of automatically proving that any C or C++ program has no buffer overflows, why do we still see CVEs for popular libraries and software that result from them?
- lapinot 8y ago`Sound' does not mean `complete'. Don't forget that no false positive or negative isn't all, the solver might just give up.
- nickpsecurity 8y agoNeither FOSS projects nor commercial software use proven methods most of the time. That's why you see the results you see. I described that here: http://www.ganssle.com/tem/tem372.html#article4 http://www.ganssle.com/tem/tem372.html#article4 The tools can also miss things. They miss more as complexity goes up. High-assurance systems used to structure things in a hierarchical way with simple functions and only call downs to aid the analysis. Basically, reduce combinatorial explosion. Most software isn't structured anything like that. It does combinatorial explosion with C not giving analyzer a lot of information to begin with. So, it causes tools to miss things. Rust might be easier to analyze due to the type system. Those labels become inputs and heuristics for future static analyzers.
- thesuperbigfrog 8y agoAgreed. Ada 2012 [1] and Spark [2] (an Ada subset with formal verification features) provide production-ready versions of most of these features. Clojure's spec [3] is also promising for better specifications and more automated testing Over the past decade or so, we have seen many mainstream programming languages adopt functional programming features. My hope is that more mainstream languages adopt preconditions, postconditions, invariants, and useful formal verification features. There are so many more great tools that could be used to build high quality software than unit testing. [1] https://www.ada2012.org/ https://www.ada2012.org/ [2] https://en.wikipedia.org/wiki/SPARK_(programming_language) https://en.wikipedia.org/wiki/SPARK_(programming_language) [3] https://clojure.org/about/spec https://clojure.org/about/spec
- int_19h 8y agoIf you look at the issue linked in the Rust tracker from the article, the people discussing this are specifically referencing Ada and SPARK. https://github.com/rust-lang-nursery/wg-verification/issues/14 https://github.com/rust-lang-nursery/wg-verification/issues/...
- thesuperbigfrog 8y agoNice! I did not have a chance to look at the issue discussion. Thank you for pointing it out. It's good to see that Rust is learning from Ada. Ada is also learning from Rust: https://arxiv.org/abs/1710.07047 https://arxiv.org/abs/1710.07047
- blub 8y agoC++20's getting contracts: https://en.cppreference.com/w/cpp/language/attributes/contract https://en.cppreference.com/w/cpp/language/attributes/contra...
- _hardwaregeek 8y agoThe Coders At Work interview with Fran Allen really hammered home that point. Which begs the question, why did C get so popular? I guess what programmers like to use isn't really what is always best for them. People like to ride motorcycles and programmers like to use C.
- pjmlp 8y agoNot exactly the same, using C is like driving motorcycles without helmet and protective gear.
- sorokod 8y agoThese people are also known as "organ donors".
- afiori 8y agoSome people would say that C got popular (apart from the obvious UNIX sponsorship) because at its core it is just a fancy way to address memory like in assembly, but almost portable.
- haberman 8y ago> Memory safety by proof was coming along well in the early 1980s. Working systems existed. Automatic prover technology was working. Then came C. K&R was published in 1978. So at best this story and timeline are incomplete. More illuminating would be an account of why C beat these other languages in the marketplace in the 80s, despite its disadvantages in safety.
- pjmlp 8y agoEasy, it came with an OS, given away for a symbolic price, with source code tapes alongside. Had Bell Labs been allowed to sell UNIX at the same price as other companies were selling theirs, and C would never have taken off. Burroughs, developed in 1961 in a memory safe systems programming language is still sold by Unisys as ClearPath MCP. Same applies to the IBM mainframes. The surviving systems from the 60-70's where C only plays a guest role at most.
- v_lisivka 8y agoBecause, C is portable assembler. In Pascal, for example, if something cannot be done in Pascal, then assembler must be used. If assembler is used, then program is tied to single platform. If you need to support two or more platforms at same time over long period, then C wins.
- pjmlp 8y agoThat is the myth, in practice ISO C specifies an abstract machine and libc is impossible to be written 100% in ISO C, some functions require either external Assembly or language extensions for their implementation.
- jcelerier 8y ago> Subscript checking optimizations had been figured out by the 1980s, so the performance penalty was coming down. well, we're in 2019 and replacing a few critical .at() by [] regularly allows me to gain a few % when benchmarking.
- Animats 8y agoThat's because the C++ compiler has no idea what you're doing. It can't hoist subscript checks out of loops, because it doesn't know they're subscript checks. They're something some template generated, and at bottom, they expand to an IF statement. The Go compiler, which knows about subscript checks, does some of those optimizations. For this optimization to work, the compiler has to be allowed to report subscript errors early. Frequent subscript checks that cause noticeable overhead tend to be inside loops. Often, the compiler could hoist the implicit assert inside the loop up to one assert checked before the loop is entered. It has to be allowed to report failure as soon as it become inevitable. If you have a loop from 0 to 100 over an array that's 0 to 99, and there's no way to exit the loop early, then failure is inevitable. As soon as failure is inevitable, it has to be OK to detect it. That means if you're printing values 0 to 100, you'll never even get the first one printed. You'll abort before entering the loop. This is a bit strange to C/C++ programmers. Once the assert has been hoisted out of the loop, the compiler may be able to prove that it can't fail. For FOR statements, this is usually easy. So the subscript checking overhead can completely disappear for many inner loops.
- int_19h 8y agoThen again, who uses at() inside a loop in C++? That's what iterators are for.
- pjmlp 8y agoPlenty of enteprise developers that learned some kind of C++ long back when, and never bothered to improve themselves in this area. I have seen plenty of code like that, specially when written by the occasional C++ coder that usually works in other languages.
- axilmar 8y agoIt's a matter of economics, mostly: proving that a feature is mathematically correct costs a lot more than implementing the feature itself, and so mathematic proofs are not done except if the cost justifies it. And because of that the tools that do these proofs do not take off, and thus they get reinvented every few years with each programming language.