hax-subcommands

The high assurance translation toolchain


Keywords
formal-verification, rust
License
Apache-2.0

Documentation

Hacspec v2

Quick start with Nix (works on Linux, MacOS and Windows)

Prerequisites: Nix package manager (with flakes enabled)
  • Either using the Determinate Nix Installer, with the following bash one-liner:
    curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
  • or following those steps.

Get the F* translation of a crate

  1. cd path/to/your/crate
  2. nix run github:hacspec/hacspec-v2#circus -- -o some/output/dir fstar
    will create fst modules in directory some/output/dir.

Get a shell with cargo circus, cargo thir-export and thir-elab

  1. nix develop github:hacspec/hacspec-v2
Other operations

Get the THIR' JSON out of a crate

  1. cd path/to/your/crate
  2. nix run github:hacspec/hacspec-v2#thir-export
    ...will create thir_export.json in the current directory.

More generally: nix run github:hacspec/hacspec-v2#thir-export -- THIR-EXPORT-ARGUMENTS. Replace THIR-EXPORT-ARGUMENTS with --help to get more information.

Running thir-elab on the JSON

  1. nix run github:hacspec/hacspec-v2#thir-elab -- -i /path/to/thir_export.json

Visualization of the THIR' JSON

  1. cd /directory/in/which/the/thir_export.json/file/lives/
  2. nix run github:hacspec/hacspec-v2#thir-json-visualizer
  3. visit http://localhost:8888/

Using Docker

  1. Clone this repo: git clone git@github.com:hacspec/hacspec-v2.git && cd hacspec-v2
  2. Go to the .docker folder: cd .docker
  3. Build the docker image: docker build . -t hacspec-v2
  4. Get a shell: docker run -it --rm -v /some/dir/with/a/crate:/work hacspec-v2 bash
  5. You can now run cargo-circus --help (notice )

Manual installation

  1. Make sure to have the following installed on your system:
  • opam (opam switch create 4.14.1)
  • rustup
  • nodejs
  1. Clone this repo git clone git@github.com:hacspec/hacspec-v2.git && cd hacspec-v2
  2. Install thir-export:
    1. cd thir-export
    2. cargo install --path cli
  3. Build thir-elab:
    1. cd thir-elab
    2. opam install --deps-only .
    3. dune build
    4. add the subfolder _build/install/default/bin in your PATH
  4. Commands available are:
    • cargo circus [--help]: export a crate to a backend (F* for instance);
    • cargo thir-export [--help]: export the THIR of a crate to a JSON file;
    • thir-elab [--help]: takes the THIR JSON export of a crate and outputs F*/... code.

The librustc library path needs to be added to DYLD_LIBRARY_PATH=$(rustc --print=sysroot)/lib Make sure to use the right Rust nightly version, which is currently nightly-2022-12-06.

Note Please use and check the setup.sh for these steps as well.

Edit the sources (Nix)

Just clone & cd into the repo, then run nix develop .#target –target being thir-export or thir-elab. You can also just use direnv, with editor integration.

Structure of this repository

  • thir-export/: a cargo subcommand that exports the THIR abstract syntax tree of a given crate into THIR' (a simplified THIR) as a JSON file. See thir-export/README.md for more details.
  • thir-json-visualizer/: a quick & dirty React web app to browse THIR' JSON files.
  • thir-elab/: a program that eats THIR' as JSON and that converts into an OCaml AST. That AST is parametrized by features (e.g. is mutation allowed? are loops allowed? etc.). Then, thir-elab offers a set of desugaring steps to, basically, lower THIR' to match F*/Coq/EasyCrypt/… feature set. Ultimately, we want to have backends that (1) ask for a certain desugar level and (2) produce code in F*/Coq/EasyCrypt/…
  • ocaml_of_json_schema.js: a quick & dirty script that translates a JSON Schema into OCaml types and serializers. (note: this will be replaced by quicktype when we our OCaml backend is ready)