pub struct Env<Fp> {
    pub instruction_counter: u64,
    pub memory: Vec<(u32, Vec<u8>)>,
    pub last_memory_accesses: [usize; 3],
    pub memory_write_index: Vec<(u32, Vec<u64>)>,
    pub last_memory_write_index_accesses: [usize; 3],
    pub registers: Registers<u32>,
    pub registers_write_index: Registers<u64>,
    pub scratch_state_idx: usize,
    pub scratch_state: [Fp; 80],
    pub halt: bool,
    pub selector: usize,
}
Expand description

This structure represents the environment the virtual machine state will use to transition. This environment will be used by the interpreter. The virtual machine has access to its internal state and some external memory. In addition to that, it has access to the environment of the Keccak interpreter that is used to verify the preimage requested during the execution.

Fields§

§instruction_counter: u64§memory: Vec<(u32, Vec<u8>)>§last_memory_accesses: [usize; 3]§memory_write_index: Vec<(u32, Vec<u64>)>§last_memory_write_index_accesses: [usize; 3]§registers: Registers<u32>§registers_write_index: Registers<u64>§scratch_state_idx: usize§scratch_state: [Fp; 80]§halt: bool§selector: usize

Implementations§

source§

impl<Fp: Field> Env<Fp>

source

pub fn create(page_size: usize, state: State) -> Self

source

pub fn next_instruction_counter(&self) -> u64

source

pub fn decode_instruction(&mut self) -> (Instruction, u32)

source

pub fn step(&mut self) -> Instruction

Execute a single step in the RISCV32i program

source

pub fn reset_scratch_state(&mut self)

source

pub fn write_column(&mut self, column: Column, value: u64)

source

pub fn write_field_column(&mut self, column: Column, value: Fp)

source

pub fn update_last_memory_access(&mut self, i: usize)

source

pub fn get_memory_page_index(&mut self, page: u32) -> usize

source

pub fn update_last_memory_write_index_access(&mut self, i: usize)

source

pub fn get_memory_access_page_index(&mut self, page: u32) -> usize

source

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

source

pub fn normalized_instruction_counter(&self) -> u64

The actual number of instructions executed results from dividing the instruction counter by MAX_ACC (floor).

NOTE: actually, in practice it will be less than that, as there is no single instruction that performs all of them.

Trait Implementations§

source§

impl<Fp: Field> InterpreterEnv for Env<Fp>

§

type Position = Column

A position can be seen as an indexed variable
source§

fn alloc_scratch(&mut self) -> Self::Position

Allocate a new abstract variable for the current step. The variable can be used to store temporary values. The variables are “freed” after each step/instruction. The variable allocation can be seen as an allocation on a stack that is popped after each step execution. At the moment, crate::interpreters::riscv32i::SCRATCH_SIZE elements can be allocated. If more temporary variables are required for an instruction, increase the value crate::interpreters::riscv32i::SCRATCH_SIZE
§

type Variable = u64

source§

fn variable(&self, _column: Self::Position) -> Self::Variable

source§

fn add_constraint(&mut self, _assert_equals_zero: Self::Variable)

Add a constraint to the proof system, asserting that assert_equals_zero is 0.
source§

fn activate_selector(&mut self, instruction: Instruction)

Activate the selector for the given instruction.
source§

fn check_is_zero(assert_equals_zero: &Self::Variable)

Check that the witness value in assert_equals_zero is 0; otherwise abort.
source§

fn check_equal(x: &Self::Variable, y: &Self::Variable)

Check that the witness values in x and y are equal; otherwise abort.
source§

fn check_boolean(x: &Self::Variable)

Check that the witness value x is a boolean (0 or 1); otherwise abort.
source§

fn add_lookup(&mut self, _lookup: RAMLookup<Self::Variable, LookupTableIDs>)

source§

fn instruction_counter(&self) -> Self::Variable

source§

fn increase_instruction_counter(&mut self)

source§

unsafe fn fetch_register( &mut self, idx: &Self::Variable, output: Self::Position ) -> Self::Variable

Fetch the value of the general purpose register with index idx and store it in local position output. Read more
source§

unsafe fn push_register_if( &mut self, idx: &Self::Variable, value: Self::Variable, if_is_true: &Self::Variable )

Set the general purpose register with index idx to value if if_is_true is true. Read more
source§

unsafe fn fetch_register_access( &mut self, idx: &Self::Variable, output: Self::Position ) -> Self::Variable

Fetch the last ‘access index’ for the general purpose register with index idx, and store it in local position output. Read more
source§

unsafe fn push_register_access_if( &mut self, idx: &Self::Variable, value: Self::Variable, if_is_true: &Self::Variable )

