Struct risc0_zkvm::ExecutorEnvBuilder
source · pub struct ExecutorEnvBuilder<'a> { /* private fields */ }
Expand description
A builder pattern used to construct an ExecutorEnv.
Implementations§
source§impl<'a> ExecutorEnvBuilder<'a>
impl<'a> ExecutorEnvBuilder<'a>
sourcepub fn build(&mut self) -> Result<ExecutorEnv<'a>>
pub fn build(&mut self) -> Result<ExecutorEnv<'a>>
Finalize this builder to construct an ExecutorEnv.
§Example
use risc0_zkvm::ExecutorEnv;
let env = ExecutorEnv::builder().build().unwrap();
After calling build
, the ExecutorEnvBuilder will be reset to
default.
sourcepub fn segment_limit_po2(&mut self, limit: u32) -> &mut Self
pub fn segment_limit_po2(&mut self, limit: u32) -> &mut Self
Set a segment limit, specified in powers of 2 cycles.
Given value must be between risc0_zkp::MIN_CYCLES_PO2 and risc0_zkp::MAX_CYCLES_PO2 (inclusive).
sourcepub fn session_limit(&mut self, limit: Option<u64>) -> &mut Self
pub fn session_limit(&mut self, limit: Option<u64>) -> &mut Self
Set a session limit, specified in number of cycles.
§Example
use risc0_zkvm::ExecutorEnv;
let env = ExecutorEnv::builder()
.session_limit(Some(32 * 1024 * 1024)) // 32M cycles
.build()
.unwrap();
sourcepub fn env_vars(&mut self, vars: HashMap<String, String>) -> &mut Self
pub fn env_vars(&mut self, vars: HashMap<String, String>) -> &mut Self
Add environment variables to the guest environment.
§Example
use std::collections::HashMap;
use risc0_zkvm::ExecutorEnv;
let mut vars = HashMap::new();
vars.insert("VAR1".to_string(), "SOME_VALUE".to_string());
vars.insert("VAR2".to_string(), "SOME_VALUE".to_string());
let env = ExecutorEnv::builder()
.env_vars(vars)
.build()
.unwrap();
sourcepub fn args(&mut self, args: &[String]) -> &mut Self
pub fn args(&mut self, args: &[String]) -> &mut Self
Add an argument array to the guest environment.
§Example
let env = ExecutorEnv::builder()
.args(&["grep".to_string(), "-c".to_string(), "foo".to_string(), "-".to_string()])
.build()
.unwrap();
sourcepub fn env_var(&mut self, name: &str, val: &str) -> &mut Self
pub fn env_var(&mut self, name: &str, val: &str) -> &mut Self
Add an environment variable to the guest environment.
§Example
use risc0_zkvm::ExecutorEnv;
let env = ExecutorEnv::builder()
.env_var("VAR1", "SOME_VALUE")
.build()
.unwrap();
sourcepub fn write<T: Serialize>(&mut self, data: &T) -> Result<&mut Self>
pub fn write<T: Serialize>(&mut self, data: &T) -> Result<&mut Self>
Write input data to the zkVM guest stdin.
This function will serialize data
using a zkVM-optimized codec that
can be deserialized in the guest with a corresponding env::read
with
the same data type.
§Example
use risc0_zkvm::ExecutorEnv;
use serde::Serialize;
#[derive(Serialize)]
struct Input {
a: u32,
b: u32,
}
let input1 = Input{ a: 1, b: 2 };
let input2 = Input{ a: 3, b: 4 };
let env = ExecutorEnv::builder()
.write(&input1).unwrap()
.write(&input2).unwrap()
.build()
.unwrap();
sourcepub fn write_slice<T: Pod>(&mut self, slice: &[T]) -> &mut Self
pub fn write_slice<T: Pod>(&mut self, slice: &[T]) -> &mut Self
Write input data to the zkVM guest stdin.
This function writes a slice directly to the underlying buffer. A
corresponding env::read_slice
can be used within the guest to read the
data.
§Example
use risc0_zkvm::ExecutorEnv;
let slice1 = [0, 1, 2, 3];
let slice2 = [3, 2, 1, 0];
let env = ExecutorEnv::builder()
.write_slice(&slice1)
.write_slice(&slice2)
.build()
.unwrap();
sourcepub fn stdout(&mut self, writer: impl Write + 'a) -> &mut Self
pub fn stdout(&mut self, writer: impl Write + 'a) -> &mut Self
Add a posix-style standard output.
sourcepub fn stderr(&mut self, writer: impl Write + 'a) -> &mut Self
pub fn stderr(&mut self, writer: impl Write + 'a) -> &mut Self
Add a posix-style standard error.
sourcepub fn read_fd(&mut self, fd: u32, reader: impl BufRead + 'a) -> &mut Self
pub fn read_fd(&mut self, fd: u32, reader: impl BufRead + 'a) -> &mut Self
Add a posix-style file descriptor for reading.
sourcepub fn write_fd(&mut self, fd: u32, writer: impl Write + 'a) -> &mut Self
pub fn write_fd(&mut self, fd: u32, writer: impl Write + 'a) -> &mut Self
Add a posix-style file descriptor for writing.
sourcepub fn slice_io(
&mut self,
channel: &str,
handler: impl SliceIo + 'a
) -> &mut Self
pub fn slice_io( &mut self, channel: &str, handler: impl SliceIo + 'a ) -> &mut Self
Add a handler for simple I/O handling.
sourcepub fn io_callback<C: AsRef<str>>(
&mut self,
channel: C,
callback: impl Fn(Bytes) -> Result<Bytes> + 'a
) -> &mut Self
pub fn io_callback<C: AsRef<str>>( &mut self, channel: C, callback: impl Fn(Bytes) -> Result<Bytes> + 'a ) -> &mut Self
Add a handler for simple I/O handling.
sourcepub fn add_assumption(&mut self, assumption: impl Into<Assumption>) -> &mut Self
pub fn add_assumption(&mut self, assumption: impl Into<Assumption>) -> &mut Self
Add an Assumption to the ExecutorEnv, for use in composition.
During execution, when the guest calls env::verify
or
env::verify_integrity
, this collection will be searched for an
Assumption that corresponds the verification call.
Either a crate::Receipt or a crate::ReceiptClaim can be provided. If a crate::Receipt is provided, then then an Assumption::Proven will be added to the ExecutorEnv and the crate::Receipt generated by proving will be unconditional.
sourcepub fn trace_callback(&mut self, callback: impl TraceCallback + 'a) -> &mut Self
pub fn trace_callback(&mut self, callback: impl TraceCallback + 'a) -> &mut Self
Add a callback handler for raw trace messages.
sourcepub fn segment_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self
pub fn segment_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self
Set the path where segments will be stored.
sourcepub fn enable_profiler<P: AsRef<Path>>(&mut self, path: P) -> &mut Self
pub fn enable_profiler<P: AsRef<Path>>(&mut self, path: P) -> &mut Self
Enable the profiler and output results to the specified path.