1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use zisk_common::io::StreamSource;
use serde::Serialize;
use std::path::Path;
use crate::input_stream::ZiskStream;
use crate::{Result, SdkError};
/// Source of hints for a guest program execution or proof.
///
/// - `Hints(ZiskHints)` — inline hints data (memory or file)
/// - `Stream(ZiskStream)` — hints delivered via a live gRPC stream
pub enum HintsSource {
/// Inline hints data, either from memory or a file.
Hints(Box<ZiskHints>),
/// Streamed hints.
Stream(Box<ZiskStream>),
}
impl From<ZiskHints> for HintsSource {
fn from(h: ZiskHints) -> Self {
HintsSource::Hints(Box::new(h))
}
}
impl From<ZiskStream> for HintsSource {
fn from(s: ZiskStream) -> Self {
HintsSource::Stream(Box::new(s))
}
}
/// Hints source for a guest program execution or proof.
pub struct ZiskHints {
source: StreamSource,
}
impl ZiskHints {
/// Creates a new empty memory-based hints source.
pub fn new() -> Self {
Self { source: StreamSource::from_vec(Vec::new()) }
}
/// Creates hints from raw bytes.
pub fn memory(data: impl AsRef<[u8]>) -> Self {
Self { source: StreamSource::from_slice(data.as_ref()) }
}
/// Creates hints from a serializable data structure.
pub fn from<T: Serialize>(data: &T) -> Self {
Self {
source: StreamSource::from_vec(
bincode::serde::encode_to_vec(data, bincode::config::standard())
.expect("Failed to serialize hints data"),
),
}
}
/// Creates hints from a file path.
///
/// # Errors
/// Returns an error if the file does not exist or is not accessible.
pub fn from_file(path: impl AsRef<Path>) -> Result<Self> {
let path = path.as_ref();
if !path.exists() {
return Err(SdkError::InvalidConfig(format!(
"Hints file not found: {}",
path.display()
)));
}
Ok(Self { source: StreamSource::from_file(path).map_err(SdkError::backend)? })
}
/// Creates hints from a URI string.
///
/// # Supported Schemes
/// - `file://path/to/file` → File-based stream
/// - `unix://path/to/socket` → Unix domain socket stream
/// - `quic://host:port` → QUIC network stream
/// - No scheme → treated as a file path
///
/// # Errors
/// Returns an error if the URI scheme is unknown or the resource is not accessible.
pub fn from_uri<S: Into<String>>(uri: S) -> Result<Self> {
Ok(Self { source: StreamSource::from_uri(uri).map_err(SdkError::backend)? })
}
pub(crate) fn into_inner(self) -> StreamSource {
self.source
}
}
impl Default for ZiskHints {
fn default() -> Self {
Self::new()
}
}