Skip to content

Commit 1c7ee27

Browse files
authored
Merge pull request #18190 from MinaProtocol/querolita/napi-vindex
(`mina`) Native Prover with Napi - Verifier Index
2 parents 88522d3 + 3c0b64c commit 1c7ee27

File tree

7 files changed

+281
-164
lines changed

7 files changed

+281
-164
lines changed

src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -20,136 +20,3 @@ var caml_opt_to_rust = function (caml_optional_value, to_rust) {
2020
return to_rust(caml_optional_value[1]);
2121
}
2222
};
23-
24-
// Provides: caml_pasta_fp_plonk_verifier_index_create
25-
// Requires: plonk_wasm, tsRustConversion
26-
var caml_pasta_fp_plonk_verifier_index_create = function (x) {
27-
console.log("caml_pasta_fp_plonk_verifier_index_create", x)
28-
var bytes = plonk_wasm.prover_index_fp_to_bytes(x);
29-
console.log("bytes", bytes)
30-
var index = plonk_wasm.WasmPastaFpPlonkIndex.deserialize(bytes)
31-
console.log("index", index)
32-
var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(index);
33-
console.log("vk", vk)
34-
return tsRustConversion.fp.verifierIndexFromRust(vk);
35-
};
36-
37-
// Provides: caml_pasta_fp_plonk_verifier_index_read
38-
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
39-
var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) {
40-
console.log("caml_pasta_fp_plonk_verifier_index_read")
41-
42-
if (offset === 0) {
43-
offset = undefined;
44-
} else {
45-
offset = offset[1];
46-
}
47-
return tsRustConversion.fp.verifierIndexFromRust(
48-
plonk_wasm.caml_pasta_fp_plonk_verifier_index_read(
49-
offset,
50-
urs,
51-
caml_jsstring_of_string(path)
52-
)
53-
);
54-
};
55-
56-
// Provides: caml_pasta_fp_plonk_verifier_index_write
57-
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
58-
var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) {
59-
console.log("caml_pasta_fp_plonk_verifier_index_write")
60-
61-
if (append === 0) {
62-
append = undefined;
63-
} else {
64-
append = append[1];
65-
}
66-
return plonk_wasm.caml_pasta_fp_plonk_verifier_index_write(
67-
append,
68-
tsRustConversion.fp.verifierIndexToRust(t),
69-
caml_jsstring_of_string(path)
70-
);
71-
};
72-
73-
74-
// Provides: caml_pasta_fp_plonk_verifier_index_dummy
75-
// Requires: plonk_wasm, tsRustConversion
76-
var caml_pasta_fp_plonk_verifier_index_dummy = function () {
77-
console.log("caml_pasta_fp_plonk_verifier_index_dummy")
78-
79-
var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy();
80-
return tsRustConversion.fp.verifierIndexFromRust(res);
81-
};
82-
83-
// Provides: caml_pasta_fp_plonk_verifier_index_deep_copy
84-
// Requires: plonk_wasm, tsRustConversion
85-
var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) {
86-
console.log("caml_pasta_fp_plonk_verifier_index_deep_copy")
87-
return tsRustConversion.fp.verifierIndexFromRust(
88-
plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy(
89-
tsRustConversion.fp.verifierIndexToRust(x)
90-
)
91-
);
92-
};
93-
94-
// Provides: caml_pasta_fq_plonk_verifier_index_create
95-
// Requires: plonk_wasm, tsRustConversion
96-
var caml_pasta_fq_plonk_verifier_index_create = function (x) {
97-
console.log("caml_pasta_fq_plonk_verifier_index_create")
98-
return tsRustConversion.fq.verifierIndexFromRust(
99-
plonk_wasm.caml_pasta_fq_plonk_verifier_index_create(x)
100-
);
101-
};
102-
103-
// Provides: caml_pasta_fq_plonk_verifier_index_read
104-
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
105-
var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) {
106-
console.log("caml_pasta_fq_plonk_verifier_index_read")
107-
if (offset === 0) {
108-
offset = undefined;
109-
} else {
110-
offset = offset[1];
111-
}
112-
return tsRustConversion.fq.verifierIndexFromRust(
113-
plonk_wasm.caml_pasta_fq_plonk_verifier_index_read(
114-
offset,
115-
urs,
116-
caml_jsstring_of_string(path)
117-
)
118-
);
119-
};
120-
121-
// Provides: caml_pasta_fq_plonk_verifier_index_write
122-
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
123-
var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) {
124-
console.log("caml_pasta_fq_plonk_verifier_index_write")
125-
if (append === 0) {
126-
append = undefined;
127-
} else {
128-
append = append[1];
129-
}
130-
return plonk_wasm.caml_pasta_fq_plonk_verifier_index_write(
131-
append,
132-
tsRustConversion.fq.verifierIndexToRust(t),
133-
caml_jsstring_of_string(path)
134-
);
135-
};
136-
137-
// Provides: caml_pasta_fq_plonk_verifier_index_dummy
138-
// Requires: plonk_wasm, tsRustConversion
139-
var caml_pasta_fq_plonk_verifier_index_dummy = function () {
140-
console.log("caml_pasta_fq_plonk_verifier_index_dummy")
141-
return tsRustConversion.fq.verifierIndexFromRust(
142-
plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy()
143-
);
144-
};
145-
146-
// Provides: caml_pasta_fq_plonk_verifier_index_deep_copy
147-
// Requires: plonk_wasm, tsRustConversion, tsRustConversion
148-
var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) {
149-
console.log("caml_pasta_fq_plonk_verifier_index_deep_copy")
150-
return tsRustConversion.fq.verifierIndexFromRust(
151-
plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy(
152-
tsRustConversion.fq.verifierIndexToRust(x)
153-
)
154-
);
155-
};

