mirror of
https://github.com/eth-act/ere.git
synced 2026-02-19 11:54:42 -05:00
InputErased -> Input
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use zkvm_interface::InputErased;
|
||||
use zkvm_interface::Input;
|
||||
|
||||
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: InputErased,
|
||||
_outputs: InputErased,
|
||||
_inputs: Input,
|
||||
_outputs: Input,
|
||||
preprocessing: jolt::JoltVerifierPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript>,
|
||||
) -> bool {
|
||||
use jolt::{Jolt, RV32IJoltVM, tracer};
|
||||
@@ -70,7 +70,7 @@ pub fn verify_generic(
|
||||
pub fn prove_generic(
|
||||
program: &jolt::host::Program,
|
||||
preprocessing: jolt::JoltProverPreprocessing<4, jolt::F, jolt::PCS, jolt::ProofTranscript>,
|
||||
_inputs: &InputErased,
|
||||
_inputs: &Input,
|
||||
) -> (Vec<u8>, jolt::JoltHyperKZGProof) {
|
||||
use jolt::{Jolt, RV32IJoltVM};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use utils::{
|
||||
serialize_public_input_with_proof,
|
||||
};
|
||||
use zkvm_interface::{
|
||||
Compiler, InputErased, ProgramExecutionReport, ProgramProvingReport, ProverResourceType, zkVM,
|
||||
Compiler, Input, ProgramExecutionReport, ProgramProvingReport, ProverResourceType, zkVM,
|
||||
zkVMError,
|
||||
};
|
||||
|
||||
@@ -52,7 +52,7 @@ impl EreJolt {
|
||||
impl zkVM for EreJolt {
|
||||
fn execute(
|
||||
&self,
|
||||
_inputs: &InputErased,
|
||||
_inputs: &Input,
|
||||
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
// TODO: check ProgramSummary
|
||||
// TODO: FIXME
|
||||
@@ -68,7 +68,7 @@ impl zkVM for EreJolt {
|
||||
|
||||
fn prove(
|
||||
&self,
|
||||
inputs: &InputErased,
|
||||
inputs: &Input,
|
||||
) -> 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);
|
||||
@@ -88,12 +88,12 @@ impl zkVM for EreJolt {
|
||||
let (public_inputs, proof) =
|
||||
deserialize_public_input_with_proof(proof_with_public_inputs).unwrap();
|
||||
|
||||
let mut outputs = InputErased::new();
|
||||
let mut outputs = Input::new();
|
||||
assert!(public_inputs.is_empty());
|
||||
outputs.write(public_inputs);
|
||||
|
||||
// TODO: I don't think we should require the inputs when verifying
|
||||
let inputs = InputErased::new();
|
||||
let inputs = Input::new();
|
||||
|
||||
let valid = verify_generic(proof, inputs, outputs, preprocessed_verifier);
|
||||
if valid {
|
||||
@@ -108,7 +108,7 @@ impl zkVM for EreJolt {
|
||||
mod tests {
|
||||
use crate::{EreJolt, JOLT_TARGET};
|
||||
use std::path::PathBuf;
|
||||
use zkvm_interface::{Compiler, InputErased, ProverResourceType, zkVM};
|
||||
use zkvm_interface::{Compiler, Input, ProverResourceType, zkVM};
|
||||
|
||||
// TODO: for now, we just get one test file
|
||||
// TODO: but this should get the whole directory and compile each test
|
||||
@@ -135,7 +135,7 @@ 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 = InputErased::new();
|
||||
let mut inputs = Input::new();
|
||||
inputs.write(1 as u32);
|
||||
|
||||
let zkvm = EreJolt::new(program, ProverResourceType::Cpu);
|
||||
|
||||
@@ -12,7 +12,7 @@ use openvm_stark_sdk::config::{
|
||||
};
|
||||
use openvm_transpiler::elf::Elf;
|
||||
use zkvm_interface::{
|
||||
Compiler, InputErased, InputItem, ProgramExecutionReport, ProgramProvingReport,
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport,
|
||||
ProverResourceType, zkVM, zkVMError,
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ impl EreOpenVM {
|
||||
impl zkVM for EreOpenVM {
|
||||
fn execute(
|
||||
&self,
|
||||
inputs: &InputErased,
|
||||
inputs: &Input,
|
||||
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
let sdk = Sdk::new();
|
||||
let vm_cfg = SdkVmConfig::builder()
|
||||
@@ -92,7 +92,7 @@ impl zkVM for EreOpenVM {
|
||||
|
||||
fn prove(
|
||||
&self,
|
||||
inputs: &InputErased,
|
||||
inputs: &Input,
|
||||
) -> 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.
|
||||
@@ -200,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 = InputErased::new();
|
||||
let empty_input = Input::new();
|
||||
let zkvm = EreOpenVM::new(elf, ProverResourceType::Cpu);
|
||||
|
||||
zkvm.execute(&empty_input).unwrap();
|
||||
@@ -210,7 +210,7 @@ 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 = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
input.write(10u64);
|
||||
|
||||
let zkvm = EreOpenVM::new(elf, ProverResourceType::Cpu);
|
||||
@@ -221,7 +221,7 @@ 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 = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
input.write(10u64);
|
||||
|
||||
let zkvm = EreOpenVM::new(elf, ProverResourceType::Cpu);
|
||||
|
||||
@@ -66,14 +66,14 @@ impl ErePico {
|
||||
impl zkVM for ErePico {
|
||||
fn execute(
|
||||
&self,
|
||||
_inputs: &zkvm_interface::InputErased,
|
||||
_inputs: &zkvm_interface::Input,
|
||||
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
todo!("pico currently does not have an execute method exposed via the SDK")
|
||||
}
|
||||
|
||||
fn prove(
|
||||
&self,
|
||||
inputs: &zkvm_interface::InputErased,
|
||||
inputs: &zkvm_interface::Input,
|
||||
) -> Result<(Vec<u8>, zkvm_interface::ProgramProvingReport), zkVMError> {
|
||||
let client = DefaultProverClient::new(&self.program);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use compile::compile_risczero_program;
|
||||
use risc0_zkvm::{ExecutorEnv, Receipt, default_executor, default_prover};
|
||||
use zkvm_interface::{
|
||||
Compiler, Input, ProgramExecutionReport, ProgramProvingReport, ProverResourceType, zkVM,
|
||||
zkVMError,
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport, ProverResourceType,
|
||||
zkVM, zkVMError,
|
||||
};
|
||||
|
||||
mod compile;
|
||||
@@ -44,10 +44,18 @@ pub struct EreRisc0 {
|
||||
impl zkVM for EreRisc0 {
|
||||
fn execute(&self, inputs: &Input) -> Result<ProgramExecutionReport, zkVMError> {
|
||||
let executor = default_executor();
|
||||
let env = ExecutorEnv::builder()
|
||||
.write_slice(inputs.bytes())
|
||||
.build()
|
||||
.map_err(|err| zkVMError::Other(err.into()))?;
|
||||
let mut env = ExecutorEnv::builder();
|
||||
for input in inputs.iter() {
|
||||
match input {
|
||||
InputItem::Object(serialize) => {
|
||||
env.write(serialize).unwrap();
|
||||
}
|
||||
InputItem::Bytes(items) => {
|
||||
env.write_slice(&items);
|
||||
}
|
||||
}
|
||||
}
|
||||
let env = env.build().map_err(|err| zkVMError::Other(err.into()))?;
|
||||
|
||||
let session_info = executor
|
||||
.execute(env, &self.program.elf)
|
||||
@@ -60,10 +68,18 @@ impl zkVM for EreRisc0 {
|
||||
|
||||
fn prove(&self, inputs: &Input) -> Result<(Vec<u8>, ProgramProvingReport), zkVMError> {
|
||||
let prover = default_prover();
|
||||
let env = ExecutorEnv::builder()
|
||||
.write_slice(inputs.bytes())
|
||||
.build()
|
||||
.map_err(|err| zkVMError::Other(err.into()))?;
|
||||
let mut env = ExecutorEnv::builder();
|
||||
for input in inputs.iter() {
|
||||
match input {
|
||||
InputItem::Object(serialize) => {
|
||||
env.write(serialize).unwrap();
|
||||
}
|
||||
InputItem::Bytes(items) => {
|
||||
env.write_slice(&items);
|
||||
}
|
||||
}
|
||||
}
|
||||
let env = env.build().map_err(|err| zkVMError::Other(err.into()))?;
|
||||
|
||||
let now = std::time::Instant::now();
|
||||
let prove_info = prover
|
||||
@@ -116,8 +132,8 @@ mod prove_tests {
|
||||
let mut input_builder = Input::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 = EreRisc0::new(program, ProverResourceType::Cpu);
|
||||
|
||||
@@ -180,8 +196,8 @@ mod execute_tests {
|
||||
let mut input_builder = Input::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 = EreRisc0::new(program, ProverResourceType::Cpu);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use sp1_sdk::{
|
||||
};
|
||||
use tracing::info;
|
||||
use zkvm_interface::{
|
||||
Compiler, InputErased, InputItem, ProgramExecutionReport, ProgramProvingReport,
|
||||
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport,
|
||||
ProverResourceType, zkVM, zkVMError,
|
||||
};
|
||||
|
||||
@@ -116,7 +116,7 @@ impl EreSP1 {
|
||||
impl zkVM for EreSP1 {
|
||||
fn execute(
|
||||
&self,
|
||||
inputs: &InputErased,
|
||||
inputs: &Input,
|
||||
) -> Result<zkvm_interface::ProgramExecutionReport, zkVMError> {
|
||||
let mut stdin = SP1Stdin::new();
|
||||
for input in inputs.iter() {
|
||||
@@ -139,7 +139,7 @@ impl zkVM for EreSP1 {
|
||||
|
||||
fn prove(
|
||||
&self,
|
||||
inputs: &zkvm_interface::InputErased,
|
||||
inputs: &zkvm_interface::Input,
|
||||
) -> Result<(Vec<u8>, zkvm_interface::ProgramProvingReport), zkVMError> {
|
||||
info!("Generating proof…");
|
||||
|
||||
@@ -178,7 +178,7 @@ mod execute_tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
use zkvm_interface::InputErased;
|
||||
use zkvm_interface::Input;
|
||||
|
||||
fn get_compiled_test_sp1_elf() -> Result<Vec<u8>, SP1Error> {
|
||||
let test_guest_path = get_execute_test_guest_program_path();
|
||||
@@ -201,7 +201,7 @@ 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 = InputErased::new();
|
||||
let mut input_builder = Input::new();
|
||||
let n: u32 = 42;
|
||||
let a: u16 = 42;
|
||||
input_builder.write(n);
|
||||
@@ -221,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 = InputErased::new();
|
||||
let empty_input = Input::new();
|
||||
|
||||
let zkvm = EreSP1::new(elf_bytes, ProverResourceType::Cpu);
|
||||
let result = zkvm.execute(&empty_input);
|
||||
@@ -238,7 +238,7 @@ mod prove_tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use super::*;
|
||||
use zkvm_interface::InputErased;
|
||||
use zkvm_interface::Input;
|
||||
|
||||
fn get_prove_test_guest_program_path() -> PathBuf {
|
||||
let workspace_dir = env!("CARGO_WORKSPACE_DIR");
|
||||
@@ -261,7 +261,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 mut input_builder = InputErased::new();
|
||||
let mut input_builder = Input::new();
|
||||
let n: u32 = 42;
|
||||
let a: u16 = 42;
|
||||
input_builder.write(n);
|
||||
@@ -290,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 = InputErased::new();
|
||||
let empty_input = Input::new();
|
||||
|
||||
let zkvm = EreSP1::new(elf_bytes, ProverResourceType::Cpu);
|
||||
let prove_result = zkvm.prove(&empty_input);
|
||||
|
||||
@@ -9,16 +9,16 @@ pub enum InputItem {
|
||||
}
|
||||
|
||||
/// Represents a builder for input data to be passed to a ZKVM guest program.
|
||||
pub struct InputErased {
|
||||
pub struct Input {
|
||||
items: Vec<InputItem>,
|
||||
}
|
||||
impl Default for InputErased {
|
||||
impl Default for Input {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl InputErased {
|
||||
impl Input {
|
||||
/// Create an empty input buffer.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -96,7 +96,7 @@ mod input_erased_tests {
|
||||
|
||||
#[test]
|
||||
fn test_write_object() {
|
||||
let mut input = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
|
||||
let person = Person {
|
||||
name: "Alice".to_string(),
|
||||
@@ -114,7 +114,7 @@ mod input_erased_tests {
|
||||
|
||||
#[test]
|
||||
fn test_write_bytes() {
|
||||
let mut input = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
|
||||
let bytes = vec![1, 2, 3, 4, 5];
|
||||
input.write_bytes(bytes.clone());
|
||||
@@ -129,7 +129,7 @@ mod input_erased_tests {
|
||||
|
||||
#[test]
|
||||
fn test_write_serialized() {
|
||||
let mut input = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
|
||||
let person = Person {
|
||||
name: "Bob".to_string(),
|
||||
@@ -150,7 +150,7 @@ mod input_erased_tests {
|
||||
|
||||
#[test]
|
||||
fn test_mixed_usage() {
|
||||
let mut input = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
|
||||
let person = Person {
|
||||
name: "Charlie".to_string(),
|
||||
@@ -187,7 +187,7 @@ mod input_erased_tests {
|
||||
|
||||
#[test]
|
||||
fn test_as_bytes() {
|
||||
let mut input = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
|
||||
// Add an object
|
||||
input.write(42i32);
|
||||
@@ -208,7 +208,7 @@ mod input_erased_tests {
|
||||
|
||||
#[test]
|
||||
fn test_iteration() {
|
||||
let mut input = InputErased::new();
|
||||
let mut input = Input::new();
|
||||
|
||||
input.write(1);
|
||||
input.write(2);
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{path::Path, time::Duration};
|
||||
use thiserror::Error;
|
||||
|
||||
mod input;
|
||||
pub use input::{InputErased, InputItem};
|
||||
pub use input::{Input, InputItem};
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
/// Compiler trait for compiling programs into an opaque sequence of bytes.
|
||||
@@ -44,10 +44,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: &InputErased) -> Result<ProgramExecutionReport, zkVMError>;
|
||||
fn execute(&self, inputs: &Input) -> Result<ProgramExecutionReport, zkVMError>;
|
||||
|
||||
/// Creates a proof for a given program
|
||||
fn prove(&self, inputs: &InputErased) -> Result<(Vec<u8>, ProgramProvingReport), zkVMError>;
|
||||
fn prove(&self, inputs: &Input) -> 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
|
||||
|
||||
Reference in New Issue
Block a user