Lita Docs
  • Introduction
    • Getting Started
  • Quick Start
    • Tutorial: Rust via Docker
    • Installation & System Requirements
    • Valida Compiler Toolchain
      • Rust Usage
      • C Usage
      • WASM Usage
      • Rust API
      • Client-side API
    • Valida zk-VM
  • ADVANCED USAGE
    • zk-VM: Advanced Usage
    • Using the Rust Toolchain
    • Using LLVM libc
  • Architecture
    • Overview
    • Proving System: Plonky3
      • Future Directions
    • Valida zk-VM
      • Technical Design: VM
      • Technical Design: Prover
      • GitHub Link
    • LLVM-Valida Compiler
      • Technical Design
      • GitHub Link
    • Benchmarks
      • Fibonacci (vs. RISC Zero)
      • Fibonacci (vs. SP1)
      • Fibonacci (vs. Jolt)
      • Fibonacci (Rust vs. C)
      • SHA-256 (vs. RISC Zero)
      • SHA-256 (vs. SP1)
      • SHA-256 (vs. Jolt)
  • Core Concepts
    • zk-VM
    • Proofs: Classical, Probabilistic, Succinct, and ZK
    • Evaluating zk-VMs
    • ZK-VM Design Tradeoffs
    • Valida Design Considerations
  • Contributing
    • Overview
    • Early Access Program
Powered by GitBook
On this page
  • Usage Instructions for C
  • C standard libraries
  • Floating point support
  1. Quick Start
  2. Valida Compiler Toolchain

C Usage

Usage Instructions for C

See the release bundle 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 the cat.c example to Valida from within the Valida shell or the Valida Docker image shell:

clang -target delendum /valida-toolchain/example/c/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 /valida-toolchain/examples/c/${NAME}.c -o ${NAME}
valida run ${NAME} log

C standard libraries

Floating point support

The LLVM Valida compiler toolchain supports floating point types via software emulation. All of the normal arithmetic operations on floating point are supported. fenv.h is not supported. It is recommended to avoid using floating point types in Valida, because it's not very efficient to do it using software emulation.

PreviousRust UsageNextWASM Usage

Last updated 4 months ago

See for instructions on how to use the partial libc support included with the Valida toolchain. This allows for the use of some libc header files and standard library functions and macros.

Using LLVM libc