18 ms·
Dafny – A programming language with a program verifier
- gravypod 10y ago"Try Dafny" is not complete. It doesn't have a link to request a special purpose keyboard to be sent to you.
- saghm 10y agoAssuming it's anything like the Emacs mode for Coq, they're probably just using an editor/editor plugin that replaces the operators/keywords with the mathematical symbols.
- vmarsy 10y agoThis is a Microsoft Research project started in 2008 [1]. It was previously hosted on codeplex [2] [1] https://www.microsoft.com/en-us/research/project/dafny-a-language-and-program-verifier-for-functional-correctness/ https://www.microsoft.com/en-us/research/project/dafny-a-lan... [2] http://dafny.codeplex.com/wikipage/history http://dafny.codeplex.com/wikipage/history
- yairharel 10y agoI love the thoughtful logo
- vbit 10y agoWould be nice to have a screenshot without the red squiggly underlines.
- dualogy 10y agoUnless..... "As you type in your program, the verifier constantly looks over your shoulders and flags any errors." .... it's a feature being highlighted =)
- seibelj 10y agoI had to use this for an algorithms class while getting my CS master's. Very, very tough to use for anything beyond simple experiments. It has confusing syntax and incomplete documentation. But when you finally get your program to execute, you can be sure it's perfect! (Supposedly)
- harpocrates 10y agoWhat were the things that were confusing? I tried it out and found it much more intuitive than Coq (especially in the proofs). The keywords made sense, and so did the error messages. That said, I come from a more math oriented background, and I've played typed around with this sort of thing for a while now. So yeah, I'm honestly interested in hearing your perspective!
- seibelj 10y agoFrom what I remember, the assignment was to write a function that implemented quick sort (or something else moderately complex) and getting it to run and satisfy the proof checker was exhausting. Edit: Found a forum post I made during it asking for help. Oh, the frustrating memories... https://dafny.codeplex.com/discussions/546995 https://dafny.codeplex.com/discussions/546995
- pierrec 10y agoWow, the feedback you got on that forum has a pretty rare level of detail and helpfulness. Confusing syntax, perhaps, but the community is point for sure!
- harpocrates 10y agoI see. Googled the for Dafny quick sort and it does have some pretty long invariants. [1]: http://rise4fun.com/Dafny/ks http://rise4fun.com/Dafny/ks
- archgoon 10y agoDoes Dafny not provide any macros for their invariants declarations ensures clauses? The QuickSort Example has a lot of the same invariants again and again, and most of them boil down to "I swear that the integer values are valid indices into the array".
- didibus 10y agoWhat are the competitors to this language? Can someone provide a list. I'd like to start learning a provable language, not sure if Dafny is the one I should start with though.
- Kametrixom 10y agoCheck out Idris maybe
- Devagamster 10y agoCoq is the one I use most. I've heard of lean as well though. Those are both proof assistants not theorem provers. Dafny uses z3 to attempt to automatically prove theorems about your code. Lean or Coq (for the most part) require that you write the proofs manually in a special language they provide and they will tell you whether or not your proof has errors. In general these languages lie on a spectrum between more automatic to more manual with the automatic ones taking potentially more time and being more limited but requiring less of you and the manual ones such as lean or coq are more expressive but harder to use because you have to provide all of the proofs. I should say all this with the caveat that I'm only learning these things now so I've probably said something wrong. Please correct me if that is the case.
- profquail 10y agoIsabelle is another language for program verification / theorem proving, similar to Dafny and Coq: https://isabelle.in.tum.de/ https://isabelle.in.tum.de/
- nickpsecurity 10y agoSPARK Ada is the main competitor & has been in industrial use a long time: http://www.spark-2014.org/uploads/itp_2014_r610.pdf http://www.spark-2014.org/uploads/itp_2014_r610.pdf http://www.anthonyhall.org/c_by_c_secure_system.pdf http://www.anthonyhall.org/c_by_c_secure_system.pdf http://libre.adacore.com/tools/spark-gpl-edition/ http://libre.adacore.com/tools/spark-gpl-edition/
- SilasX 10y agoPer this reddit comment [1], the languages supporting some kind of compile-time constraint-checking/proving include Why3, Dafny, Fstar, Coq, Agda, and Idris. Also, some languages have been extended to support it: LiquidHaskell, Frama-C, and Spark/Ada. I also recall some Java extension but can't find it atm. [1] https://www.reddit.com/r/ProgrammingLanguages/comments/4ref8v/can_pls_have_richer_more_general_compiletime/d50gwpb/?utm_content=permalink&utm_medium=front&utm_source=reddit&utm_name=ProgrammingLanguages https://www.reddit.com/r/ProgrammingLanguages/comments/4ref8...
- awinter-py 10y agoso cool! every language should have an invariant keyword. not sure how one uses it in practice -- most of the operators don't exist on my keyboard.
- Animats 10y agoI had the same argument with the Stanford Pascal Verifier people around 1980. They were using the SAIL PDP-10, with keyboards with extra characters and extra shift keys TOP and META. Assertions were written with mathematical notation but code was written in ASCII. We stuck to ASCII and Pascal operators for Pascal-F. Today, everybody has Unicode output, and all the math symbols are potentially typeable, but it drives programmers nuts if they have to enter them. If you're going to do a verification system, you have to design it for programmers, not mathematicians, or it won't be used. This is a serious problem with formal methods. The formalism is a means to an end, not an end in itself. The end goal is bug-free code. Dafny for Rust has potential. One big problem is where to put the assertions inside terse functional notation. This is word wrap in Rust: s.lines() .map(|bline| UnicodeSegmentation::graphemes(bline, true) .collect::<Vec<&str>>()) .map(|line| wordwrapline(&line, maxline, maxword)) .collect::<Vec<String>>() .join("\n") OK, where would we put assertions? Maybe intersperse .assert(|arg| assertionexpression) which is just a passthrough that returns its value but allows making assertions about what's going through it.
- houli 10y agoThe screenshot shows what looks like the emacs mode which actually just masks the ASCII you type with the unicode characters to make it look nice. In practice you're just writing plain ASCII https://github.com/houli/verification/blob/master/strings3.dfy#L101 https://github.com/houli/verification/blob/master/strings3.d...
- Animats 10y agoThat's very nice. It's surprisingly similar to the Pascal-F verifier I worked on in 1983. I recently found the sources for that, and since they were approved for release, I put them on Github.[1] (It's not runnable yet; passes 1 and 2 now work, but pass 4, which needs to be ported to a more modern LISP, doesn't.) The approach is amazingly similar - automatic range and bounds verification, entry and exit assertions, pure functions can be used in assertions, additional lemmas can be proven. Here are some Pascal-F examples that passed the verifier.[2] "bubble.pf" is a bubble sort. "circle.pf" is a circular buffer. Everybody who does verification work does those. Note how close these are to the similar Dafny examples. The terminology is different but equivalent; Dafny uses "requires" and "ensures" where Pascal-F used "entry" and "exit". Dafny used "old(f)" to talk about the old value (at function entry) of a variable, while Pascal-F uses "f.old". Both systems have lemmas, proved recursively with some extra effort by the user. A more useful Pascal-F example is "engine1.pf", which is a simple engine control program for an auto engine. This has concurrency and real time constraints. Proof goals include proving that the spark is fired exactly once per cylinder time, and that if the engine stops rotating, the fuel pump is cut off. Past this level, the next problem is scaleup. What do you want to prove about a large program? These simple verifiers don't address that. However, this sort of thing is really good at preventing buffer overflows and other things which break the program in a low-level way. I'd like to see Rust have Dafny's level of proof capability. This would help deal with "unsafe" code where the programmer claims Rust's invariants are preserved. Most of those situations just require proving that some assertion holds both before and after some data manipulation, even though there are moments when it doesn't hold. Verification technology is quite capable of that, and has been for a long time. (Having 3000x as much compute power as we had in 1982 helps a lot.) [1] https://github.com/John-Nagle/pasv https://github.com/John-Nagle/pasv [2] https://github.com/John-Nagle/pasv/blob/master/src/Examples https://github.com/John-Nagle/pasv/blob/master/src/Examples
- btat1 10y agoGreat job! I remember porting Fortran 77 programs on a Debian. The harder was to find then to understand the old compiler documentation :)
- 10y ago
- moomin 10y agoFor those of you not familiar with Haskell, it's worth pointing out that types and proofs are equivalent (with caveats). What this means in practice for Dafny is that anything you can do in it can equally be expressed in a language like Idris (with footnotes). Equally, it means that the trickiness encountered in heavily typed functional programming languages is carried over directly to working with program verifiers. At that point, it's more a case of what's easier to grok and work with. I mention this, because I see a lot of people who dismiss something like Idris out of hand saying they want correctness checking, not realizing they're basically equivalent.
- amelius 10y agoBut wouldn't it be much more cumbersome to check correctness using a type-system?
- moomin 10y agoIn short: no. It's exactly as cumbersome. If you look at the other comments you'll see plenty of people that found it hard to work with. Equally, if you look at Idris mailing lists you'll find people who love it. Another way of looking at it is which is easier to grok: imperative or functional flow.
- pron 10y agoIt's complicated. Basically, verifying programs is hard and pretty cumbersome regardless of the formalism, and the differences in the theory don't matter too much for most things people do. Having said that, making practical use of dependent types is currently behind proof tools for direct logic (in terms of automated provers, model checking etc.). What people sometimes do is start with direct logic expressed as a contract (say, like in Dafny, Java with JML or Ada SPARK), run automated tools on those (SMT solvers), and if the solvers fail, generate obligations for a logic based interactive prover or a dependent type one, at which point the differences matter even less. But working completely within a dependently typed language is currently unrecommended unless you just want to learn or play a bit, or unless you're an expert. Dependent types are just not yet "production ready".
- pron 10y agoFor those interested, Java has a mature specification language called JML, with tools similar to those provided by Dafny[1] and many more. In addition to SMT solvers, you can use interactive proofs for obligations that are not automatically discharged[2][3], or use the specifications to generate concolic tests[4]. [1]: http://www.openjml.org/ http://www.openjml.org/ [2]: http://www.key-project.org/index.php http://www.key-project.org/index.php [3]: http://krakatoa.lri.fr/ http://krakatoa.lri.fr/ [4]: https://github.com/Rafael-Baltazar/jmlcute https://github.com/Rafael-Baltazar/jmlcute
- deleted 10y ago[deleted]