Skip to content

Commit 58f9733

Browse files
committed
Merge branch 'native/napi' into florian/napi-proof
2 parents f40cf67 + c53b209 commit 58f9733

File tree

16 files changed

+183
-161
lines changed

16 files changed

+183
-161
lines changed

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ var caml_opt_to_rust = function (caml_optional_value, to_rust) {
2424
// Provides: caml_pasta_fp_plonk_verifier_index_create
2525
// Requires: plonk_wasm, tsRustConversion
2626
var caml_pasta_fp_plonk_verifier_index_create = function (x) {
27+
console.log("caml_pasta_fp_plonk_verifier_index_create")
2728
var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(x);
2829
return tsRustConversion.fp.verifierIndexFromRust(vk);
2930
};
3031

3132
// Provides: caml_pasta_fp_plonk_verifier_index_read
3233
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
3334
var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) {
35+
console.log("caml_pasta_fp_plonk_verifier_index_read")
36+
3437
if (offset === 0) {
3538
offset = undefined;
3639
} else {
@@ -48,6 +51,8 @@ var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) {
4851
// Provides: caml_pasta_fp_plonk_verifier_index_write
4952
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
5053
var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) {
54+
console.log("caml_pasta_fp_plonk_verifier_index_write")
55+
5156
if (append === 0) {
5257
append = undefined;
5358
} else {
@@ -60,24 +65,20 @@ var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) {
6065
);
6166
};
6267

63-
// Provides: caml_pasta_fp_plonk_verifier_index_shifts
64-
// Requires: plonk_wasm, tsRustConversion
65-
var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) {
66-
return tsRustConversion.fp.shiftsFromRust(
67-
plonk_wasm.caml_pasta_fp_plonk_verifier_index_shifts(log2_size)
68-
);
69-
};
7068

7169
// Provides: caml_pasta_fp_plonk_verifier_index_dummy
7270
// Requires: plonk_wasm, tsRustConversion
7371
var caml_pasta_fp_plonk_verifier_index_dummy = function () {
72+
console.log("caml_pasta_fp_plonk_verifier_index_dummy")
73+
7474
var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy();
7575
return tsRustConversion.fp.verifierIndexFromRust(res);
7676
};
7777

7878
// Provides: caml_pasta_fp_plonk_verifier_index_deep_copy
7979
// Requires: plonk_wasm, tsRustConversion
8080
var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) {
81+
console.log("caml_pasta_fp_plonk_verifier_index_deep_copy")
8182
return tsRustConversion.fp.verifierIndexFromRust(
8283
plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy(
8384
tsRustConversion.fp.verifierIndexToRust(x)
@@ -88,6 +89,7 @@ var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) {
8889
// Provides: caml_pasta_fq_plonk_verifier_index_create
8990
// Requires: plonk_wasm, tsRustConversion
9091
var caml_pasta_fq_plonk_verifier_index_create = function (x) {
92+
console.log("caml_pasta_fq_plonk_verifier_index_create")
9193
return tsRustConversion.fq.verifierIndexFromRust(
9294
plonk_wasm.caml_pasta_fq_plonk_verifier_index_create(x)
9395
);
@@ -96,6 +98,7 @@ var caml_pasta_fq_plonk_verifier_index_create = function (x) {
9698
// Provides: caml_pasta_fq_plonk_verifier_index_read
9799
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
98100
var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) {
101+
console.log("caml_pasta_fq_plonk_verifier_index_read")
99102
if (offset === 0) {
100103
offset = undefined;
101104
} else {
@@ -113,6 +116,7 @@ var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) {
113116
// Provides: caml_pasta_fq_plonk_verifier_index_write
114117
// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion
115118
var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) {
119+
console.log("caml_pasta_fq_plonk_verifier_index_write")
116120
if (append === 0) {
117121
append = undefined;
118122
} else {
@@ -125,17 +129,10 @@ var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) {
125129
);
126130
};
127131

128-
// Provides: caml_pasta_fq_plonk_verifier_index_shifts
129-
// Requires: plonk_wasm, tsRustConversion
130-
var caml_pasta_fq_plonk_verifier_index_shifts = function (log2_size) {
131-
return tsRustConversion.fq.shiftsFromRust(
132-
plonk_wasm.caml_pasta_fq_plonk_verifier_index_shifts(log2_size)
133-
);
134-
};
135-
136132
// Provides: caml_pasta_fq_plonk_verifier_index_dummy
137133
// Requires: plonk_wasm, tsRustConversion
138134
var caml_pasta_fq_plonk_verifier_index_dummy = function () {
135+
console.log("caml_pasta_fq_plonk_verifier_index_dummy")
139136
return tsRustConversion.fq.verifierIndexFromRust(
140137
plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy()
141138
);
@@ -144,6 +141,7 @@ var caml_pasta_fq_plonk_verifier_index_dummy = function () {
144141
// Provides: caml_pasta_fq_plonk_verifier_index_deep_copy
145142
// Requires: plonk_wasm, tsRustConversion, tsRustConversion
146143
var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) {
144+
console.log("caml_pasta_fq_plonk_verifier_index_deep_copy")
147145
return tsRustConversion.fq.verifierIndexFromRust(
148146
plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy(
149147
tsRustConversion.fq.verifierIndexToRust(x)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
index.d.ts
2+
plonk_napi.node

src/lib/crypto/kimchi_bindings/js/native/build.sh

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,10 @@ set -euo pipefail
44
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
55
CURRENT_DIRECTORY="${SCRIPT_DIR}"
66
PROOF_SYSTEMS_ROOT=$(cd "${SCRIPT_DIR}/../../../proof-systems" && pwd)
7-
PLONK_NAPI_ROOT="${PROOF_SYSTEMS_ROOT}/plonk-napi"
87

9-
TARGET_ROOT="${CARGO_TARGET_DIR:-"${PROOF_SYSTEMS_ROOT}/target"}"
10-
export CARGO_TARGET_DIR="${TARGET_ROOT}"
11-
12-
cargo build \
13-
--manifest-path "${PLONK_NAPI_ROOT}/Cargo.toml" \
14-
--release
15-
16-
case "$(uname -s)" in
17-
Darwin*) LIB_NAME="libplonk_napi.dylib" ;;
18-
MINGW*|MSYS*|CYGWIN*) LIB_NAME="plonk_napi.dll" ;;
19-
*) LIB_NAME="libplonk_napi.so" ;;
20-
esac
21-
22-
ARTIFACT="${TARGET_ROOT}/release/${LIB_NAME}"
23-
24-
if [[ ! -f "${ARTIFACT}" ]]; then
25-
echo "Failed to locate plonk-napi artifact at ${ARTIFACT}" >&2
26-
exit 1
27-
fi
28-
29-
rm -f "${CURRENT_DIRECTORY}/plonk_napi.node"
30-
cp "${ARTIFACT}" "${CURRENT_DIRECTORY}/plonk_napi.node"
8+
napi build \
9+
--manifest-path $PROOF_SYSTEMS_ROOT/Cargo.toml \
10+
--package plonk-napi \
11+
--output-dir ./ \
12+
--release \
13+
--esm

src/lib/crypto/kimchi_bindings/js/native/dune

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
(name native_backend)
33
(public_name bindings_js.native_backend)
44
(js_of_ocaml
5-
(flags
6-
(:include flags.sexp))
75
(javascript_files native_backend.js))
86
(instrumentation
97
(backend bisect_ppx))
108
(preprocess
119
(pps ppx_version js_of_ocaml-ppx)))
1210

1311
(rule
14-
(targets
15-
plonk_napi.node
16-
flags.sexp)
12+
(targets plonk_napi.node index.d.ts)
13+
(mode
14+
(promote
15+
(into ./artifacts)))
1716
(deps
17+
package.json
1818
build.sh
19+
header-d.ts
1920
../../dune-build-root
2021
(source_tree ../../../proof-systems))
2122
(locks /cargo-lock)
@@ -24,6 +25,4 @@
2425
(setenv
2526
CARGO_TARGET_DIR
2627
"%{read:../../dune-build-root}/cargo_kimchi_native"
27-
(run bash build.sh))
28-
(write-file flags.sexp "()"))))
29-
28+
(run bash build.sh)))))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Header section
2+
// To edit this section, look for
3+
// ./src/lib/crypto/kimchi_bindings/js/native/header-d.ts
4+
// This file gets auto-included in the generated plonk-napi types to supplement
5+
// external pointer types.
6+
7+
type WasmPastaFpPlonkIndex = {};
8+
type NapiVector<T> = {};
9+
type NapiGVesta = {};
10+
type NapiGPallas = {};
11+
type NapiPastaFpPlonkIndex = {};
12+
type NapiPastaFqPlonkIndex = {};
13+
type NapiLookupInfo = {};
14+
type NapiPastaFp = {};
15+
type NapiPastaFq = {};
16+
17+
// Header section end

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* global plonk_wasm */
1+
/* global plonk_wasm, tsRustConversionNative */
22

