pub struct KeccakEnv<F> {
pub constraints_env: Env<F>,
pub witness_env: Env<F>,
pub step: Option<Steps>,
pub(crate) hash_idx: u64,
pub(crate) step_idx: u64,
pub(crate) block_idx: u64,
pub(crate) prev_block: Vec<u64>,
pub(crate) blocks_left_to_absorb: u64,
pub(crate) padded: Vec<u8>,
pub(crate) pad_len: u64,
two_to_pad: [F; 136],
pad_suffixes: [[F; 5]; 136],
}Expand description
This struct contains all that needs to be kept track of during the execution of the Keccak step interpreter
Fields§
§constraints_env: Env<F>Environment for the constraints (includes lookups). The step of the hash that is being executed can be None if just ended
witness_env: Env<F>Environment for the witness (includes multiplicities)
step: Option<Steps>Current step
hash_idx: u64Hash index in the circuit
step_idx: u64Step counter of the total number of steps executed so far in the current hash (starts with 0)
block_idx: u64Current block of preimage data
prev_block: Vec<u64>Expanded block of previous step
blocks_left_to_absorb: u64How many blocks are left to absorb (including current absorb)
padded: Vec<u8>Padded preimage data
pad_len: u64Byte-length of the 10*1 pad (<=136)
two_to_pad: [F; 136]Precomputed 2^pad_len
pad_suffixes: [[F; 5]; 136]Precomputed suffixes for the padding blocks
Implementations§
Source§impl<F: Field> KeccakEnv<F>
impl<F: Field> KeccakEnv<F>
Sourcepub fn new(hash_idx: u64, preimage: &[u8]) -> Self
pub fn new(hash_idx: u64, preimage: &[u8]) -> Self
Starts a new Keccak environment for a given hash index and bytestring of preimage data
Sourcepub fn write_column(&mut self, column: KeccakColumn, value: u64)
pub fn write_column(&mut self, column: KeccakColumn, value: u64)
Writes an integer value to a column of the Keccak witness
Sourcepub fn write_column_field(&mut self, column: KeccakColumn, value: F)
pub fn write_column_field(&mut self, column: KeccakColumn, value: F)
Writes a field value to a column of the Keccak witness
Sourcepub fn null_state(&mut self)
pub fn null_state(&mut self)
Nullifies the Witness and Constraint environments by resetting it to default values (except for table-related) This way, each row only adds the constraints of that step (do not nullify the step)
Sourcepub fn step(&mut self)
pub fn step(&mut self)
Entrypoint for the interpreter. It executes one step of the Keccak circuit (one row),
and updates the environment accordingly (including the witness and inter-step lookups).
When it finishes, it updates the value of the current step, so that the next call to
the step() function executes the next step.
Sourcepub fn update_step(&mut self)
pub fn update_step(&mut self)
This function updates the next step of the environment depending on the current step
Sourcefn set_flag_round(&mut self, round: u64)
fn set_flag_round(&mut self, round: u64)
Updates the witness corresponding to the round value in [0..23]
Sourcefn set_flag_absorb(&mut self, absorb: Absorbs)
fn set_flag_absorb(&mut self, absorb: Absorbs)
Updates and any other sponge flag depending on the kind of absorb step (root, padding, both).
Sourcefn set_flags_pad(&mut self)
fn set_flags_pad(&mut self)
Sets the flag columns related to padding flags such as PadLength, TwoToPad, PadBytesFlags, and PadSuffix.
Sourcefn run_sponge(&mut self, sponge: Sponges)
fn run_sponge(&mut self, sponge: Sponges)
Assigns the witness values needed in a sponge step (absorb or squeeze)
Sourcefn run_absorb(&mut self, absorb: Absorbs)
fn run_absorb(&mut self, absorb: Absorbs)
Assigns the witness values needed in an absorb step (root, padding, or middle)
Sourcefn run_squeeze(&mut self)
fn run_squeeze(&mut self)
Assigns the witness values needed in a squeeze step
Sourcefn run_round(&mut self, round: u64)
fn run_round(&mut self, round: u64)
Assigns the witness values needed in the round step for the given round index
Sourcefn run_theta(&mut self, state_a: &[u64]) -> Vec<u64>
fn run_theta(&mut self, state_a: &[u64]) -> Vec<u64>
Assigns the witness values needed in the theta algorithm
for x in 0…4
C[x] = A[x,0] xor A[x,1] xor \
A[x,2] xor A[x,3] xor \
A[x,4]
for x in 0…4
D[x] = C[x-1] xor rot(C[x+1],1)
for (x,y) in (0…4,0…4)
A[x,y] = A[x,y] xor D[x]Sourcefn run_pirho(&mut self, state_e: &[u64]) -> Vec<u64>
fn run_pirho(&mut self, state_e: &[u64]) -> Vec<u64>
Assigns the witness values needed in the pirho algorithm
for (x,y) in (0…4,0…4)
B[y,2*x+3*y] = rot(A[x,y], r[x,y])