Getting Started with LLVM-Valida

Welcome to LLVM-Valida! This guide will walk you through the process of setting up and using LLVM-Valida, a compiler backend for the Valida Virtual Machine. LLVM-Valida allows you to compile programs written in languages like C, with planned support for C++ and Rust, for execution on the Valida VM, a STARK-based virtual machine designed for efficient zero-knowledge proofs.

Supported Operating Systems

LLVM-Valida is currently tested and known to work on the following operating systems:

  • Ubuntu 22.04.3 LTS

  • Arch Linux

Download

Grab the latest binary release from GitHub:

wget https://github.com/lita-xyz/llvm-valida-releases/releases/latest/download/llvm-valida-v0.1.0-alpha-linux-x86_64.tar.gz

Extract the archive:

tar xzvf llvm-valida-*-linux-x86_64.tar.gz

Usage

Once you have the binaries, you can compile, run, prove, and verify programs for the Valida VM using the following steps:

  1. Compile your program: Replace <your-program.c> with the path to your C source file.

    ./clang -c -target delendum <your-program.c> -o <output-file.o>
  2. Link your program and get the `.out` file:

    e.o>
  3. Run your program on Valida and write the program log to a `.log` file:

    ./valida run ./<output-file.out> ./<output-file.log>
  4. Prove your program on Valida and write the proof to a `.proof` file:

    ./valida prove ./<output-file.out>  ./<output-file.proof>
  5. Verify the proof of your program on Valida:

    ./valida verify ./<output-file.out> ./<output-file.proof>

Example

The following is a simple Fibonacci test written in C that checks if the 6th Fibonacci number is 8 and returns nonzero if not:

int fib(int n) {
        if (n == 0) {
    return 0;
  } else if (n == 1) {
    return 1;
  } else {
    return fib(n-1) + fib(n-2);
  }
}

int main () {
        if (fib(6) == 8)  {
                return 0;
        } else {
                return 1;
        }
}

Compile the source file with the LLVM-Valida clang compiler:

./clang -c -target delendum fibonacci.c -o fibonacci.o

Link the object file:

./ld.lld --script=valida.ld -o fibonacci.bin fibonacci.o

Generate a proof:

./valida prove fibonacci.bin fibonacci.proof

Verify the proof:

./valida verify fibonacci.bin fibonacci.proof

Valida should output "Proof verified" on successful verification.

Building From Source

Prerequisites

Before you begin, ensure you have the following prerequisites installed on your system:

  • git

  • cmake (version 3.22.1 or later)

  • ninja (version 1.10.1 or later)

  • clang (LLVM's C compiler)

  • lld (LLVM's linker)

  • libstdc++-12-dev

Build

Follow these steps to build the Valida virtual machine:

git clone git@github.com:valida-xyz/valida.git
cargo build --release

Contributing

We welcome contributions to LLVM-Valida! To contribute, follow these steps:

  1. Open a Pull Request (PR): Fork the repository, make your changes, and open a PR.

  2. Get Approval: Get at least one approval from another maintainer.

  3. Ensure Compliance:

    • Make sure your code compiles.

    • Ensure all tests pass.

    • Add tests when possible and include them in the test script (run-valida-tests.sh).

  4. Formatting: Keep the code formatting consistent using clang-format. Activate the pre-commit hook or run git clang-format before committing.

Additional Resources

Last updated