Skip to content

Commit 88522d3

Browse files
authored
Merge pull request #18115 from MinaProtocol/shigoto/native/napi/oracles
(Native Prover) Kimchi bindings: native overrides for napi Oracles conversions
2 parents 6189fa7 + 3116ffc commit 88522d3

File tree

8 files changed

+102
-98
lines changed

8 files changed

+102
-98
lines changed

src/lib/crypto/kimchi_bindings/js/bindings/oracles.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,5 @@
11
/* global plonk_wasm, tsRustConversion,*/
22

3-
// Provides: fp_oracles_create
4-
// Requires: plonk_wasm, tsRustConversion
5-
var fp_oracles_create = function (lgr_comm, verifier_index, proof) {
6-
return tsRustConversion.fp.oraclesFromRust(
7-
plonk_wasm.fp_oracles_create(
8-
tsRustConversion.fp.polyCommsToRust(lgr_comm),
9-
tsRustConversion.fp.verifierIndexToRust(verifier_index),
10-
tsRustConversion.fp.proofToRust(proof)
11-
)
12-
);
13-
};
14-
15-
// Provides: fp_oracles_create_no_public
16-
// Requires: fp_oracles_create
17-
var fp_oracles_create_no_public = function (lgr_comm, verifier_index, proof) {
18-
return fp_oracles_create(lgr_comm, verifier_index, [0, 0, proof]);
19-
};
20-
21-
// Provides: fp_oracles_dummy
22-
// Requires: plonk_wasm, tsRustConversion
23-
var fp_oracles_dummy = function () {
24-
return tsRustConversion.fp.oraclesFromRust(plonk_wasm.fp_oracles_dummy());
25-
};
26-
27-
// Provides: fp_oracles_deep_copy
28-
// Requires: plonk_wasm, tsRustConversion
29-
var fp_oracles_deep_copy = function (x) {
30-
return tsRustConversion.fp.oraclesFromRust(
31-
plonk_wasm.fp_oracles_deep_copy(tsRustConversion.fp.oraclesToRust(x))
32-
);
33-
};
34-
35-
// Provides: fq_oracles_create
36-
// Requires: plonk_wasm, tsRustConversion
37-
var fq_oracles_create = function (lgr_comm, verifier_index, proof) {
38-
return tsRustConversion.fq.oraclesFromRust(
39-
plonk_wasm.fq_oracles_create(
40-
tsRustConversion.fq.polyCommsToRust(lgr_comm),
41-
tsRustConversion.fq.verifierIndexToRust(verifier_index),
42-
tsRustConversion.fq.proofToRust(proof)
43-
)
44-
);
45-
};
46-
47-
// Provides: fq_oracles_create_no_public
48-
// Requires: fq_oracles_create
49-
var fq_oracles_create_no_public = function (lgr_comm, verifier_index, proof) {
50-
return fq_oracles_create(lgr_comm, verifier_index, [0, 0, proof]);
51-
};
52-
53-
// Provides: fq_oracles_dummy
54-
// Requires: plonk_wasm, tsRustConversion
55-
var fq_oracles_dummy = function () {
56-
return tsRustConversion.fq.oraclesFromRust(plonk_wasm.fq_oracles_dummy());
57-
};
58-
59-
// Provides: fq_oracles_deep_copy
60-
// Requires: plonk_wasm, tsRustConversion
61-
var fq_oracles_deep_copy = function (x) {
62-
return tsRustConversion.fq.oraclesFromRust(
63-
plonk_wasm.fq_oracles_deep_copy(tsRustConversion.fq.oraclesToRust(x))
64-
);
65-
};
66-
673
// This is fake -- parameters are only needed on the Rust side, so no need to return something meaningful
684
// Provides: caml_pasta_fp_poseidon_params_create
695
function caml_pasta_fp_poseidon_params_create() {

src/lib/crypto/kimchi_bindings/js/native/header-d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
// This file gets auto-included in the generated plonk-napi types to supplement
55
// external pointer types.
66

7-
type NapiGVesta = {};
8-
type NapiGPallas = {};
9-
type NapiPastaFpPlonkIndex = {};
10-
type NapiPastaFqPlonkIndex = {};
11-
type NapiPastaFp = {};
12-
type NapiPastaFq = {};
13-
type NapiLookupInfo = {};
7+
type WasmGVesta = {};
8+
type WasmGPallas = {};
9+
type WasmPastaFp = {};
10+
type WasmPastaFq = {};
11+
type WasmLookupInfo = {};
1412
type WasmPastaFpPlonkIndex = {};
1513
type WasmPastaFqPlonkIndex = {};
1614
type Proof = {}
17-
type NapiVector<T> = {};
18-
type NapiFlatVector<T> = {};
15+
type WasmVector<T> = {};
16+
type WasmFlatVector<T> = {};
1917
type WasmVecVecFp = {};
2018
type WasmVecVecFq = {};
19+
type WasmFpSrs = {};
20+
type WasmFqSrs = {};
2121
type Self = {};
2222

2323
// Header section end

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,68 @@
11
/* global plonk_wasm, tsRustConversionNative,*/
22

3+
// Provides: fp_oracles_create
4+
// Requires: plonk_wasm, tsRustConversionNative
5+
var fp_oracles_create = function (lgr_comm, verifier_index, proof) {
6+
return tsRustConversionNative.fp.oraclesFromRust(
7+
plonk_wasm.fp_oracles_create(
8+
tsRustConversionNative.fp.polyCommsToRust(lgr_comm),
9+
tsRustConversionNative.fp.verifierIndexToRust(verifier_index),
10+
tsRustConversionNative.fp.proofToRust(proof)
11+
)
12+
);
13+
};
14+
15+
// Provides: fp_oracles_create_no_public
16+
// Requires: fp_oracles_create
17+
var fp_oracles_create_no_public = function (lgr_comm, verifier_index, proof) {
18+
return fp_oracles_create(lgr_comm, verifier_index, [0, 0, proof]);
19+
};
20+
21+
// Provides: fp_oracles_dummy
22+
// Requires: plonk_wasm, tsRustConversionNative
23+
var fp_oracles_dummy = function () {
24+
return tsRustConversionNative.fp.oraclesFromRust(plonk_wasm.fp_oracles_dummy());
25+
};
26+
27+
// Provides: fp_oracles_deep_copy
28+
// Requires: plonk_wasm, tsRustConversionNative
29+
var fp_oracles_deep_copy = function (x) {
30+
return tsRustConversionNative.fp.oraclesFromRust(
31+
plonk_wasm.fp_oracles_deep_copy(tsRustConversionNative.fp.oraclesToRust(x))
32+
);
33+
};
34+
35+
// Provides: fq_oracles_create
36+
// Requires: plonk_wasm, tsRustConversionNative
37+
var fq_oracles_create = function (lgr_comm, verifier_index, proof) {
38+
return tsRustConversionNative.fq.oraclesFromRust(
39+
plonk_wasm.fq_oracles_create(
40+
tsRustConversionNative.fq.polyCommsToRust(lgr_comm),
41+
tsRustConversionNative.fq.verifierIndexToRust(verifier_index),
42+
tsRustConversionNative.fq.proofToRust(proof)
43+
)
44+
);
45+
};
46+
47+
// Provides: fq_oracles_create_no_public
48+
// Requires: fq_oracles_create
49+
var fq_oracles_create_no_public = function (lgr_comm, verifier_index, proof) {
50+
return fq_oracles_create(lgr_comm, verifier_index, [0, 0, proof]);
51+
};
52+
53+
// Provides: fq_oracles_dummy
54+
// Requires: plonk_wasm, tsRustConversionNative
55+
var fq_oracles_dummy = function () {
56+
return tsRustConversionNative.fq.oraclesFromRust(plonk_wasm.fq_oracles_dummy());
57+
};
58+
59+
// Provides: fq_oracles_deep_copy
60+
// Requires: plonk_wasm, tsRustConversionNative
61+
var fq_oracles_deep_copy = function (x) {
62+
return tsRustConversionNative.fq.oraclesFromRust(
63+
plonk_wasm.fq_oracles_deep_copy(tsRustConversionNative.fq.oraclesToRust(x))
64+
);
65+
};
366

467
// Provides: caml_pasta_fq_poseidon_block_cipher
568
// Requires: plonk_wasm, tsRustConversionNative

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function caml_pasta_fq_plonk_index_domain_d8_size(prover_index) {
106106

107107

108108
// Provides: caml_pasta_fp_plonk_index_create
109-
// Requires: plonk_wasm, free_on_finalize, tsRustConversionNative
109+
// Requires: plonk_wasm, tsRustConversionNative
110110
var caml_pasta_fp_plonk_index_create = function (
111111
gates,
112112
public_inputs,
@@ -121,10 +121,10 @@ var caml_pasta_fp_plonk_index_create = function (
121121
var wasm_runtime_table_cfgs = tsRustConversionNative.fp.runtimeTableCfgsToRust(
122122
caml_runtime_table_cfgs
123123
);
124-
console.time("conversion")
124+
console.time("conversion plonk index create")
125125
var gate_vec = plonk_wasm.caml_pasta_fp_plonk_gate_vector_from_bytes(gates.serialize());
126126
var urs_ser = plonk_wasm.caml_fp_srs_from_bytes_external(urs.serialize())
127-
console.timeEnd("conversion")
127+
console.timeEnd("conversion plonk index create")
128128

129129
console.time("index_create")
130130
var t = plonk_wasm.caml_pasta_fp_plonk_index_create(
@@ -138,11 +138,7 @@ var caml_pasta_fp_plonk_index_create = function (
138138
);
139139
console.timeEnd("index_create");
140140

141-
console.time("finalize_conversion")
142-
var wasm_t = plonk_wasm.WasmPastaFpPlonkIndex.deserialize(plonk_wasm.prover_index_fp_to_bytes(t))
143-
console.timeEnd("finalize_conversion")
144-
145-
return free_on_finalize(wasm_t);
141+
return plonk_wasm.prover_index_fp_to_bytes(t);
146142
};
147143

148144
// Provides: caml_pasta_fp_plonk_index_create_bytecode
@@ -198,7 +194,7 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) {
198194
};
199195

200196
// Provides: caml_pasta_fq_plonk_index_create
201-
// Requires: plonk_wasm, free_on_finalize, tsRustConversionNative
197+
// Requires: plonk_wasm, tsRustConversionNative
202198
var caml_pasta_fq_plonk_index_create = function (
203199
gates,
204200
public_inputs,
@@ -208,16 +204,20 @@ var caml_pasta_fq_plonk_index_create = function (
208204
urs,
209205
lazy_mode
210206
) {
207+
console.log("anais: 1");
211208
var wasm_lookup_tables =
212209
tsRustConversionNative.fq.lookupTablesToRust(caml_lookup_tables);
210+
console.log("anais: 2");
213211
var wasm_runtime_table_cfgs = tsRustConversionNative.fq.runtimeTableCfgsToRust(
214212
caml_runtime_table_cfgs
215213
);
214+
console.log("anais: 3");
216215

217216
console.time("conversion")
218217
var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize());
219218
var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize())
220219
console.timeEnd("conversion")
220+
console.log("anais: 4");
221221

222222
console.time("index_create")
223223
var t = plonk_wasm.caml_pasta_fq_plonk_index_create(
@@ -231,11 +231,7 @@ var caml_pasta_fq_plonk_index_create = function (
231231
);
232232
console.timeEnd("index_create");
233233

234-
console.time("finalize_conversion")
235-
var wasm_t = plonk_wasm.WasmPastaFqPlonkIndex.deserialize(plonk_wasm.prover_index_fq_to_bytes(t))
236-
console.timeEnd("finalize_conversion")
237-
238-
return free_on_finalize(wasm_t);
234+
return plonk_wasm.prover_index_fq_to_bytes(t);
239235
};
240236

241237
// Provides: caml_pasta_fq_plonk_index_create_bytecode

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var plonk_wasm = (function() {
1818
"caml_pasta_fp_poseidon_block_cipher",
1919
"caml_pasta_fq_poseidon_block_cipher",
2020
"caml_pasta_fp_plonk_proof_create",
21+
"caml_pasta_fp_plonk_verifier_index_create",
2122
"caml_pasta_fp_plonk_verifier_index_shifts",
2223
"caml_pasta_fq_plonk_verifier_index_shifts",
2324
"caml_pasta_fp_plonk_gate_vector_create",
@@ -98,16 +99,24 @@ var plonk_wasm = (function() {
9899
"caml_fq_srs_batch_accumulator_check",
99100
"caml_fq_srs_batch_accumulator_generate",
100101
"caml_fq_srs_h",
101-
/* "WasmFpPolyComm",
102-
"WasmFqPolyComm", */
103-
/* "WasmGPallas",
104-
"WasmGVesta", */
102+
"WasmFpPolyComm",
103+
"WasmFqPolyComm",
104+
"WasmGPallas",
105+
"WasmGVesta",
105106
"WasmPastaFp",
106107
"WasmPastaFq",
107108
"caml_pasta_fp_plonk_proof_create",
108109
"caml_pasta_fp_plonk_proof_verify",
109110
"caml_pasta_fq_plonk_proof_create",
110111
"caml_pasta_fq_plonk_proof_verify",
112+
"fp_oracles_create",
113+
"fp_oracles_create_no_public",
114+
"fp_oracles_dummy",
115+
"fp_oracles_deep_copy",
116+
"fq_oracles_create",
117+
"fq_oracles_create_no_public",
118+
"fq_oracles_dummy",
119+
"fq_oracles_deep_copy",
111120
"WasmFpOpeningProof",
112121
"WasmFqOpeningProof",
113122
"WasmFpLookupCommitments",

src/lib/crypto/kimchi_bindings/stubs/kimchi_bindings.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ module Protocol = struct
215215
-> SRS.Fp.t
216216
-> bool
217217
-> t
218-
= "caml_pasta_fp_plonk_index_create_bytecode"
219-
"caml_pasta_fp_plonk_index_create"
218+
= "caml_pasta_fp_plonk_index_create_bytecode" "caml_pasta_fp_plonk_index_create"
220219

221220
external max_degree : t -> int = "caml_pasta_fp_plonk_index_max_degree"
222221

@@ -251,8 +250,7 @@ module Protocol = struct
251250
-> SRS.Fq.t
252251
-> bool
253252
-> t
254-
= "caml_pasta_fq_plonk_index_create_bytecode"
255-
"caml_pasta_fq_plonk_index_create"
253+
= "caml_pasta_fq_plonk_index_create_bytecode" "caml_pasta_fq_plonk_index_create"
256254

257255
external max_degree : t -> int = "caml_pasta_fq_plonk_index_max_degree"
258256

src/lib/pickles/plonk_checks/scalars.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,8 @@ module Tick : S = struct
28312831
+ if_feature
28322832
( LookupPattern RangeCheck
28332833
, (fun () ->
2834-
cell (var (LookupKindIndex RangeCheck, Curr)) )
2834+
cell (var (LookupKindIndex RangeCheck, Curr))
2835+
)
28352836
, fun () ->
28362837
field
28372838
"0x0000000000000000000000000000000000000000000000000000000000000000"
@@ -2841,7 +2842,8 @@ module Tick : S = struct
28412842
, (fun () ->
28422843
cell
28432844
(var
2844-
(LookupKindIndex ForeignFieldMul, Curr) ) )
2845+
(LookupKindIndex ForeignFieldMul, Curr) )
2846+
)
28452847
, fun () ->
28462848
field
28472849
"0x0000000000000000000000000000000000000000000000000000000000000000"

0 commit comments

Comments
 (0)