Then we absorb it to the buffer, and if it’s full we run a round function.
if buffer.len() >=136 {let buffer_for_round: [UInt8<F>; KECCAK_RATE_BYTES] = buffer[..136].try_into().unwrap();let buffer_for_round = buffer_for_round.map(|el| el.get_variable());let carry_on = buffer[136..].to_vec(); buffer = carry_on;// absorb if we are not done yetkeccak256_conditionally_absorb_and_run_permutation( cs, continue_to_absorb,&mut keccak_accumulator_state,&buffer_for_round, );}
If this element was the last one, we create a padding and run a round function.
if tail_len == KECCAK_RATE_BYTES -1 {// unreachable, but we set it for completeness last_round_buffer[tail_len] =UInt8::allocated_constant(cs, 0x81);} else { last_round_buffer[tail_len] =UInt8::allocated_constant(cs, 0x01); last_round_buffer[KECCAK_RATE_BYTES -1] =UInt8::allocated_constant(cs, 0x80);}let last_round_buffer = last_round_buffer.map(|el| el.get_variable());// absorb if it's the last roundkeccak256_conditionally_absorb_and_run_permutation( cs, absorb_as_last_round,&mut keccak_accumulator_state,&last_round_buffer,);
Finally, we compute a commitment to PI and allocate it as witness variables.
let input_commitment =commit_variable_length_encodable_item(cs, &compact_form, round_function);for el in input_commitment.iter() {let gate =PublicInputGate::new(el.get_variable()); gate.add_to_cs(cs);}