From 5c30c4c1a84531bef6ca1eace76d7c37043508dc Mon Sep 17 00:00:00 2001 From: Zach Obront Date: Tue, 23 Jul 2024 13:11:54 -0500 Subject: [PATCH] feat: add zkvm target for io (#394) * recreate old zkvm io * lint --- crates/common/src/io.rs | 5 ++++- crates/common/src/lib.rs | 3 +++ crates/common/src/zkvm/io.rs | 20 ++++++++++++++++++++ crates/common/src/zkvm/mod.rs | 3 +++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 crates/common/src/zkvm/io.rs create mode 100644 crates/common/src/zkvm/mod.rs diff --git a/crates/common/src/io.rs b/crates/common/src/io.rs index 611540ac..19481227 100644 --- a/crates/common/src/io.rs +++ b/crates/common/src/io.rs @@ -12,6 +12,9 @@ cfg_if! { } else if #[cfg(target_arch = "riscv64")] { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `riscv64` target architecture."] pub type ClientIO = crate::asterisc::io::AsteriscIO; + } else if #[cfg(target_os = "zkvm")] { + #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `SP1` target architecture."] + pub type ClientIO = crate::zkvm::io::ZkvmIO; } else { #[doc = "Concrete implementation of the [BasicKernelInterface] trait for the `native` target architecture."] pub type ClientIO = native_io::NativeIO; @@ -54,7 +57,7 @@ pub fn exit(code: usize) -> ! { ClientIO::exit(code) } -#[cfg(not(any(target_arch = "mips", target_arch = "riscv64")))] +#[cfg(not(any(target_arch = "mips", target_arch = "riscv64", target_os = "zkvm")))] mod native_io { extern crate std; diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 59945c94..9d54a5dd 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -25,3 +25,6 @@ pub(crate) mod cannon; #[cfg(target_arch = "riscv64")] pub(crate) mod asterisc; + +#[cfg(target_os = "zkvm")] +pub(crate) mod zkvm; diff --git a/crates/common/src/zkvm/io.rs b/crates/common/src/zkvm/io.rs new file mode 100644 index 00000000..20d107d6 --- /dev/null +++ b/crates/common/src/zkvm/io.rs @@ -0,0 +1,20 @@ +use crate::{BasicKernelInterface, FileDescriptor}; +use anyhow::Result; + +/// Concrete implementation of the [`KernelIO`] trait for the `SP1` target architecture. +#[derive(Debug)] +pub struct ZkvmIO; + +impl BasicKernelInterface for ZkvmIO { + fn write(_fd: FileDescriptor, _buf: &[u8]) -> Result { + unimplemented!(); + } + + fn read(_fd: FileDescriptor, _buf: &mut [u8]) -> Result { + unimplemented!(); + } + + fn exit(_code: usize) -> ! { + unimplemented!(); + } +} diff --git a/crates/common/src/zkvm/mod.rs b/crates/common/src/zkvm/mod.rs new file mode 100644 index 00000000..9e71ea8c --- /dev/null +++ b/crates/common/src/zkvm/mod.rs @@ -0,0 +1,3 @@ +//! This module contains raw syscall bindings for the `ZKVM` compilation context. + +pub(crate) mod io;