pub struct Env<F> {
    pub witness: KeccakWitness<F>,
    pub tables: HashMap<LookupTableIDs, LogupTable<F, LookupTableIDs>>,
    pub multiplicities: HashMap<LookupTableIDs, Vec<u32>>,
    /* private fields */
}
Expand description

This struct contains all that needs to be kept track of during the execution of the Keccak step interpreter

Fields§

§witness: KeccakWitness<F>

The full state of the Keccak gate (witness)

§tables: HashMap<LookupTableIDs, LogupTable<F, LookupTableIDs>>

The fixed tables used in the Keccak gate

§multiplicities: HashMap<LookupTableIDs, Vec<u32>>

The multiplicities of each lookup entry. Should not be cleared between steps.

Trait Implementations§

source§

impl<F: Field> ArithHelpers<F> for Env<F>

source§

fn two_pow(x: u64) -> <Env<F> as Interpreter<F>>::Variable

Returns a variable representing the value 2^x
source§

fn zero() -> Self::Variable

Returns a variable representing the value zero
source§

fn one() -> Self::Variable

Returns a variable representing the value one
source§

fn two() -> Self::Variable

Returns a variable representing the value two
source§

impl<F: Field> BoolHelpers<F> for Env<F>

source§

fn is_boolean(x: Self::Variable) -> Self::Variable

Degree-2 variable encoding whether the input is a boolean value (0 = yes)
source§

fn not(x: Self::Variable) -> Self::Variable

Degree-1 variable encoding the negation of the input Note: it only works as expected if the input is a boolean value
source§

fn is_one(x: Self::Variable) -> Self::Variable

Degree-1 variable encoding whether the input is the value one (0 = yes)
source§

fn is_nonzero(x: Self::Variable, x_inv: Self::Variable) -> Self::Variable

Degree-2 variable encoding whether the first input is nonzero (0 = yes). It requires the second input to be the multiplicative inverse of the first. Note: if the first input is zero, there is no multiplicative inverse.
source§

fn is_zero( x: Self::Variable, x_inv: Self::Variable, z: Self::Variable ) -> (Self::Variable, Self::Variable)

source§

fn xor(x: Self::Variable, y: Self::Variable) -> Self::Variable

Degree-2 variable encoding the XOR of two variables which should be boolean (1 = true)
source§

fn or(x: Self::Variable, y: Self::Variable) -> Self::Variable

Degree-2 variable encoding the OR of two variables, which should be boolean (1 = true)
source§

fn either_zero(x: Self::Variable, y: Self::Variable) -> Self::Variable

Degree-2 variable encoding whether at least one of the two inputs is zero (0 = yes)
source§

impl<F: Clone> Clone for Env<F>

source§

fn clone(&self) -> Env<F>

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<F: Debug> Debug for Env<F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<F: Field> Default for Env<F>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<F: Field> Interpreter<F> for Env<F>

source§

fn constrain( &mut self, tag: Constraint, if_true: Self::Variable, x: Self::Variable )

Checks the constraint tag by checking that the input x is zero

§

type Variable = F

source§

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

Creates a variable from a constant integer
source§

fn constant_field(x: F) -> Self::Variable

Creates a variable from a constant field element
source§

fn variable(&self, column: KeccakColumn) -> Self::Variable

Returns the variable corresponding to a given column alias.
source§

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

Adds a given Lookup to the environment if the condition holds
source§

impl<F: Field> KeccakInterpreter<F> for Env<F>

source§

fn constraints(&mut self, step: Steps)

Creates all 879 constraints/checks to the environment: Read more
source§

fn constrain_flags(&mut self, step: Steps)where Self: Interpreter<F>,

Constrains 136 checks of correctness of mode flags Read more
source§

fn constrain_booleanity(&mut self, step: Steps)where Self: Interpreter<F>,

Constrains 136 checks of booleanity for some mode flags. Read more
source§

fn constrain_sponge(&mut self, step: Steps)

Constrains 354 checks of sponge steps Read more
source§

fn constrain_absorb(&mut self, step: Steps)

Constrains 332 checks of absorb sponges Read more
source§

fn constrain_padding(&mut self, step: Steps)

