Skip to main content

miden_air/constraints/stack/
columns.rs

1use miden_core::program::MIN_STACK_DEPTH;
2
3/// Stack columns in the main execution trace (19 columns).
4#[repr(C)]
5#[derive(Debug, Clone, Default)]
6pub struct StackCols<T> {
7    /// Top 16 stack elements s0-s15.
8    pub top: [T; MIN_STACK_DEPTH],
9    /// Stack depth.
10    pub b0: T,
11    /// Overflow table parent address.
12    pub b1: T,
13    /// Helper: 1/(b0 - 16) when b0 != 16, else 0.
14    pub h0: T,
15}
16
17impl<T: Copy> StackCols<T> {
18    /// Returns the stack element at position `idx` (0 = top of stack).
19    pub fn get(&self, idx: usize) -> T {
20        self.top[idx]
21    }
22}
23
24impl<T> StackCols<T> {
25    /// Returns a slice of stack elements for the given range.
26    pub fn elements(&self, range: impl core::slice::SliceIndex<[T], Output = [T]>) -> &[T] {
27        &self.top[range]
28    }
29}