p3_keccak_air/
round_flags.rs

1use core::borrow::Borrow;
2
3use p3_air::AirBuilder;
4use p3_matrix::Matrix;
5
6use crate::columns::KeccakCols;
7use crate::NUM_ROUNDS;
8
9#[inline]
10pub(crate) fn eval_round_flags<AB: AirBuilder>(builder: &mut AB) {
11    let main = builder.main();
12    let (local, next) = (main.row_slice(0), main.row_slice(1));
13    let local: &KeccakCols<AB::Var> = (*local).borrow();
14    let next: &KeccakCols<AB::Var> = (*next).borrow();
15
16    // Initially, the first step flag should be 1 while the others should be 0.
17    builder.when_first_row().assert_one(local.step_flags[0]);
18    for i in 1..NUM_ROUNDS {
19        builder.when_first_row().assert_zero(local.step_flags[i]);
20    }
21
22    for i in 0..NUM_ROUNDS {
23        let current_round_flag = local.step_flags[i];
24        let next_round_flag = next.step_flags[(i + 1) % NUM_ROUNDS];
25        builder
26            .when_transition()
27            .assert_eq(next_round_flag, current_round_flag);
28    }
29}