Constrains 6 checks of padding absorb sponges Read more
source§

fn constrain_squeeze(&mut self, step: Steps)

Constrains 16 checks of squeeze sponges Read more
source§

fn constrain_round(&mut self, step: Steps)

Constrains 389 checks of round steps Read more
source§

fn constrain_theta(&mut self, step: Steps) -> Vec<Vec<Vec<Self::Variable>>>

Constrains 35 checks of the theta algorithm in round steps Read more
source§

fn constrain_pirho( &mut self, step: Steps, state_e: Vec<Vec<Vec<Self::Variable>>> ) -> Vec<Vec<Vec<Self::Variable>>>

Constrains 150 checks of the pirho algorithm in round steps Read more
source§

fn constrain_chi( &mut self, step: Steps, state_b: Vec<Vec<Vec<Self::Variable>>> ) -> Vec<Vec<Vec<Self::Variable>>>

Constrains 200 checks of the chi algorithm in round steps Read more
source§

fn constrain_iota( &mut self, step: Steps, state_f: Vec<Vec<Vec<Self::Variable>>> )

Constrains 4 checks of the iota algorithm in round steps Read more
source§

fn lookups(&mut self, step: Steps)

Creates all possible lookups to the Keccak constraints environment: Read more
source§

fn lookup_syscall_preimage(&mut self, step: Steps)

When in Absorb mode, reads Lookups containing the 136 bytes of the block of the preimage Read more
source§

fn lookup_syscall_hash(&mut self, step: Steps)

When in Squeeze mode, writes a Lookup containing the 31byte output of the hash (excludes the MSB) Read more
source§

fn lookup_steps(&mut self, step: Steps)

Reads a Lookup containing the input of a step and writes a Lookup containing the output of the next step Read more
source§

fn lookups_sponge(&mut self, step: Steps)

Adds the 601 lookups required for the sponge Read more
source§

fn lookups_round_theta(&mut self, step: Steps)

Adds the 120 lookups required for Theta in the round
source§

fn lookups_round_pirho(&mut self, step: Steps)

Adds the 700 lookups required for PiRho in the round
source§

fn lookups_round_chi(&mut self, step: Steps)

Adds the 800 lookups required for Chi in the round
source§

fn lookups_round_iota(&mut self, step: Steps)

Adds the 1 lookup required for Iota in the round
source§

fn is_sponge(&self, step: Steps) -> Self::Variable

SELECTOR OPERATIONS /// Returns a degree-2 variable that encodes whether the current step is a sponge (1 = yes)
source§

