use InputErased

This commit is contained in:
Kevaundray Wedderburn
2025-05-24 19:10:07 +01:00
parent 841f6872ca
commit e76f265dd3
6 changed files with 81 additions and 58 deletions

View File

@@ -1,4 +1,4 @@
use zkvm_interface::Input;
use zkvm_interface::{Input, InputErased};
pub fn preprocess_prover(
program: &jolt::host::Program,
@@ -40,8 +40,8 @@ pub fn preprocess_verifier(
pub fn verify_generic(
proof: jolt::JoltHyperKZGProof,
// TODO: input should be private input
inputs: Input,
outputs: Input,
inputs: InputErased,
outputs: InputErased,
preprocessing: jolt::JoltVerifierPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript>,
) -> bool {
use jolt::{Jolt, RV32IJoltVM, tracer};
@@ -53,8 +53,9 @@ pub fn verify_generic(
preprocessing.memory_layout.max_output_size,
);
io_device.inputs = inputs.bytes().to_vec();
io_device.outputs = outputs.bytes().to_vec();
// TODO: FIXME
// io_device.inputs = inputs.bytes().to_vec();
// io_device.outputs = outputs.bytes().to_vec();
RV32IJoltVM::verify(
preprocessing,
@@ -69,14 +70,15 @@ pub fn verify_generic(
pub fn prove_generic(
program: &jolt::host::Program,
preprocessing: jolt::JoltProverPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript>,
inputs: &Input,
inputs: &InputErased,
) -> (Vec<u8>, jolt::JoltHyperKZGProof) {
use jolt::{Jolt, RV32IJoltVM};
let mut program = program.clone();
// Convert inputs to a flat vector
let input_bytes = inputs.bytes().to_vec();
// TODO: FIXME
let input_bytes = Vec::new();
let (io_device, trace) = program.trace(&input_bytes);

View File

@@ -7,8 +7,8 @@ use utils::{
serialize_public_input_with_proof,
};
use zkvm_interface::{
Compiler, Input, ProgramExecutionReport, ProgramProvingReport, ProverResourceType, zkVM,
zkVMError,
Compiler, Input, InputErased, ProgramExecutionReport, ProgramProvingReport, ProverResourceType,
zkVM, zkVMError,
};
mod error;
@@ -52,21 +52,23 @@ impl EreJolt {
impl zkVM for EreJolt {
fn execute(
&self,
inputs: &zkvm_interface::Input,
inputs: &InputErased,
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
// TODO: check ProgramSummary
let summary = self
.program
.clone()
.trace_analyze::<jolt::F>(inputs.bytes());
let trace_len = summary.trace_len();
// TODO: FIXME
// let summary = self
// .program
// .clone()
// .trace_analyze::<jolt::F>(inputs.bytes());
// let trace_len = summary.trace_len();
let trace_len = 0;
Ok(ProgramExecutionReport::new(trace_len as u64))
}
fn prove(
&self,
inputs: &zkvm_interface::Input,
inputs: &InputErased,
) -> Result<(Vec<u8>, zkvm_interface::ProgramProvingReport), zkVMError> {
// TODO: make this stateful and do in setup since its expensive and should be done once per program;
let preprocessed_key = preprocess_prover(&self.program);
@@ -86,12 +88,12 @@ impl zkVM for EreJolt {
let (public_inputs, proof) =
deserialize_public_input_with_proof(proof_with_public_inputs).unwrap();
let mut outputs = Input::new();
let mut outputs = InputErased::new();
assert!(public_inputs.is_empty());
outputs.write(&public_inputs).unwrap();
outputs.write(public_inputs);
// TODO: I don't think we should require the inputs when verifying
let inputs = Input::new();
let inputs = InputErased::new();
let valid = verify_generic(proof, inputs, outputs, preprocessed_verifier);
if valid {
@@ -106,7 +108,7 @@ impl zkVM for EreJolt {
mod tests {
use crate::{EreJolt, JOLT_TARGET};
use std::path::PathBuf;
use zkvm_interface::{Compiler, Input, ProverResourceType, zkVM};
use zkvm_interface::{Compiler, Input, InputErased, ProverResourceType, zkVM};
// TODO: for now, we just get one test file
// TODO: but this should get the whole directory and compile each test
@@ -133,8 +135,8 @@ mod tests {
fn test_execute() {
let test_guest_path = get_compile_test_guest_program_path();
let program = JOLT_TARGET::compile(&test_guest_path).unwrap();
let mut inputs = Input::new();
inputs.write(&(1 as u32)).unwrap();
let mut inputs = InputErased::new();
inputs.write(1 as u32);
let zkvm = EreJolt::new(program, ProverResourceType::Cpu);
let _execution = zkvm.execute(&inputs).unwrap();

View File

@@ -12,7 +12,8 @@ use openvm_stark_sdk::config::{
};
use openvm_transpiler::elf::Elf;
use zkvm_interface::{
Compiler, ProgramExecutionReport, ProgramProvingReport, ProverResourceType, zkVM, zkVMError,
Compiler, InputErased, InputItem, ProgramExecutionReport, ProgramProvingReport,
ProverResourceType, zkVM, zkVMError,
};
mod error;
@@ -58,7 +59,7 @@ impl EreOpenVM {
impl zkVM for EreOpenVM {
fn execute(
&self,
inputs: &zkvm_interface::Input,
inputs: &InputErased,
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
let sdk = Sdk::new();
let vm_cfg = SdkVmConfig::builder()
@@ -74,8 +75,11 @@ impl zkVM for EreOpenVM {
.map_err(OpenVMError::from)?;
let mut stdin = StdIn::default();
for input in inputs.chunked_iter() {
stdin.write_bytes(input);
for input in inputs.iter() {
match input {
InputItem::Object(serialize) => stdin.write(serialize),
InputItem::Bytes(items) => stdin.write_bytes(items),
}
}
let _outputs = sdk
@@ -88,7 +92,7 @@ impl zkVM for EreOpenVM {
fn prove(
&self,
inputs: &zkvm_interface::Input,
inputs: &InputErased,
) -> Result<(Vec<u8>, zkvm_interface::ProgramProvingReport), zkVMError> {
// TODO: We need a stateful version in order to not spend a lot of time
// TODO doing things like computing the pk and vk.
@@ -107,8 +111,11 @@ impl zkVM for EreOpenVM {
.map_err(OpenVMError::from)?;
let mut stdin = StdIn::default();
for input in inputs.chunked_iter() {
stdin.write_bytes(input);
for input in inputs.iter() {
match input {
InputItem::Object(serialize) => stdin.write(serialize),
InputItem::Bytes(items) => stdin.write_bytes(items),
}
}
let app_config = AppConfig::new(FriParameters::standard_fast(), vm_cfg);
@@ -193,7 +200,7 @@ mod tests {
// Panics because the program expects input arguments, but we supply none
let test_guest_path = get_compile_test_guest_program_path();
let elf = OPENVM_TARGET::compile(&test_guest_path).expect("compilation failed");
let empty_input = zkvm_interface::Input::new();
let empty_input = InputErased::new();
let zkvm = EreOpenVM::new(elf, ProverResourceType::Cpu);
zkvm.execute(&empty_input).unwrap();
@@ -203,8 +210,8 @@ mod tests {
fn test_execute() {
let test_guest_path = get_compile_test_guest_program_path();
let elf = OPENVM_TARGET::compile(&test_guest_path).expect("compilation failed");
let mut input = zkvm_interface::Input::new();
input.write(&10u64).unwrap();
let mut input = InputErased::new();
input.write(10u64);
let zkvm = EreOpenVM::new(elf, ProverResourceType::Cpu);
zkvm.execute(&input).unwrap();
@@ -214,8 +221,8 @@ mod tests {
fn test_prove_verify() {
let test_guest_path = get_compile_test_guest_program_path();
let elf = OPENVM_TARGET::compile(&test_guest_path).expect("compilation failed");
let mut input = zkvm_interface::Input::new();
input.write(&10u64).unwrap();
let mut input = InputErased::new();
input.write(10u64);
let zkvm = EreOpenVM::new(elf, ProverResourceType::Cpu);
let (proof, _) = zkvm.prove(&input).unwrap();

View File

@@ -1,6 +1,8 @@
use pico_sdk::client::DefaultProverClient;
use std::process::Command;
use zkvm_interface::{Compiler, ProgramProvingReport, ProverResourceType, zkVM, zkVMError};
use zkvm_interface::{
Compiler, InputItem, ProgramProvingReport, ProverResourceType, zkVM, zkVMError,
};
mod error;
use error::PicoError;
@@ -64,20 +66,23 @@ impl ErePico {
impl zkVM for ErePico {
fn execute(
&self,
_inputs: &zkvm_interface::Input,
_inputs: &zkvm_interface::InputErased,
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
todo!("pico currently does not have an execute method exposed via the SDK")
}
fn prove(
&self,
inputs: &zkvm_interface::Input,
inputs: &zkvm_interface::InputErased,
) -> Result<(Vec<u8>, zkvm_interface::ProgramProvingReport), zkVMError> {
let client = DefaultProverClient::new(&self.program);
let mut stdin = client.new_stdin_builder();
for input in inputs.chunked_iter() {
stdin.write_slice(input);
for input in inputs.iter() {
match input {
InputItem::Object(serialize) => stdin.write(serialize),
InputItem::Bytes(items) => stdin.write_slice(items),
}
}
let now = std::time::Instant::now();
let meta_proof = client.prove(stdin).expect("Failed to generate proof");

View File

@@ -7,7 +7,8 @@ use sp1_sdk::{
};
use tracing::info;
use zkvm_interface::{
Compiler, ProgramExecutionReport, ProgramProvingReport, ProverResourceType, zkVM, zkVMError,
Compiler, InputErased, InputItem, ProgramExecutionReport, ProgramProvingReport,
ProverResourceType, zkVM, zkVMError,
};
mod compile;
@@ -115,11 +116,14 @@ impl EreSP1 {
impl zkVM for EreSP1 {
fn execute(
&self,
inputs: &zkvm_interface::Input,
inputs: &InputErased,
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
let mut stdin = SP1Stdin::new();
for input in inputs.chunked_iter() {
stdin.write_slice(input);
for input in inputs.iter() {
match input {
InputItem::Object(serialize) => stdin.write(serialize),
InputItem::Bytes(items) => stdin.write_slice(items),
}
}
let (_, exec_report) = self.client.execute(&self.program, &stdin)?;
@@ -135,13 +139,16 @@ impl zkVM for EreSP1 {
fn prove(
&self,
inputs: &zkvm_interface::Input,
inputs: &zkvm_interface::InputErased,
) -> Result<(Vec<u8>, zkvm_interface::ProgramProvingReport), zkVMError> {
info!("Generating proof…");
let mut stdin = SP1Stdin::new();
for input in inputs.chunked_iter() {
stdin.write_slice(input);
for input in inputs.iter() {
match input {
InputItem::Object(serialize) => stdin.write(serialize),
InputItem::Bytes(items) => stdin.write_slice(items),
};
}
let start = std::time::Instant::now();
@@ -171,7 +178,7 @@ mod execute_tests {
use std::path::PathBuf;
use super::*;
use zkvm_interface::Input;
use zkvm_interface::InputErased;
fn get_compiled_test_sp1_elf() -> Result<Vec<u8>, SP1Error> {
let test_guest_path = get_execute_test_guest_program_path();
@@ -194,11 +201,11 @@ mod execute_tests {
let elf_bytes = get_compiled_test_sp1_elf()
.expect("Failed to compile test SP1 guest for execution test");
let mut input_builder = Input::new();
let mut input_builder = InputErased::new();
let n: u32 = 42;
let a: u16 = 42;
input_builder.write(&n).unwrap();
input_builder.write(&a).unwrap();
input_builder.write(n);
input_builder.write(a);
let zkvm = EreSP1::new(elf_bytes, ProverResourceType::Cpu);
@@ -214,7 +221,7 @@ mod execute_tests {
let elf_bytes = get_compiled_test_sp1_elf()
.expect("Failed to compile test SP1 guest for execution test");
let empty_input = Input::new();
let empty_input = InputErased::new();
let zkvm = EreSP1::new(elf_bytes, ProverResourceType::Cpu);
let result = zkvm.execute(&empty_input);
@@ -231,7 +238,7 @@ mod prove_tests {
use std::path::PathBuf;
use super::*;
use zkvm_interface::Input;
use zkvm_interface::InputErased;
fn get_prove_test_guest_program_path() -> PathBuf {
let workspace_dir = env!("CARGO_WORKSPACE_DIR");
@@ -254,11 +261,11 @@ mod prove_tests {
let elf_bytes = get_compiled_test_sp1_elf_for_prove()
.expect("Failed to compile test SP1 guest for proving test");
let mut input_builder = Input::new();
let mut input_builder = InputErased::new();
let n: u32 = 42;
let a: u16 = 42;
input_builder.write(&n).unwrap();
input_builder.write(&a).unwrap();
input_builder.write(n);
input_builder.write(a);
let zkvm = EreSP1::new(elf_bytes, ProverResourceType::Cpu);
@@ -283,7 +290,7 @@ mod prove_tests {
let elf_bytes = get_compiled_test_sp1_elf_for_prove()
.expect("Failed to compile test SP1 guest for proving test");
let empty_input = Input::new();
let empty_input = InputErased::new();
let zkvm = EreSP1::new(elf_bytes, ProverResourceType::Cpu);
let prove_result = zkvm.prove(&empty_input);

View File

@@ -45,10 +45,10 @@ pub enum zkVMError {
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
fn execute(&self, inputs: &Input) -> Result<ProgramExecutionReport, zkVMError>;
fn execute(&self, inputs: &InputErased) -> Result<ProgramExecutionReport, zkVMError>;
/// Creates a proof for a given program
fn prove(&self, inputs: &Input) -> Result<(Vec<u8>, ProgramProvingReport), zkVMError>;
fn prove(&self, inputs: &InputErased) -> Result<(Vec<u8>, ProgramProvingReport), zkVMError>;
/// Verifies a proof for the given program
/// TODO: Pass public inputs too and check that they match if they come with the