From 33085b7319539ee166b734e602665760f666e875 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Sun, 11 May 2025 22:21:18 +0100 Subject: [PATCH] Program now is AsRef<[u8>] --- crates/zkvm-interface/src/lib.rs | 40 ++++---------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/crates/zkvm-interface/src/lib.rs b/crates/zkvm-interface/src/lib.rs index 814da75..59c1266 100644 --- a/crates/zkvm-interface/src/lib.rs +++ b/crates/zkvm-interface/src/lib.rs @@ -1,13 +1,15 @@ use indexmap::IndexMap; -use serde::Serialize; use std::{path::Path, time::Duration}; +mod input; +pub use input::Input; + #[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; + type Program: AsRef<[u8]> + Clone + Send + Sync; /// Compiles the program and returns the program fn compile(path_to_program: &Path) -> Result; @@ -72,37 +74,3 @@ impl ProgramProvingReport { Self { proving_time } } } - -/// Represents a builder for input data to be passed to a ZKVM guest program. -/// Values are serialized sequentially into an internal byte buffer. -#[derive(Debug, Clone, Default)] // Added Default for easy initialization -pub struct Input { - // TODO: Succinct has Vec while R0 has Vec - // TODO: Maybe change back to Vec with markers for perf - pub data: Vec>, -} - -impl Input { - pub fn new() -> Self { - Input { data: Vec::new() } - } - - /// Serializes the given value using bincode and appends it to the internal data buffer. - pub fn write(&mut self, value: &T) -> anyhow::Result<()> { - // TODO: Remove anyhow::error for thiserror - use anyhow::Context; - - let mut data = Vec::new(); - - let _ = bincode::serialize_into(&mut data, value).with_context(|| { - format!( - "Failed to serialize and write value of type {}", - std::any::type_name::() - ) - })?; - - self.data.push(data); - - Ok(()) - } -}