1use ark_ec::AffineRepr;
2use kimchi::{
3 circuits::lookup::{
4 index::LookupSelectors,
5 lookups::{LookupFeatures, LookupInfo},
6 },
7 verifier_index::LookupVerifierIndex,
8};
9use poly_commitment::{commitment::CommitmentCurve, PolyComm};
10
11#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
12pub struct CamlPlonkDomain<Fr> {
13 pub log_size_of_group: ocaml::Int,
14 pub group_gen: Fr,
15}
16
17#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
18pub struct CamlPlonkVerificationEvals<PolyComm> {
19 pub sigma_comm: Vec<PolyComm>,
20 pub coefficients_comm: Vec<PolyComm>,
21 pub generic_comm: PolyComm,
22 pub psm_comm: PolyComm,
23 pub complete_add_comm: PolyComm,
24 pub mul_comm: PolyComm,
25 pub emul_comm: PolyComm,
26 pub endomul_scalar_comm: PolyComm,
27 pub xor_comm: Option<PolyComm>,
28 pub range_check0_comm: Option<PolyComm>,
29 pub range_check1_comm: Option<PolyComm>,
30 pub foreign_field_add_comm: Option<PolyComm>,
31 pub foreign_field_mul_comm: Option<PolyComm>,
32 pub rot_comm: Option<PolyComm>,
33}
34
35#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Enum)]
36pub enum CamlLookupsUsed {
37 Single,
38 Joint,
39}
40
41#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
42pub struct CamlLookupSelectors<T> {
43 pub lookup: Option<T>,
44 pub xor: Option<T>,
45 pub range_check: Option<T>,
46 pub ffmul: Option<T>,
47}
48
49impl<G, CamlPolyComm> From<LookupSelectors<PolyComm<G>>> for CamlLookupSelectors<CamlPolyComm>
50where
51 G: AffineRepr + CommitmentCurve,
52 CamlPolyComm: From<PolyComm<G>>,
53{
54 fn from(val: LookupSelectors<PolyComm<G>>) -> Self {
55 let LookupSelectors {
56 xor,
57 lookup,
58 range_check,
59 ffmul,
60 } = val;
61 CamlLookupSelectors {
62 lookup: lookup.map(From::from),
63 xor: xor.map(From::from),
64 range_check: range_check.map(From::from),
65 ffmul: ffmul.map(From::from),
66 }
67 }
68}
69
70impl<G, CamlPolyComm> From<CamlLookupSelectors<CamlPolyComm>> for LookupSelectors<PolyComm<G>>
71where
72 G: AffineRepr + CommitmentCurve,
73 PolyComm<G>: From<CamlPolyComm>,
74{
75 fn from(val: CamlLookupSelectors<CamlPolyComm>) -> Self {
76 let CamlLookupSelectors {
77 xor,
78 lookup,
79 range_check,
80 ffmul,
81 } = val;
82 LookupSelectors {
83 lookup: lookup.map(From::from),
84 xor: xor.map(From::from),
85 range_check: range_check.map(From::from),
86 ffmul: ffmul.map(From::from),
87 }
88 }
89}
90
91#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
92pub struct CamlLookupInfo {
93 pub max_per_row: ocaml::Int,
95 pub max_joint_size: ocaml::Int,
97 pub features: LookupFeatures,
98}
99
100impl From<LookupInfo> for CamlLookupInfo {
101 fn from(li: LookupInfo) -> CamlLookupInfo {
102 let LookupInfo {
103 features,
104 max_per_row,
105 max_joint_size,
106 } = li;
107 CamlLookupInfo {
108 features,
109 max_per_row: max_per_row as ocaml::Int,
110 max_joint_size: max_joint_size as ocaml::Int,
111 }
112 }
113}
114
115impl From<CamlLookupInfo> for LookupInfo {
116 fn from(li: CamlLookupInfo) -> LookupInfo {
117 let CamlLookupInfo {
118 features,
119 max_per_row,
120 max_joint_size,
121 } = li;
122 LookupInfo {
123 features,
124 max_per_row: max_per_row as usize,
125 max_joint_size: max_joint_size as u32,
126 }
127 }
128}
129
130#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
131pub struct CamlLookupVerifierIndex<PolyComm> {
132 pub joint_lookup_used: bool,
133 pub lookup_table: Vec<PolyComm>,
134 pub lookup_selectors: CamlLookupSelectors<PolyComm>,
135 pub table_ids: Option<PolyComm>,
136 pub lookup_info: CamlLookupInfo,
137 pub runtime_tables_selector: Option<PolyComm>,
138}
139
140impl<G, CamlPolyComm> From<LookupVerifierIndex<G>> for CamlLookupVerifierIndex<CamlPolyComm>
141where
142 G: AffineRepr + CommitmentCurve,
143 CamlPolyComm: From<PolyComm<G>>,
144{
145 fn from(li: LookupVerifierIndex<G>) -> Self {
146 let LookupVerifierIndex {
147 joint_lookup_used,
148 lookup_table,
149 lookup_selectors,
150 table_ids,
151 lookup_info,
152 runtime_tables_selector,
153 } = li;
154 CamlLookupVerifierIndex {
155 joint_lookup_used,
156 lookup_table: lookup_table.into_iter().map(From::from).collect(),
157
158 lookup_selectors: lookup_selectors.into(),
159 table_ids: table_ids.map(From::from),
160 lookup_info: lookup_info.into(),
161 runtime_tables_selector: runtime_tables_selector.map(From::from),
162 }
163 }
164}
165
166impl<G, CamlPolyComm> From<CamlLookupVerifierIndex<CamlPolyComm>> for LookupVerifierIndex<G>
167where
168 G: AffineRepr + CommitmentCurve,
169 PolyComm<G>: From<CamlPolyComm>,
170{
171 fn from(li: CamlLookupVerifierIndex<CamlPolyComm>) -> Self {
172 let CamlLookupVerifierIndex {
173 joint_lookup_used,
174 lookup_table,
175 lookup_selectors,
176 table_ids,
177 lookup_info,
178 runtime_tables_selector,
179 } = li;
180 LookupVerifierIndex {
181 joint_lookup_used,
182 lookup_table: lookup_table.into_iter().map(From::from).collect(),
183 lookup_selectors: lookup_selectors.into(),
184 table_ids: table_ids.map(From::from),
185 lookup_info: lookup_info.into(),
186 runtime_tables_selector: runtime_tables_selector.map(From::from),
187 }
188 }
189}
190
191#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
192pub struct CamlPlonkVerifierIndex<Fr, SRS, PolyComm> {
193 pub domain: CamlPlonkDomain<Fr>,
194 pub max_poly_size: ocaml::Int,
195 pub public: ocaml::Int,
196 pub prev_challenges: ocaml::Int,
197 pub srs: SRS,
198 pub evals: CamlPlonkVerificationEvals<PolyComm>,
199 pub shifts: Vec<Fr>,
200 pub lookup_index: Option<CamlLookupVerifierIndex<PolyComm>>,
201 pub zk_rows: ocaml::Int,
202}