Set the last ‘access index’ for the general purpose register with index idx to value if if_is_true is true. Read more
source§

unsafe fn fetch_memory( &mut self, addr: &Self::Variable, output: Self::Position ) -> Self::Variable

Fetch the memory value at address addr and store it in local position output. Read more
source§

unsafe fn push_memory(&mut self, addr: &Self::Variable, value: Self::Variable)

Set the memory value at address addr to value. Read more
source§

unsafe fn fetch_memory_access( &mut self, addr: &Self::Variable, output: Self::Position ) -> Self::Variable

Fetch the last ‘access index’ that the memory at address addr was written at, and store it in local position output. Read more
source§

unsafe fn push_memory_access( &mut self, addr: &Self::Variable, value: Self::Variable )

Set the last ‘access index’ for the memory at address addr to value. Read more
source§

fn constant(x: u32) -> Self::Variable

source§

unsafe fn bitmask( &mut self, x: &Self::Variable, highest_bit: u32, lowest_bit: u32, position: Self::Position ) -> Self::Variable

Extract the bits from the variable x between highest_bit and lowest_bit, and store the result in position. lowest_bit becomes the least-significant bit of the resulting value. Read more
source§

unsafe fn shift_left( &mut self, x: &Self::Variable, by: &Self::Variable, position: Self::Position ) -> Self::Variable

Return the result of shifting x by by, storing the result in position. Read more
source§

unsafe fn shift_right( &mut self, x: &Self::Variable, by: &Self::Variable, position: Self::Position ) -> Self::Variable

Return the result of shifting x by by, storing the result in position. Read more
source§

unsafe fn shift_right_arithmetic( &mut self, x: &Self::Variable, by: &Self::Variable, position: Self::Position ) -> Self::Variable

Return the result of shifting x by by, storing the result in position. Read more
source§

