Source file gates_common.ml
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
open Bls
open Identities
module L = Plompiler.LibCircuit
type public = {public_inputs : Scalar.t array; input_coms_size : int}
let one = Scalar.one
let mone = Scalar.negate one
let two = Scalar.add one one
let wire_name = Plompiler.Csir.wire_name
let com_label = "com"
let tmp_buffers = ref [||]
type answers = {q : Scalar.t; wires : Scalar.t array; wires_g : Scalar.t array}
type witness = {q : Evaluations.t; wires : Evaluations.t array}
let get_buffers ~nb_buffers ~nb_ids =
let precomputed = !tmp_buffers in
let nb_precomputed = Array.length precomputed in
let size_eval = Evaluations.length precomputed.(0) in
let buffers =
Array.init (max nb_buffers nb_precomputed) (fun i ->
if i < nb_precomputed then precomputed.(i)
else Evaluations.create size_eval)
in
tmp_buffers := buffers ;
(buffers, Array.init nb_ids (fun _ -> Evaluations.create size_eval))
let get_answers ~q_label ~blinds ~prefix ~prefix_common answers : answers =
let dummy = Scalar.zero in
let answer = get_answer answers in
let answer_wire w =
let w = wire_name w in
match SMap.find_opt w blinds with
| Some array ->
assert (Array.length array = 2) ;
let w' = prefix w in
let x = if array.(0) = 0 then dummy else answer X w' in
let gx = if array.(1) = 0 then dummy else answer GX w' in
(x, gx)
| None -> (dummy, dummy)
in
let q = prefix_common q_label |> answer X in
let wires, wires_g =
Array.init Plompiler.Csir.nb_wires_arch answer_wire |> Array.split
in
{q; wires; wires_g}
let get_evaluations ~q_label ~blinds ~prefix ~prefix_common evaluations =
let dummy = Evaluations.zero in
let find_wire w =
let w = wire_name w in
match SMap.find_opt w blinds with
| Some array ->
assert (Array.length array = 2) ;
if array.(0) = 0 && array.(1) = 0 then dummy
else Evaluations.find_evaluation evaluations (prefix w)
| None -> dummy
in
{
q = Evaluations.find_evaluation evaluations (prefix_common q_label);
wires = Array.init Plompiler.Csir.nb_wires_arch find_wire;
}
let arith = "Arith"
let qadv_label = "qadv"
let map_singleton m =
let map f t =
let open L in
let* x = t in
ret (f x)
in
map (fun x -> [x]) m
module type Base_sig = sig
val q_label : string
val blinds : int array SMap.t
val identity : string * int
val index_com : int option
val nb_advs : int
val nb_buffers : int
val gx_composition : bool
val equations :
q:Scalar.t ->
wires:Scalar.t array ->
wires_g:Scalar.t array ->
?precomputed_advice:Scalar.t SMap.t ->
unit ->
Scalar.t list
val prover_identities :
prefix_common:(string -> string) ->
prefix:(string -> string) ->
public:public ->
domain:Domain.t ->
prover_identities
val verifier_identities :
prefix_common:(string -> string) ->
prefix:(string -> string) ->
public:public ->
generator:Scalar.t ->
size_domain:int ->
verifier_identities
val polynomials_degree : int SMap.t
val cs :
q:L.scalar L.repr ->
wires:L.scalar L.repr array ->
wires_g:L.scalar L.repr array ->
?precomputed_advice:L.scalar L.repr SMap.t ->
unit ->
L.scalar L.repr list L.t
end