pub struct CoreVM<'a> {
pub mem_reads: MemReads<'a>,
pub program: Arc<Program>,
pub opts: SP1CoreOpts,
pub clk_end: u64,
pub public_value_digest: [u32; 8],
pub proof_nonce: [u32; 4],
/* private fields */
}Expand description
A RISC-V VM that uses a MinimalTrace to oracle memory access.
Fields§
§mem_reads: MemReads<'a>The memory reads cursoir.
program: Arc<Program>The program that is being executed.
opts: SP1CoreOptsThe options to configure the VM, mostly for syscall / shard handling.
clk_end: u64The end clk of the trace chunk.
public_value_digest: [u32; 8]The public value digest.
proof_nonce: [u32; 4]The nonce associated with the proof.
Implementations§
Source§impl<'a> CoreVM<'a>
impl<'a> CoreVM<'a>
Sourcepub fn new<T: MinimalTrace>(
trace: &'a T,
program: Arc<Program>,
opts: SP1CoreOpts,
proof_nonce: [u32; 4],
) -> Self
pub fn new<T: MinimalTrace>( trace: &'a T, program: Arc<Program>, opts: SP1CoreOpts, proof_nonce: [u32; 4], ) -> Self
Create a CoreVM from a MinimalTrace and a Program.
Sourcepub fn fetch(&mut self) -> Option<&Instruction>
pub fn fetch(&mut self) -> Option<&Instruction>
Fetch the next instruction from the program.
Sourcepub fn advance(&mut self) -> CycleResult
pub fn advance(&mut self) -> CycleResult
Increment the state of the VM by one cycle. Calling this method will update the pc and the clk to the next cycle.
Sourcepub fn execute_load(
&mut self,
instruction: &Instruction,
) -> Result<LoadResult, ExecutionError>
pub fn execute_load( &mut self, instruction: &Instruction, ) -> Result<LoadResult, ExecutionError>
Execute a load instruction.
Sourcepub fn execute_store(
&mut self,
instruction: &Instruction,
) -> Result<StoreResult, ExecutionError>
pub fn execute_store( &mut self, instruction: &Instruction, ) -> Result<StoreResult, ExecutionError>
Execute a store instruction.
Sourcepub fn execute_alu(&mut self, instruction: &Instruction) -> AluResult
pub fn execute_alu(&mut self, instruction: &Instruction) -> AluResult
Execute an ALU instruction.
Sourcepub fn execute_jump(&mut self, instruction: &Instruction) -> JumpResult
pub fn execute_jump(&mut self, instruction: &Instruction) -> JumpResult
Execute a jump instruction.
Sourcepub fn execute_branch(&mut self, instruction: &Instruction) -> BranchResult
pub fn execute_branch(&mut self, instruction: &Instruction) -> BranchResult
Execute a branch instruction.
Sourcepub fn execute_utype(&mut self, instruction: &Instruction) -> UTypeResult
pub fn execute_utype(&mut self, instruction: &Instruction) -> UTypeResult
Execute a U-type instruction.
Sourcepub fn execute_ecall<RT>(
rt: &mut RT,
instruction: &Instruction,
code: SyscallCode,
) -> Result<EcallResult, ExecutionError>where
RT: SyscallRuntime<'a>,
pub fn execute_ecall<RT>(
rt: &mut RT,
instruction: &Instruction,
code: SyscallCode,
) -> Result<EcallResult, ExecutionError>where
RT: SyscallRuntime<'a>,
Execute an ecall instruction.
§WARNING:
Its up to the syscall handler to update the shape checker abouut sent/internal ecalls.
Sourcepub fn read_code(&self) -> SyscallCode
pub fn read_code(&self) -> SyscallCode
Peek to get the code from the x5 register.
Source§impl CoreVM<'_>
impl CoreVM<'_>
Sourcepub fn register_refresh(&mut self) -> [MemoryReadRecord; 32]
pub fn register_refresh(&mut self) -> [MemoryReadRecord; 32]
Touch all the registers in the VM, bumping thier clock to self.clk - 1.
Source§impl CoreVM<'_>
impl CoreVM<'_>
Sourcepub const fn timestamp(&self, position: MemoryAccessPosition) -> u64
pub const fn timestamp(&self, position: MemoryAccessPosition) -> u64
Get the current timestamp for a given memory access position.
Sourcepub const fn needs_bump_clk_high(&self) -> bool
pub const fn needs_bump_clk_high(&self) -> bool
Check if the top 24 bits have changed, which imply a state bump event needs to be emitted.
Sourcepub const fn needs_state_bump(&self, instruction: &Instruction) -> bool
pub const fn needs_state_bump(&self, instruction: &Instruction) -> bool
Check if the state needs to be bumped, which implies a state bump event needs to be
emitted.
Source§impl<'a> CoreVM<'a>
impl<'a> CoreVM<'a>
Sourcepub const fn clk(&self) -> u64
pub const fn clk(&self) -> u64
Get the current clock, this clock is incremented by [CLK_INC] each cycle.
Sourcepub fn set_next_clk(&mut self, clk: u64)
pub fn set_next_clk(&mut self, clk: u64)
Set the next clock.
Sourcepub fn global_clk(&self) -> u64
pub fn global_clk(&self) -> u64
Get the global clock, this clock is incremented by 1 each cycle.
Sourcepub const fn next_pc(&self) -> u64
pub const fn next_pc(&self) -> u64
Get the next program counter that will be set in CoreVM::advance.
Sourcepub fn set_next_pc(&mut self, pc: u64)
pub fn set_next_pc(&mut self, pc: u64)
Set the next program counter.
Sourcepub fn set_exit_code(&mut self, exit_code: u32)
pub fn set_exit_code(&mut self, exit_code: u32)
Set the exit code.
Sourcepub fn set_global_clk(&mut self, global_clk: u64)
pub fn set_global_clk(&mut self, global_clk: u64)
Set the global clock.
Sourcepub const fn next_clk(&self) -> u64
pub const fn next_clk(&self) -> u64
Get the next clock that will be set in CoreVM::advance.
Sourcepub fn registers(&self) -> &[MemoryRecord; 32]
pub fn registers(&self) -> &[MemoryRecord; 32]
Get the current registers (immutable).
Sourcepub fn registers_mut(&mut self) -> &mut [MemoryRecord; 32]
pub fn registers_mut(&mut self) -> &mut [MemoryRecord; 32]
Get the current registers (mutable).
Sourcepub fn is_retained_syscall(&self, syscall_code: SyscallCode) -> bool
pub fn is_retained_syscall(&self, syscall_code: SyscallCode) -> bool
Check if the syscall is retained.
Sourcepub const fn is_trace_end(&self) -> bool
pub const fn is_trace_end(&self) -> bool
Check if the trace has ended.
Auto Trait Implementations§
impl<'a> Freeze for CoreVM<'a>
impl<'a> RefUnwindSafe for CoreVM<'a>
impl<'a> !Send for CoreVM<'a>
impl<'a> !Sync for CoreVM<'a>
impl<'a> Unpin for CoreVM<'a>
impl<'a> UnsafeUnpin for CoreVM<'a>
impl<'a> UnwindSafe for CoreVM<'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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.