diff --git a/README.md b/README.md index 015c1a6..7c02a07 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ ere-sp1 = { path = "crates/ere-sp1" } ### 3. Compile & Prove Example ```rust -use zkvm_interface::{Compiler, zkVM, Input}; +use zkvm_interface::{Compiler, zkVM, Input, ProverResourceType}; use ere_sp1::{EreSP1, RV32_IM_SUCCINCT_ZKVM_ELF}; let mount_directory = std::path::Path::new("."); @@ -82,9 +82,9 @@ let guest_relative = std::path::Path::new("guest/hello"); let elf = RV32_IM_SUCCINCT_ZKVM_ELF::compile(mount_directory, guest_relative)?; // compile let mut io = Input::new(); io.write(&42u32)?; -let zkvm = EreSP1::new(elf); -let (proof, _report) = zkvm.prove(&io)?; // prove -zkvm.verify(&elf, &proof)?; // verify +let zkvm = EreSP1::new(elf, ProverResourceType::Cpu); // create zkVM instance +let (proof, _report) = zkvm.prove(&io)?; // prove +zkvm.verify(&proof)?; // verify ``` ### 4. Run the Test Suite @@ -113,7 +113,7 @@ docker/ ← Dockerfiles & build contexts `zkvm-interface` exposes two core traits: * **Compiler** – compile a guest project into the correct zkVM artifact. For most this will be a RISCV ELF binary or some type that wraps it and includes extra metadata such as a proving and verifying key. -* **zkVM** – execute, prove & verify that artifact +* **zkVM** – execute, prove & verify that artifact. A zkVM instance is created for specific `program`, where the `program` comes from the `Compiler`. ### Backend Crates diff --git a/crates/zkvm-interface/src/lib.rs b/crates/zkvm-interface/src/lib.rs index aacd652..12dda57 100644 --- a/crates/zkvm-interface/src/lib.rs +++ b/crates/zkvm-interface/src/lib.rs @@ -71,16 +71,23 @@ pub enum zkVMError { #[allow(non_camel_case_types)] #[auto_impl::auto_impl(&, Arc, Box)] -/// zkVM trait to abstract away the differences between each zkVM +/// zkVM trait to abstract away the differences between each zkVM. +/// +/// This trait provides a unified interface, the workflow is: +/// 1. Compile a guest program using the corresponding `Compiler`. +/// 2. Create a zkVM instance with the compiled program and prover resource. +/// 3. Execute, prove, and verify using the zkVM instance methods. +/// +/// Note that a zkVM instance is created for specific program, each zkVM +/// implementation will have their own construction function. pub trait zkVM { - /// Executes the given program with the inputs accumulated in the Input struct. - /// For RISCV programs, `program_bytes` will be the ELF binary + /// Executes the program with the provided inputs. fn execute(&self, inputs: &Input) -> Result; - /// Creates a proof for a given program + /// Creates a proof of the program execution with given inputs. fn prove(&self, inputs: &Input) -> Result<(Vec, ProgramProvingReport), zkVMError>; - /// Verifies a proof for the given program + /// Verifies a proof of the program used to create this zkVM instance. /// 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