Struct sp1_core::runtime::Runtime

source ·
pub struct Runtime<'a> {
Show 20 fields pub program: Arc<Program>, pub state: ExecutionState, pub record: ExecutionRecord, pub records: Vec<ExecutionRecord>, pub memory_accesses: MemoryAccessRecord, pub shard_size: u32, pub shard_batch_size: u32, pub cycle_tracker: HashMap<String, (u64, u32)>, pub io_buf: HashMap<u32, String>, pub trace_buf: Option<BufWriter<File>>, pub unconstrained: bool, pub syscall_map: HashMap<SyscallCode, Arc<dyn Syscall>>, pub max_syscall_cycles: u32, pub emit_events: bool, pub report: ExecutionReport, pub print_report: bool, pub subproof_verifier: Arc<dyn SubproofVerifier + 'a>, pub hook_registry: HookRegistry<'a>, pub opts: SP1CoreOpts, pub max_cycles: Option<u64>, /* private fields */
}
Expand description

An implementation of a runtime for the SP1 RISC-V zkVM.

The runtime is responsible for executing a user program and tracing important events which occur during execution (i.e., memory reads, alu operations, etc).

For more information on the RV32IM instruction set, see the following: https://www.cs.sfu.ca/~ashriram/Courses/CS295/assets/notebooks/RISCV/RISCV_CARD.pdf

Fields§

§program: Arc<Program>

The program.

§state: ExecutionState

The state of the execution.

§record: ExecutionRecord

The current trace of the execution that is being collected.

§records: Vec<ExecutionRecord>

The collected records, split by cpu cycles.

§memory_accesses: MemoryAccessRecord

The memory accesses for the current cycle.

§shard_size: u32

The maximum size of each shard.

§shard_batch_size: u32§cycle_tracker: HashMap<String, (u64, u32)>

A counter for the number of cycles that have been executed in certain functions.

§io_buf: HashMap<u32, String>

A buffer for stdout and stderr IO.

§trace_buf: Option<BufWriter<File>>

A buffer for writing trace events to a file.

§unconstrained: bool

Whether the runtime is in constrained mode or not.

In unconstrained mode, any events, clock, register, or memory changes are reset after leaving the unconstrained block. The only thing preserved is writes to the input stream.

§syscall_map: HashMap<SyscallCode, Arc<dyn Syscall>>

The mapping between syscall codes and their implementations.

§max_syscall_cycles: u32

The maximum number of cycles for a syscall.

§emit_events: bool

Whether to emit events during execution.

§report: ExecutionReport

Report of the program execution.

§print_report: bool

Whether we should write to the report.

§subproof_verifier: Arc<dyn SubproofVerifier + 'a>

Verifier used to sanity check verify_sp1_proof during runtime.

§hook_registry: HookRegistry<'a>

Registry of hooks, to be invoked by writing to certain file descriptors.

§opts: SP1CoreOpts§max_cycles: Option<u64>

The maximum number of cpu cycles to use for execution.

Implementations§

source§

impl<'a> Runtime<'a>

source

pub fn write_stdin<T: Serialize>(&mut self, input: &T)

source

pub fn write_stdin_slice(&mut self, input: &[u8])

source

pub fn write_vecs(&mut self, inputs: &[Vec<u8>])

source

pub fn write_proof( &mut self, proof: ShardProof<BabyBearPoseidon2>, vk: StarkVerifyingKey<BabyBearPoseidon2>, )

source

pub fn read_public_values<T: DeserializeOwned>(&mut self) -> T

source

pub fn read_public_values_slice(&mut self, buf: &mut [u8])

source§

impl<'a> Runtime<'a>

source

pub fn log(&mut self, instruction: &Instruction)

source§

impl<'a> Runtime<'a>

source

pub fn new(program: Program, opts: SP1CoreOpts) -> Self

source

pub fn with_context( program: Program, opts: SP1CoreOpts, context: SP1Context<'a>, ) -> Self

Create a new runtime from a program, options, and a context.

source

pub fn hook(&self, fd: u32, buf: &[u8]) -> Vec<Vec<u8>>

Invokes the hook corresponding to the given file descriptor fd with the data buf, returning the resulting data.

source

pub fn hook_env<'b>(&'b self) -> HookEnv<'b, 'a>

Prepare a HookEnv for use by hooks.

source

pub fn recover( program: Program, state: ExecutionState, opts: SP1CoreOpts, ) -> Self

Recover runtime state from a program and existing execution state.

source

pub fn registers(&self) -> [u32; 32]

Get the current values of the registers.

source

pub fn register(&self, register: Register) -> u32

Get the current value of a register.

source

pub fn word(&self, addr: u32) -> u32

Get the current value of a word.

source

pub fn byte(&self, addr: u32) -> u8

Get the current value of a byte.

source

pub const fn timestamp(&self, position: &MemoryAccessPosition) -> u32

Get the current timestamp for a given memory access position.

source

pub fn shard(&self) -> u32

Get the current shard.

source

pub fn channel(&self) -> u32

source

pub fn mr(&mut self, addr: u32, shard: u32, timestamp: u32) -> MemoryReadRecord

Read a word from memory and create an access record.

source

pub fn mw( &mut self, addr: u32, value: u32, shard: u32, timestamp: u32, ) -> MemoryWriteRecord

Write a word to memory and create an access record.

source

pub fn mr_cpu(&mut self, addr: u32, position: MemoryAccessPosition) -> u32

Read from memory, assuming that all addresses are aligned.

source

pub fn mw_cpu(&mut self, addr: u32, value: u32, position: MemoryAccessPosition)

Write to memory.

source

pub fn rr(&mut self, register: Register, position: MemoryAccessPosition) -> u32

Read from a register.

source

pub fn rw(&mut self, register: Register, value: u32)

Write to a register.

source

pub fn bump_record(&mut self)

source

pub fn execute_record( &mut self, ) -> Result<(Vec<ExecutionRecord>, bool), ExecutionError>

Execute up to self.shard_batch_size cycles, returning the events emitted and whether the program ended.

source

pub fn execute_state( &mut self, ) -> Result<(ExecutionState, bool), ExecutionError>

Execute up to self.shard_batch_size cycles, returning a copy of the prestate and whether the program ended.

source

pub fn run_untraced(&mut self) -> Result<(), ExecutionError>

source

pub fn run(&mut self) -> Result<(), ExecutionError>

source

pub fn dry_run(&mut self)

Trait Implementations§

source§

impl<'a> Read for Runtime<'a>

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Runtime<'a>

§

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

§

impl<'a> Send for Runtime<'a>

§

impl<'a> Sync for Runtime<'a>

§

impl<'a> Unpin for Runtime<'a>

§

impl<'a> !UnwindSafe for Runtime<'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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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
source§

impl<T> JsonSchemaMaybe for T