unsafe fn test_zero( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns 1 if x is 0, or 0 otherwise, storing the result in position. Read more
source§

unsafe fn inverse_or_zero( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns x^(-1), or 0 if x is 0, storing the result in position. Read more
source§

fn is_zero(&mut self, x: &Self::Variable) -> Self::Variable

source§

fn equal(&mut self, x: &Self::Variable, y: &Self::Variable) -> Self::Variable

Returns 1 if x is equal to y, or 0 otherwise, storing the result in position.
source§

unsafe fn test_less_than( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns 1 if x < y as unsigned integers, or 0 otherwise, storing the result in position. Read more
source§

unsafe fn test_less_than_signed( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns 1 if x < y as signed integers, or 0 otherwise, storing the result in position. Read more
source§

unsafe fn and_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns x or y, storing the result in position. Read more
source§

unsafe fn nor_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns x nor y, storing the result in position. Read more
source§

unsafe fn or_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns x or y, storing the result in position. Read more
source§

unsafe fn xor_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns x xor y, storing the result in position. Read more
source§

unsafe fn add_witness( &mut self, x: &Self::Variable, y: &Self::Variable, out_position: Self::Position, overflow_position: Self::Position ) -> (Self::Variable, Self::Variable)

Returns x + y and the overflow bit, storing the results in position_out and position_overflow respectively. Read more
source§

unsafe fn sub_witness( &mut self, x: &Self::Variable, y: &Self::Variable, out_position: Self::Position, underflow_position: Self::Position ) -> (Self::Variable, Self::Variable)

Returns x + y and the underflow bit, storing the results in position_out and position_underflow respectively. Read more
source§

unsafe fn mul_signed_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns x * y, where x and y are treated as integers, storing the result in position. Read more
source§

unsafe fn mul_hi_lo_signed( &mut self, x: &Self::Variable, y: &Self::Variable, position_hi: Self::Position, position_lo: Self::Position ) -> (Self::Variable, Self::Variable)

Returns ((x * y) >> 32, (x * y) & ((1 << 32) - 1)), storing the results in position_hi and position_lo respectively. Read more
source§

unsafe fn mul_hi_lo( &mut self, x: &Self::Variable, y: &Self::Variable, position_hi: Self::Position, position_lo: Self::Position ) -> (Self::Variable, Self::Variable)

Returns ((x * y) >> 32, (x * y) & ((1 << 32) - 1)), storing the results in position_hi and position_lo respectively. Read more
source§

unsafe fn divmod_signed( &mut self, x: &Self::Variable, y: &Self::Variable, position_quotient: Self::Position, position_remainder: Self::Position ) -> (Self::Variable, Self::Variable)

Returns (x / y, x % y), storing the results in position_quotient and position_remainder respectively. Read more
source§

unsafe fn divmod( &mut self, x: &Self::Variable, y: &Self::Variable, position_quotient: Self::Position, position_remainder: Self::Position ) -> (Self::Variable, Self::Variable)

Returns (x / y, x % y), storing the results in position_quotient and position_remainder respectively. Read more
source§

unsafe fn count_leading_zeros( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns the number of leading 0s in x, storing the result in position. Read more
source§

unsafe fn count_leading_ones( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable

Returns the number of leading 1s in x, storing the result in position. Read more
source§

fn copy( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable

source§

fn set_halted(&mut self, flag: Self::Variable)

source§

fn report_exit(&mut self, exit_code: &Self::Variable)

source§

fn reset(&mut self)

source§

fn assert_is_zero(&mut self, assert_equals_zero: Self::Variable)

Assert that the value assert_equals_zero is 0, and add a constraint in the proof system.
source§

fn assert_equal(&mut self, x: Self::Variable, y: Self::Variable)

Assert that the values x and y are equal, and add a constraint in the proof system.
source§

fn assert_boolean(&mut self, x: Self::Variable)

Assert that the value x is boolean, and add a constraint in the proof system.
source§

unsafe fn push_register(&mut self, idx: &Self::Variable, value: Self::Variable)

Set the general purpose register with index idx to value. Read more
source§

unsafe fn push_register_access( &mut self, idx: &Self::Variable, value: Self::Variable )

Set the last ‘access index’ for the general purpose register with index idx to value. Read more
source§

unsafe fn access_register_if( &mut self, idx: &Self::Variable, old_value: &Self::Variable, new_value: &Self::Variable, if_is_true: &Self::Variable )

Access the general purpose register with index idx, adding constraints asserting that the old value was old_value and that the new value will be new_value, if if_is_true is true. Read more
source§

fn read_register(&mut self, idx: &Self::Variable) -> Self::Variable

source§

unsafe fn access_register( &mut self, idx: &Self::Variable, old_value: &Self::Variable, new_value: &Self::Variable )

Access the general purpose register with index idx, adding constraints asserting that the old value was old_value and that the new value will be new_value. Read more
source§

fn write_register_if( &mut self, idx: &Self::Variable, new_value: Self::Variable, if_is_true: &Self::Variable )

source§

fn write_register(&mut self, idx: &Self::Variable, new_value: Self::Variable)

source§

unsafe fn access_memory( &mut self, addr: &Self::Variable, old_value: &Self::Variable, new_value: &Self::Variable )

Access the memory address addr, adding constraints asserting that the old value was old_value and that the new value will be new_value. Read more
source§

fn read_memory(&mut self, addr: &Self::Variable) -> Self::Variable

source§

fn write_memory(&mut self, addr: &Self::Variable, new_value: Self::Variable)

source§

fn lookup_16bits(&mut self, value: &Self::Variable)

Adds a lookup to the RangeCheck16Lookup table
source§

fn range_check16(&mut self, value: &Self::Variable, bits: u32)

Range checks with 2 lookups to the RangeCheck16Lookup table that a value is at most 2^bits-1 (bits <= 16).
source§

fn lookup_8bits(&mut self, value: &Self::Variable)

Adds a lookup to the ByteLookup table
source§

fn range_check8(&mut self, value: &Self::Variable, bits: u32)

Range checks with 2 lookups to the ByteLookup table that a value is at most 2^bits-1 (bits <= 8).
source§

fn lookup_2bits(&mut self, value: &Self::Variable)

Adds a lookup to the AtMost4Lookup table
source§

fn range_check64(&mut self, _value: &Self::Variable)

source§

fn set_instruction_pointer(&mut self, ip: Self::Variable)

source§

fn get_instruction_pointer(&mut self) -> Self::Variable

source§

fn set_next_instruction_pointer(&mut self, ip: Self::Variable)

source§

fn get_next_instruction_pointer(&mut self) -> Self::Variable

source§

fn increase_heap_pointer( &mut self, by_amount: &Self::Variable, if_is_true: &Self::Variable ) -> Self::Variable

Increases the heap pointer by by_amount if if_is_true is 1, and returns the previous value of the heap pointer.
source§

fn sign_extend(&mut self, x: &Self::Variable, bitlength: u32) -> Self::Variable

Given a variable x, this function extends it to a signed integer of bitlength bits.

Auto Trait Implementations§

§

impl<Fp> RefUnwindSafe for Env<Fp>where Fp: RefUnwindSafe,

§

impl<Fp> Send for Env<Fp>where Fp: Send,

§

impl<Fp> Sync for Env<Fp>where Fp: Sync,

§

impl<Fp> Unpin for Env<Fp>where Fp: Unpin,

§

impl<Fp> UnwindSafe for Env<Fp>where Fp: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

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

§

fn vzip(self) -> V