lita-xyz / valida-releases

Public releases for the Valida toolchain
6 stars 2 forks source link

See 'Releases' section for downloads.

Docker Support

We provide a Docker container with the Valida LLVM and Rust toolchains already installed. Docker is the only supported method of running on platforms other than x86 Linux.

# Download the container
docker pull ghcr.io/lita-xyz/llvm-valida-releases/valida-build-container:v0.5.0-alpha

cd your-valida-project

# Enter the container:
docker run --platform linux/amd64 -it --rm -v $(realpath .):/src ghcr.io/lita-xyz/llvm-valida-releases/valida-build-container:v0.5.0-alpha

# You are now in a shell with the valida rust toolchain installed!

Usage instructions

Entering the Valida shell (non-Docker only)

This step applies only if you are using a non-Docker installation of the toolchain.

Upon having installed the toolchain, the Valida shell should be on your PATH, and if you run which valida-shell, you should see:

$ which valida-shell
/usr/local/bin/valida-shell

If the result is something else, then either the installation did not complete successfully, or you had another valida-shell executable somewhere on your PATH.

If you run valida-shell, then you should see a shell prompt that reads valida>. You should then have on your PATH all of the executables from the Valida toolchain needed to follow the instructions below.

Compiling and running Rust programs

For examples of how to build a Rust program which compiles and runs on Valida, see lita-xyz/rust-examples on GitHub. You can use any of these examples as a starting point for developing your own programs using the Valida toolchain. Here are steps for doing so:

  1. Clone the project template:
$ git clone https://github.com/lita-xyz/fibonacci.git
  1. cd into the project template:
$ cd fibonacci
  1. Enter the Valida shell (skip this step if you are using the Docker toolchain):
$ valida-shell
  1. Build the project:
valida> cargo +valida build
  1. Run the code (taking input from stdin):
valida> valida run --fast target/delendum-unknown-baremetal-gnu/debug/fibonacci log
  1. Prove the execution (taking input from stdin):
valida> valida prove target/delendum-unknown-baremetal-gnu/debug/fibonacci proof
  1. Verify the proof:
valida> valida verify target/delendum-unknown-baremetal-gnu/debug/fibonacci proof

Writing Rust programs to run on Valida

The Valida Rust compiler can currently compile in no_std mode, I.E. it cannot yet provide access to the std library, but can compile Rust programs which only use functionality contained within core, and which are annotated as #![no_std].

We do not (yet) support a main function signature that takes any arguments, so it's not possible to follow the normal method of specifying a main function in a #![no_std] program. The following is a demonstration of a simple program that shows how the main function must be declared instead:

#![no_main]

valida_rs::entrypoint!main(main);

#[no_mangle]
fn main() {
   ...
}

For a starting point to build a project using the Rust Valida toolchain, please take a look at the template project. You can clone this repo and use it as a starting point for your project.

The template project depends on the valida-rs crate. This contains a macro for generating an entry point, and some custom versions of standard library functions.

For projects with dependencies on io or rand, make sure your main and Cargo.toml include the code in this template. Also, make sure you have the same .cargo/config.toml in your project. If you want to build the project not targeting Valida, remove the [build] section in .cargo/config.toml and cargo will build the project targeting the host machine, unless otherwise specified.

We edited some functions to make them compatible with the Valida VM. When using these, the default Rust functions won't work. We call the Valida version with the entrypoint:: prefix.

These implementations are in valida-rs/src/io.rs and valida-rs/src/rand.rs.

Compiling and running C programs

To enter the Valida shell, run:

valida-shell

You can skip the above step if you are using the Docker toolchain.

See the lita-xyz/valida-c-examples repo on Github for some examples of C programs which can be compiled and run on Valida. Here is an example C program from this repo, called cat.c:

const unsigned EOF = 0xFFFFFFFF;

int main() {
    unsigned c = 0;
    while (1) {
        c = __builtin_delendum_read_advice();
        if (c == EOF) {
            break;
        } else {
            __builtin_delendum_write(c);
        }
    }
}

To compile, for example, the cat.c example, from within the Valida shell:

clang -target delendum ./cat.c -o cat
valida run cat log

Once running, the cat example will wait for input. After you are done providing input, press ctrl+D. The program should echo back what you wrote, writing its output to log.

Compiling and running the other examples follows the same procedure, substituting $NAME for the name of the example:

clang -target delendum ./examples/${NAME}.c -o ${NAME}
valida run ${NAME} log

Some other examples that are provided in the valida-c-examples repo:

Reporting issues

If you have any issues to report, please report them at the llvm-valida-releases issue tracker. Please include the following elements in your bug report: what release version you encountered the bug on, steps to reproduce, expected behavior, and actual behavior.

Known issues