33

44
// Provides: prover_to_json
5-
// Requires: plonk_wasm
5+
// Requires: plonk_wasm, tsRustConversionNative
66
function prover_to_json(prover_index) {
77
var bytes = prover_index.serialize()
88
var index = plonk_wasm.prover_index_fp_from_bytes(bytes);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) {
198198
};
199199

200200
// Provides: caml_pasta_fq_plonk_index_create
201-
// Requires: plonk_wasm, free_on_finalize, tsRustConversion
201+
// Requires: plonk_wasm, free_on_finalize, tsRustConversionNative
202202
var caml_pasta_fq_plonk_index_create = function (
203203
gates,
204204
public_inputs,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ var caml_fq_srs_b_poly_commitment = function (srs, chals) {
181181
};
182182

183183
// Provides: caml_fq_srs_batch_accumulator_check
184-
// Requires: plonk_wasm, tsRustConversion
184+
// Requires: plonk_wasm, tsRustConversionNative
185185
var caml_fq_srs_batch_accumulator_check = function (srs, comms, chals) {
186186
console.log("native caml_fq_srs_batch_accumulator_check");
187187
var rust_comms = tsRustConversionNative.fq.pointsToRust(comms);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* global plonk_wasm, tsRustConversionNative */
2+
3+
4+
// Provides: caml_pasta_fq_plonk_verifier_index_shifts
5+
// Requires: plonk_wasm, tsRustConversionNative
6+
var caml_pasta_fq_plonk_verifier_index_shifts = function (log2_size) {
7+
return tsRustConversionNative.fq.shiftsFromRust(
8+
plonk_wasm.caml_pasta_fq_plonk_verifier_index_shifts(log2_size)
9+
);
10+
};
11+
12+
// Provides: caml_pasta_fp_plonk_verifier_index_shifts
13+
// Requires: plonk_wasm, tsRustConversionNative
14+
var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) {
15+
return tsRustConversionNative.fp.shiftsFromRust(
16+
plonk_wasm.caml_pasta_fp_plonk_verifier_index_shifts(log2_size)
17+
);
18+
};
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
// Provides: plonk_napi
2-
var plonk_napi = require('./plonk_napi.node');
3-
4-
module.exports = plonk_napi;
2+
var plonk_napi = require('@o1js/native-' + process.platform + '-' + process.arch)

0 commit comments

Comments
 (0)