pub struct Env<Fp, PreImageOracle: PreImageOracleT> {Show 18 fields
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; 98],
pub halt: bool,
pub syscall_env: SyscallEnv,
pub selector: usize,
pub preimage_oracle: PreImageOracle,
pub preimage: Option<Vec<u8>>,
pub preimage_bytes_read: u64,
pub preimage_key: Option<[u8; 32]>,
pub keccak_env: Option<KeccakEnv<Fp>>,
pub hash_counter: u64,
}
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; 98]
§halt: bool
§syscall_env: SyscallEnv
§selector: usize
§preimage_oracle: PreImageOracle
§preimage: Option<Vec<u8>>
§preimage_bytes_read: u64
§preimage_key: Option<[u8; 32]>
§keccak_env: Option<KeccakEnv<Fp>>
§hash_counter: u64
Implementations§
source§impl<Fp: Field, PreImageOracle: PreImageOracleT> Env<Fp, PreImageOracle>
impl<Fp: Field, PreImageOracle: PreImageOracleT> Env<Fp, PreImageOracle>
pub fn create( page_size: usize, state: State, preimage_oracle: PreImageOracle ) -> Self
pub fn reset_scratch_state(&mut self)
pub fn write_column(&mut self, column: Column, value: u64)
pub fn write_field_column(&mut self, column: Column, value: Fp)
pub fn update_last_memory_access(&mut self, i: usize)
pub fn get_memory_page_index(&mut self, page: u32) -> usize
pub fn update_last_memory_write_index_access(&mut self, i: usize)
pub fn get_memory_access_page_index(&mut self, page: u32) -> usize
pub fn get_memory_direct(&mut self, addr: u32) -> u8
pub fn decode_instruction(&mut self) -> (Instruction, u32)
sourcepub fn normalized_instruction_counter(&self) -> u64
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.
sourcepub fn next_instruction_counter(&self) -> u64
pub fn next_instruction_counter(&self) -> u64
Computes what is the non-normalized next instruction counter, which accounts for the maximum number of register and memory accesses per instruction.
Because MAX_NB_REG_ACC = 7 and MAX_NB_MEM_ACC = 12, at most the same instruction will increase the instruction counter by MAX_ACC = 19.
Then, in order to update the instruction counter, we need to add 1 to the real instruction counter and multiply it by MAX_ACC to have a unique representation of each step (which is helpful for debugging).
sourcepub fn step(
&mut self,
config: &VmConfiguration,
metadata: &Meta,
start: &Start
) -> Instruction
pub fn step( &mut self, config: &VmConfiguration, metadata: &Meta, start: &Start ) -> Instruction
Execute a single step of the MIPS program. Returns the instruction that was executed.
Trait Implementations§
source§impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreImageOracle>
impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreImageOracle>
§type Position = ColumnAlias
type Position = ColumnAlias
source§fn alloc_scratch(&mut self) -> Self::Position
fn alloc_scratch(&mut self) -> Self::Position
type Variable = u64
fn variable(&self, _column: Self::Position) -> Self::Variable
source§fn add_constraint(&mut self, _assert_equals_zero: Self::Variable)
fn add_constraint(&mut self, _assert_equals_zero: Self::Variable)
assert_equals_zero
is 0.source§fn activate_selector(&mut self, instruction: Instruction)
fn activate_selector(&mut self, instruction: Instruction)
source§fn check_is_zero(assert_equals_zero: &Self::Variable)
fn check_is_zero(assert_equals_zero: &Self::Variable)
assert_equals_zero
is 0; otherwise abort.source§fn check_equal(x: &Self::Variable, y: &Self::Variable)
fn check_equal(x: &Self::Variable, y: &Self::Variable)
x
and y
are equal; otherwise abort.source§fn check_boolean(x: &Self::Variable)
fn check_boolean(x: &Self::Variable)
x
is a boolean (0
or 1
); otherwise abort.fn add_lookup(&mut self, _lookup: RAMLookup<Self::Variable, LookupTableIDs>)
fn instruction_counter(&self) -> Self::Variable
fn increase_instruction_counter(&mut self)
source§unsafe fn fetch_register(
&mut self,
idx: &Self::Variable,
output: Self::Position
) -> Self::Variable
unsafe fn fetch_register( &mut self, idx: &Self::Variable, output: Self::Position ) -> Self::Variable
idx
and store it in local
position output
. Read moresource§unsafe fn push_register_if(
&mut self,
idx: &Self::Variable,
value: Self::Variable,
if_is_true: &Self::Variable
)
unsafe fn push_register_if( &mut self, idx: &Self::Variable, value: Self::Variable, if_is_true: &Self::Variable )
source§unsafe fn fetch_register_access(
&mut self,
idx: &Self::Variable,
output: Self::Position
) -> Self::Variable
unsafe fn fetch_register_access( &mut self, idx: &Self::Variable, output: Self::Position ) -> Self::Variable
idx
, and store
it in local position output
. Read moresource§unsafe fn push_register_access_if(
&mut self,
idx: &Self::Variable,
value: Self::Variable,
if_is_true: &Self::Variable
)
unsafe fn push_register_access_if( &mut self, idx: &Self::Variable, value: Self::Variable, if_is_true: &Self::Variable )
idx
to value
if
if_is_true
is true. Read moresource§unsafe fn fetch_memory(
&mut self,
addr: &Self::Variable,
output: Self::Position
) -> Self::Variable
unsafe fn fetch_memory( &mut self, addr: &Self::Variable, output: Self::Position ) -> Self::Variable
source§unsafe fn push_memory(&mut self, addr: &Self::Variable, value: Self::Variable)
unsafe fn push_memory(&mut self, addr: &Self::Variable, value: Self::Variable)
source§unsafe fn fetch_memory_access(
&mut self,
addr: &Self::Variable,
output: Self::Position
) -> Self::Variable
unsafe fn fetch_memory_access( &mut self, addr: &Self::Variable, output: Self::Position ) -> Self::Variable
addr
was written at, and store
it in local position output
. Read moresource§unsafe fn push_memory_access(
&mut self,
addr: &Self::Variable,
value: Self::Variable
)
unsafe fn push_memory_access( &mut self, addr: &Self::Variable, value: Self::Variable )
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
unsafe fn bitmask( &mut self, x: &Self::Variable, highest_bit: u32, lowest_bit: u32, position: Self::Position ) -> Self::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 moresource§unsafe fn shift_left(
&mut self,
x: &Self::Variable,
by: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn shift_left( &mut self, x: &Self::Variable, by: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn shift_right(
&mut self,
x: &Self::Variable,
by: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn shift_right( &mut self, x: &Self::Variable, by: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn shift_right_arithmetic(
&mut self,
x: &Self::Variable,
by: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn shift_right_arithmetic( &mut self, x: &Self::Variable, by: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn test_zero(
&mut self,
x: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn test_zero( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn inverse_or_zero(
&mut self,
x: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn inverse_or_zero( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable
fn is_zero(&mut self, x: &Self::Variable) -> Self::Variable
source§fn equal(&mut self, x: &Self::Variable, y: &Self::Variable) -> Self::Variable
fn equal(&mut self, x: &Self::Variable, y: &Self::Variable) -> Self::Variable
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
unsafe fn test_less_than( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn test_less_than_signed(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn test_less_than_signed( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn and_witness(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn and_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn nor_witness(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn nor_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn or_witness(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn or_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn xor_witness(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn xor_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
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)
unsafe fn add_witness( &mut self, x: &Self::Variable, y: &Self::Variable, out_position: Self::Position, overflow_position: Self::Position ) -> (Self::Variable, Self::Variable)
x + y
and the overflow bit, storing the results in position_out
and
position_overflow
respectively. Read moresource§unsafe fn sub_witness(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
out_position: Self::Position,
underflow_position: Self::Position
) -> (Self::Variable, Self::Variable)
unsafe fn sub_witness( &mut self, x: &Self::Variable, y: &Self::Variable, out_position: Self::Position, underflow_position: Self::Position ) -> (Self::Variable, Self::Variable)
x + y
and the underflow bit, storing the results in position_out
and
position_underflow
respectively. Read moresource§unsafe fn mul_signed_witness(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn mul_signed_witness( &mut self, x: &Self::Variable, y: &Self::Variable, position: Self::Position ) -> Self::Variable
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)
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)
((x * y) >> 32, (x * y) & ((1 << 32) - 1))
, storing the results in position_hi
and position_lo
respectively. Read moresource§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)
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)
((x * y) >> 32, (x * y) & ((1 << 32) - 1))
, storing the results in position_hi
and position_lo
respectively. Read moresource§unsafe fn divmod_signed(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position_quotient: Self::Position,
position_remainder: Self::Position
) -> (Self::Variable, Self::Variable)
unsafe fn divmod_signed( &mut self, x: &Self::Variable, y: &Self::Variable, position_quotient: Self::Position, position_remainder: Self::Position ) -> (Self::Variable, Self::Variable)
(x / y, x % y)
, storing the results in position_quotient
and
position_remainder
respectively. Read moresource§unsafe fn divmod(
&mut self,
x: &Self::Variable,
y: &Self::Variable,
position_quotient: Self::Position,
position_remainder: Self::Position
) -> (Self::Variable, Self::Variable)
unsafe fn divmod( &mut self, x: &Self::Variable, y: &Self::Variable, position_quotient: Self::Position, position_remainder: Self::Position ) -> (Self::Variable, Self::Variable)
(x / y, x % y)
, storing the results in position_quotient
and
position_remainder
respectively. Read moresource§unsafe fn count_leading_zeros(
&mut self,
x: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn count_leading_zeros( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable
source§unsafe fn count_leading_ones(
&mut self,
x: &Self::Variable,
position: Self::Position
) -> Self::Variable
unsafe fn count_leading_ones( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable
fn copy( &mut self, x: &Self::Variable, position: Self::Position ) -> Self::Variable
fn set_halted(&mut self, flag: Self::Variable)
fn report_exit(&mut self, exit_code: &Self::Variable)
source§fn request_preimage_write(
&mut self,
addr: &Self::Variable,
len: &Self::Variable,
pos: Self::Position
) -> Self::Variable
fn request_preimage_write( &mut self, addr: &Self::Variable, len: &Self::Variable, pos: Self::Position ) -> Self::Variable
len
bytes and store the bytes starting
from addr
, and it returns the number of bytes actually read.
The number of bytes actually read will be set into pos
.
The first 8 bytes will be the length of the preimage, encoded as an
unsigned 64bits, and the rest will be the preimage.fn request_hint_write(&mut self, addr: &Self::Variable, len: &Self::Variable)
source§fn assert_is_zero(&mut self, assert_equals_zero: Self::Variable)
fn assert_is_zero(&mut self, assert_equals_zero: Self::Variable)
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)
fn assert_equal(&mut self, x: Self::Variable, y: Self::Variable)
x
and y
are equal, and add a constraint in the proof system.source§fn assert_boolean(&mut self, x: Self::Variable)
fn assert_boolean(&mut self, x: Self::Variable)
x
is boolean, and add a constraint in the proof system.source§unsafe fn push_register(&mut self, idx: &Self::Variable, value: Self::Variable)
unsafe fn push_register(&mut self, idx: &Self::Variable, value: Self::Variable)
source§unsafe fn push_register_access(
&mut self,
idx: &Self::Variable,
value: Self::Variable
)
unsafe fn push_register_access( &mut self, idx: &Self::Variable, value: Self::Variable )
source§unsafe fn access_register_if(
&mut self,
idx: &Self::Variable,
old_value: &Self::Variable,
new_value: &Self::Variable,
if_is_true: &Self::Variable
)
unsafe fn access_register_if( &mut self, idx: &Self::Variable, old_value: &Self::Variable, new_value: &Self::Variable, if_is_true: &Self::Variable )
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 morefn 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
)
unsafe fn access_register( &mut self, idx: &Self::Variable, old_value: &Self::Variable, new_value: &Self::Variable )
idx
, adding constraints asserting that the
old value was old_value
and that the new value will be new_value
. Read morefn write_register_if( &mut self, idx: &Self::Variable, new_value: Self::Variable, if_is_true: &Self::Variable )
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
)
unsafe fn access_memory( &mut self, addr: &Self::Variable, old_value: &Self::Variable, new_value: &Self::Variable )
addr
, adding constraints asserting that the old value was
old_value
and that the new value will be new_value
. Read morefn read_memory(&mut self, addr: &Self::Variable) -> Self::Variable
fn write_memory(&mut self, addr: &Self::Variable, new_value: Self::Variable)
source§fn lookup_16bits(&mut self, value: &Self::Variable)
fn lookup_16bits(&mut self, value: &Self::Variable)
source§fn range_check16(&mut self, value: &Self::Variable, bits: u32)
fn range_check16(&mut self, value: &Self::Variable, bits: u32)
bits
-1 (bits <= 16).source§fn lookup_8bits(&mut self, value: &Self::Variable)
fn lookup_8bits(&mut self, value: &Self::Variable)
source§fn range_check8(&mut self, value: &Self::Variable, bits: u32)
fn range_check8(&mut self, value: &Self::Variable, bits: u32)
bits
-1 (bits <= 8).