pub struct Executor<'a> {Show 33 fields
pub program: Arc<Program>,
pub state: ExecutionState,
pub memory_checkpoint: Memory<Option<MemoryRecord>>,
pub uninitialized_memory_checkpoint: Memory<bool>,
pub report: ExecutionReport,
pub executor_mode: ExecutorMode,
pub memory_accesses: MemoryAccessRecord,
pub unconstrained: bool,
pub print_report: bool,
pub record_estimator: Option<Box<RecordEstimator>>,
pub emit_global_memory_events: bool,
pub shard_size: u32,
pub shard_batch_size: u32,
pub max_syscall_cycles: u32,
pub syscall_map: HashMap<SyscallCode, Arc<dyn Syscall>>,
pub opts: SP1CoreOpts,
pub max_cycles: Option<u64>,
pub record: Box<ExecutionRecord>,
pub records: Vec<Box<ExecutionRecord>>,
pub local_memory_access: HashMap<u32, MemoryLocalEvent>,
pub cycle_tracker: HashMap<String, (u64, u32)>,
pub io_buf: HashMap<u32, String>,
pub unconstrained_state: Box<ForkState>,
pub local_counts: LocalCounts,
pub subproof_verifier: Option<&'a dyn SubproofVerifier>,
pub hook_registry: HookRegistry<'a>,
pub maximal_shapes: Option<MaximalShapes>,
pub costs: HashMap<RiscvAirId, u64>,
pub deferred_proof_verification: DeferredProofVerification,
pub shape_check_frequency: u64,
pub lde_size_check: bool,
pub lde_size_threshold: u64,
pub io_options: IoOptions<'a>,
/* private fields */
}
Expand description
An executor for the SP1 RISC-V zkVM.
The exeuctor is responsible for executing a user program and tracing important events which occur during execution (i.e., memory reads, alu operations, etc).
Fields§
§program: Arc<Program>
The program.
state: ExecutionState
The state of the execution.
memory_checkpoint: Memory<Option<MemoryRecord>>
Memory addresses that were touched in this batch of shards. Used to minimize the size of checkpoints.
uninitialized_memory_checkpoint: Memory<bool>
Memory addresses that were initialized in this batch of shards. Used to minimize the size of checkpoints. The value stored is whether or not it had a value at the beginning of the batch.
report: ExecutionReport
Report of the program execution.
executor_mode: ExecutorMode
The mode the executor is running in.
memory_accesses: MemoryAccessRecord
The memory accesses for the current cycle.
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.
print_report: bool
Whether we should write to the report.
record_estimator: Option<Box<RecordEstimator>>
Data used to estimate total trace area.
emit_global_memory_events: bool
Whether we should emit global memory init and finalize events. This can be enabled in Checkpoint mode and disabled in Trace mode.
shard_size: u32
The maximum size of each shard.
shard_batch_size: u32
The maximum number of shards to execute at once.
max_syscall_cycles: u32
The maximum number of cycles for a syscall.
syscall_map: HashMap<SyscallCode, Arc<dyn Syscall>>
The mapping between syscall codes and their implementations.
opts: SP1CoreOpts
The options for the runtime.
max_cycles: Option<u64>
The maximum number of cpu cycles to use for execution.
record: Box<ExecutionRecord>
The current trace of the execution that is being collected.
records: Vec<Box<ExecutionRecord>>
The collected records, split by cpu cycles.
local_memory_access: HashMap<u32, MemoryLocalEvent>
Local memory access events.
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.
unconstrained_state: Box<ForkState>
The state of the runtime when in unconstrained mode.
local_counts: LocalCounts
Statistics for event counts.
subproof_verifier: Option<&'a dyn SubproofVerifier>
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.
maximal_shapes: Option<MaximalShapes>
The maximal shapes for the program.
costs: HashMap<RiscvAirId, u64>
The costs of the program.
deferred_proof_verification: DeferredProofVerification
Skip deferred proof verification. This check is informational only, not related to circuit correctness.
shape_check_frequency: u64
The frequency to check the stopping condition.
lde_size_check: bool
Early exit if the estimate LDE size is too big.
lde_size_threshold: u64
The maximum LDE size to allow.
io_options: IoOptions<'a>
The options for the IO.
Implementations§
Source§impl<'a> Executor<'a>
impl<'a> Executor<'a>
Sourcepub fn new(program: Program, opts: SP1CoreOpts) -> Self
pub fn new(program: Program, opts: SP1CoreOpts) -> Self
Create a new Executor
from a program and options.
Sourcepub fn maybe_setup_profiler(&mut self, elf_bytes: &[u8])
pub fn maybe_setup_profiler(&mut self, elf_bytes: &[u8])
WARNING: This function’s API is subject to change without a major version bump.
If the feature "profiling"
is enabled, this sets up the profiler. Otherwise, it does
nothing. The argument elf_bytes
must describe the same program as self.program
.
The profiler is configured by the following environment variables:
TRACE_FILE
: writes Gecko traces to this path. If unspecified, the profiler is disabled.TRACE_SAMPLE_RATE
: The period between clock cycles where samples are taken. Defaults to 1.
Sourcepub fn with_context(
program: Program,
opts: SP1CoreOpts,
context: SP1Context<'a>,
) -> Self
pub fn with_context( program: Program, opts: SP1CoreOpts, context: SP1Context<'a>, ) -> Self
Create a new runtime from a program, options, and a context.
Sourcepub fn hook(&self, fd: u32, buf: &[u8]) -> Result<Vec<Vec<u8>>>
pub fn hook(&self, fd: u32, buf: &[u8]) -> Result<Vec<Vec<u8>>>
Invokes a hook with the given file descriptor fd
with the data buf
.
§Errors
If the file descriptor is not found in the HookRegistry
, this function will return an
error.
Sourcepub fn recover(
program: Program,
state: ExecutionState,
opts: SP1CoreOpts,
) -> Self
pub fn recover( program: Program, state: ExecutionState, opts: SP1CoreOpts, ) -> Self
Recover runtime state from a program and existing execution state.
Sourcepub fn word(&mut self, addr: u32) -> u32
pub fn word(&mut self, addr: u32) -> u32
Get the current value of a word.
Assumes addr
is a valid memory address, not a register.
Sourcepub fn byte(&mut self, addr: u32) -> u8
pub fn byte(&mut self, addr: u32) -> u8
Get the current value of a byte.
Assumes addr
is a valid memory address, not a register.
Sourcepub const fn timestamp(&self, position: &MemoryAccessPosition) -> u32
pub const fn timestamp(&self, position: &MemoryAccessPosition) -> u32
Get the current timestamp for a given memory access position.
Sourcepub fn mr(
&mut self,
addr: u32,
shard: u32,
timestamp: u32,
local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>,
) -> MemoryReadRecord
pub fn mr( &mut self, addr: u32, shard: u32, timestamp: u32, local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>, ) -> MemoryReadRecord
Read a word from memory and create an access record.
Sourcepub fn rr(&mut self, register: Register, shard: u32, timestamp: u32) -> u32
pub fn rr(&mut self, register: Register, shard: u32, timestamp: u32) -> u32
Read a register and return its value.
Assumes that the executor mode IS NOT ExecutorMode::Trace
Sourcepub fn rr_traced(
&mut self,
register: Register,
shard: u32,
timestamp: u32,
local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>,
) -> MemoryReadRecord
pub fn rr_traced( &mut self, register: Register, shard: u32, timestamp: u32, local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>, ) -> MemoryReadRecord
Read a register and create an access record.
Assumes that self.mode IS ExecutorMode::Trace
.
Sourcepub fn mw(
&mut self,
addr: u32,
value: u32,
shard: u32,
timestamp: u32,
local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>,
) -> MemoryWriteRecord
pub fn mw( &mut self, addr: u32, value: u32, shard: u32, timestamp: u32, local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>, ) -> MemoryWriteRecord
Write a word to memory and create an access record.
Sourcepub fn rw_traced(
&mut self,
register: Register,
value: u32,
shard: u32,
timestamp: u32,
local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>,
) -> MemoryWriteRecord
pub fn rw_traced( &mut self, register: Register, value: u32, shard: u32, timestamp: u32, local_memory_access: Option<&mut HashMap<u32, MemoryLocalEvent>>, ) -> MemoryWriteRecord
Write a word to a register and create an access record.
Assumes that self.mode IS ExecutorMode::Trace
.
Sourcepub fn rw(&mut self, register: Register, value: u32, shard: u32, timestamp: u32)
pub fn rw(&mut self, register: Register, value: u32, shard: u32, timestamp: u32)
Write a word to a register and create an access record.
Assumes that the executor mode IS NOT ExecutorMode::Trace
.
Sourcepub fn mr_cpu(&mut self, addr: u32) -> u32
pub fn mr_cpu(&mut self, addr: u32) -> u32
Read from memory, assuming that all addresses are aligned.
Sourcepub fn rr_cpu(
&mut self,
register: Register,
position: MemoryAccessPosition,
) -> u32
pub fn rr_cpu( &mut self, register: Register, position: MemoryAccessPosition, ) -> u32
Read a register.
Sourcepub fn mw_cpu(&mut self, addr: u32, value: u32)
pub fn mw_cpu(&mut self, addr: u32, value: u32)
Write to memory.
§Panics
This function will panic if the address is not aligned or if the memory accesses are already initialized.
Sourcepub fn bump_record(&mut self)
pub fn bump_record(&mut self)
Bump the record.
Sourcepub fn execute_record(
&mut self,
emit_global_memory_events: bool,
) -> Result<(Vec<Box<ExecutionRecord>>, bool), ExecutionError>
pub fn execute_record( &mut self, emit_global_memory_events: bool, ) -> Result<(Vec<Box<ExecutionRecord>>, bool), ExecutionError>
Execute up to self.shard_batch_size
cycles, returning the events emitted and whether the
program ended.
§Errors
This function will return an error if the program execution fails.
Sourcepub fn execute_state(
&mut self,
emit_global_memory_events: bool,
) -> Result<(ExecutionState, PublicValues<u32, u32>, bool), ExecutionError>
pub fn execute_state( &mut self, emit_global_memory_events: bool, ) -> Result<(ExecutionState, PublicValues<u32, u32>, bool), ExecutionError>
Execute up to self.shard_batch_size
cycles, returning the checkpoint from before execution
and whether the program ended.
§Errors
This function will return an error if the program execution fails.
Sourcepub fn run_fast(&mut self) -> Result<(), ExecutionError>
pub fn run_fast(&mut self) -> Result<(), ExecutionError>
Executes the program without tracing and without emitting events.
§Errors
This function will return an error if the program execution fails.
Sourcepub fn run_checkpoint(
&mut self,
emit_global_memory_events: bool,
) -> Result<(), ExecutionError>
pub fn run_checkpoint( &mut self, emit_global_memory_events: bool, ) -> Result<(), ExecutionError>
Executes the program in checkpoint mode, without emitting the checkpoints.
§Errors
This function will return an error if the program execution fails.
Sourcepub fn run(&mut self) -> Result<(), ExecutionError>
pub fn run(&mut self) -> Result<(), ExecutionError>
Executes the program and prints the execution report.
§Errors
This function will return an error if the program execution fails.
Sourcepub fn execute(&mut self) -> Result<bool, ExecutionError>
pub fn execute(&mut self) -> Result<bool, ExecutionError>
Executes up to self.shard_batch_size
cycles of the program, returning whether the program
has finished.
Source§impl Executor<'_>
impl Executor<'_>
Sourcepub fn write_stdin<T: Serialize>(&mut self, input: &T)
pub fn write_stdin<T: Serialize>(&mut self, input: &T)
Write a serializable input to the standard input stream.
Sourcepub fn write_stdin_slice(&mut self, input: &[u8])
pub fn write_stdin_slice(&mut self, input: &[u8])
Write a slice of bytes to the standard input stream.
Sourcepub fn write_vecs(&mut self, inputs: &[Vec<u8>])
pub fn write_vecs(&mut self, inputs: &[Vec<u8>])
Write a slice of vecs to the standard input stream.
Sourcepub fn write_proof(
&mut self,
proof: SP1ReduceProof<BabyBearPoseidon2>,
vk: StarkVerifyingKey<BabyBearPoseidon2>,
)
pub fn write_proof( &mut self, proof: SP1ReduceProof<BabyBearPoseidon2>, vk: StarkVerifyingKey<BabyBearPoseidon2>, )
Write a proof and verifying key to the proof stream.
Sourcepub fn read_public_values<T: DeserializeOwned>(&mut self) -> T
pub fn read_public_values<T: DeserializeOwned>(&mut self) -> T
Read a serializable public values from the public values stream.
Sourcepub fn read_public_values_slice(&mut self, buf: &mut [u8])
pub fn read_public_values_slice(&mut self, buf: &mut [u8])
Read a slice of bytes from the public values stream.
Trait Implementations§
Source§impl Read for Executor<'_>
impl Read for Executor<'_>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreAuto Trait Implementations§
impl<'a> Freeze for Executor<'a>
impl<'a> !RefUnwindSafe for Executor<'a>
impl<'a> Send for Executor<'a>
impl<'a> !Sync for Executor<'a>
impl<'a> Unpin for Executor<'a>
impl<'a> !UnwindSafe for Executor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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