RISCV

A RISCV frontend for powdr is already available.

How to run the Rust-RISCV example

# Install the riscv target for the rust compiler
rustup target add riscv32imac-unknown-none-elf
# Run the powdr-rs compiler. It will generate files in ./output/
powdr-rs compile riscv/tests/riscv_data/sum -o output
# Run powdr to compile powdr-asm to powdr-PIL and generate the witness
# -i specifies the prover witness input (see below)
powdr pil output/sum.asm -o output -f -i 10,2,4,6

The example Rust code verifies that a supplied list of integers sums up to a specified value.

#![no_main]
#![no_std]

extern crate alloc;
use alloc::vec::Vec;

use powdr_riscv_runtime::io::read_u32;

#[no_mangle]
pub fn main() {
    // This is the sum claimed by the prover.
    let proposed_sum = read_u32(0);
    // The number of integers we want to sum.
    let len = read_u32(1) as usize;
    // Read the numbers from the prover and store them
    // in a vector.
    let data: Vec<_> = (2..(len + 2)).map(|idx| read_u32(idx as u32)).collect();
    // Compute the sum.
    let sum: u32 = data.iter().sum();
    // Check that our sum matches the prover's.
    assert_eq!(sum, proposed_sum);
}

The function read_u32 reads a number from the list supplied with -i.

This is just a first mechanism to provide access to the outside world. The plan is to be able to call arbitrary user-defined ffi functions that will translate to prover queries, and can then ask for e.g. the value of a storage slot at a certain address or the root hash of a Merkle tree.