forked from andrewmilson/ministark
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tables.rs
185 lines (155 loc) Β· 4.68 KB
/
tables.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
pub trait BrainfuckColumn {
const FIRST_TRACE_COL_INDEX: usize;
const LAST_TRACE_COL_INDEX: usize;
const NUM_TRACE_COLUMNS: usize = Self::LAST_TRACE_COL_INDEX - Self::FIRST_TRACE_COL_INDEX + 1;
}
#[derive(Clone, Copy)]
pub enum Challenge {
A,
B,
C,
D,
E,
F,
Alpha,
Beta,
Gamma,
Delta,
Eta,
}
impl ministark::constraints::VerifierChallenge for Challenge {
fn index(&self) -> usize {
*self as usize
}
}
#[derive(Clone, Copy)]
pub enum EvaluationArgumentHint {
Instruction,
Input,
InputOffset,
Output,
OutputOffset,
}
impl ministark::constraints::Hint for EvaluationArgumentHint {
fn index(&self) -> usize {
*self as usize
}
}
#[derive(Clone, Copy)]
pub enum ProcessorBaseColumn {
Cycle,
Ip, // instruction pointer
CurrInstr,
NextInstr,
Mp, // memory pointer
MemVal,
MemValInv,
Dummy, // indicate if a row is padding
}
#[derive(Clone, Copy)]
pub enum ProcessorExtensionColumn {
InstructionPermutation, // 18
MemoryPermutation,
InputEvaluation,
OutputEvaluation,
}
#[derive(Clone, Copy)]
pub enum MemoryBaseColumn {
Cycle,
Mp,
MemVal,
Dummy,
}
#[derive(Clone, Copy)]
pub enum MemoryExtensionColumn {
Permutation,
}
#[derive(Clone, Copy)]
pub enum InstructionBaseColumn {
Ip,
CurrInstr, // 13
NextInstr,
// Dummy, // indicate if a row is padding
}
#[derive(Clone, Copy)]
pub enum InstructionExtensionColumn {
ProcessorPermutation,
ProgramEvaluation,
}
#[derive(Clone, Copy)]
pub enum InputBaseColumn {
Value,
}
#[derive(Clone, Copy)]
pub enum InputExtensionColumn {
Evaluation,
}
#[derive(Clone, Copy)]
pub enum OutputBaseColumn {
Value,
}
#[derive(Clone, Copy)]
pub enum OutputExtensionColumn {
Evaluation,
}
impl BrainfuckColumn for ProcessorBaseColumn {
const FIRST_TRACE_COL_INDEX: usize = ProcessorBaseColumn::Cycle as usize;
const LAST_TRACE_COL_INDEX: usize = ProcessorBaseColumn::Dummy as usize;
}
impl BrainfuckColumn for MemoryBaseColumn {
const FIRST_TRACE_COL_INDEX: usize = ProcessorBaseColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::Dummy as usize;
}
impl BrainfuckColumn for InstructionBaseColumn {
const FIRST_TRACE_COL_INDEX: usize = MemoryBaseColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::NextInstr as usize;
}
impl BrainfuckColumn for InputBaseColumn {
const FIRST_TRACE_COL_INDEX: usize = InstructionBaseColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::Value as usize;
}
impl BrainfuckColumn for OutputBaseColumn {
const FIRST_TRACE_COL_INDEX: usize = InputBaseColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::Value as usize;
}
impl BrainfuckColumn for ProcessorExtensionColumn {
const FIRST_TRACE_COL_INDEX: usize = OutputBaseColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize =
Self::FIRST_TRACE_COL_INDEX + Self::OutputEvaluation as usize;
}
impl BrainfuckColumn for MemoryExtensionColumn {
const FIRST_TRACE_COL_INDEX: usize = ProcessorExtensionColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::Permutation as usize;
}
impl BrainfuckColumn for InstructionExtensionColumn {
const FIRST_TRACE_COL_INDEX: usize = MemoryExtensionColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize =
Self::FIRST_TRACE_COL_INDEX + Self::ProgramEvaluation as usize;
}
impl BrainfuckColumn for InputExtensionColumn {
const FIRST_TRACE_COL_INDEX: usize = InstructionExtensionColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::Evaluation as usize;
}
impl BrainfuckColumn for OutputExtensionColumn {
const FIRST_TRACE_COL_INDEX: usize = InputExtensionColumn::LAST_TRACE_COL_INDEX + 1;
const LAST_TRACE_COL_INDEX: usize = Self::FIRST_TRACE_COL_INDEX + Self::Evaluation as usize;
}
macro_rules! impl_column {
($t:ty) => {
impl ministark::constraints::ExecutionTraceColumn for $t {
fn index(&self) -> usize {
Self::FIRST_TRACE_COL_INDEX + *self as usize
}
}
};
}
impl_column!(ProcessorBaseColumn);
impl_column!(ProcessorExtensionColumn);
impl_column!(MemoryBaseColumn);
impl_column!(MemoryExtensionColumn);
impl_column!(InstructionBaseColumn);
impl_column!(InstructionExtensionColumn);
impl_column!(InputBaseColumn);
impl_column!(InputExtensionColumn);
impl_column!(OutputBaseColumn);
impl_column!(OutputExtensionColumn);