pub struct ExecutorEnvBuilder<'a> { /* private fields */ }
Expand description

A builder pattern used to construct an ExecutorEnv.

Implementations§

source§

impl<'a> ExecutorEnvBuilder<'a>

source

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.

source

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).

source

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();
source

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();
source

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();
source

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();
source

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();
source

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();
source

pub fn stdin(&mut self, reader: impl Read + 'a) -> &mut Self

Add a posix-style standard input.

source

pub fn stdout(&mut self, writer: impl Write + 'a) -> &mut Self

Add a posix-style standard output.

source

pub fn stderr(&mut self, writer: impl Write + 'a) -> &mut Self

Add a posix-style standard error.

source

pub fn read_fd(&mut self, fd: u32, reader: impl BufRead + 'a) -> &mut Self

Add a posix-style file descriptor for reading.

source

pub fn write_fd(&mut self, fd: u32, writer: impl Write + 'a) -> &mut Self

Add a posix-style file descriptor for writing.

source

pub fn slice_io( &mut self, channel: &str, handler: impl SliceIo + 'a ) -> &mut Self

Add a handler for simple I/O handling.

source

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.

source

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.

source

pub fn trace_callback(&mut self, callback: impl TraceCallback + 'a) -> &mut Self

Add a callback handler for raw trace messages.

source

pub fn segment_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self

Set the path where segments will be stored.

source

pub fn enable_profiler<P: AsRef<Path>>(&mut self, path: P) -> &mut Self

Enable the profiler and output results to the specified path.

Trait Implementations§

source§

impl<'a> Default for ExecutorEnvBuilder<'a>

source§

fn default() -> ExecutorEnvBuilder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ExecutorEnvBuilder<'a>

§

impl<'a> !RefUnwindSafe for ExecutorEnvBuilder<'a>

§

impl<'a> !Send for ExecutorEnvBuilder<'a>

§

impl<'a> !Sync for ExecutorEnvBuilder<'a>

§

impl<'a> Unpin for ExecutorEnvBuilder<'a>

§

impl<'a> !UnwindSafe for ExecutorEnvBuilder<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more