zisk-core 1.1.0-alpha

Core types and proving primitives for the ZisK zkVM
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
use crate::ops_core::*;
use crate::InstContext;

/* Internal instructions */

/// InstContext-based wrapper over op_flag()
#[inline(always)]
pub fn opc_flag(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_flag(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_copyb()
#[inline(always)]
pub fn opc_copyb(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_copyb(ctx.a, ctx.b);
}

/* SIGN EXTEND operations for different data widths (i8, i16 and i32) --> i64 --> u64 */

/// InstContext-based wrapper over op_signextend_b()
#[inline(always)]
pub fn opc_signextend_b(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_signextend_b(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_signextend_h()
#[inline(always)]
pub fn opc_signextend_h(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_signextend_h(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_signextend_w()
#[inline(always)]
pub fn opc_signextend_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_signextend_w(ctx.a, ctx.b);
}

/* ADD AND SUB operations for different data widths (i32 and u64) */

/// InstContext-based wrapper over op_add()
#[inline(always)]
pub fn opc_add(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_add(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_add_w()
#[inline(always)]
pub fn opc_add_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_add_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sub()
#[inline(always)]
pub fn opc_sub(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sub(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sub_w()
#[inline(always)]
pub fn opc_sub_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sub_w(ctx.a, ctx.b);
}

/* SHIFT operations */

/// InstContext-based wrapper over op_sll()
#[inline(always)]
pub fn opc_sll(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sll(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sll_w()
#[inline(always)]
pub fn opc_sll_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sll_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sra()
#[inline(always)]
pub fn opc_sra(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sra(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_srl()
#[inline(always)]
pub fn opc_srl(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_srl(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sra_w()
#[inline(always)]
pub fn opc_sra_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sra_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_srl_w()
#[inline(always)]
pub fn opc_srl_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_srl_w(ctx.a, ctx.b);
}

/* COMPARISON operations */

/// InstContext-based wrapper over op_eq()
#[inline(always)]
pub fn opc_eq(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_eq(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_eq_w()
#[inline(always)]
pub fn opc_eq_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_eq_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_ltu()
#[inline(always)]
pub fn opc_ltu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_ltu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_lt()
#[inline(always)]
pub fn opc_lt(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_lt(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_ltu_w()
#[inline(always)]
pub fn opc_ltu_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_ltu_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_lt_w()
#[inline(always)]
pub fn opc_lt_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_lt_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_leu()
#[inline(always)]
pub fn opc_leu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_leu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_le()
#[inline(always)]
pub fn opc_le(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_le(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_leu_w()
#[inline(always)]
pub fn opc_leu_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_leu_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_le_w()
#[inline(always)]
pub fn opc_le_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_le_w(ctx.a, ctx.b);
}

/* LOGICAL operations */

/// InstContext-based wrapper over op_and()
#[inline(always)]
pub fn opc_and(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_and(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_or()
#[inline(always)]
pub fn opc_or(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_or(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_xor()
#[inline(always)]
pub fn opc_xor(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_xor(ctx.a, ctx.b);
}

/* ARITHMETIC operations: div / mul / rem */

/// InstContext-based wrapper over op_mulu()
#[inline(always)]
pub fn opc_mulu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_mulu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_mul()
#[inline(always)]
pub fn opc_mul(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_mul(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_mul_w()
#[inline(always)]
pub fn opc_mul_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_mul_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_muluh()
#[inline(always)]
pub fn opc_muluh(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_muluh(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_mulh()
#[inline(always)]
pub fn opc_mulh(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_mulh(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_mulsuh()
#[inline(always)]
pub fn opc_mulsuh(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_mulsuh(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_divu()
#[inline(always)]
pub fn opc_divu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_divu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_div()
#[inline(always)]
pub fn opc_div(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_div(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_divu_w()
#[inline(always)]
pub fn opc_divu_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_divu_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_div_w()
#[inline(always)]
pub fn opc_div_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_div_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_remu()
#[inline(always)]
pub fn opc_remu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_remu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_rem()
#[inline(always)]
pub fn opc_rem(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_rem(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_remu_w()
#[inline(always)]
pub fn opc_remu_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_remu_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_rem_w()
#[inline(always)]
pub fn opc_rem_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_rem_w(ctx.a, ctx.b);
}

/* MIN / MAX operations */

/// InstContext-based wrapper over op_minu()
#[inline(always)]
pub fn opc_minu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_minu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_min()
#[inline(always)]
pub fn opc_min(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_min(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_minu_w()
#[inline(always)]
pub fn opc_minu_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_minu_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_min_w()
#[inline(always)]
pub fn opc_min_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_min_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_maxu()
#[inline(always)]
pub fn opc_maxu(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_maxu(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_max()
#[inline(always)]
pub fn opc_max(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_max(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_maxu_w()
#[inline(always)]
pub fn opc_maxu_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_maxu_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_max_w()
#[inline(always)]
pub fn opc_max_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_max_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_rev8()
#[inline(always)]
pub fn opc_rev8(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_rev8(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_brev8()
#[inline(always)]
pub fn opc_brev8(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_brev8(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_andn()
#[inline(always)]
pub fn opc_andn(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_andn(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_orn()
#[inline(always)]
pub fn opc_orn(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_orn(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_xnor()
#[inline(always)]
pub fn opc_xnor(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_xnor(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_pack()
#[inline(always)]
pub fn opc_pack(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_pack(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_pack_h()
#[inline(always)]
pub fn opc_pack_h(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_pack_h(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_pack_w()
#[inline(always)]
pub fn opc_pack_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_pack_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_rol()
#[inline(always)]
pub fn opc_rol(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_rol(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_rol_w()
#[inline(always)]
pub fn opc_rol_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_rol_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_ror()
#[inline(always)]
pub fn opc_ror(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_ror(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_ror_w()
#[inline(always)]
pub fn opc_ror_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_ror_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_clz()
#[inline(always)]
pub fn opc_clz(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_clz(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_clz_w()
#[inline(always)]
pub fn opc_clz_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_clz_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_ctz()
#[inline(always)]
pub fn opc_ctz(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_ctz(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_ctz_w()
#[inline(always)]
pub fn opc_ctz_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_ctz_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_cpop()
#[inline(always)]
pub fn opc_cpop(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_cpop(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_cpop_w()
#[inline(always)]
pub fn opc_cpop_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_cpop_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_orc_b()
#[inline(always)]
pub fn opc_orc_b(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_orc_b(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_bclr()
#[inline(always)]
pub fn opc_bclr(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_bclr(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_bext()
#[inline(always)]
pub fn opc_bext(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_bext(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_binv()
#[inline(always)]
pub fn opc_binv(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_binv(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_bset()
#[inline(always)]
pub fn opc_bset(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_bset(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_add_u_w()
#[inline(always)]
pub fn opc_add_u_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_add_u_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sh1add()
#[inline(always)]
pub fn opc_sh1add(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sh1add(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sh1add_u_w()
#[inline(always)]
pub fn opc_sh1add_u_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sh1add_u_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sh2add()
#[inline(always)]
pub fn opc_sh2add(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sh2add(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sh2add_u_w()
#[inline(always)]
pub fn opc_sh2add_u_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sh2add_u_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sh3add()
#[inline(always)]
pub fn opc_sh3add(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sh3add(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sh3add_u_w()
#[inline(always)]
pub fn opc_sh3add_u_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sh3add_u_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_sll_u_w()
#[inline(always)]
pub fn opc_sll_u_w(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_sll_u_w(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_clmul()
#[inline(always)]
pub fn opc_clmul(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_clmul(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_clmul_h()
#[inline(always)]
pub fn opc_clmul_h(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_clmul_h(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_clmul_r()
#[inline(always)]
pub fn opc_clmul_r(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_clmul_r(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_xperm4()
#[inline(always)]
pub fn opc_xperm4(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_xperm4(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_xperm8()
#[inline(always)]
pub fn opc_xperm8(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_xperm8(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_czero_eqz()
#[inline(always)]
pub fn opc_czero_eqz(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_czero_eqz(ctx.a, ctx.b);
}

/// InstContext-based wrapper over op_czero_nez()
#[inline(always)]
pub fn opc_czero_nez(ctx: &mut InstContext) {
    (ctx.c, ctx.flag) = op_czero_nez(ctx.a, ctx.b);
}