Assignment 7b – Dafny
1 Install Dafny
2 Solve these Dafny Exercises

Assignment 7b – Dafny

Due Sun 6/4 11:59pm

1 Install Dafny

If you are not able to use the setup instructions below, an VM with the right environment has been created (userid and password are both dafny).

  1. Download and Install VSCode

  2. Download and Install Dotnet 6.0. On the left hand side of the page, there are links for the different versions of the SDK. Select the installers appropriate for your operating system and CPU architecture

  3. Open VScode and install the Dafny Extension

  4. If you have not used VScode before, visit this link to learn about how to install and configure extensions

  5. If you are on a Windows or x86-64 Mac machine, go to the extension setting for the dafny extension, and select the “Dafny: Version” to 4.0.0.

  6. If you are on a ARM Mac (advertised as Apple Silicon, M1, M2, etc.)
    • Download the ARM64 Mac Dafny binary to some directory

    • Unzip the zip file to some directory, open terminal and run the allow_on_mac.sh script in that directory

    • Go to the extension setting for the dafny extension (open Settings in VS Code and search for “Dafny” and you’ll find a pane with all of the dafny settings), in “Dafny: Cli Path”, put the path to the dafny executable in the directory. For example if I unzipped my files in /Users/peterzhong/dafny-unzipped, the path I would put would be /Users/peterzhong/dafny-unzipped/dafny

    • In the same settings pane, set “Dafny: Version” in the extension settings to Custom

  7. Open the homework file, you should see the green checkmarks next to the isNegHelper function indicating a successful proof, and a red checkmark next to the isNeg function indicating an unsuccessful proof

2 Solve these Dafny Exercises

Solve the exercises laid out in hw7b.dfy. The reference hw7-reference.dfy could be very helpful. This is the code we went through in lecture.

Possibly useful tips and reminders:
  • Use assert liberally to check what the verifier knows at any point in your program.

  • You can use expect to write dynamic tests, as well as print if necessary for debugging.

  • You can run the Main method of a program (see the reference for example) that doesn’t verify with

    dafny run --no-verify  my-program.dfy

    This is most useful if you want to print or run tests with expect.

  • You can verify and then run the Main method of a program (see the reference for example) with

    dafny run  my-program.dfy