src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,39 @@ var caml_pasta_fp_plonk_proof_create = function (
1212
prev_sgs
1313
) {
1414
var w = new plonk_wasm.WasmVecVecFp(witness_cols.length - 1);
15+
var ww = new w.WasmVecVecFp(witness_cols.length - 1)
1516
for (var i = 1; i < witness_cols.length; i++) {
16-
w.push(tsRustConversionNative.fp.vectorToRust(witness_cols[i]));
17+
ww.push(tsRustConversionNative.fp.vectorToRust(witness_cols[i]));
1718
}
18-
witness_cols = w;
19+
20+
witness_cols = ww;
1921
prev_challenges = tsRustConversionNative.fp.vectorToRust(prev_challenges);
2022
var wasm_runtime_tables =
2123
tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables);
2224
prev_sgs = tsRustConversionNative.fp.pointsToRust(prev_sgs);
23-
/*w.push(tsRustConversion.fp.vectorToRust(witness_cols[i]));
24-
}
25-
witness_cols = w;
26-
prev_challenges = tsRustConversion.fp.vectorToRust(prev_challenges);
27-
var wasm_runtime_tables =
28-
tsRustConversion.fp.runtimeTablesToRust(caml_runtime_tables);
29-
prev_sgs = tsRustConversion.fp.pointsToRust(prev_sgs);
25+
26+
/*
27+
index: &External<$NapiIndex>,
28+
witness: $NapiVecVec,
29+
runtime_tables: NapiVector<JsRuntimeTableF>,
30+
prev_challenges: NapiFlatVector<$NapiF>,
31+
prev_sgs: NapiVector<$NapiG>,
3032
*/
33+
34+
console.log('index: ', index);
35+
console.log('witness cols: ', witness_cols)
36+
console.log("wasm_runtime_tables: ", wasm_runtime_tables)
37+
console.log('prev challenges: ', prev_challenges)
38+
console.log('prev_sgs: ', prev_sgs)
3139
var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create(
3240
index,
3341
witness_cols,
3442
wasm_runtime_tables,
3543
prev_challenges,
3644
prev_sgs
3745
);
46+
console.log('proof?')
3847
return tsRustConversionNative.fp.proofFromRust(proof);
39-
/* return tsRustConversion.fp.proofFromRust(proof); */
4048
};
4149

