Skip to content

Commit 0fd6efb

Browse files
committed
bindings: exposing serde helpers
1 parent 3747ee2 commit 0fd6efb

File tree

4 files changed

+99
-27
lines changed

4 files changed

+99
-27
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@ var caml_pasta_fp_plonk_proof_create = function (
2020
var wasm_runtime_tables =
2121
tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables);
2222
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);
30-
*/
23+
3124
var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create(
3225
index,
3326
witness_cols,
@@ -36,7 +29,6 @@ var caml_pasta_fp_plonk_proof_create = function (
3629
prev_sgs
3730
);
3831
return tsRustConversionNative.fp.proofFromRust(proof);
39-
/* return tsRustConversion.fp.proofFromRust(proof); */
4032
};
4133

4234
// Provides: caml_pasta_fp_plonk_proof_verify

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

Lines changed: 53 additions & 13 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 (
@@ -138,7 +158,7 @@ var caml_pasta_fp_plonk_index_create = function (
138158
);
139159
console.timeEnd("index_create");
140160

141-
return plonk_wasm.prover_index_fp_to_bytes(t);
161+
return t;
142162
};
143163

144164
// Provides: caml_pasta_fp_plonk_index_create_bytecode
@@ -193,6 +213,26 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) {
193213
);
194214
};
195215

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

216256
console.time("conversion")
217-
var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize());
257+
var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_deserialize(gates.serialize());
218258
var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize())
219259
console.timeEnd("conversion")
220260
console.log("anais: 4");
@@ -231,7 +271,7 @@ var caml_pasta_fq_plonk_index_create = function (
231271
);
232272
console.timeEnd("index_create");
233273

234-
return plonk_wasm.prover_index_fq_to_bytes(t);
274+
return t;
235275
};
236276

237277
// Provides: caml_pasta_fq_plonk_index_create_bytecode

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,40 @@ var caml_fq_srs_lagrange_commitments_whole_domain =
6363
// Requires: tsSrs
6464
var caml_fp_srs_lagrange_commitment = tsSrs.fp.lagrangeCommitment;
6565

66+
// Provides: caml_fp_srs_to_bytes_external
67+
// Requires: plonk_wasm
68+
var caml_fp_srs_to_bytes_external = function (srs) {
69+
console.log("native caml_fp_srs_to_bytes_external");
70+
return plonk_wasm.caml_fp_srs_to_bytes_external(srs);
71+
};
72+
73+
// Provides: caml_fp_srs_from_bytes_external
74+
// Requires: plonk_wasm
75+
var caml_fp_srs_from_bytes_external = function (bytes) {
76+
console.log("native caml_fp_srs_from_bytes_external");
77+
return plonk_wasm.caml_fp_srs_from_bytes_external(bytes);
78+
};
79+
6680
// Provides: caml_fp_srs_lagrange_commitment
6781
// Requires: tsSrs
6882
var caml_fp_srs_lagrange_commitment = function (srs, i) {
6983
console.log("native caml_fp_srs_lagrange_commitment");
7084
return tsSrs.fp.lagrangeCommitment(srs, i);
7185
}
7286

87+
// Provides: caml_fp_srs_maybe_lagrange_commitment
88+
// Requires: plonk_wasm, tsRustConversionNative
89+
var caml_fp_srs_maybe_lagrange_commitment = function (srs, domain_size, i) {
90+
console.log("native caml_fp_srs_maybe_lagrange_commitment");
91+
var result = plonk_wasm.caml_fp_srs_maybe_lagrange_commitment(srs, domain_size, i);
92+
console.log("result", result);
93+
if (result == null) return 0; // None
94+
var polyComm = tsRustConversionNative.fp.polyCommFromRust(result);
95+
console.log("polyComm", polyComm);
96+
if (polyComm == undefined) return 0; // None
97+
return [0, polyComm]; // Some(...)
98+
};
99+
73100
// Provides: caml_fp_srs_commit_evaluations
74101
// Requires: plonk_wasm, tsRustConversionNative
75102
var caml_fp_srs_commit_evaluations = function (t, domain_size, fps) {
@@ -181,6 +208,17 @@ var caml_fq_srs_lagrange_commitment = function (srs, i) {
181208
return tsSrs.fq.lagrangeCommitment(srs, i);
182209
};
183210

211+
// Provides: caml_fq_srs_maybe_lagrange_commitment
212+
// Requires: plonk_wasm, tsRustConversionNative
213+
var caml_fq_srs_maybe_lagrange_commitment = function (srs, domain_size, i) {
214+
console.log("native caml_fq_srs_maybe_lagrange_commitment");
215+
var result = plonk_wasm.caml_fq_srs_maybe_lagrange_commitment(srs, domain_size, i);
216+
if (result == null) return 0; // None
217+
var polyComm = tsRustConversionNative.fq.polyCommFromRust(result);
218+
if (polyComm == undefined) return 0; // None
219+
return [0, polyComm]; // Some(...)
220+
};
221+
184222
// Provides: caml_fq_srs_commit_evaluations
185223
// Requires: plonk_wasm, tsRustConversionNative
186224
var caml_fq_srs_commit_evaluations = function (t, domain_size, fqs) {
@@ -247,4 +285,4 @@ var caml_fq_srs_h = function (t) {
247285
var caml_fq_srs_add_lagrange_basis = function (srs, domain_size) {
248286
console.log("native caml_fq_srs_add_lagrange_basis");
249287
return tsSrs.fq.addLagrangeBasis(srs, domain_size);
250-
};
288+
};

src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ var plonk_wasm = (function() {
1111
// IS SET
1212
var overrides = [
1313
"prover_to_json",
14-
"prover_index_fp_from_bytes",
15-
"prover_index_fq_from_bytes",
16-
"prover_index_fp_to_bytes",
17-
"prover_index_fq_to_bytes",
14+
"prover_index_fp_deserialize",
15+
"prover_index_fq_deserialize",
16+
"prover_index_fp_serialize",
17+
"prover_index_fq_serialize",
18+
"WasmPastaFpPlonkIndex",
19+
"WasmPastaFqPlonkIndex",
1820
"caml_pasta_fp_poseidon_block_cipher",
1921
"caml_pasta_fq_poseidon_block_cipher",
2022
"caml_pasta_fp_plonk_proof_create",

0 commit comments

Comments
 (0)