miden_ace_codegen/layout/
keys.rs1use super::InputLayout;
2use crate::EXT_DEGREE;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum InputKey {
7 Public(usize),
9 AuxRandAlpha,
11 AuxRandBeta,
13 Main { offset: usize, index: usize },
15 AuxCoord {
17 offset: usize,
18 index: usize,
19 coord: usize,
20 },
21 AuxBusBoundary(usize),
23 Z,
25 Alpha,
27 ZPowN,
29 GInv,
31 GInv2,
33 ZK,
35 Weight0,
37 G,
39 S0,
41 InvZMinusGInv,
43 InvZMinusOne,
45 InvVanishing,
47 QuotientChunkCoord {
50 offset: usize,
51 chunk: usize,
52 coord: usize,
53 },
54}
55
56#[derive(Debug, Clone, Copy)]
58pub(crate) struct InputKeyMapper<'a> {
59 pub(super) layout: &'a InputLayout,
60}
61
62impl InputKeyMapper<'_> {
63 pub(crate) fn index_of(&self, key: InputKey) -> Option<usize> {
65 let layout = self.layout;
66 match key {
67 InputKey::Public(i) => layout.regions.public_values.index(i),
68 InputKey::AuxRandAlpha => Some(layout.aux_rand_alpha),
69 InputKey::AuxRandBeta => Some(layout.aux_rand_beta),
70 InputKey::Main { offset, index } => match offset {
71 0 => layout.regions.main_curr.index(index),
72 1 => layout.regions.main_next.index(index),
73 _ => None,
74 },
75 InputKey::AuxCoord { offset, index, coord } => {
76 if index >= layout.counts.aux_width || coord >= EXT_DEGREE {
77 return None;
78 }
79 let local = index * EXT_DEGREE + coord;
80 match offset {
81 0 => layout.regions.aux_curr.index(local),
82 1 => layout.regions.aux_next.index(local),
83 _ => None,
84 }
85 },
86 InputKey::AuxBusBoundary(i) => layout.regions.aux_bus_boundary.index(i),
87 InputKey::Z => Some(layout.stark.z),
88 InputKey::Alpha => Some(layout.stark.alpha),
89 InputKey::GInv => Some(layout.stark.g_inv),
90 InputKey::ZPowN => Some(layout.stark.z_pow_n),
91 InputKey::GInv2 => Some(layout.stark.g_inv2),
92 InputKey::ZK => Some(layout.stark.z_k),
93 InputKey::Weight0 => Some(layout.stark.weight0),
94 InputKey::G => Some(layout.stark.g),
95 InputKey::S0 => Some(layout.stark.s0),
96 InputKey::InvZMinusGInv => Some(layout.stark.inv_z_minus_g_inv),
97 InputKey::InvZMinusOne => Some(layout.stark.inv_z_minus_one),
98 InputKey::InvVanishing => Some(layout.stark.inv_vanishing),
99 InputKey::QuotientChunkCoord { offset, chunk, coord } => {
100 if chunk >= layout.counts.num_quotient_chunks || coord >= EXT_DEGREE {
101 return None;
102 }
103 let idx = chunk * EXT_DEGREE + coord;
104 match offset {
105 0 => layout.regions.quotient_curr.index(idx),
106 1 => layout.regions.quotient_next.index(idx),
107 _ => None,
108 }
109 },
110 }
111 }
112}