openvm_keccak256_circuit/keccakf_op/
columns.rs

1use openvm_circuit::system::memory::offline_checker::{MemoryBaseAuxCols, MemoryReadAuxCols};
2use openvm_circuit_primitives::{StructReflection, StructReflectionHelper};
3use openvm_circuit_primitives_derive::AlignedBorrow;
4use openvm_instructions::riscv::RV32_REGISTER_NUM_LIMBS;
5
6use crate::{KECCAK_WIDTH_BYTES, KECCAK_WIDTH_WORDS};
7
8#[repr(C)]
9#[derive(Copy, Clone, Debug, AlignedBorrow, StructReflection)]
10pub struct KeccakfOpCols<T> {
11    /// Program counter
12    pub pc: T,
13    /// True on the row handling execution for an instruction.
14    pub is_valid: T,
15    /// The starting timestamp for execution in this row.
16    /// A single row will do multiple memory accesses.
17    pub timestamp: T,
18    /// Pointer to address space 1 `rd` register.
19    /// The `rd` register holds the value of `buffer_ptr`.
20    pub rd_ptr: T,
21    /// `buffer_ptr <- [rd_ptr:4]_1`.
22    /// Limbs of the pointer to address space 2 `buffer`.
23    pub buffer_ptr_limbs: [T; RV32_REGISTER_NUM_LIMBS],
24    /// The preimage state, to be permuted in the `keccakf` operation.
25    pub preimage: [T; KECCAK_WIDTH_BYTES],
26    /// The postimage state after `keccakf` permute of `preimage`.
27    ///
28    /// Note: there is 2 row per instruction design where these columns can be shared with
29    /// `preimage`. However due to the interactions necessary for range checks, currently we
30    /// determined it is better to minimum number of rows while using more main columns.
31    pub postimage: [T; KECCAK_WIDTH_BYTES],
32    /// Auxiliary columns for timestamp checking for the read of `[rd_ptr:4]_1`.
33    pub rd_aux: MemoryReadAuxCols<T>,
34    /// Auxiliary columns for timestamp checking of the writes to `buffer`. The writes are done one
35    /// word at a time, and each write requires a separate previous timestamp.
36    pub buffer_word_aux: [MemoryBaseAuxCols<T>; KECCAK_WIDTH_WORDS],
37}
38
39pub const NUM_KECCAKF_OP_COLS: usize = size_of::<KeccakfOpCols<u8>>();