-
Notifications
You must be signed in to change notification settings - Fork 2
/
sieve_ir.fbs
259 lines (222 loc) · 4.9 KB
/
sieve_ir.fbs
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// This is a FlatBuffers schema.
// See https://google.github.io/flatbuffers/
namespace sieve_ir;
// REGEX used:
// - VERSION_REGEX = "^\d+.\d+.\d+$"
// - STRING_REGEX = "^[a-zA-Z_][\w]*((\.|::)[a-zA-Z_][\w]*)*$"
// - NUMBER_REGEX = "^((\d+)|(0x[0-9a-fA-F]+))$"
// ==== Message types that can be exchanged. ====
union Message {
Relation,
PublicInputs,
PrivateInputs,
}
// The 'version' field must match VERSION_REGEX
// Each string in the 'plugins' list must match STRING_REGEX
table Relation {
version :string;
plugins :[string];
types :[Type];
conversions :[Conversion];
directives :[Directive];
}
// The 'version' field must match VERSION_REGEX
table PublicInputs {
version :string;
type :Type;
inputs :[Value];
}
// The 'version' field must match VERSION_REGEX
table PrivateInputs {
version :string;
type :Type;
inputs :[Value];
}
// ==== Helper types ====
// Type element is encoded in a vector of bytes in little-endian
// order. There is no minimum or maximum length; trailing zeros
// may be omitted.
table Value {
value :[ubyte];
}
struct Count {
type_id :ubyte;
count :uint64;
}
// ==== Directive ====
union DirectiveSet {
Gate,
Function,
}
table Directive {
directive :DirectiveSet;
}
// ==== Conversion ====
struct Conversion {
output_count :Count;
input_count :Count;
}
// ==== Type ====
union TypeU {
Field,
PluginType
}
table Type {
element :TypeU;
}
table Field {
modulo :Value;
}
// 'name' and 'operation' must match STRING_REGEX
// Strings of the 'params' list must match either
// STRING_REGEX or NUMBER_REGEX
table PluginType {
name :string;
operation :string;
params :[string];
}
// ==== Gate types ====
table GateConstant {
type_id :ubyte;
out_id :uint64;
// 'constant' is encoded in a vector of bytes in little-endian
// order. There is no minimum or maximum length; trailing zeros
// may be omitted.
constant :[ubyte];
}
table GateAssertZero {
type_id :ubyte;
in_id :uint64;
}
table GateCopy {
type_id :ubyte;
out_id :uint64;
in_id :uint64;
}
table GateAdd {
type_id :ubyte;
out_id :uint64;
left_id :uint64;
right_id :uint64;
}
table GateMul {
type_id :ubyte;
out_id :uint64;
left_id :uint64;
right_id :uint64;
}
table GateAddConstant {
type_id :ubyte;
out_id :uint64;
in_id :uint64;
// 'constant' is encoded in a vector of bytes in little-endian
// order. There is no minimum or maximum length; trailing zeros
// may be omitted.
constant :[ubyte];
}
table GateMulConstant {
type_id :ubyte;
out_id :uint64;
in_id :uint64;
// 'constant' is encoded in a vector of bytes in little-endian
// order. There is no minimum or maximum length; trailing zeros
// may be omitted.
constant :[ubyte];
}
table GatePublic {
type_id :ubyte;
out_id :uint64;
}
table GatePrivate {
type_id :ubyte;
out_id :uint64;
}
// To allocate in a contiguous space all wires between
// first_id and last_id inclusive.
table GateNew {
type_id :ubyte;
first_id :uint64;
last_id :uint64;
}
table GateDelete {
type_id :ubyte;
first_id :uint64;
last_id :uint64;
}
table GateConvert {
out_type_id :ubyte;
out_first_id :uint64;
out_last_id :uint64;
in_type_id :ubyte;
in_first_id :uint64;
in_last_id :uint64;
}
// ==== Function declaration ====
union FunctionBody {
Gates,
PluginBody,
}
table Gates {
gates :[Gate];
}
// 'name' and 'operation' must match STRING_REGEX
// Strings of the 'params' list must match either
// STRING_REGEX or NUMBER_REGEX
table PluginBody {
name :string;
operation :string;
params :[string];
public_count :[Count]; // Each type_id must be unique
private_count :[Count]; // Each type_id must be unique
}
// Declare a Function gate as a custom computation or from a plugin
// The 'name' must match STRING_REGEX
table Function {
name :string;
output_count :[Count];
input_count :[Count];
body :FunctionBody;
}
struct WireRange {
first_id :uint64;
last_id :uint64;
}
// Invokes a previously defined Function gate
// The 'name' must match STRING_REGEX
table GateCall {
name :string;
out_ids :[WireRange];
in_ids :[WireRange];
}
union GateSet {
GateConstant,
GateAssertZero,
GateCopy,
GateAdd,
GateMul,
GateAddConstant,
GateMulConstant,
GatePublic,
GatePrivate,
GateNew,
GateDelete,
GateConvert,
GateCall,
}
table Gate {
gate :GateSet;
}
// ==== Flatbuffers details ====
// All message types are encapsulated in the FlatBuffers root table.
table Root {
message :Message;
}
root_type Root;
// When storing messages to files, this extension and identifier
// should be used.
file_extension "sieve";
file_identifier "siev"; // a.k.a. magic bytes.
// Message framing:
//
// All messages must be prefixed by its size in bytes,
// as a 4-bytes little-endian unsigned integer.