From 4642bb304df7d7d0a22fe1091417e775fabea3cc Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sun, 11 May 2025 21:56:20 +0100 Subject: [PATCH] split compiler from zkVM --- crates/zkvm-interface/src/lib.rs | 34 +++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/crates/zkvm-interface/src/lib.rs b/crates/zkvm-interface/src/lib.rs index a723f1c..814da75 100644 --- a/crates/zkvm-interface/src/lib.rs +++ b/crates/zkvm-interface/src/lib.rs @@ -2,25 +2,41 @@ use indexmap::IndexMap; use serde::Serialize; use std::{path::Path, time::Duration}; +#[allow(non_camel_case_types)] +/// Compiler trait for compiling programs into an opaque sequence of bytes. +pub trait Compiler { + type Error: std::error::Error + Send + Sync + 'static; + // TODO: check if this can be removed and we just use bytes + type Program: Clone; + + /// Compiles the program and returns the program + fn compile(path_to_program: &Path) -> Result; +} + #[allow(non_camel_case_types)] /// zkVM trait to abstract away the differences between each zkVM -pub trait zkVM { +pub trait zkVM { type Error: std::error::Error + Send + Sync + 'static; - /// Compiles the program and returns the `ELF` as bytes - fn compile(path_to_program: &Path) -> Result, Self::Error>; + /// Executes the given program with the inputs accumulated in the Input struct. + /// For RISCV programs, `program_bytes` will be the ELF binary + fn execute( + program_bytes: &C::Program, + inputs: &Input, + ) -> Result; - /// Executes the given ELF binary with the inputs accumulated in the Input struct. - fn execute(elf_bytes: &[u8], inputs: &Input) -> Result; - - /// Creates a proof for the given program + /// Creates a proof for a given program fn prove( - elf_bytes: &[u8], + program_bytes: &C::Program, inputs: &Input, ) -> Result<(Vec, ProgramProvingReport), Self::Error>; /// Verifies a proof for the given program - fn verify(elf_bytes: &[u8], proof: &[u8]) -> Result<(), Self::Error>; + /// TODO: Pass public inputs too and check that they match if they come with the + /// TODO: proof, or append them if they do not. + /// TODO: We can also just have this return the public inputs, but then the user needs + /// TODO: ensure they check it for correct #[must_use] + fn verify(program_bytes: &C::Program, proof: &[u8]) -> Result<(), Self::Error>; } /// ProgramExecutionReport produces information about a particular program