pub struct MemoryImage {
    pub pages: BTreeMap<u32, Vec<u8>>,
    pub info: PageTableInfo,
    pub pc: u32,
}
Expand description

An image of a zkVM guest’s memory

This is an image of the full memory state of the zkVM, including the data, text, inputs, page table, and system memory. In addition to the memory image proper, this includes some metadata about the page table.

Fields§

§pages: BTreeMap<u32, Vec<u8>>

Sparse memory memory image as a map from page index to page.

§info: PageTableInfo

Metadata about the structure of the page table

§pc: u32

Program Counter from Program entry point

Implementations§

source§

impl MemoryImage

source

pub fn new(program: &Program, page_size: u32) -> Result<Self>

Construct the initial memory image for program

The result is a MemoryImage with the ELF of program loaded (but execution not yet begun), and with the page table Merkle tree constructed.

source

pub fn load_page(&self, page_idx: u32) -> Vec<u8>

Load a page specified by page_idx. If no page is found, a zero page is returned.

source

pub fn store_region_in_page(&mut self, addr: u32, bytes: &[u8])

Writes the given byte array in this memory image at the given address. The caller is responsible for ensuring the bytes do not overlap a page boundary.

source

pub fn load_region_in_page(&self, addr: u32, bytes: &mut [u8]) -> Result<()>

Reads the given byte array in this memory image at the given address The caller is responsible for ensuring the bytes do not overlap a page boundary.

source

pub fn hash_pages(&mut self) -> Result<()>

Calculate and update the image merkle tree within this image.

source

pub fn hash_pages_iter<I: Iterator<Item = u32>>( &mut self, iter: I ) -> Result<()>

Calculate and update the image merkle tree within this image based on the supplied page indices.

source

pub fn compute_root_hash(&self) -> Result<Digest>

Compute and return the root merkle entry of this image.

source

pub fn compute_id(&self) -> Result<Digest>

Compute and return the ImageID of this image.

source

pub fn get_system_state(&self) -> Result<SystemState>

Return the SystemState for this image.

Trait Implementations§

source§

impl Clone for MemoryImage

source§

fn clone(&self) -> MemoryImage

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'de> Deserialize<'de> for MemoryImage

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for MemoryImage

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,