Skip to content

Commit 4d28733

Browse files
rework native bindings
1 parent 4c083b0 commit 4d28733

File tree

6 files changed

+53
-39
lines changed

6 files changed

+53
-39
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@ var caml_pasta_fp_plonk_proof_deep_copy = function (proof) {
6969
);
7070
};
7171

72+
// Provides: caml_pasta_fq_plonk_proof_create
73+
// Requires: plonk_wasm, tsRustConversion
74+
var caml_pasta_fq_plonk_proof_create = function (
75+
index,
76+
witness_cols,
77+
caml_runtime_tables,
78+
prev_challenges,
79+
prev_sgs
80+
) {
81+
var w = new plonk_wasm.WasmVecVecFq(witness_cols.length - 1);
82+
for (var i = 1; i < witness_cols.length; i++) {
83+
w.push(tsRustConversion.fq.vectorToRust(witness_cols[i]));
84+
}
85+
witness_cols = w;
86+
prev_challenges = tsRustConversion.fq.vectorToRust(prev_challenges);
87+
var wasm_runtime_tables =
88+
tsRustConversion.fq.runtimeTablesToRust(caml_runtime_tables);
89+
prev_sgs = tsRustConversion.fq.pointsToRust(prev_sgs);
90+
var proof = plonk_wasm.caml_pasta_fq_plonk_proof_create(
91+
index,
92+
witness_cols,
93+
wasm_runtime_tables,
94+
prev_challenges,
95+
prev_sgs
96+
);
97+
return tsRustConversion.fq.proofFromRust(proof);
98+
};
99+
72100
// Provides: caml_pasta_fq_plonk_proof_verify
73101
// Requires: plonk_wasm, tsRustConversion
74102
var caml_pasta_fq_plonk_proof_verify = function (index, proof) {

src/lib/crypto/kimchi_bindings/js/dune

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
bindings/verifier-index.js
1818
native/native-overrides/oracles.js
1919
native/native-overrides/util.js
20-
native/native-overrides/circuit.js
21-
native/native-overrides/pasta-plonk-proof.js))
20+
native/native-overrides/circuit.js))
2221
(instrumentation
2322
(backend bisect_ppx))
2423
(preprocess

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// Provides: caml_pasta_fq_poseidon_block_cipher
55
// Requires: plonk_wasm, tsRustConversionNative
66
function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) {
7-
8-
console.log("overriding the old wasm caml_pasta_fq_poseidon_block_cipher, now using the native one")
9-
107
// 1. get permuted field vector from rust
118
var wasm_flat_vector = plonk_wasm.caml_pasta_fq_poseidon_block_cipher(
129
tsRustConversionNative.fq.vectorToRust(fq_vector)
@@ -22,10 +19,6 @@ function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) {
2219
// Provides: caml_pasta_fp_poseidon_block_cipher
2320
// Requires: plonk_wasm, tsRustConversionNative
2421
function caml_pasta_fp_poseidon_block_cipher(_fake_params, fp_vector) {
25-
26-
console.log("overriding the old wasm caml_pasta_fp_poseidon_block_cipher, now using the native one")
27-
28-
2922
// 1. get permuted field vector from rust
3023
var wasm_flat_vector = plonk_wasm.caml_pasta_fp_poseidon_block_cipher(
3124
tsRustConversionNative.fp.vectorToRust(fp_vector)

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,31 @@ var plonk_wasm = (function() {
55
try {
66
var native = require('@o1js/native-' + process.platform + '-' + process.arch)
77

8-
wasm["caml_pasta_fp_poseidon_block_cipher"] = native["caml_pasta_fp_poseidon_block_cipher"]
9-
wasm["caml_pasta_fq_poseidon_block_cipher"] = native["caml_pasta_fq_poseidon_block_cipher"]
8+
// THIS IS A RUNTIME OVERRIDE
9+
// YOU HAVE TO RUN IT TO SEE IF IT BREAKS
10+
// IT WON'T CRASH UNLESS O1JS_REQUIRE_NATIVE_BINDINGS
11+
// IS SET
12+
var overrides = [
13+
"prover_to_json",
14+
"prover_index_from_bytes",
15+
"prover_index_to_bytes",
16+
"caml_pasta_fp_poseidon_block_cipher",
17+
"caml_pasta_fq_poseidon_block_cipher",
18+
"caml_pasta_fp_plonk_proof_create",
19+
]
20+
21+
overrides.forEach(function (override) {
22+
wasm[override] = native[override]
23+
})
24+
25+
wasm.native = true;
1026
} catch (e) {
11-
console.error(e)
12-
console.log("native didn't load")
13-
process.exit(1);
27+
if (process.env.O1JS_REQUIRE_NATIVE_BINDINGS) {
28+
console.error(e)
29+
console.log("native didn't load")
30+
process.exit(1);
31+
}
1432
}
1533

1634
return wasm
1735
})()
18-

0 commit comments

Comments
 (0)