proofman-starks-lib-c 1.1.0-alpha

Rust FFI bindings to the pil2-stark C/CUDA proving library
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
// FFI bindings for the pil2-stark C++ library
// These functions use C linkage (extern "C") so they have consistent names across platforms

#[allow(dead_code)]
extern "C" {
    pub fn build_const_tree_c(
        const_file: *const ::std::os::raw::c_char,
        stark_info_file: *const ::std::os::raw::c_char,
        const_tree_file: *const ::std::os::raw::c_char,
        ver_key_file: *const ::std::os::raw::c_char,
        out_root: *mut u64,
    ) -> ::std::os::raw::c_int;

    pub fn fflonk_setup_c(
        r1cs_file: *const ::std::os::raw::c_char,
        ptau_file: *const ::std::os::raw::c_char,
        zkey_file: *const ::std::os::raw::c_char,
    ) -> ::std::os::raw::c_int;

    pub fn plonk_setup_c(
        r1cs_file: *const ::std::os::raw::c_char,
        ptau_file: *const ::std::os::raw::c_char,
        zkey_file: *const ::std::os::raw::c_char,
    ) -> ::std::os::raw::c_int;

    pub fn plonk_circuit_stats_c(
        r1cs_file: *const ::std::os::raw::c_char,
        n_constraints: *mut u64,
        n_additions: *mut u64,
    ) -> ::std::os::raw::c_int;

    // SetupCtx
    // ========================================================================================
    pub fn n_hints_by_name(
        p_expression_bin: *mut ::std::os::raw::c_void, 
        hintName: *mut ::std::os::raw::c_char
    ) -> u64;
    
    pub fn get_hint_ids_by_name(
        p_expression_bin: *mut ::std::os::raw::c_void,
        hintIds: *mut u64,
        hintName: *mut ::std::os::raw::c_char,
    );

    // Stark Info
    // ========================================================================================
    pub fn stark_info_new(
        filename: *mut ::std::os::raw::c_char,
        recursive_final: bool,
        recursive: bool,
        verify_constraints: bool,
        verify: bool,
        gpu: bool,
        preallocate: bool,
        single_use: bool,
    ) -> *mut ::std::os::raw::c_void;
    
    pub fn set_hash_family(fam: u8);

    pub fn get_proof_size(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;

    pub fn get_proof_pinned_size(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;

    pub fn register_host_memory(ptr: *mut ::std::os::raw::c_void, size: u64) -> u32;

    pub fn unregister_host_memory(ptr: *mut ::std::os::raw::c_void);

    pub fn wait_trace_h2d_done(d_buffers: *mut ::std::os::raw::c_void, stream_id: u64);

    pub fn set_memory_expressions(pStarkInfo: *mut ::std::os::raw::c_void, nTmp1: u64, nTmp3: u64);
    
    pub fn get_map_total_n(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;
        
    pub fn get_map_total_n_contributions(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_map_total_n_custom_commits_fixed(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_tree_size(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn stark_info_free(pStarkInfo: *mut ::std::os::raw::c_void);

    // Const Pols
    // ========================================================================================
    pub fn load_const_tree(
        pStarkInfo: *mut ::std::os::raw::c_void,
        pConstTree: *mut ::std::os::raw::c_void,
        treeFilename: *mut ::std::os::raw::c_char,
        constTreeSize: u64,
        verkeyFilename: *mut ::std::os::raw::c_char,
    ) -> bool;
    
    pub fn load_const_pols(
        pConstPols: *mut ::std::os::raw::c_void,
        constFilename: *mut ::std::os::raw::c_char,
        constSize: u64,
    );
    
    pub fn get_const_tree_size(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;

    pub fn get_const_size(pStarkInfo: *mut ::std::os::raw::c_void) -> u64;

    pub fn calculate_words_per_row(
        pStarkinfo: *mut ::std::os::raw::c_void,
        constPolsPath: *mut ::std::os::raw::c_char,
    ) -> u64;

    pub fn init_gpu_setup(arity: u64);

    pub fn pack_const_pols(
        pStarkinfo: *mut ::std::os::raw::c_void,
        pConstPols: *mut ::std::os::raw::c_void,
        constFile: *mut ::std::os::raw::c_char,
    );

    pub fn tile_const_pols(
        pStarkInfo: *mut ::std::os::raw::c_void,
        pConstPols: *mut ::std::os::raw::c_void,
        constFile: *mut ::std::os::raw::c_char,
        pConstTree: *mut ::std::os::raw::c_void,
        constTreeFile: *mut ::std::os::raw::c_char,
        unified_buffer_gpu: *mut ::std::os::raw::c_void,
    ); 

    pub fn prepare_blocks(pol: *mut u64, N: u64, nCols: u64, unified_buffer_gpu: *mut ::std::os::raw::c_void);

    pub fn calculate_const_tree(
        pStarkInfo: *mut ::std::os::raw::c_void,
        pConstPolsAddress: *mut ::std::os::raw::c_void,
        pConstTree: *mut ::std::os::raw::c_void,
        unified_buffer_gpu: *mut ::std::os::raw::c_void,
    );

    pub fn calculate_const_tree_bn128(
        pStarkInfo: *mut ::std::os::raw::c_void,
        pConstPolsAddress: *mut ::std::os::raw::c_void,
        pConstTree: *mut ::std::os::raw::c_void,
    );
    
    pub fn write_const_tree(
        pStarkInfo: *mut ::std::os::raw::c_void,
        pConstTreeAddress: *mut ::std::os::raw::c_void,
        treeFilename: *mut ::std::os::raw::c_char,
    );

    pub fn write_const_tree_bn128(
        pStarkInfo: *mut ::std::os::raw::c_void,
        pConstTreeAddress: *mut ::std::os::raw::c_void,
        treeFilename: *mut ::std::os::raw::c_char,
    );

    pub fn verify_root_bn128_from_tree(
        treeFilename: *mut ::std::os::raw::c_char,
        expectedRoot: *mut ::std::os::raw::c_char,
    ) -> bool;

    // Expressions Bin
    // ========================================================================================
    pub fn expressions_bin_new(
        filename: *mut ::std::os::raw::c_char,
        global: bool,
        verifier: bool,
    ) -> *mut ::std::os::raw::c_void;
    
    pub fn get_max_n_tmp1(pExpressionsBin: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_max_n_tmp3(pExpressionsBin: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_max_args(pExpressionsBin: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_max_ops(pExpressionsBin: *mut ::std::os::raw::c_void) -> u64;

    pub fn get_operations_quotient(pExpressionsBin: *mut ::std::os::raw::c_void, pStarkInfo: *mut ::std::os::raw::c_void) -> u64;

    pub fn expressions_bin_free(pExpressionsBin: *mut ::std::os::raw::c_void);

    // Hints
    // ========================================================================================
    pub fn get_hint_field(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        stepsParams: *mut ::std::os::raw::c_void,
        hintFieldValues: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
        hintOptions: *mut ::std::os::raw::c_void,
        d_buffers: *mut ::std::os::raw::c_void,
        streamId: u64,
        constant: bool,
    );
    
    pub fn get_hint_field_values(
        pSetupCtx: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
    ) -> u64;
    
    pub fn get_hint_field_sizes(
        pSetupCtx: *mut ::std::os::raw::c_void,
        hintFieldValues: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
        hintOptions: *mut ::std::os::raw::c_void,
    );
    
    pub fn mul_hint_fields(
        pSetupCtx: *mut ::std::os::raw::c_void,
        stepsParams: *mut ::std::os::raw::c_void,
        nHints: u64,
        hintId: *mut u64,
        hintFieldNameDest: *mut *mut ::std::os::raw::c_char,
        hintFieldName1: *mut *mut ::std::os::raw::c_char,
        hintFieldName2: *mut *mut ::std::os::raw::c_char,
        hintOptions1: *mut *mut ::std::os::raw::c_void,
        hintOptions2: *mut *mut ::std::os::raw::c_void,
    );
    
    pub fn acc_hint_field(
        pSetupCtx: *mut ::std::os::raw::c_void,
        stepsParams: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldNameDest: *mut ::std::os::raw::c_char,
        hintFieldNameAirgroupVal: *mut ::std::os::raw::c_char,
        hintFieldName: *mut ::std::os::raw::c_char,
        add: bool,
    );
    
    pub fn acc_mul_hint_fields(
        pSetupCtx: *mut ::std::os::raw::c_void,
        stepsParams: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldNameDest: *mut ::std::os::raw::c_char,
        hintFieldNameAirgroupVal: *mut ::std::os::raw::c_char,
        hintFieldName1: *mut ::std::os::raw::c_char,
        hintFieldName2: *mut ::std::os::raw::c_char,
        hintOptions1: *mut ::std::os::raw::c_void,
        hintOptions2: *mut ::std::os::raw::c_void,
        add: bool,
    );
    
    pub fn update_airgroupvalue(
        pSetupCtx: *mut ::std::os::raw::c_void,
        stepsParams: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldNameAirgroupVal: *mut ::std::os::raw::c_char,
        hintFieldName1: *mut ::std::os::raw::c_char,
        hintFieldName2: *mut ::std::os::raw::c_char,
        hintOptions1: *mut ::std::os::raw::c_void,
        hintOptions2: *mut ::std::os::raw::c_void,
        add: bool,
    ) -> u64;
    
    pub fn set_hint_field(
        pSetupCtx: *mut ::std::os::raw::c_void,
        stepsParams: *mut ::std::os::raw::c_void,
        values: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
    ) -> u64;
    
    pub fn get_hint_id(
        pSetupCtx: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
    ) -> u64;

    // Calculate impols expressions
    // ========================================================================================
    pub fn calculate_impols_expressions(
        pSetupCtx: *mut ::std::os::raw::c_void,
        step: u64,
        stepsParams: *mut ::std::os::raw::c_void,
    );

    pub fn calculate_witness_expr(
        pSetupCtx: *mut ::std::os::raw::c_void,
        stepsParams: *mut ::std::os::raw::c_void,
    );

    // Custom Commits
    // ========================================================================================
    pub fn custom_commit_size(pSetup: *mut ::std::os::raw::c_void, commitId: u64) -> u64;
    
    pub fn load_custom_commit(
        pSetup: *mut ::std::os::raw::c_void,
        commitId: u64,
        buffer: *mut ::std::os::raw::c_void,
        customCommitFile: *mut ::std::os::raw::c_char,
    );

    pub fn write_custom_commit(
        root: *mut ::std::os::raw::c_void,
        arity: u64,
        nBits: u64,
        nBitsExt: u64,
        nCols: u64,
        d_buffers: *mut ::std::os::raw::c_void,
        buffer: *mut ::std::os::raw::c_void,
        bufferFile: *mut ::std::os::raw::c_char,
    );

    // Witness Commit
    // ========================================================================================
    pub fn commit_witness(
        pSetupCtx: *mut ::std::os::raw::c_void,
        params: *mut ::std::os::raw::c_void,
        instanceId: u64,
        airgroupId: u64,
        airId: u64,
        root: *mut ::std::os::raw::c_void,
        d_buffers: *mut ::std::os::raw::c_void,
        customCommitsFixedPath: *mut ::std::os::raw::c_char,
    ) -> u64;

    // Constraints Verification
    // ========================================================================================
    pub fn get_n_constraints(pSetupCtx: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_constraints_lines_sizes(pSetupCtx: *mut ::std::os::raw::c_void, constraintsLinesSizes: *mut u64);
    
    pub fn get_constraints_lines(pSetupCtx: *mut ::std::os::raw::c_void, constraintsLines: *mut *mut u8);

    pub fn initialize_instance(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        instanceId: u64,
        stepsParams: *mut ::std::os::raw::c_void,
        d_buffers: *mut ::std::os::raw::c_void,
        customCommitsFixedPath: *mut ::std::os::raw::c_char,
    ) -> u64;

    pub fn calculate_trace_instance(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        stepsParams: *mut ::std::os::raw::c_void,
        d_buffers: *mut ::std::os::raw::c_void,
        streamId: u64,
    );

    pub fn verify_constraints(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        stepsParams: *mut ::std::os::raw::c_void,
        constraintsInfo: *mut ::std::os::raw::c_void,
        d_buffers: *mut ::std::os::raw::c_void,
        streamId: u64,
    );

    // Global Constraints
    // ========================================================================================
    pub fn get_n_global_constraints(p_globalinfo_bin: *mut ::std::os::raw::c_void) -> u64;
    
    pub fn get_global_constraints_lines_sizes(
        p_globalinfo_bin: *mut ::std::os::raw::c_void,
        constraintsLinesSizes: *mut u64,
    );
    
    pub fn get_global_constraints_lines(p_globalinfo_bin: *mut ::std::os::raw::c_void, constraintsLines: *mut *mut u8);
    
    pub fn verify_global_constraints(
        globalInfoFile: *mut ::std::os::raw::c_char,
        globalBin: *mut ::std::os::raw::c_void,
        publics: *mut ::std::os::raw::c_void,
        challenges: *mut ::std::os::raw::c_void,
        proofValues: *mut ::std::os::raw::c_void,
        airgroupValues: *mut *mut ::std::os::raw::c_void,
        globalConstraintsInfo: *mut ::std::os::raw::c_void,
    );
    
    pub fn get_hint_field_global_constraints_values(
        p_globalinfo_bin: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
    ) -> u64;
    
    pub fn get_hint_field_global_constraints_sizes(
        globalInfoFile: *mut ::std::os::raw::c_char,
        p_globalinfo_bin: *mut ::std::os::raw::c_void,
        hintFieldValues: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
        print_expression: bool,
    );
    
    pub fn get_hint_field_global_constraints(
        globalInfoFile: *mut ::std::os::raw::c_char,
        p_globalinfo_bin: *mut ::std::os::raw::c_void,
        hintFieldValues: *mut ::std::os::raw::c_void,
        publics: *mut ::std::os::raw::c_void,
        challenges: *mut ::std::os::raw::c_void,
        proofValues: *mut ::std::os::raw::c_void,
        airgroupValues: *mut *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
        print_expression: bool,
    );
    
    pub fn set_hint_field_global_constraints(
        globalInfoFile: *mut ::std::os::raw::c_char,
        p_globalinfo_bin: *mut ::std::os::raw::c_void,
        proofValues: *mut ::std::os::raw::c_void,
        values: *mut ::std::os::raw::c_void,
        hintId: u64,
        hintFieldName: *mut ::std::os::raw::c_char,
    ) -> u64;

    // Proof Generation
    // ========================================================================================
    pub fn gen_proof(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        instanceId: u64,
        params: *mut ::std::os::raw::c_void,
        globalChallenge: *mut ::std::os::raw::c_void,
        proofBuffer: *mut u64,
        proofFile: *mut ::std::os::raw::c_char,
        d_buffers: *mut ::std::os::raw::c_void,
        skipRecalculation: bool,
        streamId: u64,
        constPolsPath: *mut ::std::os::raw::c_char,
        constTreePath: *mut ::std::os::raw::c_char,
        customCommitsFixedPath: *mut ::std::os::raw::c_char,
    ) -> u64;
    
    pub fn gen_recursive_proof(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        instanceId: u64,
        witness: *mut ::std::os::raw::c_void,
        aux_trace: *mut ::std::os::raw::c_void,
        pConstPols: *mut ::std::os::raw::c_void,
        pConstTree: *mut ::std::os::raw::c_void,
        pPublicInputs: *mut ::std::os::raw::c_void,
        proofBuffer: *mut u64,
        proof_file: *mut ::std::os::raw::c_char,
        vadcop: bool,
        d_buffers: *mut ::std::os::raw::c_void,
        constPolsPath: *mut ::std::os::raw::c_char,
        constTreePath: *mut ::std::os::raw::c_char,
        proofType: *mut ::std::os::raw::c_char,
        force_recursive_stream: bool,
        recurser_id: *mut ::std::os::raw::c_char,
        streamId_: u64,
    ) -> u64;

    pub fn reserve_best_stream_nonblock(
        d_buffers_: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        proofType: *mut ::std::os::raw::c_char,
        recursive: bool,
        force_recursive: bool,
    ) -> u32;

    pub fn reserve_stream_if_free(
        d_buffers_: *mut ::std::os::raw::c_void,
        streamId: u32,
        airgroupId: u64,
        airId: u64,
        proofType: *mut ::std::os::raw::c_char,
        force_recursive: bool,
    ) -> u32;

    pub fn release_stream_reservation(d_buffers_: *mut ::std::os::raw::c_void, streamId: u32);

    pub fn calculate_const_tree_fixed(
        pSetupCtx_: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        proofType: *mut ::std::os::raw::c_char,
        d_buffers_: *mut ::std::os::raw::c_void
    );
    
    pub fn read_exec_file(exec_data: *mut u64, exec_file: *mut ::std::os::raw::c_char, nCommitedPols: u64);
    
    pub fn get_committed_pols(
        circomWitness: *mut ::std::os::raw::c_void,
        execData: *mut u64,
        witness: *mut ::std::os::raw::c_void,
        pPublics: *mut ::std::os::raw::c_void,
        sizeWitness: u64,
        N: u64,
        nPublics: u64,
        nCols: u64,
    );
    
    pub fn gen_recursive_proof_final(
        pSetupCtx: *mut ::std::os::raw::c_void,
        airgroupId: u64,
        airId: u64,
        instanceId: u64,
        witness: *mut ::std::os::raw::c_void,
        aux_trace: *mut ::std::os::raw::c_void,
        pConstPols: *mut ::std::os::raw::c_void,
        pConstTree: *mut ::std::os::raw::c_void,
        pPublicInputs: *mut ::std::os::raw::c_void,
        proof_file: *mut ::std::os::raw::c_char,
        prover_buffer_size: u64,
        d_buffers: *mut ::std::os::raw::c_void,
    ) -> *mut ::std::os::raw::c_void;

    // Stream Management
    // ========================================================================================
    pub fn get_stream_proofs(d_buffers_: *mut ::std::os::raw::c_void);
    
    pub fn get_stream_proofs_non_blocking(d_buffers_: *mut ::std::os::raw::c_void);
    
    pub fn get_stream_id_proof(d_buffers_: *mut ::std::os::raw::c_void, streamId: u64);

    // Aggregation
    // ========================================================================================
    pub fn add_publics_aggregation(
        pProof: *mut ::std::os::raw::c_void,
        offset: u64,
        pPublics: *mut ::std::os::raw::c_void,
        nPublicsAggregation: u64,
    );
    
    // Final proof
    // ========================================================================================

    pub fn init_final_snark_prover(zkeyFile: *mut ::std::os::raw::c_char, d_buffers_recursivef: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void;

    pub fn get_snark_protocol_id(prover: *mut ::std::os::raw::c_void) -> u64;

    pub fn free_final_snark_prover(prover: *mut ::std::os::raw::c_void);

    pub fn gen_final_snark_proof(
        proverSnark: *mut ::std::os::raw::c_void,
        circomWitnessFinal: *mut ::std::os::raw::c_void,
        proof: *mut u8,
        publicsSnark: *mut u8,
        d_buffers_recursivef: *mut ::std::os::raw::c_void,
    );

    pub fn pre_allocate_final_snark_prover(prover: *mut ::std::os::raw::c_void, unified_buffer_gpu: *mut ::std::os::raw::c_void, d_buffers_recursivef: *mut ::std::os::raw::c_void);

    pub fn free_json_string(json_str: *mut ::std::os::raw::c_char);

    pub fn snark_proof_bytes_to_json(
        proof_bytes: *const u8,
        proof_size: u64,
        public_bytes: *const u8,
        public_size: u64,
        protocol_id: ::std::os::raw::c_int,
        proof_json_out: *mut *mut ::std::os::raw::c_char,
        publics_json_out: *mut *mut ::std::os::raw::c_char,
    );

    // Utilities
    // ========================================================================================
    pub fn setLogLevel(level: u64);

    // Verification
    // ========================================================================================
    pub fn stark_verify(
        jProof: *mut u64,
        pStarkInfo: *mut ::std::os::raw::c_void,
        pExpressionsBin: *mut ::std::os::raw::c_void,
        verkey: *mut ::std::os::raw::c_char,
        pPublics: *mut ::std::os::raw::c_void,
        pProofValues: *mut ::std::os::raw::c_void,
        challenges: *mut ::std::os::raw::c_void,
    ) -> bool;
    
    pub fn stark_verify_bn128(
        jProof: *mut ::std::os::raw::c_void,
        pStarkInfo: *mut ::std::os::raw::c_void,
        pExpressionsBin: *mut ::std::os::raw::c_void,
        verkey: *mut ::std::os::raw::c_char,
        pPublics: *mut ::std::os::raw::c_void,
    ) -> bool;
    
    pub fn stark_verify_from_file(
        proof: *mut ::std::os::raw::c_char,
        pStarkInfo: *mut ::std::os::raw::c_void,
        pExpressionsBin: *mut ::std::os::raw::c_void,
        verkey: *mut ::std::os::raw::c_char,
        pPublics: *mut ::std::os::raw::c_void,
        pProofValues: *mut ::std::os::raw::c_void,
        challenges: *mut ::std::os::raw::c_void,
    ) -> bool;

    // Fixed Columns
    // ========================================================================================
    pub fn write_fixed_cols_bin(
        binFile: *mut ::std::os::raw::c_char,
        airgroupName: *mut ::std::os::raw::c_char,
        airName: *mut ::std::os::raw::c_char,
        N: u64,
        nFixedPols: u64,
        fixedPolsInfo: *mut ::std::os::raw::c_void,
    );

    // OpenMP
    // ========================================================================================
    pub fn get_omp_max_threads() -> u64;
    
    pub fn set_omp_num_threads(num_threads: u64);

    // GPU/Device Management
    // ========================================================================================
    pub fn gen_device_buffers(
        node_rank: u32,
        node_size: u32,
        numa_nodes: *const i32,
        arity: u32,
        max_n_bits_ext: u32,
    ) -> *mut ::std::os::raw::c_void;

    pub fn gen_device_buffers_recursivef(
        pSetupCtx_: *mut ::std::os::raw::c_void,
        proverBufferSize: u64,
        d_commit_buffers: *mut ::std::os::raw::c_void,
        verkey: *mut ::std::os::raw::c_char,
    ) -> *mut ::std::os::raw::c_void;

    pub fn use_packed_trace(
        d_commit_buffers: *mut ::std::os::raw::c_void,
        packed_trace: bool,
    );

    pub fn register_instruction_table(
        d_commit_buffers: *mut ::std::os::raw::c_void,
        airgroup_id: u64,
        air_id: u64,
        table: *const u64,
        num_entries: u64,
        words_per_entry: u64,
    );

    pub fn free_device_buffers_recursivef(d_buffers: *mut ::std::os::raw::c_void);
    
    pub fn free_device_buffers(d_buffers: *mut ::std::os::raw::c_void);
    
    pub fn load_device_const_pols(
        airgroupId: u64,
        airId: u64,
        initial_offset: u64,
        d_buffers: *mut ::std::os::raw::c_void,
        constFilename: *mut ::std::os::raw::c_char,
        constSize: u64,
        constTreeFilename: *mut ::std::os::raw::c_char,
        constTreeSize: u64,
        proofType: *mut ::std::os::raw::c_char,
        onlyFirstGPU: bool,
        alreadyLoaded: bool,
    );
    
    pub fn load_device_setup(
        airgroupId: u64,
        airId: u64,
        proofType: *mut ::std::os::raw::c_char,
        pSetupCtx_: *mut ::std::os::raw::c_void,
        d_buffers_: *mut ::std::os::raw::c_void,
        verkeyRoot_: *mut ::std::os::raw::c_void,
        packedInfo_: *mut ::std::os::raw::c_void,
    );
    
    pub fn gen_device_streams(
        d_buffers_: *mut ::std::os::raw::c_void,
        nStreams: u64,
        nStreamsRecursive: u64,
        auxTraceSizes: *const u64,
        maxSizeProverBufferAggregation: u64,
        maxProofSize: u64,
        merkle_tree_arity: u64,
    ) -> u64;

    pub fn alloc_device_large_buffers(
        d_buffers_: *mut ::std::os::raw::c_void,
        auxTraceRecursiveArea: u64,
        totalConstPols: u64,
        totalConstPolsAggregation: u64,
    );   
    
    pub fn get_instances_ready(
        d_buffers_: *mut ::std::os::raw::c_void,
        instances_ready: *mut i64,
    );

    pub fn reset_device_streams(
        d_buffers_: *mut ::std::os::raw::c_void,
    );
    
    pub fn check_device_memory(
        node_rank: u32,
        node_size: u32,
    ) -> u64;
    
    pub fn get_num_gpus() -> u64;
    pub fn set_gpu_mode(use_gpu: bool) -> bool;

    pub fn get_unified_buffer_gpu(d_buffers: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void;
    pub fn get_unified_buffer_gpu_size(d_buffers: *mut ::std::os::raw::c_void) -> u64;
    pub fn acquire_first_gpu_buffer(d_buffers: *mut ::std::os::raw::c_void);
    pub fn release_first_gpu_buffer(d_buffers: *mut ::std::os::raw::c_void);
    pub fn is_first_gpu_buffer_borrowed(d_buffers: *mut ::std::os::raw::c_void) -> u32;
    pub fn get_first_gpu_id(d_buffers: *mut ::std::os::raw::c_void) -> u32;
    pub fn get_first_gpu_buffer(d_buffers: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void;

    pub fn get_const_pols_aggregation_offset(d_buffers: *mut ::std::os::raw::c_void) -> u64;
    pub fn get_stream_commit_slots(d_buffers: *mut ::std::os::raw::c_void) -> u64;
    pub fn get_stream_commit_floor(d_buffers: *mut ::std::os::raw::c_void) -> u64;
    pub fn stream_commit_slot_bytes(n_bits: u64, n_bits_ext: u64, n_cols: u64, words_per_row: u64) -> u64;
    pub fn configure_stream_commit_slots(
        d_buffers: *mut ::std::os::raw::c_void,
        n_slots: u64,
        slot_bytes: u64,
    );
    pub fn commit_witness_streaming(
        d_buffers: *mut ::std::os::raw::c_void,
        slot_idx: u64,
        airgroup_id: u64,
        air_id: u64,
        packed: *mut ::std::os::raw::c_void,
        n_bits: u64,
        n_bits_ext: u64,
        n_cols: u64,
        words_per_row: u64,
        col_widths: *mut ::std::os::raw::c_void,
        root: *mut ::std::os::raw::c_void,
    ) -> i64;
    pub fn stream_commit_pause();
    pub fn get_unified_buffer_gpu_for_recursivef(d_buffers: *mut ::std::os::raw::c_void, d_buffers_recursivef: *mut ::std::os::raw::c_void) -> *mut ::std::os::raw::c_void;

    pub fn alloc_fixed_pols_buffer_gpu(d_buffers: *mut ::std::os::raw::c_void);
    pub fn free_fixed_pols_buffer_gpu(d_buffers: *mut ::std::os::raw::c_void);
    pub fn load_fixed_pols_recursivef(pSetupCtx: *mut ::std::os::raw::c_void, pConstTree: *mut ::std::os::raw::c_void, d_buffers: *mut ::std::os::raw::c_void);

    // Callback Management
    // ========================================================================================
    pub fn register_proof_done_callback(cb: ProofDoneCallback);
    
    pub fn launch_callback(instanceId: u64, proofType: *mut ::std::os::raw::c_char);

    // MPI calls
    // ========================================================================================
    pub fn initialize_agg_readiness_tracker();
    pub fn free_agg_readiness_tracker();
    pub fn agg_is_ready() -> i32;
    pub fn reset_agg_readiness_tracker();
}

// Type definitions
pub type ProofDoneCallback =
    ::std::option::Option<unsafe extern "C" fn(instanceId: u64, proofType: *const ::std::os::raw::c_char)>;