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
use crate::plonk::{self, Any};
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Column {
pub(super) column_type: Any,
pub(super) index: usize,
}
impl fmt::Display for Column {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Column('{:?}', {})", self.column_type, self.index)
}
}
impl From<(Any, usize)> for Column {
fn from((column_type, index): (Any, usize)) -> Self {
Column { column_type, index }
}
}
impl From<plonk::Column<Any>> for Column {
fn from(column: plonk::Column<Any>) -> Self {
Column {
column_type: *column.column_type(),
index: column.index(),
}
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct VirtualCell {
name: &'static str,
pub(super) column: Column,
pub(super) rotation: i32,
}
impl From<(Column, i32)> for VirtualCell {
fn from((column, rotation): (Column, i32)) -> Self {
VirtualCell {
name: "",
column,
rotation,
}
}
}
impl From<(&'static str, Column, i32)> for VirtualCell {
fn from((name, column, rotation): (&'static str, Column, i32)) -> Self {
VirtualCell {
name,
column,
rotation,
}
}
}
impl From<plonk::VirtualCell> for VirtualCell {
fn from(c: plonk::VirtualCell) -> Self {
VirtualCell {
name: "",
column: c.column.into(),
rotation: c.rotation.0,
}
}
}
impl fmt::Display for VirtualCell {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}@{}", self.column, self.rotation)?;
if !self.name.is_empty() {
write!(f, "({})", self.name)?;
}
Ok(())
}
}
#[derive(Debug, PartialEq)]
pub struct Gate {
pub(super) index: usize,
pub(super) name: &'static str,
}
impl fmt::Display for Gate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Gate {} ('{}')", self.index, self.name)
}
}
impl From<(usize, &'static str)> for Gate {
fn from((index, name): (usize, &'static str)) -> Self {
Gate { index, name }
}
}
#[derive(Debug, PartialEq)]
pub struct Constraint {
pub(super) gate: Gate,
pub(super) index: usize,
pub(super) name: &'static str,
}
impl fmt::Display for Constraint {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Constraint {}{} in gate {} ('{}')",
self.index,
if self.name.is_empty() {
String::new()
} else {
format!(" ('{}')", self.name)
},
self.gate.index,
self.gate.name,
)
}
}
impl From<(Gate, usize, &'static str)> for Constraint {
fn from((gate, index, name): (Gate, usize, &'static str)) -> Self {
Constraint { gate, index, name }
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct Region {
pub(super) index: usize,
pub(super) name: String,
}
impl fmt::Display for Region {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Region {} ('{}')", self.index, self.name)
}
}
impl From<(usize, String)> for Region {
fn from((index, name): (usize, String)) -> Self {
Region { index, name }
}
}
impl From<(usize, &str)> for Region {
fn from((index, name): (usize, &str)) -> Self {
Region {
index,
name: name.to_owned(),
}
}
}