openvm_keccak256_circuit/xorin/
columns.rs

1use openvm_circuit::system::memory::offline_checker::{MemoryReadAuxCols, MemoryWriteAuxCols};
2use openvm_circuit_primitives::{StructReflection, StructReflectionHelper};
3use openvm_circuit_primitives_derive::AlignedBorrow;
4use openvm_instructions::riscv::RV32_REGISTER_NUM_LIMBS;
5
6use crate::{KECCAK_RATE_BYTES, KECCAK_WORD_SIZE};
7
8#[repr(C)]
9#[derive(Debug, AlignedBorrow, StructReflection)]
10pub struct XorinVmCols<T> {
11    pub sponge: XorinSpongeCols<T>,
12    pub instruction: XorinInstructionCols<T>,
13    pub mem_oc: XorinMemoryCols<T>,
14}
15
16#[repr(C)]
17#[derive(Copy, Clone, Debug, Default, AlignedBorrow, StructReflection, derive_new::new)]
18#[allow(clippy::too_many_arguments)]
19pub struct XorinInstructionCols<T> {
20    pub pc: T,
21    pub is_enabled: T,
22    pub buffer_reg_ptr: T,
23    pub input_reg_ptr: T,
24    pub len_reg_ptr: T,
25    pub buffer_ptr: T,
26    pub buffer_ptr_limbs: [T; RV32_REGISTER_NUM_LIMBS],
27    pub input_ptr: T,
28    pub input_ptr_limbs: [T; RV32_REGISTER_NUM_LIMBS],
29    pub len: T,
30    pub len_limbs: [T; RV32_REGISTER_NUM_LIMBS],
31    pub start_timestamp: T,
32}
33
34#[repr(C)]
35#[derive(Copy, Clone, Debug, AlignedBorrow, StructReflection)]
36pub struct XorinSpongeCols<T> {
37    // is_padding_bytes is a boolean where is_padding_bytes[i] = 1 if 4*(i+1) >= len
38    // and is_padding_bytes[i] = 0 otherwise
39    // safety: notice that each 4 bytes has to have equal is_padding_bytes value
40    pub is_padding_bytes: [T; KECCAK_RATE_BYTES / KECCAK_WORD_SIZE],
41    pub preimage_buffer_bytes: [T; KECCAK_RATE_BYTES],
42    pub input_bytes: [T; KECCAK_RATE_BYTES],
43    pub postimage_buffer_bytes: [T; KECCAK_RATE_BYTES],
44}
45
46#[repr(C)]
47#[derive(Clone, Debug, AlignedBorrow, StructReflection)]
48pub struct XorinMemoryCols<T> {
49    pub register_aux_cols: [MemoryReadAuxCols<T>; 3],
50    pub input_bytes_read_aux_cols: [MemoryReadAuxCols<T>; KECCAK_RATE_BYTES / KECCAK_WORD_SIZE],
51    pub buffer_bytes_read_aux_cols: [MemoryReadAuxCols<T>; KECCAK_RATE_BYTES / KECCAK_WORD_SIZE],
52    pub buffer_bytes_write_aux_cols:
53        [MemoryWriteAuxCols<T, RV32_REGISTER_NUM_LIMBS>; KECCAK_RATE_BYTES / KECCAK_WORD_SIZE],
54}
55
56pub const NUM_XORIN_VM_COLS: usize = size_of::<XorinVmCols<u8>>();