4250
// Provides: caml_pasta_fp_plonk_proof_verify
@@ -120,7 +128,7 @@ var caml_pasta_fq_plonk_proof_verify = function (index, proof) {
120128
var caml_pasta_fq_plonk_proof_batch_verify = function (indexes, proofs) {
121129
indexes = tsRustConversionNative.mapMlArrayToRustVector(
122130
indexes,
123-
tsRustConversionNatsRustConversionNativetive.fq.verifierIndexToRust
131+
tsRustConversionNative.fq.verifierIndexToRust
124132
);
125133
proofs = tsRustConversionNative.mapMlArrayToRustVector(
126134
proofs,

src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Requires: plonk_wasm
55
function caml_pasta_fp_plonk_index_max_degree(prover_index) {
66
var bytes = prover_index.serialize()
7-
var index = plonk_wasm.prover_index_fp_from_bytes(bytes);
7+
var index = plonk_wasm.prover_index_fp_deserialize(bytes);
88
// TODO: ^ remove the round trip when napi has direct access to the object
99

1010
return plonk_wasm.caml_pasta_fp_plonk_index_max_degree(index);
@@ -14,7 +14,7 @@ function caml_pasta_fp_plonk_index_max_degree(prover_index) {
1414
// Requires: plonk_wasm
1515
function caml_pasta_fp_plonk_index_public_inputs(prover_index) {
1616
var bytes = prover_index.serialize()
17-
var index = plonk_wasm.prover_index_fp_from_bytes(bytes);
17+
var index = plonk_wasm.prover_index_fp_deserialize(bytes);
1818
// TODO: ^ remove the round trip when napi has direct access to the object
1919

2020
return plonk_wasm.caml_pasta_fp_plonk_index_public_inputs(index);
@@ -24,7 +24,7 @@ function caml_pasta_fp_plonk_index_public_inputs(prover_index) {
2424
// Requires: plonk_wasm
2525
function caml_pasta_fp_plonk_index_domain_d1_size(prover_index) {
2626
var bytes = prover_index.serialize()
27-
var index = plonk_wasm.prover_index_fp_from_bytes(bytes);
27+
var index = plonk_wasm.prover_index_fp_deserialize(bytes);
2828
// TODO: ^ remove the round trip when napi has direct access to the object
2929

3030
return plonk_wasm.caml_pasta_fp_plonk_index_domain_d1_size(index);
@@ -34,7 +34,7 @@ function caml_pasta_fp_plonk_index_domain_d1_size(prover_index) {
3434
// Requires: plonk_wasm
3535
function caml_pasta_fp_plonk_index_domain_d4_size(prover_index) {
3636
var bytes = prover_index.serialize()
37-
var index = plonk_wasm.prover_index_fp_from_bytes(bytes);
37+
var index = plonk_wasm.prover_index_fp_deserialize(bytes);
3838
// TODO: ^ remove the round trip when napi has direct access to the object
3939

4040
return plonk_wasm.caml_pasta_fp_plonk_index_domain_d4_size(index);
@@ -44,7 +44,7 @@ function caml_pasta_fp_plonk_index_domain_d4_size(prover_index) {
4444
// Requires: plonk_wasm
4545
function caml_pasta_fp_plonk_index_domain_d8_size(prover_index) {
4646
var bytes = prover_index.serialize()
47-
var index = plonk_wasm.prover_index_fp_from_bytes(bytes);
47+
var index = plonk_wasm.prover_index_fp_deserialize(bytes);
4848
// TODO: ^ remove the round trip when napi has direct access to the object
4949

5050
return plonk_wasm.caml_pasta_fp_plonk_index_domain_d8_size(index);
@@ -58,7 +58,7 @@ function caml_pasta_fp_plonk_index_domain_d8_size(prover_index) {
5858
// Requires: plonk_wasm
5959
function caml_pasta_fq_plonk_index_max_degree(prover_index) {
6060
var bytes = prover_index.serialize()
61-
var index = plonk_wasm.prover_index_fq_from_bytes(bytes);
61+
var index = plonk_wasm.prover_index_fq_deserialize(bytes);
6262
// TODO: ^ remove the round trip when napi has direct access to the object
6363

6464
return plonk_wasm.caml_pasta_fq_plonk_index_max_degree(index);
@@ -68,7 +68,7 @@ function caml_pasta_fq_plonk_index_max_degree(prover_index) {
6868
// Requires: plonk_wasm
6969
function caml_pasta_fq_plonk_index_public_inputs(prover_index) {
7070
var bytes = prover_index.serialize()
71-
var index = plonk_wasm.prover_index_fq_from_bytes(bytes);
71+
var index = plonk_wasm.prover_index_fq_deserialize(bytes);
7272
// TODO: ^ remove the round trip when napi has direct access to the object
7373

7474
return plonk_wasm.caml_pasta_fq_plonk_index_public_inputs(index);
@@ -78,7 +78,7 @@ function caml_pasta_fq_plonk_index_public_inputs(prover_index) {
7878
// Requires: plonk_wasm
7979
function caml_pasta_fq_plonk_index_domain_d1_size(prover_index) {
8080
var bytes = prover_index.serialize()
81-
var index = plonk_wasm.prover_index_fq_from_bytes(bytes);
81+
var index = plonk_wasm.prover_index_fq_deserialize(bytes);
8282
// TODO: ^ remove the round trip when napi has direct access to the object
8383

8484
return plonk_wasm.caml_pasta_fq_plonk_index_domain_d1_size(index);
@@ -88,7 +88,7 @@ function caml_pasta_fq_plonk_index_domain_d1_size(prover_index) {
8888
// Requires: plonk_wasm
8989
function caml_pasta_fq_plonk_index_domain_d4_size(prover_index) {
9090
var bytes = prover_index.serialize()
91-
var index = plonk_wasm.prover_index_fq_from_bytes(bytes);
91+
var index = plonk_wasm.prover_index_fq_deserialize(bytes);
9292
// TODO: ^ remove the round trip when napi has direct access to the object
9393

9494
return plonk_wasm.caml_pasta_fq_plonk_index_domain_d4_size(index);
@@ -98,13 +98,33 @@ function caml_pasta_fq_plonk_index_domain_d4_size(prover_index) {
9898
// Requires: plonk_wasm
9999
function caml_pasta_fq_plonk_index_domain_d8_size(prover_index) {
100100
var bytes = prover_index.serialize()
101-
var index = plonk_wasm.prover_index_fq_from_bytes(bytes);
101+
var index = plonk_wasm.prover_index_fq_deserialize(bytes);
102102
// TODO: ^ remove the round trip when napi has direct access to the object
103103

104104
return plonk_wasm.caml_pasta_fq_plonk_index_domain_d8_size(index);
105105
}
106106

107107

108+
// Provides: caml_pasta_fp_plonk_index_serialize
109+
// Requires: plonk_wasm
110+
var caml_pasta_fp_plonk_index_serialize = function (index) {
111+
// Workaround for napi issue where methods on External objects are not accessible
112+
if (typeof index.serialize === 'function') {
113+
return index.serialize();
114+
}
115+
return plonk_wasm.prover_index_fp_serialize(index);
116+
};
117+
118+
// Provides: caml_pasta_fp_plonk_index_deserialize
119+
// Requires: plonk_wasm
120+
var caml_pasta_fp_plonk_index_deserialize = function (index) {
121+
// Workaround for napi issue where methods on External objects are not accessible
122+
if (typeof index.deserialize === 'function') {
123+
return index.deserialize();
124+
}
125+
return plonk_wasm.prover_index_fp_deserialize(index);
126+
};
127+
108128
// Provides: caml_pasta_fp_plonk_index_create
109129
// Requires: plonk_wasm, tsRustConversionNative
110130
var caml_pasta_fp_plonk_index_create = function (
@@ -116,6 +136,7 @@ var caml_pasta_fp_plonk_index_create = function (
116136
urs,
117137
lazy_mode
118138
) {
139+
console.log('passing through wasm lookup tables')
119140
var wasm_lookup_tables =
120141
tsRustConversionNative.fp.lookupTablesToRust(caml_lookup_tables);
121142
var wasm_runtime_table_cfgs = tsRustConversionNative.fp.runtimeTableCfgsToRust(
@@ -138,7 +159,7 @@ var caml_pasta_fp_plonk_index_create = function (
138159
);
139160
console.timeEnd("index_create");
140161

141-
return plonk_wasm.prover_index_fp_to_bytes(t);
162+
return t;
142163
};
143164

144165
// Provides: caml_pasta_fp_plonk_index_create_bytecode
@@ -193,6 +214,26 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) {
193214
);
194215
};
195216

217+
// Provides: caml_pasta_fq_plonk_index_serialize
218+
// Requires: plonk_wasm
219+
var caml_pasta_fq_plonk_index_serialize = function (index) {
220+
// Workaround for napi issue where methods on External objects are not accessible
221+
if (typeof index.serialize === 'function') {
222+
return index.serialize();
223+
}
224+
return plonk_wasm.prover_index_fq_serialize(index);
225+
};
226+
227+
// Provides: caml_pasta_fq_plonk_index_deserialize
228+
// Requires: plonk_wasm
229+
var caml_pasta_fq_plonk_index_deserialize = function (index) {
230+
// Workaround for napi issue where methods on External objects are not accessible
231+
if (typeof index.deserialize === 'function') {
232+
return index.deserialize();
233+
}
234+
return plonk_wasm.prover_index_fq_deserialize(index);
235+
};
236+
196237
// Provides: caml_pasta_fq_plonk_index_create
197238
// Requires: plonk_wasm, tsRustConversionNative
198239
var caml_pasta_fq_plonk_index_create = function (
@@ -214,7 +255,7 @@ var caml_pasta_fq_plonk_index_create = function (
214255
console.log("anais: 3");
215256

216257
console.time("conversion")
217-
var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize());
258+
var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_deserialize(gates.serialize());
218259
var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize())
219260
console.timeEnd("conversion")
220261
console.log("anais: 4");
@@ -231,7 +272,7 @@ var caml_pasta_fq_plonk_index_create = function (
231272
);
232273
console.timeEnd("index_create");
233274

234-
return plonk_wasm.prover_index_fq_to_bytes(t);
275+
return t;
235276
};
236277

237278
// Provides: caml_pasta_fq_plonk_index_create_bytecode
@@ -284,4 +325,4 @@ var caml_pasta_fq_plonk_index_write = function (append, t, path) {
284325
t,
285326
caml_jsstring_of_string(path)
286327
);
287-
};
328+
};

0 commit comments

Comments
 (0)