Skip to main content

miden_air/constraints/decoder/
columns.rs

1use crate::trace::decoder::{
2    NUM_HASHER_COLUMNS, NUM_OP_BATCH_FLAGS, NUM_OP_BITS, NUM_OP_BITS_EXTRA_COLS,
3    NUM_USER_OP_HELPERS,
4};
5
6/// Decoder columns in the main execution trace (24 columns).
7#[repr(C)]
8#[derive(Debug, Clone, Default)]
9pub struct DecoderCols<T> {
10    /// Block address (hasher table row pointer).
11    pub addr: T,
12    /// Opcode bits b0-b6.
13    pub op_bits: [T; NUM_OP_BITS],
14    /// Hasher state h0-h7 (shared between decoding and MAST node hashing).
15    pub hasher_state: [T; NUM_HASHER_COLUMNS],
16    /// In-span flag (1 inside a basic block).
17    pub in_span: T,
18    /// Remaining operation group count.
19    pub group_count: T,
20    /// Position within operation group (0-8).
21    pub op_index: T,
22    /// Operation batch flags c0, c1, c2.
23    pub batch_flags: [T; NUM_OP_BATCH_FLAGS],
24    /// Degree-reduction extra columns e0, e1.
25    pub extra: [T; NUM_OP_BITS_EXTRA_COLS],
26}
27
28impl<T: Copy> DecoderCols<T> {
29    /// Returns the 6 user-op helper registers (hasher_state[2..8]).
30    pub fn user_op_helpers(&self) -> [T; NUM_USER_OP_HELPERS] {
31        [
32            self.hasher_state[2],
33            self.hasher_state[3],
34            self.hasher_state[4],
35            self.hasher_state[5],
36            self.hasher_state[6],
37            self.hasher_state[7],
38        ]
39    }
40
41    /// Returns the 4 end-block flags (hasher_state[4..8]).
42    pub fn end_block_flags(&self) -> EndBlockFlags<T> {
43        EndBlockFlags {
44            is_loop_body: self.hasher_state[4],
45            is_loop: self.hasher_state[5],
46            is_call: self.hasher_state[6],
47            is_syscall: self.hasher_state[7],
48        }
49    }
50}
51
52/// Named end-block flag overlay for `hasher_state[4..8]`.
53#[repr(C)]
54#[derive(Clone, Debug)]
55pub struct EndBlockFlags<T> {
56    pub is_loop_body: T,
57    pub is_loop: T,
58    pub is_call: T,
59    pub is_syscall: T,
60}