fn is_absorb(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is an absorb sponge (1 = yes)
source§

fn is_squeeze(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is a squeeze sponge (1 = yes)
source§

fn is_root(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is the first absorb sponge (1 = yes)
source§

fn is_pad(&self, step: Steps) -> Self::Variable

Returns a degree-1 variable that encodes whether the current step is the last absorb sponge (1 = yes)
source§

fn is_round(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is a permutation round (1 = yes)
source§

fn mode_absorb(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is an absorb sponge (1 = yes)
source§

fn mode_squeeze(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is a squeeze sponge (1 = yes)
source§

fn mode_root(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is the first absorb sponge (1 = yes)
source§

fn mode_pad(&self, step: Steps) -> Self::Variable

Returns a degree-1 variable that encodes whether the current step is the last absorb sponge (1 = yes)
source§

fn mode_rootpad(&self, step: Steps) -> Self::Variable

Returns a degree-1 variable that encodes whether the current step is the first and last absorb sponge (1 = yes)
source§

fn mode_round(&self, step: Steps) -> Self::Variable

Returns a variable that encodes whether the current step is a permutation round (1 = yes)
source§

fn from_shifts( shifts: &[Self::Variable], i: Option<usize>, y: Option<usize>, x: Option<usize>, q: Option<usize> ) -> Self::Variable

COLUMN OPERATIONS /// This function returns the composed sparse variable from shifts of any correct length: Read more
source§

fn from_quarters( quarters: &[Self::Variable], y: Option<usize>, x: usize ) -> Self::Variable

This function returns the composed variable from dense quarters of any correct length: Read more
source§

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

Returns a variable that encodes the current round number [0..24)
source§

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

Returns a variable that encodes the bytelength of the padding if any [0..136)
source§

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

Returns a variable that encodes the value 2^pad_length
source§

fn in_padding(&self, idx: usize) -> Self::Variable

Returns a variable that encodes whether the idx-th byte of the new block is involved in the padding (1 = yes)
source§

fn pad_suffix(&self, idx: usize) -> Self::Variable

Returns a variable that encodes the idx-th chunk of the padding suffix Read more
source§

fn bytes_block(&self, idx: usize) -> Vec<Self::Variable>

Returns a variable that encodes the idx-th block of bytes of the new block by composing the bytes variables, with idx in [0..5)
source§

fn pad_bytes_flags(&self) -> [Self::Variable; 136]

Returns the 136 flags indicating which bytes of the new block are involved in the padding, as variables
source§

fn flags_block(&self, idx: usize) -> Vec<Self::Variable>

Returns a vector of pad bytes flags as variables, with idx in [0..5) Read more
source§

fn block_in_padding(&self, idx: usize) -> Self::Variable

This function returns a degree-2 variable that is computed as the accumulated value of the operation byte * flag * 2^8 for each byte block and flag block of the new block. This function will be used in constraints to determine whether the padding is located at the end of the preimage data, as consecutive bits that are involved in the padding.
source§

fn round_constants(&self) -> [Self::Variable; 4]

Returns the 4 expanded quarters that encode the round constant, as variables
source§

fn old_state(&self, idx: usize) -> Self::Variable

Returns the idx-th old state expanded quarter, as a variable
source§

fn new_state(&self, idx: usize) -> Self::Variable

Returns the idx-th new state expanded quarter, as a variable
source§

fn xor_state(&self, idx: usize) -> Self::Variable

Returns the output of an absorb sponge, which is the XOR of the old state and the new state
source§

fn sponge_zeros(&self) -> [Self::Variable; 32]

Returns the last 32 terms that are added to the new block in an absorb sponge, as variables which should be zeros
source§

fn vec_sponge_shifts(&self) -> [Self::Variable; 400]

Returns the 400 terms that compose the shifts of the sponge, as variables
source§

fn sponge_shifts(&self, idx: usize) -> Self::Variable

Returns the idx-th term of the shifts of the sponge, as a variable
source§

fn sponge_bytes(&self) -> [Self::Variable; 200]

Returns the 200 bytes of the sponge, as variables
source§

fn sponge_byte(&self, idx: usize) -> Self::Variable

Returns the idx-th byte of the sponge, as a variable
source§

fn state_a(&self, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (y,x,q)-th input of the theta algorithm, as a variable
source§

fn vec_shifts_c(&self) -> [Self::Variable; 80]

Returns the 80 variables corresponding to ThetaShiftsC
source§

fn shifts_c(&self, i: usize, x: usize, q: usize) -> Self::Variable

Returns the (i,x,q)-th variable of ThetaShiftsC
source§

fn vec_dense_c(&self) -> [Self::Variable; 20]

Returns the 20 variables corresponding to ThetaDenseC
source§

fn dense_c(&self, x: usize, q: usize) -> Self::Variable

Returns the (x,q)-th term of ThetaDenseC, as a variable
source§

fn vec_quotient_c(&self) -> [Self::Variable; 5]

Returns the 5 variables corresponding to ThetaQuotientC
source§

fn quotient_c(&self, x: usize) -> Self::Variable

Returns the (x)-th term of ThetaQuotientC, as a variable
source§

fn vec_remainder_c(&self) -> [Self::Variable; 20]

Returns the 20 variables corresponding to ThetaRemainderC
source§

fn remainder_c(&self, x: usize, q: usize) -> Self::Variable

Returns the (x,q)-th variable of ThetaRemainderC
source§

fn vec_dense_rot_c(&self) -> [Self::Variable; 20]

Returns the 20 variables corresponding to ThetaDenseRotC
source§

fn dense_rot_c(&self, x: usize, q: usize) -> Self::Variable

Returns the (x,q)-th variable of ThetaDenseRotC
source§

fn vec_expand_rot_c(&self) -> [Self::Variable; 20]

Returns the 20 variables corresponding to ThetaExpandRotC
source§

fn expand_rot_c(&self, x: usize, q: usize) -> Self::Variable

Returns the (x,q)-th variable of ThetaExpandRotC
source§

fn vec_shifts_e(&self) -> [Self::Variable; 400]

Returns the 400 variables corresponding to PiRhoShiftsE
source§

fn shifts_e(&self, i: usize, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (i,y,x,q)-th variable of PiRhoShiftsE
source§

fn vec_dense_e(&self) -> [Self::Variable; 100]

Returns the 100 variables corresponding to PiRhoDenseE
source§

fn dense_e(&self, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (y,x,q)-th variable of PiRhoDenseE
source§

fn vec_quotient_e(&self) -> [Self::Variable; 100]

Returns the 100 variables corresponding to PiRhoQuotientE
source§

fn quotient_e(&self, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (y,x,q)-th variable of PiRhoQuotientE
source§

fn vec_remainder_e(&self) -> [Self::Variable; 100]

Returns the 100 variables corresponding to PiRhoRemainderE
source§

fn remainder_e(&self, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (y,x,q)-th variable of PiRhoRemainderE
source§

fn vec_dense_rot_e(&self) -> [Self::Variable; 100]

Returns the 100 variables corresponding to PiRhoDenseRotE
source§

fn dense_rot_e(&self, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (y,x,q)-th variable of PiRhoDenseRotE
source§

fn vec_expand_rot_e(&self) -> [Self::Variable; 100]

Returns the 100 variables corresponding to PiRhoExpandRotE
source§

fn expand_rot_e(&self, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (y,x,q)-th variable of PiRhoExpandRotE
source§

fn vec_shifts_b(&self) -> [Self::Variable; 400]

Returns the 400 variables corresponding to ChiShiftsB
source§

fn shifts_b(&self, i: usize, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (i,y,x,q)-th variable of ChiShiftsB
source§

fn vec_shifts_sum(&self) -> [Self::Variable; 400]

Returns the 400 variables corresponding to ChiShiftsSum
source§

fn shifts_sum(&self, i: usize, y: usize, x: usize, q: usize) -> Self::Variable

Returns the (i,y,x,q)-th variable of ChiShiftsSum
source§

fn state_g(&self, idx: usize) -> Self::Variable

Returns the idx-th output of a round step as a variable
source§

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

Returns the hash index as a variable
source§

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

Returns the block index as a variable
source§

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

Returns the step index as a variable
source§

fn input(&self) -> [Self::Variable; 100]

Returns the 100 step input variables, which correspond to the: Read more
source§

fn input_of_step(&self) -> Vec<Self::Variable>

Returns a slice of the input variables of the current step including the current hash index and step index
source§

fn output(&self) -> [Self::Variable; 100]

Returns the 100 step output variables, which correspond to the: Read more
source§

fn output_of_step(&self) -> Vec<Self::Variable>

Returns a slice of the output variables of the current step (= input of next step) including the current hash index and step index
source§

impl<F: Field> LogupHelpers<F> for Env<F>

source§

fn lookup_rc16(&mut self, flag: Self::Variable, value: Self::Variable)

Adds a lookup to the RangeCheck16 table
source§

fn lookup_reset( &mut self, flag: Self::Variable, dense: Self::Variable, sparse: Self::Variable )

Adds a lookup to the Reset table
source§

fn lookup_sparse(&mut self, flag: Self::Variable, value: Self::Variable)

Adds a lookup to the Shift table
source§

fn lookup_byte(&mut self, flag: Self::Variable, value: Self::Variable)

Adds a lookup to the Byte table
source§

fn lookup_pad(&mut self, flag: Self::Variable, value: Vec<Self::Variable>)

Adds a lookup to the Pad table
source§

fn lookup_round_constants( &mut self, flag: Self::Variable, value: Vec<Self::Variable> )

Adds a lookup to the RoundConstants table
source§

fn read_syscall(&mut self, flag: Self::Variable, value: Vec<Self::Variable>)

source§

fn write_syscall(&mut self, flag: Self::Variable, value: Vec<Self::Variable>)

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<F> UnwindSafe for Env<F>where F: 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> ToOwned for Twhere 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 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